elastic-apm 3.2.0 → 3.3.0

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.
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
@@ -9,9 +9,7 @@ module ElasticAPM
9
9
  # It is recommended to use the Railtie instead.
10
10
  module Rails
11
11
  extend self
12
-
13
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
14
- # rubocop:disable Metrics/CyclomaticComplexity
12
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
15
13
  # Start the ElasticAPM agent and hook into Rails.
16
14
  # Note that the agent won't be started if the Rails console is being used.
17
15
  #
@@ -50,8 +48,7 @@ module ElasticAPM
50
48
  puts "Backtrace:\n" + e.backtrace.join("\n")
51
49
  end
52
50
  end
53
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
54
- # rubocop:enable Metrics/CyclomaticComplexity
51
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
55
52
 
56
53
  private
57
54
 
@@ -30,7 +30,7 @@ module ElasticAPM
30
30
  end
31
31
 
32
32
  def format_name(str)
33
- str && str.gsub('::', '_')
33
+ str&.gsub('::', '_')
34
34
  end
35
35
  end
36
36
  end
@@ -10,7 +10,7 @@ module ElasticAPM
10
10
 
11
11
  DEFAULT_TYPE = 'custom'
12
12
 
13
- # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
13
+ # rubocop:disable Metrics/ParameterLists
14
14
  def initialize(
15
15
  name:,
16
16
  transaction:,
@@ -39,7 +39,7 @@ module ElasticAPM
39
39
  @context = context || Span::Context.new
40
40
  @stacktrace_builder = stacktrace_builder
41
41
  end
42
- # rubocop:enable Metrics/ParameterLists, Metrics/MethodLength
42
+ # rubocop:enable Metrics/ParameterLists
43
43
 
44
44
  def_delegators :@trace_context, :trace_id, :parent_id, :id
45
45
 
@@ -28,12 +28,28 @@ module ElasticAPM
28
28
  # @api private
29
29
  class Http
30
30
  def initialize(url: nil, status_code: nil, method: nil)
31
- @url = url
31
+ @url = sanitize_url(url)
32
32
  @status_code = status_code
33
33
  @method = method
34
34
  end
35
35
 
36
36
  attr_accessor :url, :status_code, :method
37
+
38
+ private
39
+
40
+ def sanitize_url(url)
41
+ uri = URI(url)
42
+
43
+ return url unless uri.userinfo
44
+
45
+ format(
46
+ '%s://%s@%s%s',
47
+ uri.scheme,
48
+ uri.user,
49
+ uri.hostname,
50
+ uri.path
51
+ )
52
+ end
37
53
  end
38
54
  end
39
55
  end
@@ -7,8 +7,6 @@ module ElasticAPM
7
7
  class ElasticsearchSpy
8
8
  NAME_FORMAT = '%s %s'
9
9
  TYPE = 'db.elasticsearch'
10
-
11
- # rubocop:disable Metrics/MethodLength
12
10
  def install
13
11
  ::Elasticsearch::Transport::Client.class_eval do
14
12
  alias perform_request_without_apm perform_request
@@ -24,7 +22,6 @@ module ElasticAPM
24
22
  end
25
23
  end
26
24
  end
27
- # rubocop:enable Metrics/MethodLength
28
25
  end
29
26
 
30
27
  register(
@@ -16,8 +16,7 @@ module ElasticAPM
16
16
  end
17
17
  end
18
18
 
19
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
20
- # rubocop:disable Metrics/BlockLength, Metrics/PerceivedComplexity
19
+ # rubocop:disable Metrics/PerceivedComplexity
21
20
  # rubocop:disable Metrics/CyclomaticComplexity
22
21
  def install
23
22
  ::Faraday::Connection.class_eval do
@@ -61,8 +60,7 @@ module ElasticAPM
61
60
  end
62
61
  end
63
62
  # rubocop:enable Metrics/CyclomaticComplexity
64
- # rubocop:enable Metrics/BlockLength, Metrics/PerceivedComplexity
65
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
63
+ # rubocop:enable Metrics/PerceivedComplexity
66
64
  end
67
65
 
68
66
  register 'Faraday', 'faraday', FaradaySpy.new
@@ -7,8 +7,6 @@ module ElasticAPM
7
7
  class HTTPSpy
8
8
  TYPE = 'ext'
9
9
  SUBTYPE = 'http_rb'
10
-
11
- # rubocop:disable Metrics/MethodLength
12
10
  def install
13
11
  ::HTTP::Client.class_eval do
14
12
  alias perform_without_apm perform
@@ -36,7 +34,6 @@ module ElasticAPM
36
34
  end
37
35
  end
38
36
  end
39
- # rubocop:enable Metrics/MethodLength
40
37
  end
41
38
 
42
39
  register 'HTTP', 'http', HTTPSpy.new
@@ -36,15 +36,21 @@ module ElasticAPM
36
36
 
37
37
  private
38
38
 
39
- # rubocop:disable Metrics/MethodLength
40
39
  def push_event(event)
41
40
  return unless ElasticAPM.current_transaction
42
41
  # Some MongoDB commands are not on collections but rather are db
43
42
  # admin commands. For these commands, the value at the `command_name`
44
43
  # key is the integer 1.
45
- unless event.command[event.command_name] == 1
46
- collection = event.command[event.command_name]
47
- end
44
+ # For getMore commands, the value at `command_name` is the cursor id
45
+ # and the collection name is at the key `collection`
46
+ collection =
47
+ if event.command[event.command_name] == 1 ||
48
+ event.command[event.command_name].is_a?(BSON::Int64)
49
+ event.command[:collection]
50
+ else
51
+ event.command[event.command_name]
52
+ end
53
+
48
54
  name = [event.database_name,
49
55
  collection,
50
56
  event.command_name].compact.join('.')
@@ -60,7 +66,6 @@ module ElasticAPM
60
66
 
61
67
  @events[event.operation_id] = span
62
68
  end
63
- # rubocop:enable Metrics/MethodLength
64
69
 
65
70
  def pop_event(event)
66
71
  return unless (curr = ElasticAPM.current_span)
@@ -8,8 +8,6 @@ module ElasticAPM
8
8
  KEY = :__elastic_apm_net_http_disabled
9
9
  TYPE = 'ext'
10
10
  SUBTYPE = 'net_http'
11
-
12
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
13
11
  class << self
14
12
  def disabled=(disabled)
15
13
  Thread.current[KEY] = disabled
@@ -42,7 +40,7 @@ module ElasticAPM
42
40
  return request_without_apm(req, body, &block)
43
41
  end
44
42
 
45
- host, = req['host'] && req['host'].split(':')
43
+ host, = req['host']&.split(':')
46
44
  method = req.method
47
45
 
48
46
  host ||= address
@@ -62,7 +60,6 @@ module ElasticAPM
62
60
  end
63
61
  end
64
62
  end
65
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
66
63
  end
67
64
 
68
65
  register 'Net::HTTP', 'net/http', NetHTTPSpy.new
@@ -5,7 +5,6 @@ module ElasticAPM
5
5
  module Spies
6
6
  # @api private
7
7
  class RakeSpy
8
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
9
8
  def install
10
9
  ::Rake::Task.class_eval do
11
10
  alias execute_without_apm execute
@@ -38,7 +37,6 @@ module ElasticAPM
38
37
  end
39
38
  end
40
39
  end
41
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
42
40
  end
43
41
  register 'Rake::Task', 'rake', RakeSpy.new
44
42
  end
@@ -19,7 +19,6 @@ module ElasticAPM
19
19
  )
20
20
  end
21
21
 
22
- # rubocop:disable Metrics/MethodLength
23
22
  def install
24
23
  require 'sequel/database/logging'
25
24
 
@@ -39,7 +38,6 @@ module ElasticAPM
39
38
  end
40
39
  end
41
40
  end
42
- # rubocop:enable Metrics/MethodLength
43
41
  end
44
42
 
45
43
  register 'Sequel', 'sequel', SequelSpy.new
@@ -10,7 +10,6 @@ module ElasticAPM
10
10
 
11
11
  # @api private
12
12
  class Middleware
13
- # rubocop:disable Metrics/MethodLength
14
13
  def call(_worker, job, queue)
15
14
  name = SidekiqSpy.name_for(job)
16
15
  transaction = ElasticAPM.start_transaction(name, 'Sidekiq')
@@ -18,15 +17,14 @@ module ElasticAPM
18
17
 
19
18
  yield
20
19
 
21
- transaction.done :success if transaction
20
+ transaction&.done :success
22
21
  rescue ::Exception => e
23
22
  ElasticAPM.report(e, handled: false)
24
- transaction.done :error if transaction
23
+ transaction&.done :error
25
24
  raise
26
25
  ensure
27
26
  ElasticAPM.end_transaction
28
27
  end
29
- # rubocop:enable Metrics/MethodLength
30
28
  end
31
29
 
32
30
  def self.name_for(job)
@@ -48,7 +46,6 @@ module ElasticAPM
48
46
  end
49
47
  end
50
48
 
51
- # rubocop:disable Metrics/MethodLength
52
49
  def install_processor
53
50
  require 'sidekiq/processor'
54
51
 
@@ -76,7 +73,6 @@ module ElasticAPM
76
73
  end
77
74
  end
78
75
  end
79
- # rubocop:enable Metrics/MethodLength
80
76
 
81
77
  def install
82
78
  install_processor
@@ -5,7 +5,6 @@ module ElasticAPM
5
5
  module Spies
6
6
  # @api private
7
7
  class SinatraSpy
8
- # rubocop:disable Metrics/MethodLength
9
8
  def install
10
9
  ::Sinatra::Base.class_eval do
11
10
  alias dispatch_without_apm! dispatch!
@@ -31,7 +30,6 @@ module ElasticAPM
31
30
  end
32
31
  end
33
32
  end
34
- # rubocop:enable Metrics/MethodLength
35
33
  end
36
34
 
37
35
  register 'Sinatra::Base', 'sinatra/base', SinatraSpy.new
@@ -21,8 +21,6 @@ module ElasticAPM
21
21
  :module,
22
22
  :colno
23
23
  )
