elastic-apm 3.2.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.ci/.jenkins_exclude.yml +8 -1
  3. data/.ci/.jenkins_ruby.yml +1 -0
  4. data/.ci/Jenkinsfile +64 -31
  5. data/.github/workflows/main.yml +14 -0
  6. data/.pre-commit-config.yaml +1 -5
  7. data/.rubocop.yml +35 -29
  8. data/CHANGELOG.asciidoc +20 -4
  9. data/Gemfile +1 -0
  10. data/README.md +2 -2
  11. data/bin/dev +1 -1
  12. data/bin/run-tests +3 -0
  13. data/docs/api.asciidoc +0 -29
  14. data/docs/configuration.asciidoc +11 -0
  15. data/docs/context.asciidoc +4 -4
  16. data/lib/elastic_apm.rb +5 -9
  17. data/lib/elastic_apm/agent.rb +0 -9
  18. data/lib/elastic_apm/central_config.rb +10 -10
  19. data/lib/elastic_apm/central_config/cache_control.rb +1 -1
  20. data/lib/elastic_apm/config.rb +4 -11
  21. data/lib/elastic_apm/config/options.rb +2 -4
  22. data/lib/elastic_apm/config/wildcard_pattern_list.rb +35 -0
  23. data/lib/elastic_apm/context_builder.rb +0 -2
  24. data/lib/elastic_apm/error.rb +1 -1
  25. data/lib/elastic_apm/error/exception.rb +2 -2
  26. data/lib/elastic_apm/error_builder.rb +0 -2
  27. data/lib/elastic_apm/grape.rb +0 -3
  28. data/lib/elastic_apm/instrumenter.rb +3 -13
  29. data/lib/elastic_apm/metadata/service_info.rb +0 -5
  30. data/lib/elastic_apm/metadata/system_info/container_info.rb +4 -6
  31. data/lib/elastic_apm/metrics.rb +0 -3
  32. data/lib/elastic_apm/metrics/cpu_mem_set.rb +0 -10
  33. data/lib/elastic_apm/metrics/metric.rb +6 -2
  34. data/lib/elastic_apm/metrics/set.rb +4 -4
  35. data/lib/elastic_apm/metrics/span_scoped_set.rb +1 -1
  36. data/lib/elastic_apm/metrics/transaction_set.rb +0 -2
  37. data/lib/elastic_apm/metrics/vm_set.rb +0 -3
  38. data/lib/elastic_apm/middleware.rb +0 -2
  39. data/lib/elastic_apm/normalizers/grape/endpoint_run.rb +2 -1
  40. data/lib/elastic_apm/normalizers/rails/active_record.rb +1 -1
  41. data/lib/elastic_apm/opentracing.rb +6 -15
  42. data/lib/elastic_apm/rails.rb +2 -5
  43. data/lib/elastic_apm/sinatra.rb +1 -1
  44. data/lib/elastic_apm/span.rb +2 -2
  45. data/lib/elastic_apm/span/context.rb +17 -1
  46. data/lib/elastic_apm/spies/elasticsearch.rb +0 -3
  47. data/lib/elastic_apm/spies/faraday.rb +2 -4
  48. data/lib/elastic_apm/spies/http.rb +0 -3
  49. data/lib/elastic_apm/spies/mongo.rb +10 -5
  50. data/lib/elastic_apm/spies/net_http.rb +1 -4
  51. data/lib/elastic_apm/spies/rake.rb +0 -2
  52. data/lib/elastic_apm/spies/sequel.rb +0 -2
  53. data/lib/elastic_apm/spies/sidekiq.rb +2 -6
  54. data/lib/elastic_apm/spies/sinatra.rb +0 -2
  55. data/lib/elastic_apm/stacktrace/frame.rb +0 -3
  56. data/lib/elastic_apm/stacktrace_builder.rb +0 -2
  57. data/lib/elastic_apm/subscriber.rb +2 -3
  58. data/lib/elastic_apm/trace_context.rb +0 -3
  59. data/lib/elastic_apm/transaction.rb +2 -2
  60. data/lib/elastic_apm/transport/base.rb +0 -6
  61. data/lib/elastic_apm/transport/connection.rb +1 -4
  62. data/lib/elastic_apm/transport/connection/http.rb +0 -2
  63. data/lib/elastic_apm/transport/filters.rb +1 -1
  64. data/lib/elastic_apm/transport/filters/secrets_filter.rb +1 -3
  65. data/lib/elastic_apm/transport/serializers.rb +0 -3
  66. data/lib/elastic_apm/transport/serializers/context_serializer.rb +0 -2
  67. data/lib/elastic_apm/transport/serializers/error_serializer.rb +0 -2
  68. data/lib/elastic_apm/transport/serializers/metadata_serializer.rb +0 -2
  69. data/lib/elastic_apm/transport/serializers/metricset_serializer.rb +0 -2
  70. data/lib/elastic_apm/transport/serializers/span_serializer.rb +0 -3
  71. data/lib/elastic_apm/transport/serializers/transaction_serializer.rb +0 -2
  72. data/lib/elastic_apm/transport/worker.rb +10 -6
  73. data/lib/elastic_apm/util.rb +1 -1
  74. data/lib/elastic_apm/version.rb +1 -1
  75. metadata +5 -5
  76. data/.ci/bin/check_paths_for_matches.py +0 -80
  77. data/.hound.yml +0 -2
