plain_apm 0.2.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/plain_apm/agent.rb +2 -1
- data/lib/plain_apm/config.rb +24 -6
- data/lib/plain_apm/helpers.rb +12 -0
- data/lib/plain_apm/hooks/deploy.rb +7 -1
- data/lib/plain_apm/hooks/manual.rb +29 -0
- data/lib/plain_apm/version.rb +1 -1
- data/lib/plain_apm.rb +2 -1
- metadata +4 -3
- data/lib/plain_apm/extensions/context/helpers.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c90c84af568ff044876f532e72d6275670a0866f13ca3bc81de6ef726ae4d4a
|
4
|
+
data.tar.gz: 3be569a19a2b5f7aed767336ba39490a56435608db9f387c52ca3980d0d5303c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 681bf3e9efd941ff2dbb88e38af19ffd96d6f790756b82e831f81e4ee33cc44f1d486aac53ca0417fd1fb3990a8b19811563473d765087d96b400e3f33708f84
|
7
|
+
data.tar.gz: b5a9cd30b8fd458a95ecfb8f2e9caf5c9e6b2a6d2e98c4ad7446c06ea5539efb8eca38b35a58fd9c3578e45a5a3272c2febac68bdca092ae4283330562783145
|
data/lib/plain_apm/agent.rb
CHANGED
data/lib/plain_apm/config.rb
CHANGED
@@ -7,19 +7,37 @@ module PlainApm
|
|
7
7
|
attr_accessor :endpoint, :app_key, :enabled
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@enabled = enabled?
|
10
|
+
@enabled = enabled? && key_present?
|
11
11
|
@endpoint = ENV["PLAIN_APM_ENDPOINT"] || DEFAULT_EVENT_ENDPOINT
|
12
|
-
@app_key = ENV["PLAIN_APM_APP_KEY"]
|
12
|
+
@app_key = ENV["PLAIN_APM_APP_KEY"]
|
13
|
+
|
14
|
+
if enabled? && !key_present?
|
15
|
+
warn("Missing PLAIN_APM_APP_KEY environment variable, plain_apm agent won't start.")
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
private
|
16
20
|
|
17
21
|
def enabled?
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
(production? || force_enabled?) && !force_disabled?
|
23
|
+
end
|
24
|
+
|
25
|
+
def key_present?
|
26
|
+
ENV["PLAIN_APM_APP_KEY"] != ""
|
27
|
+
end
|
28
|
+
|
29
|
+
def production?
|
30
|
+
(ENV["RAILS_ENV"] || ENV["RACK_ENV"]) == "production"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Allow to start in e.g. development.
|
34
|
+
def force_enabled?
|
35
|
+
ENV["PLAIN_APM_ENABLED"] == "1"
|
36
|
+
end
|
21
37
|
|
22
|
-
|
38
|
+
# Do not instrument
|
39
|
+
def force_disabled?
|
40
|
+
ENV["PLAIN_APM_DISABLED"] == "1"
|
23
41
|
end
|
24
42
|
end
|
25
43
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module PlainApm
|
2
|
+
module Helpers
|
3
|
+
def plain_apm_context(context = {})
|
4
|
+
PlainApm::Extensions::Context.context.merge!(context)
|
5
|
+
end
|
6
|
+
|
7
|
+
def plain_apm_instrument(name, context = {}, &block)
|
8
|
+
sanitized_name = name.gsub(/\W/, "_").gsub(/(?!^)([A-Z])/) { |m| "_#{m}" }.gsub(/_+/, "_").downcase
|
9
|
+
ActiveSupport::Notifications.instrument("#{sanitized_name}.manual.plain_apm", **context, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -18,7 +18,13 @@ module PlainApm
|
|
18
18
|
tool, revision = *result
|
19
19
|
|
20
20
|
Agent.instance.collect(
|
21
|
-
{
|
21
|
+
{
|
22
|
+
"source" => tool,
|
23
|
+
"revision" => revision,
|
24
|
+
"name" => "deploy",
|
25
|
+
"started_at" => Time.now.to_f,
|
26
|
+
"finished_at" => Time.now.to_f
|
27
|
+
}
|
22
28
|
)
|
23
29
|
end
|
24
30
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PlainApm
|
4
|
+
module Hooks
|
5
|
+
class Manual < ActiveSupportSubscriber
|
6
|
+
NOTIFICATION_PATTERN = /\A[^!]\w+\.manual\.plain_apm\Z/.freeze
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def notification_pattern
|
11
|
+
NOTIFICATION_PATTERN
|
12
|
+
end
|
13
|
+
|
14
|
+
def payload(event)
|
15
|
+
name, source, _ = *event.name.split(".")
|
16
|
+
|
17
|
+
{
|
18
|
+
"source" => source,
|
19
|
+
"name" => name,
|
20
|
+
"backtrace" => filtered_backtrace,
|
21
|
+
"started_at" => event.time,
|
22
|
+
"finished_at" => event.end,
|
23
|
+
"allocations" => event.allocations,
|
24
|
+
"payload" => event.payload
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/plain_apm/version.rb
CHANGED
data/lib/plain_apm.rb
CHANGED
@@ -12,10 +12,10 @@ begin
|
|
12
12
|
require "rack/body_proxy"
|
13
13
|
|
14
14
|
require_relative "plain_apm/extensions/context"
|
15
|
-
require_relative "plain_apm/extensions/context/helpers"
|
16
15
|
require_relative "plain_apm/extensions/context/middleware"
|
17
16
|
require_relative "plain_apm/extensions/context/active_job" if defined?(ActiveSupport)
|
18
17
|
require_relative "plain_apm/extensions/context/railtie" if defined?(Rails::Railtie)
|
18
|
+
require_relative "plain_apm/helpers"
|
19
19
|
rescue LoadError
|
20
20
|
nil
|
21
21
|
end
|
@@ -31,6 +31,7 @@ require_relative "plain_apm/hooks/action_pack"
|
|
31
31
|
require_relative "plain_apm/hooks/action_view"
|
32
32
|
require_relative "plain_apm/hooks/active_job"
|
33
33
|
require_relative "plain_apm/hooks/active_record"
|
34
|
+
require_relative "plain_apm/hooks/manual"
|
34
35
|
require_relative "plain_apm/hooks/error_reporter"
|
35
36
|
|
36
37
|
module PlainApm
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plain_apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PlainAPM Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -85,12 +85,12 @@ files:
|
|
85
85
|
- lib/plain_apm/extensions/context.rb
|
86
86
|
- lib/plain_apm/extensions/context/LICENSE.txt
|
87
87
|
- lib/plain_apm/extensions/context/active_job.rb
|
88
|
-
- lib/plain_apm/extensions/context/helpers.rb
|
89
88
|
- lib/plain_apm/extensions/context/middleware.rb
|
90
89
|
- lib/plain_apm/extensions/context/railtie.rb
|
91
90
|
- lib/plain_apm/extensions/exceptions/active_job.rb
|
92
91
|
- lib/plain_apm/extensions/exceptions/rack.rb
|
93
92
|
- lib/plain_apm/extensions/exceptions/railtie.rb
|
93
|
+
- lib/plain_apm/helpers.rb
|
94
94
|
- lib/plain_apm/hooks/action_mailer.rb
|
95
95
|
- lib/plain_apm/hooks/action_pack.rb
|
96
96
|
- lib/plain_apm/hooks/action_view.rb
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/plain_apm/hooks/active_support_subscriber.rb
|
100
100
|
- lib/plain_apm/hooks/deploy.rb
|
101
101
|
- lib/plain_apm/hooks/error_reporter.rb
|
102
|
+
- lib/plain_apm/hooks/manual.rb
|
102
103
|
- lib/plain_apm/transport.rb
|
103
104
|
- lib/plain_apm/version.rb
|
104
105
|
homepage: https://plainapm.com
|