24
-
25
- # rubocop:disable Metrics/AbcSize
26
24
  def build_context(context_line_count)
27
25
  return unless abs_path && context_line_count > 0
28
26
 
@@ -38,7 +36,6 @@ module ElasticAPM
38
36
  self.pre_context = file_lines.first(padding)
39
37
  self.post_context = file_lines.last(padding)
40
38
  end
41
- # rubocop:enable Metrics/AbcSize
42
39
 
43
40
  private
44
41
 
@@ -31,7 +31,6 @@ module ElasticAPM
31
31
 
32
32
  private
33
33
 
34
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
35
34
  def build_frame(cache, keys)
36
35
  line, type = keys
37
36
  abs_path, lineno, function, _module_name = parse_line(line)
@@ -49,7 +48,6 @@ module ElasticAPM
49
48
 
50
49
  cache[[line, type]] = frame
51
50
  end
52
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
53
51
 
54
52
  def parse_line(line)
55
53
  ruby_match = line.match(RUBY_FORMAT)
@@ -28,8 +28,6 @@ module ElasticAPM
28
28
  # AS::Notifications API
29
29
 
30
30
  Notification = Struct.new(:id, :span)
31
-
32
- # rubocop:disable Metrics/MethodLength
33
31
  def start(name, id, payload)