@@ -7,8 +7,6 @@ module ElasticAPM
7
7
  # Module for starting the ElasticAPM agent and hooking into Grape.
8
8
  module Grape
9
9
  extend self
10
-
11
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
12
10
  # Start the ElasticAPM agent and hook into Grape.
13
11
  #
14
12
  # @param app [Grape::API] A Grape app.
@@ -27,7 +25,6 @@ module ElasticAPM
27
25
  config.logger.error format('Failed to start: %s', e.message)
28
26
  config.logger.debug "Backtrace:\n" + e.backtrace.join("\n")
29
27
  end
30
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
31
28
 
32
29
  private
33
30
 
@@ -7,7 +7,6 @@ require 'elastic_apm/transaction'
7
7
  require 'elastic_apm/span_helpers'
8
8
 
9
9
  module ElasticAPM
10
- # rubocop:disable Metrics/ClassLength
11
10
  # @api private
12
11
  class Instrumenter
13
12
  TRANSACTION_KEY = :__elastic_instrumenter_transaction_key
@@ -61,7 +60,7 @@ module ElasticAPM
61
60
  self.current_transaction = nil
62
61
  current_spans.pop until current_spans.empty?
63
62
 
64
- @subscriber.unregister! if @subscriber
63
+ @subscriber&.unregister!
65
64
  end
66
65
 
67
66
  def subscriber=(subscriber)
@@ -80,7 +79,6 @@ module ElasticAPM
80
79
  @current.transaction = transaction
81
80
  end
82
81
 
83
- # rubocop:disable Metrics/MethodLength
84
82
  def start_transaction(
85
83
  name = nil,
86
84
  type = nil,
@@ -112,7 +110,6 @@ module ElasticAPM
112
110
 
113
111
  self.current_transaction = transaction
114
112
  end
115
- # rubocop:enable Metrics/MethodLength
116
113
 
117
114
  def end_transaction(result = nil)
118
115
  return nil unless (transaction = current_transaction)
@@ -138,8 +135,7 @@ module ElasticAPM
138
135
  current_spans.last
139
136
  end
140
137
 
141
- # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
142
- # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
138
+ # rubocop:disable Metrics/CyclomaticComplexity
143
139
  # rubocop:disable Metrics/ParameterLists
144
140
  def start_span(
145
141
  name,
@@ -183,8 +179,7 @@ module ElasticAPM
183
179
  span.start
184
180
  end
185
181
  # rubocop:enable Metrics/ParameterLists
186
- # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
187
- # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
182
+ # rubocop:enable Metrics/CyclomaticComplexity
188
183
 
189
184
  def end_span
190
185
  return unless (span = current_spans.pop)
@@ -229,7 +224,6 @@ module ElasticAPM
229
224
  rand <= config.transaction_sample_rate
230
225
  end
231
226
 
232
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
233
227
  def update_transaction_metrics(transaction)
234
228
  return unless transaction.config.collect_metrics?
235
229
 
@@ -268,9 +262,7 @@ module ElasticAPM
268
262
  tags: span_tags, reset_on_collect: true
269
263
  ).inc!
270
264
  end
271
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
272
265
 
273
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
274
266
  def update_span_metrics(span)
275
267
  return unless span.transaction.config.breakdown_metrics?
276
268
 
@@ -292,7 +284,5 @@ module ElasticAPM
292
284
  tags: tags, reset_on_collect: true
293
285
  ).inc!
