plain_apm 0.9.7 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa551d3d06407550f5b0dcdb0290d00044097193060a3652314835d77de94880
4
- data.tar.gz: 1f6240ab1462eecbbb9ddf83378a7eb02dc13d3e4daf9008150f94d5a312ae28
3
+ metadata.gz: f234cdb0d7afa540ac0ae06405ca89a2476bf4e18a44062aebe6fda4868b8b63
4
+ data.tar.gz: 1c3b2039cd4ce11b9d26d23a1dda6c9fba208fb2e3e8c50bccb0947e1f0161da
5
5
  SHA512:
6
- metadata.gz: ee98c2b0f5d46042248423b8e3b8c57eeab8144ce3417b94483b63a03bc7fad694ce7cd4ee125f726a678a932a90311dbce7b39173fa458769a07d3c1ebe48f9
7
- data.tar.gz: dbcdf5c2b5faf4bdd7e7b2c8a268b09cf726455b853d650d0e04717f0a90d519412c93da0e534448e8590e5a3e817208a893eb414a95a6013441ea3096ff6214
6
+ metadata.gz: 7695a907666719056596c427615ca736b39e19a09ee5de97d6999eaec49a55b0a41853e6796076e5acc5e6433f3b8378cab802eadd682b27070b7e3bfe260a51
7
+ data.tar.gz: d2ce1c8a4e12681f661c3b09307a32211cfcb3e65d449bb00f90b995bdb5ed4d9726db2edc6722e1d4a9c97a2035d3b6cc1f75d3e1767bf6f0baacdcfba71a36
@@ -19,11 +19,11 @@ module PlainApm
19
19
  end
20
20
 
21
21
  def key_present?
22
- ENV["PLAIN_APM_APP_KEY"] != ""
22
+ ENV["PLAIN_APM_APP_KEY"].to_s != ""
23
23
  end
24
24
 
25
25
  def production?
26
- (ENV["RAILS_ENV"] || ENV["RACK_ENV"]) == "production"
26
+ (ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["APP_ENV"]) == "production"
27
27
  end
28
28
 
29
29
  def interactive?
@@ -16,7 +16,7 @@ module PlainApm
16
16
  end
17
17
 
18
18
  def heroku_revision
19
- rev = ENV["HEROKU_SLUG_COMMIT"].to_s[0..8]
19
+ rev = ENV.fetch("GIT_REV", ENV.fetch("HEROKU_SLUG_COMMIT", ""))[0...8]
20
20
  rev if !rev.empty?
21
21
  end
22
22
 
@@ -17,9 +17,9 @@ module PlainApm
17
17
  ].freeze
18
18
 
19
19
  def attributes_from_exception(e, context, error_source)
20
- source = "exception"
20
+ name = "exception"
21
21
 
22
- return [source, nil] if IGNORED_EXCEPTIONS.include?(e.class.name)
22
+ return [name, nil] if IGNORED_EXCEPTIONS.include?(e.class.name)
23
23
 
24
24
  attrs = context_attributes
25
25
 
@@ -31,8 +31,8 @@ module PlainApm
31
31
  attrs[:event_source] = error_source
32
32
  end
33
33
 
34
- if context[:env]
35
- attrs[:params] = context[:env]["action_dispatch.request.parameters"]
34
+ if context[:controller]&.is_a?(ActionController::Base)
35
+ attrs[:controller] = context[:controller].class.name
36
36
  end
37
37
 
38
38
  if context[:job]&.is_a?(ActiveJob::Base)
@@ -40,6 +40,12 @@ module PlainApm
40
40
  attrs[:queue_name] = context[:job].queue_name
41
41
  end
42
42
 
43
+ if context[:env]
44
+ attrs[:params] = context.dig(:env, "action_dispatch.request.parameters")
45
+ attrs[:action] = context.dig(:env, "action_dispatch.request.parameters", :action)
46
+ attrs[:controller] = context.dig(:env, "action_controller.instance")&.class.name
47
+ end
48
+
43
49
  # https://bugs.ruby-lang.org/issues/19197
44
50
  root_cause = e
45
51
  root_cause = root_cause.cause while root_cause.cause
@@ -61,7 +67,7 @@ module PlainApm
61
67
 
62
68
  add_trace_attributes(attrs)
63
69
 
64
- [source, attrs]
70
+ [name, attrs]
65
71
  end
66
72
 
67
73
  def attributes_from_notification(event)
@@ -73,9 +79,22 @@ module PlainApm
73
79
  attrs[:source] = source
74
80
  attrs[:name] = name
75
81
  attrs[:allocations] = event.allocations
82
+ attrs[:thread_cpu_time] = event.cpu_time
76
83
  attrs[:event_time] = event.time
77
84
  attrs[:duration] = event.duration
78
85
 