34
32
  return unless (transaction = @agent.current_transaction)
35
33
 
@@ -52,8 +50,8 @@ module ElasticAPM
52
50
 
53
51
  transaction.notifications << Notification.new(id, span)
54
52
  end
55
- # rubocop:enable Metrics/MethodLength
56
53
 
54
+ # rubocop:disable Metrics/CyclomaticComplexity
57
55
  def finish(name, id, payload)
58
56
  # debug "AS::Notification#finish:#{name}:#{id}"
59
57
  return unless (transaction = @agent.current_transaction)
@@ -70,6 +68,7 @@ module ElasticAPM
70
68
  return
71
69
  end
72
70
  end
71
+ # rubocop:enable Metrics/CyclomaticComplexity
73
72
 
74
73
  private
75
74
 
@@ -29,8 +29,6 @@ module ElasticAPM
29
29
  attr_accessor :version, :id, :trace_id, :parent_id, :recorded
30
30
 
31
31
  alias :recorded? :recorded
32
-
33
- # rubocop:disable Metrics/AbcSize
34
32
  def self.parse(header)
35
33
  raise InvalidTraceparentHeader unless header.length == 55
36
34
  raise InvalidTraceparentHeader unless header[0..1] == VERSION
@@ -45,7 +43,6 @@ module ElasticAPM
45
43
  raise InvalidTraceparentHeader if HEX_REGEX =~ t.parent_id