294
286
  end
295
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
296
287
  end
297
- # rubocop:enable Metrics/ClassLength
298
288
  end
@@ -17,8 +17,6 @@ module ElasticAPM
17
17
  class Framework < Versioned; end
18
18
  class Language < Versioned; end
19
19
  class Runtime < Versioned; end
20
-
21
- # rubocop:disable Metrics/MethodLength
22
20
  def initialize(config)
23
21
  @config = config
24
22
 
@@ -33,14 +31,12 @@ module ElasticAPM
33
31
  @runtime = lookup_runtime
34
32
  @version = @config.service_version || Util.git_sha
35
33
  end
36
- # rubocop:enable Metrics/MethodLength
37
34
 
38
35
  attr_reader :name, :environment, :agent, :framework, :language, :runtime,
39
36
  :version
40
37
 
41
38
  private
42
39
 
43
- # rubocop:disable Metrics/MethodLength
44
40
  def lookup_runtime
45
41
  case RUBY_ENGINE
46
42
  when 'ruby'
@@ -55,7 +51,6 @@ module ElasticAPM
55
51
  )
56
52
  end
57
53
  end
58
- # rubocop:enable Metrics/MethodLength
59
54
  end
60
55
  end
61
56
  end
@@ -34,7 +34,6 @@ module ElasticAPM
34
34
  end
35
35
  end
36
36
 
37
- # rubocop:disable Metrics/MethodLength
38
37
  def kubernetes
39
38
  @kubernetes =
40
39
  begin
@@ -51,7 +50,6 @@ module ElasticAPM
51
50
  kubernetes
52
51
  end
53
52
  end
54
- # rubocop:enable Metrics/MethodLength
55
53
 
56
54
  private
57
55
 
@@ -70,8 +68,8 @@ module ElasticAPM
70
68
  KUBEPODS_REGEX = %r{(?:^/kubepods/[^/]+/pod([^/]+)$)|(?:^/kubepods\.slice/kubepods-[^/]+\.slice/kubepods-[^/]+-pod([^/]+)\.slice$)}.freeze # rubocop:disable Metrics/LineLength
71
69
  SYSTEMD_SCOPE_SUFFIX = '.scope'
72
70
 
73
- # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
74
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
71
+ # rubocop:disable Metrics/PerceivedComplexity
72
+ # rubocop:disable Metrics/CyclomaticComplexity
75
73
  def read_from_cgroup!
76
74
  return unless File.exist?(cgroup_path)
77
75
  IO.readlines(cgroup_path).each do |line|
@@ -113,8 +111,8 @@ module ElasticAPM
113
111
  end
114
112
  end
115
113
  end
116
- # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
117
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize
114
+ # rubocop:enable Metrics/PerceivedComplexity
115
+ # rubocop:enable Metrics/CyclomaticComplexity
118
116
  end
119
117
  end
120
118
  end
@@ -23,8 +23,6 @@ module ElasticAPM
23
23
  end
24
24
 
25
25
  attr_reader :config, :sets, :callback
26
-
27
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
28
26
  def start
29
27
  unless config.collect_metrics?
30
28
  debug 'Skipping metrics'
@@ -61,7 +59,6 @@ module ElasticAPM
61
59
 
62
60
  @running = true
63
61
  end
64
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
65
62
 
66
63
  def stop
67
64
  return unless running?
@@ -68,7 +68,6 @@ module ElasticAPM
68
68
  end
69
69
  end
70
70
 
71
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
72
71
  def read!
73
72
  return if disabled?
74
73
 
@@ -91,7 +90,6 @@ module ElasticAPM
91
90
 
92
91
  @previous = current
93
92
  end
94
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
95
93
 
96
94
  def calculate_deltas(current, previous)
97
95
  system_cpu_total =
@@ -109,7 +107,6 @@ module ElasticAPM
109
107
 