86
+ if event.respond_to?(:gc_time)
87
+ attrs[:gc_time] = event.gc_time
88
+ end
89
+
90
+ if event.respond_to?(:gc_major_count)
91
+ attrs[:gc_major_count] = event.gc_major_count
92
+ end
93
+
94
+ if event.respond_to?(:gc_minor_count)
95
+ attrs[:gc_minor_count] = event.gc_minor_count
96
+ end
97
+
79
98
  if event.respond_to?(:thread_allocations)
80
99
  attrs[:thread_allocations] = event.thread_allocations
81
100
  end
@@ -0,0 +1,77 @@
1
+ module PlainApm
2
+ module Extensions
3
+ module ActiveSupport
4
+ module Event
5
+ def start!
6
+ super
7
+ @thread_allocation_count_start = now_thread_allocations
8
+ @gc_time_start = now_gc_time
9
+ @gc_major_count_start = now_gc_major_count
10
+ @gc_minor_count_start = now_gc_minor_count
11
+ end
12
+
13
+ def finish!
14
+ super
15
+ @thread_allocation_count_finish = now_thread_allocations
16
+ @gc_time_finish = now_gc_time
17
+ @gc_major_count_finish = now_gc_major_count
18
+ @gc_minor_count_finish = now_gc_minor_count
19
+ end
20
+
21
+ def thread_allocations
22
+ @thread_allocation_count_finish - @thread_allocation_count_start
23
+ end
24
+
25
+ def gc_time
26
+ @gc_time_finish - @gc_time_start
27
+ end
28
+
29
+ def gc_major_count
30
+ @gc_major_count_finish - @gc_major_count_start
31
+ end
32
+
33
+ def gc_minor_count
34
+ @gc_minor_count_finish - @gc_minor_count_start
35
+ end
36
+
37
+ private
38
+
39
+ # Per thread GC counter
40
+ def now_thread_allocations
41
+ PlainApm::ObjectTracing.total_thread_allocated_objects
42
+ end
43
+
44
+ if GC.stat.key?(:major_gc_count)
45
+ def now_gc_major_count
46
+ GC.stat(:major_gc_count)
47
+ end
48
+ else
49
+ def now_gc_major_count
50
+ 0
51
+ end
52
+ end
53
+
54
+ if GC.stat.key?(:minor_gc_count)
55
+ def now_gc_minor_count
56
+ GC.stat(:minor_gc_count)
57
+ end
58
+ else
59
+ def now_gc_minor_count
60
+ 0
61
+ end
62
+ end
63
+
64
+ # Time in ms spent in GC
65
+ if GC.stat.key?(:time)
66
+ def now_gc_time
67
+ GC.stat(:time)
68
+ end
69
+ else
70
+ def now_gc_time
71
+ 0
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PlainApm
4
+ module Extensions
5
+ module ActiveSupport
6
+ class Railtie < Rails::Railtie
7
+ initializer(:plain_apm_thread_allocations, after: :plain_apm_agent_start) do
8
+ next if !PlainApm.agent.enabled?
9
+
10
+ require "object_tracing"
11
+
12
+ ::ActiveSupport::Notifications::Event.prepend(
13
+ PlainApm::Extensions::ActiveSupport::Event
14
+ )
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "active_support/event"
2
+ require_relative "active_support/railtie" if defined?(Rails::Railtie)
@@ -14,7 +14,7 @@ module PlainApm
14
14
  initializer(:plain_apm_thread_context, after: :plain_apm_agent_start) do |app|
15
15
  next if !PlainApm.agent.enabled?
16
16
 
17
- ActiveSupport.on_load(:active_job, run_once: true) do |klass|
17
+ ::ActiveSupport.on_load(:active_job, run_once: true) do |klass|
18
18
  klass.prepend(PlainApm::Extensions::Context::ActiveJob)
19
19
  end
20
20
 
@@ -25,12 +25,12 @@ module PlainApm
25
25
  private
26
26
 
27
27
  def report_exception(e, env)
28
- source, event = attributes_from_exception(e, {env: env}, nil)
28
+ name, event = attributes_from_exception(e, {env: env}, nil)
29
29
 
30
30
  return if event.nil?
31
31
 
32
- event[:source] = source
33
- event[:name] = "rack_middleware"
32
+ event[:source] = "rack_middleware"
33
+ event[:name] = name
34
34
 
35
35
  PlainApm.agent.collect(event)
36
36
  end
@@ -25,6 +25,7 @@ module PlainApm
25
25
  base.tap do |o|
26
26
  o[:sql] = payload[:sql]
27
27
  o[:sql_name] = payload[:name]
28
+ o[:async] = payload[:async]
28
29
  end
29
30
  when "instantiation"
30
31
  base.tap do |o|
@@ -23,12 +23,12 @@ module PlainApm
23
23
  end
24
24
 
25
25
  def collect(e, handled:, severity:, context: {}, source: nil)
26
- event_source, event = attributes_from_exception(e, context, source)
26
+ name, event = attributes_from_exception(e, context, source)
27
27
 
28
28
  return if event.nil?
29
29
 
30
- event[:source] = event_source
31
- event[:name] = "error_reporter"
30
+ event[:source] = "error_reporter"
31
+ event[:name] = name
32
32
 