46
44
  end
47
45
  end
48
- # rubocop:enable Metrics/AbcSize
49
46
 
50
47
  def flags=(flags)
51
48
  @flags = flags
@@ -11,7 +11,7 @@ module ElasticAPM
11
11
 
12
12
  DEFAULT_TYPE = 'custom'
13
13
 
14
- # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
14
+ # rubocop:disable Metrics/ParameterLists
15
15
  def initialize(
16
16
  name = nil,
17
17
  type = nil,
@@ -38,7 +38,7 @@ module ElasticAPM
38
38
 
39
39
  @notifications = [] # for AS::Notifications
40
40
  end
41
- # rubocop:enable Metrics/MethodLength, Metrics/ParameterLists
41
+ # rubocop:enable Metrics/ParameterLists
42
42
 
43
43
  attr_accessor :name, :type, :result
44
44
 
@@ -13,7 +13,6 @@ require 'elastic_apm/util/throttle'
13
13
 
14
14
  module ElasticAPM
15
15
  module Transport
16
- # rubocop:disable Metrics/ClassLength
17
16
  # @api private
18
17
  class Base
19
18
  include Logging
@@ -56,7 +55,6 @@ module ElasticAPM
56
55
  stop_workers
57
56
  end
58
57
 
59
- # rubocop:disable Metrics/MethodLength
60
58
  def submit(resource)
61
59
  if @stopped.true?
62
60
  warn '%s: Transport stopping, no new events accepted', pid_str
@@ -75,7 +73,6 @@ module ElasticAPM
75
73
  error '%s: Failed adding to the transport queue: %p', pid_str, e.inspect
76
74
  nil
77
75
  end
78
- # rubocop:enable Metrics/MethodLength
79
76
 
80
77
  def add_filter(key, callback)
81
78
  @filters.add(key, callback)
@@ -131,7 +128,6 @@ module ElasticAPM
131
128
  end
132
129
  end
133
130
 
134
- # rubocop:disable Metrics/MethodLength
135
131
  def stop_workers
136
132
  debug '%s: Stopping workers', pid_str
137
133
 
@@ -152,7 +148,6 @@ module ElasticAPM
152
148
  @workers.clear
153
149
  end
154
150
  end
155
- # rubocop:enable Metrics/MethodLength
156
151
 
157
152
  def send_stop_messages
158
153
  config.pool_size.times { queue.push(Worker::StopMessage.new, true) }
@@ -176,6 +171,5 @@ module ElasticAPM
176
171
  end).call
177
172
  end
178
173
  end
179
- # rubocop:enable Metrics/ClassLength
180
174
  end
181
175
  end
@@ -30,8 +30,6 @@ module ElasticAPM
30
30
  end
31
31
 
32
32
  attr_reader :http
33
-
34
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
35
33
  def write(str)
36
34
  return false if @config.disable_send
37
35
 
@@ -57,7 +55,6 @@ module ElasticAPM
57
55
  flush(:connection_error)
58
56
  end
59
57
  end
60
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
61
58
 
62
59
  def flush(reason = :force)
63
60
  # Could happen from the timertask so we need to sync
@@ -70,7 +67,7 @@ module ElasticAPM
70
67
  def inspect
71
68
  format(
72
69
  '<%s url:%s closed:%s >',
73
- super.split.first, url, http&.closed?
70
+ super.split.first, @url, http&.closed?
74
71
  )
75
72
  end
76
73