plain_apm 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/plain_apm/agent.rb +14 -2
- data/lib/plain_apm/extensions/{trace_id → context}/LICENSE.txt +0 -0
- data/lib/plain_apm/extensions/{trace_id → context}/active_job.rb +5 -3
- data/lib/plain_apm/extensions/context/helpers.rb +11 -0
- data/lib/plain_apm/extensions/{trace_id → context}/middleware.rb +4 -4
- data/lib/plain_apm/extensions/{trace_id → context}/railtie.rb +4 -4
- data/lib/plain_apm/extensions/context.rb +41 -0
- data/lib/plain_apm/extensions/exceptions/rack.rb +1 -2
- data/lib/plain_apm/hooks/action_mailer.rb +1 -2
- data/lib/plain_apm/hooks/action_pack.rb +1 -2
- data/lib/plain_apm/hooks/action_view.rb +1 -2
- data/lib/plain_apm/hooks/active_job.rb +0 -1
- data/lib/plain_apm/hooks/active_record.rb +1 -2
- data/lib/plain_apm/hooks/active_support_subscriber.rb +0 -7
- data/lib/plain_apm/hooks/error_reporter.rb +1 -2
- data/lib/plain_apm/version.rb +1 -1
- data/lib/plain_apm.rb +5 -4
- metadata +7 -6
- data/lib/plain_apm/extensions/trace_id.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fae5b33c61e3205e05e0321b6e2189f458095998d466c5f8f3494902eb279f26
|
4
|
+
data.tar.gz: 0e46fdbd9c5a3e7c6a41c4e75767046a03811c7d6c0af8688f72e14b5dce1a4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10f006bfd8ef860ca46a4af5656f99665c0de125d41d611a07678364650e50de6ca0b45cb34f2962a6344f6425ec8cf47af93c512bad50c2f712eca0bd3a9f65
|
7
|
+
data.tar.gz: 8f6d46f2e471fe8f5a917ececcee37db2f0c6e056e62f0320eb17797424ec86a73a43b942b54fd2e619becfdd0725705f8af3d3a299e8a5c6aab4ea1499de3b7
|
data/lib/plain_apm/agent.rb
CHANGED
@@ -18,11 +18,23 @@ module PlainApm
|
|
18
18
|
def collect(event)
|
19
19
|
return unless @config.enabled
|
20
20
|
|
21
|
-
|
21
|
+
##
|
22
|
+
# Context contains the trace ID (which comes from either
|
23
|
+
# HTTP_X_REQUEST_ID header, the deserialized job,
|
24
|
+
# or is generated by the trace_id middleware).
|
25
|
+
# It can also carry user inserted app data.
|
26
|
+
if defined?(PlainApm::Extensions::Context)
|
27
|
+
event.merge!(PlainApm::Extensions::Context.current)
|
28
|
+
end
|
29
|
+
|
30
|
+
event.merge!(
|
31
|
+
"version" => PlainApm::VERSION,
|
22
32
|
"collected_at" => Time.now.utc.to_f,
|
23
33
|
"pid" => Process.pid,
|
24
|
-
"thread_id" => Thread.current.object_id.to_s
|
34
|
+
"thread_id" => Thread.current.object_id.to_s,
|
25
35
|
)
|
36
|
+
|
37
|
+
@events << event
|
26
38
|
end
|
27
39
|
|
28
40
|
def start
|
File without changes
|
@@ -2,15 +2,17 @@
|
|
2
2
|
|
3
3
|
module PlainApm
|
4
4
|
module Extensions
|
5
|
-
module
|
5
|
+
module Context
|
6
6
|
module ActiveJob
|
7
|
+
# TODO: would it be useful to de-serialize the whole context (e.g. user
|
8
|
+
# IDs, subscriptions, etc?)
|
7
9
|
def serialize
|
8
|
-
trace_id = PlainApm::Extensions::
|
10
|
+
trace_id = PlainApm::Extensions::Context.trace_id || SecureRandom.uuid
|
9
11
|
super.update("trace_id" => trace_id)
|
10
12
|
end
|
11
13
|
|
12
14
|
def deserialize(job)
|
13
|
-
PlainApm::Extensions::
|
15
|
+
PlainApm::Extensions::Context.trace_id = job["trace_id"]
|
14
16
|
|
15
17
|
super(job)
|
16
18
|
end
|
@@ -10,26 +10,26 @@ require "securerandom"
|
|
10
10
|
# See LICENSE.txt in the current directory for the license.
|
11
11
|
module PlainApm
|
12
12
|
module Extensions
|
13
|
-
module
|
13
|
+
module Context
|
14
14
|
class Middleware
|
15
15
|
def initialize(app)
|
16
16
|
@app = app
|
17
17
|
end
|
18
18
|
|
19
19
|
def call(env)
|
20
|
-
|
20
|
+
Context.trace_id = trace_id(env)
|
21
21
|
|
22
22
|
status, headers, body = @app.call(env)
|
23
23
|
|
24
24
|
body = Rack::BodyProxy.new(body) do
|
25
|
-
|
25
|
+
Context.clear!
|
26
26
|
end
|
27
27
|
|
28
28
|
processed = true
|
29
29
|
|
30
30
|
[status, headers, body]
|
31
31
|
ensure
|
32
|
-
|
32
|
+
Context.clear! if !processed
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
@@ -8,13 +8,13 @@
|
|
8
8
|
# See LICENSE.txt in the current directory for the license.
|
9
9
|
module PlainApm
|
10
10
|
module Extensions
|
11
|
-
module
|
11
|
+
module Context
|
12
12
|
class Railtie < Rails::Railtie
|
13
|
-
initializer "plain_apm.
|
13
|
+
initializer "plain_apm.insert_context_middleware" do |app|
|
14
14
|
if defined?(ActionDispatch::RequestId)
|
15
|
-
app.config.middleware.insert_after ActionDispatch::RequestId, PlainApm::Extensions::
|
15
|
+
app.config.middleware.insert_after ActionDispatch::RequestId, PlainApm::Extensions::Context::Middleware
|
16
16
|
else
|
17
|
-
app.config.middleware.insert_after Rack::MethodOverride, PlainApm::Extensions::
|
17
|
+
app.config.middleware.insert_after Rack::MethodOverride, PlainApm::Extensions::Context::Middleware
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module PlainApm
|
2
|
+
module Extensions
|
3
|
+
module Context
|
4
|
+
STORE_KEY = :plain_apm_extensions_store
|
5
|
+
TRACE_ID_KEY = :trace_id
|
6
|
+
CONTEXT_KEY = :context
|
7
|
+
|
8
|
+
def self.current
|
9
|
+
Thread.current[STORE_KEY] ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.clear!
|
13
|
+
Thread.current[STORE_KEY] = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.[](key)
|
17
|
+
current[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.[]=(key, value)
|
21
|
+
current[key] = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.context
|
25
|
+
current[CONTEXT_KEY] ||= {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.context=(hash)
|
29
|
+
current[CONTEXT_KEY] = hash
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.trace_id
|
33
|
+
current[TRACE_ID_KEY]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.trace_id=(id)
|
37
|
+
current[TRACE_ID_KEY] = id
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -29,8 +29,7 @@ module PlainApm
|
|
29
29
|
"class" => e.class.name,
|
30
30
|
"message" => e.message,
|
31
31
|
"backtrace" => e.backtrace,
|
32
|
-
"params" => env["action_dispatch.request.parameters"]
|
33
|
-
"trace_id" => PlainApm::Extensions::TraceId.current
|
32
|
+
"params" => env["action_dispatch.request.parameters"]
|
34
33
|
}
|
35
34
|
|
36
35
|
PlainApm::Agent.collect(event)
|
@@ -45,13 +45,6 @@ module PlainApm
|
|
45
45
|
@cleaner.clean(caller)
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# The trace ID (comes from either HTTP_X_REQUEST_ID header, or is
|
51
|
-
# generated by the trace_id middleware)
|
52
|
-
def trace_id
|
53
|
-
PlainApm::Extensions::TraceId.current
|
54
|
-
end
|
55
48
|
end
|
56
49
|
end
|
57
50
|
end
|
data/lib/plain_apm/version.rb
CHANGED
data/lib/plain_apm.rb
CHANGED
@@ -11,10 +11,11 @@ require_relative "plain_apm/hooks/deploy"
|
|
11
11
|
begin
|
12
12
|
require "rack/body_proxy"
|
13
13
|
|
14
|
-
require_relative "plain_apm/extensions/
|
15
|
-
require_relative "plain_apm/extensions/
|
16
|
-
require_relative "plain_apm/extensions/
|
17
|
-
require_relative "plain_apm/extensions/
|
14
|
+
require_relative "plain_apm/extensions/context"
|
15
|
+
require_relative "plain_apm/extensions/context/helpers"
|
16
|
+
require_relative "plain_apm/extensions/context/middleware"
|
17
|
+
require_relative "plain_apm/extensions/context/active_job" if defined?(ActiveSupport)
|
18
|
+
require_relative "plain_apm/extensions/context/railtie" if defined?(Rails::Railtie)
|
18
19
|
rescue LoadError
|
19
20
|
nil
|
20
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plain_apm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PlainAPM Team
|
@@ -82,14 +82,15 @@ files:
|
|
82
82
|
- lib/plain_apm/agent.rb
|
83
83
|
- lib/plain_apm/backoff.rb
|
84
84
|
- lib/plain_apm/config.rb
|
85
|
+
- lib/plain_apm/extensions/context.rb
|
86
|
+
- lib/plain_apm/extensions/context/LICENSE.txt
|
87
|
+
- lib/plain_apm/extensions/context/active_job.rb
|
88
|
+
- lib/plain_apm/extensions/context/helpers.rb
|
89
|
+
- lib/plain_apm/extensions/context/middleware.rb
|
90
|
+
- lib/plain_apm/extensions/context/railtie.rb
|
85
91
|
- lib/plain_apm/extensions/exceptions/active_job.rb
|
86
92
|
- lib/plain_apm/extensions/exceptions/rack.rb
|
87
93
|
- lib/plain_apm/extensions/exceptions/railtie.rb
|
88
|
-
- lib/plain_apm/extensions/trace_id.rb
|
89
|
-
- lib/plain_apm/extensions/trace_id/LICENSE.txt
|
90
|
-
- lib/plain_apm/extensions/trace_id/active_job.rb
|
91
|
-
- lib/plain_apm/extensions/trace_id/middleware.rb
|
92
|
-
- lib/plain_apm/extensions/trace_id/railtie.rb
|
93
94
|
- lib/plain_apm/hooks/action_mailer.rb
|
94
95
|
- lib/plain_apm/hooks/action_pack.rb
|
95
96
|
- lib/plain_apm/hooks/action_view.rb
|