33
33
  ::PlainApm.agent.collect(event)
34
34
  end
@@ -92,7 +92,7 @@ module PlainApm
92
92
 
93
93
  {
94
94
  "Content-Type" => "application/json, charset=UTF-8",
95
- "Content-Encoding" => "gzip",
95
+ "Content-Encoding" => "deflate",
96
96
  "X-PlainApm-Key" => app_key
97
97
  }.merge(meta_headers)
98
98
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlainApm
4
- VERSION = "0.9.7"
4
+ VERSION = "0.10.0"
5
5
  end
data/lib/plain_apm.rb CHANGED
@@ -24,8 +24,8 @@ require_relative "plain_apm/extensions/context"
24
24
  # Rack exceptions. Activate the middleware if in Rails.
25
25
  require_relative "plain_apm/extensions/exceptions"
26
26
 
27
- # Per thread allocations in ASN events
28
- require_relative "plain_apm/extensions/thread_allocations"
27
+ # Extra stats in ASN events
28
+ require_relative "plain_apm/extensions/active_support"
29
29
 
30
30
  # Rails instrumentation. The hooks won't install unless
31
31
  # ActiveSupport::Notifications is loaded.
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.9.7
4
+ version: 0.10.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: 2024-03-24 00:00:00.000000000 Z
11
+ date: 2024-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -101,6 +101,9 @@ files:
101
101
  - lib/plain_apm/config.rb
102
102
  - lib/plain_apm/deploy_tracking.rb
103
103
  - lib/plain_apm/event_attributes.rb
104
+ - lib/plain_apm/extensions/active_support.rb
105
+ - lib/plain_apm/extensions/active_support/event.rb
106
+ - lib/plain_apm/extensions/active_support/railtie.rb
104
107
  - lib/plain_apm/extensions/context.rb
105
108
  - lib/plain_apm/extensions/context/LICENSE.txt
106
109
  - lib/plain_apm/extensions/context/active_job.rb
@@ -108,12 +111,8 @@ files:
108
111
  - lib/plain_apm/extensions/context/rack.rb
109
112
  - lib/plain_apm/extensions/context/railtie.rb
110
113
  - lib/plain_apm/extensions/exceptions.rb
111
- - lib/plain_apm/extensions/exceptions/active_job.rb
112
114
  - lib/plain_apm/extensions/exceptions/rack.rb
113
115
  - lib/plain_apm/extensions/exceptions/railtie.rb
114
- - lib/plain_apm/extensions/thread_allocations.rb
115
- - lib/plain_apm/extensions/thread_allocations/active_support_event.rb
116
- - lib/plain_apm/extensions/thread_allocations/railtie.rb
117
116
  - lib/plain_apm/helpers.rb
118
117
  - lib/plain_apm/hooks/action_mailer.rb
119
118
  - lib/plain_apm/hooks/action_pack.rb
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PlainApm
4
- module Extensions
5
- module TraceId
6
- module ActiveJob
7
- attr_accessor :trace_id
8
-
9
- def initialize(*arguments)
10
- super(*arguments)
11
-
12
- # Either from request headers / a previous job, or a new trace.
13
- @trace_id = PlainApm::Extensions::TraceId.current || SecureRandom.uuid
14
- end
15
-
16
- def serialize
17
- super.update("trace_id" => trace_id)
18
- end
19
-
20
- def deserialize(job)
21
- PlainApm::Extensions::TraceId.current = job["trace_id"]
22
-
23
- super(job)
24
- end
25
- end
26
-
27
- ##
28
- # Allow tracing request ID through jobs
29
- ActiveSupport.on_load(:active_job, run_once: true) do |klass|
30
- klass.prepend(ActiveJob)
31
- end
32
- end
33
- end
34
- end
@@ -1,25 +0,0 @@
1
- module PlainApm
2
- module Extensions
3
- module ThreadAllocations
4
- module ActiveSupportEvent
5
- def start!
6
- super
7
- @thread_allocation_count_start = now_thread_allocations
8
- end
9
-
10
- def finish!
11
- super
12
- @thread_allocation_count_finish = now_thread_allocations
13
- end
14
-
15
- def thread_allocations
16
- @thread_allocation_count_finish - @thread_allocation_count_start
17
- end
18
-
19
- def now_thread_allocations
20
- PlainApm::ObjectTracing.total_thread_allocated_objects
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PlainApm
4
- module Extensions
5
- module ThreadAllocations
6
- class Railtie < Rails::Railtie
7
- initializer(:plain_apm_thread_allocationss, after: :plain_apm_agent_start) do
8
- next if !PlainApm.agent.enabled?
9
-
10
- require "object_tracing"
11
-
12
- ActiveSupport::Notifications::Event.prepend(
13
- PlainApm::Extensions::ThreadAllocations::ActiveSupportEvent
14
- )
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,2 +0,0 @@
1
- require_relative "thread_allocations/active_support_event"
2
- require_relative "thread_allocations/railtie" if defined?(Rails::Railtie)