110
108
  # @api private
111
109
  class Linux
112
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
113
110
  def sample
114
111
  proc_stat = ProcStat.new.read!
115
112
  proc_self_stat = ProcSelfStat.new.read!
@@ -126,7 +123,6 @@ module ElasticAPM
126
123
  page_size: meminfo.page_size
127
124
  )
128
125
  end
129
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
130
126
 
131
127
  # @api private
132
128
  class ProcStat
@@ -144,8 +140,6 @@ module ElasticAPM
144
140
  guest
145
141
  guest_nice
146
142
  ].freeze
147
-
148
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
149
143
  def read!
150
144
  stat =
151
145
  IO.readlines('/proc/stat')
@@ -173,7 +167,6 @@ module ElasticAPM
173
167
 
174
168
  self
175
169
  end
176
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
177
170
  end
178
171
 
179
172
  UTIME_POS = 13
@@ -204,8 +197,6 @@ module ElasticAPM
204
197
  # @api private
205
198
  class Meminfo
206
199
  attr_reader :total, :available, :page_size
207
-
208
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
209
200
  # rubocop:disable Metrics/PerceivedComplexity
210
201
  # rubocop:disable Metrics/CyclomaticComplexity
211
202
  def read!
@@ -240,7 +231,6 @@ module ElasticAPM
240
231
  end
241
232
  # rubocop:enable Metrics/CyclomaticComplexity
242
233
  # rubocop:enable Metrics/PerceivedComplexity
243
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
244
234
  end
245
235
  end
246
236
  end
@@ -75,11 +75,15 @@ module ElasticAPM
75
75
  end
76
76
 
77
77
  def inc!
78
- @value += 1
78
+ @mutex.synchronize do
79
+ @value += 1
80
+ end
79
81
  end
80
82
 
81
83
  def dec!
82
- @value -= 1
84
+ @mutex.synchronize do
85
+ @value -= 1
86
+ end
83
87
  end
84
88
  end
85
89
 
@@ -40,8 +40,11 @@ module ElasticAPM
40
40
  metric(Timer, key, tags: tags, **args)
41
41
  end
42
42
 
43
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
44
43
  def metric(kls, key, tags: nil, **args)
44
+ if @config.disable_metrics.any? { |p| p.match? key }
45
+ return NOOP
46
+ end
47
+
45
48
  key = key_with_tags(key, tags)
46
49
  return metrics[key] if metrics[key]
47
50
 
@@ -64,9 +67,7 @@ module ElasticAPM
64
67
  end
65
68
  end
66
69
  end
67
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
68
70
 
69
- # rubocop:disable Metrics/MethodLength
70
71
  def collect
71
72
  return if disabled?
72
73
 
@@ -90,7 +91,6 @@ module ElasticAPM
90
91
  end.values
91
92
  end
92
93
  end
93
- # rubocop:enable Metrics/MethodLength
94
94
 
95
95
  private
96
96
 
@@ -6,7 +6,7 @@ module ElasticAPM
6
6
  class SpanScopedSet < Set
7
7
  def collect
8
8
  super.tap do |sets|
9
- return unless sets
9
+ next unless sets
10
10
 
11
11
  sets.each do |set|
12
12
  move_transaction(set)
@@ -7,5 +7,3 @@ module ElasticAPM
7
7
  end
8
8
  end
9
9
  end
10
-
11
-
@@ -11,7 +11,6 @@ module ElasticAPM
11
11
  super
12
12
  end
13
13
 
14
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
15
14
  def read!
16
15
  return if disabled?
17
16
 
@@ -37,8 +36,6 @@ module ElasticAPM
37
36
 
38
37
  disable!
39
38
  end
40
-
41
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
42
39
  end
43
40
  end
44
41
  end
@@ -10,7 +10,6 @@ module ElasticAPM
10
10
  @app = app
11
11
  end
12
12
 
13
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
14
13
  def call(env)
15
14
  begin
16
15
  if running? && !path_ignored?(env)
@@ -35,7 +34,6 @@ module ElasticAPM
35
34
 
36
35
  resp
37
36
  end
38
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
39
37
 
40
38
  private
41
39
 
@@ -37,7 +37,8 @@ module ElasticAPM
37
37
  end
38
38
 
39
39
  def endpoint(env)
40
- route_name = env['api.endpoint']&.routes&.first&.pattern&.origin ||
40
+ route_name =
41
+ env['api.endpoint']&.routes&.first&.pattern&.origin ||
41
42
  env['REQUEST_PATH']
42
43
  [env['REQUEST_METHOD'], route_name].join(' ')
43
44
  end
@@ -34,7 +34,7 @@ module ElasticAPM
34
34
 
35
35
  def subtype(payload)
36
36
  cached_adapter_name(
37
- payload[:connection] ? payload[:connection].adapter_name :
37
+ payload[:connection]&.adapter_name ||
38
38
  ::ActiveRecord::Base.connection_config[:adapter]
39
39
  )
40
40
  end
@@ -22,7 +22,6 @@ module ElasticAPM
22
22
  @span_context
23
23
  end
24
24
 
25
- # rubocop:disable Metrics/MethodLength
26
25
  def set_label(key, val)
27
26
  if elastic_span.is_a?(Transaction)
28
27
  case key.to_s
@@ -39,7 +38,6 @@ module ElasticAPM
39
38
  elastic_span.context.labels[key] = val
40
39
  end
41
40
  end
42
- # rubocop:enable Metrics/MethodLength
43
41
 
44
42
  def set_baggage_item(_key, _value)
45
43
  ElasticAPM.agent.config.logger.warn(
@@ -63,9 +61,8 @@ module ElasticAPM
63
61
  ElasticAPM.report_message message
64
62
  end
65
63
  end
66
- # rubocop:enable Lint/UnusedMethodArgument
67
64
 
68
- # rubocop:disable Metrics/MethodLength
65
+ # rubocop:enable Lint/UnusedMethodArgument
69
66
  def finish(clock_end: Util.monotonic_micros, end_time: nil)
70
67
  return unless (agent = ElasticAPM.agent)
71
68
 
@@ -86,7 +83,6 @@ module ElasticAPM
86
83
 
87
84
  agent.enqueue elastic_span
88
85
  end
89
- # rubocop:enable Metrics/MethodLength
90
86
 
91
87
  private
92
88
 
@@ -179,8 +175,6 @@ module ElasticAPM
179
175
  @scope_stack.last
180
176
  end
181
177
  end
182
-
183
- # rubocop:disable Metrics/ClassLength
184
178
  # A custom tracer to use the OpenTracing API with ElasticAPM
185
179
  class Tracer
186
180
  def initialize
@@ -193,7 +187,7 @@ module ElasticAPM
193
187
  scope_manager.active&.span
194
188
  end
195
189
 
196
- # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
190
+ # rubocop:disable Metrics/ParameterLists
197
191
  def start_active_span(
198
192
  operation_name,
199
193
  child_of: nil,
@@ -224,10 +218,9 @@ module ElasticAPM
224
218
 
225
219
  scope
226
220
  end
227
- # rubocop:enable Metrics/MethodLength, Metrics/ParameterLists
221
+ # rubocop:enable Metrics/ParameterLists
228
222
 
229
- # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
230
- # rubocop:disable Metrics/AbcSize
223
+ # rubocop:disable Metrics/ParameterLists
231
224
  def start_span(
232
225
  operation_name,
233
226
  child_of: nil,
@@ -245,7 +238,6 @@ module ElasticAPM
245
238
 
246
239
  if span_context
247
240
  trace_context =
248
- span_context &&
249
241
  span_context.respond_to?(:trace_context) &&
250
242
  span_context.trace_context
251
243
  end
@@ -279,8 +271,8 @@ module ElasticAPM
279
271
 
280
272
  Span.new(elastic_span, span_context)
281
273
  end
282
- # rubocop:enable Metrics/AbcSize
283
- # rubocop:enable Metrics/MethodLength, Metrics/ParameterLists
274
+
275
+ # rubocop:enable Metrics/ParameterLists
284
276
 
285
277
  def inject(span_context, format, carrier)
286
278
  case format
@@ -341,6 +333,5 @@ module ElasticAPM
341
333
  @scope_manager.active&.span&.context
342
334
  end
343
335
  end
344
- # rubocop:enable Metrics/ClassLength
345
336
  end
346
337
  end