atatus 1.3.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Gemfile +72 -22
  4. data/LICENSE +1 -1
  5. data/atatus.gemspec +2 -2
  6. data/lib/atatus/agent.rb +78 -29
  7. data/lib/atatus/central_config/cache_control.rb +18 -1
  8. data/lib/atatus/central_config.rb +72 -27
  9. data/lib/atatus/child_durations.rb +64 -0
  10. data/lib/atatus/collector/base.rb +102 -43
  11. data/lib/atatus/collector/builder.rb +134 -4
  12. data/lib/atatus/collector/hist.rb +54 -0
  13. data/lib/atatus/collector/layer.rb +1 -0
  14. data/lib/atatus/collector/transport.rb +41 -11
  15. data/lib/atatus/config/bytes.rb +17 -0
  16. data/lib/atatus/config/duration.rb +17 -0
  17. data/lib/atatus/config/options.rb +29 -9
  18. data/lib/atatus/config/regexp_list.rb +17 -0
  19. data/lib/atatus/config/wildcard_pattern_list.rb +64 -0
  20. data/lib/atatus/config.rb +129 -28
  21. data/lib/atatus/context/request/socket.rb +18 -1
  22. data/lib/atatus/context/request/url.rb +17 -0
  23. data/lib/atatus/context/request.rb +17 -0
  24. data/lib/atatus/context/response.rb +27 -2
  25. data/lib/atatus/context/user.rb +17 -0
  26. data/lib/atatus/context.rb +32 -1
  27. data/lib/atatus/context_builder.rb +19 -4
  28. data/lib/atatus/deprecations.rb +17 -0
  29. data/lib/atatus/error/exception.rb +24 -0
  30. data/lib/atatus/error/log.rb +17 -0
  31. data/lib/atatus/error.rb +27 -0
  32. data/lib/atatus/error_builder.rb +21 -2
  33. data/lib/atatus/grape.rb +62 -0
  34. data/lib/atatus/graphql.rb +91 -0
  35. data/lib/atatus/grpc.rb +99 -0
  36. data/lib/atatus/instrumenter.rb +135 -30
  37. data/lib/atatus/internal_error.rb +17 -0
  38. data/lib/atatus/logging.rb +17 -2
  39. data/lib/atatus/metadata/process_info.rb +17 -0
  40. data/lib/atatus/metadata/service_info.rb +21 -6
  41. data/lib/atatus/metadata/system_info/container_info.rb +49 -10
  42. data/lib/atatus/metadata/system_info/hw_info.rb +1 -1
  43. data/lib/atatus/metadata/system_info.rb +22 -3
  44. data/lib/atatus/metadata.rb +17 -0
  45. data/lib/atatus/metrics/breakdown_set.rb +31 -0
  46. data/lib/atatus/metrics/{cpu_mem.rb → cpu_mem_set.rb} +110 -63
  47. data/lib/atatus/metrics/metric.rb +140 -0
  48. data/lib/atatus/metrics/set.rb +123 -0
  49. data/lib/atatus/metrics/span_scoped_set.rb +56 -0
  50. data/lib/atatus/metrics/transaction_set.rb +26 -0
  51. data/lib/atatus/metrics/vm_set.rb +58 -0
  52. data/lib/atatus/metrics.rb +69 -27
  53. data/lib/atatus/metricset.rb +48 -4
  54. data/lib/atatus/middleware.rb +28 -8
  55. data/lib/atatus/naively_hashable.rb +17 -0
  56. data/lib/atatus/normalizers/grape/endpoint_run.rb +65 -0
  57. data/lib/atatus/normalizers/grape.rb +22 -0
  58. data/lib/atatus/normalizers/rails/action_controller.rb +44 -0
  59. data/lib/atatus/normalizers/rails/action_mailer.rb +43 -0
  60. data/lib/atatus/normalizers/{action_view.rb → rails/action_view.rb} +17 -0
  61. data/lib/atatus/normalizers/rails/active_record.rb +80 -0
  62. data/lib/atatus/normalizers/rails.rb +27 -0
  63. data/lib/atatus/normalizers.rb +23 -9
  64. data/lib/atatus/opentracing.rb +75 -42
  65. data/lib/atatus/rails.rb +29 -13
  66. data/lib/atatus/railtie.rb +19 -6
  67. data/lib/atatus/resque.rb +29 -0
  68. data/lib/atatus/sinatra.rb +53 -0
  69. data/lib/atatus/span/context/db.rb +43 -0
  70. data/lib/atatus/span/context/destination.rb +77 -0
  71. data/lib/atatus/span/context/http.rb +43 -0
  72. data/lib/atatus/span/context.rb +43 -28
  73. data/lib/atatus/span.rb +44 -15
  74. data/lib/atatus/span_helpers.rb +18 -1
  75. data/lib/atatus/spies/action_dispatch.rb +27 -6
  76. data/lib/atatus/spies/delayed_job.rb +26 -5
  77. data/lib/atatus/spies/dynamo_db.rb +62 -0
  78. data/lib/atatus/spies/elasticsearch.rb +53 -7
  79. data/lib/atatus/spies/faraday.rb +54 -20
  80. data/lib/atatus/spies/http.rb +36 -6
  81. data/lib/atatus/spies/json.rb +18 -0
  82. data/lib/atatus/spies/mongo.rb +41 -10
  83. data/lib/atatus/spies/net_http.rb +52 -11
  84. data/lib/atatus/spies/rake.rb +42 -23
  85. data/lib/atatus/spies/redis.rb +17 -0
  86. data/lib/atatus/spies/resque.rb +57 -0
  87. data/lib/atatus/spies/sequel.rb +54 -17
  88. data/lib/atatus/spies/shoryuken.rb +69 -0
  89. data/lib/atatus/spies/sidekiq.rb +46 -25
  90. data/lib/atatus/spies/sinatra.rb +20 -4
  91. data/lib/atatus/spies/sneakers.rb +74 -0
  92. data/lib/atatus/spies/sucker_punch.rb +58 -0
  93. data/lib/atatus/spies/tilt.rb +20 -1
  94. data/lib/atatus/spies.rb +33 -15
  95. data/lib/atatus/sql/signature.rb +169 -0
  96. data/lib/atatus/sql/tokenizer.rb +264 -0
  97. data/lib/atatus/sql/tokens.rb +63 -0
  98. data/lib/atatus/sql.rb +36 -0
  99. data/lib/atatus/sql_summarizer.rb +24 -6
  100. data/lib/atatus/stacktrace/frame.rb +17 -3
  101. data/lib/atatus/stacktrace.rb +17 -0
  102. data/lib/atatus/stacktrace_builder.rb +23 -3
  103. data/lib/atatus/subscriber.rb +23 -4
  104. data/lib/atatus/trace_context/traceparent.rb +111 -0
  105. data/lib/atatus/trace_context/tracestate.rb +148 -0
  106. data/lib/atatus/trace_context.rb +84 -51
  107. data/lib/atatus/transaction.rb +74 -18
  108. data/lib/atatus/transport/base.rb +44 -27
  109. data/lib/atatus/transport/connection/http.rb +58 -35
  110. data/lib/atatus/transport/connection/proxy_pipe.rb +24 -5
  111. data/lib/atatus/transport/connection.rb +28 -72
  112. data/lib/atatus/transport/filters/hash_sanitizer.rb +77 -0
  113. data/lib/atatus/transport/filters/secrets_filter.rb +30 -55
  114. data/lib/atatus/transport/filters.rb +18 -1
  115. data/lib/atatus/transport/headers.rb +83 -0
  116. data/lib/atatus/transport/serializers/context_serializer.rb +30 -3
  117. data/lib/atatus/transport/serializers/error_serializer.rb +17 -2
  118. data/lib/atatus/transport/serializers/metadata_serializer.rb +44 -22
  119. data/lib/atatus/transport/serializers/metricset_serializer.rb +34 -6
  120. data/lib/atatus/transport/serializers/span_serializer.rb +47 -12
  121. data/lib/atatus/transport/serializers/transaction_serializer.rb +18 -2
  122. data/lib/atatus/transport/serializers.rb +17 -5
  123. data/lib/atatus/transport/user_agent.rb +48 -0
  124. data/lib/atatus/transport/worker.rb +31 -7
  125. data/lib/atatus/util/inflector.rb +17 -0
  126. data/lib/atatus/util/lru_cache.rb +17 -0
  127. data/lib/atatus/util/throttle.rb +17 -0
  128. data/lib/atatus/util.rb +18 -1
  129. data/lib/atatus/version.rb +19 -1
  130. data/lib/atatus.rb +84 -16
  131. metadata +46 -26
  132. data/Rakefile +0 -19
  133. data/bench/.gitignore +0 -2
  134. data/bench/app.rb +0 -53
  135. data/bench/benchmark.rb +0 -36
  136. data/bench/report.rb +0 -55
  137. data/bench/rubyprof.rb +0 -39
  138. data/bench/stackprof.rb +0 -23
  139. data/bin/build_docs +0 -5
  140. data/bin/console +0 -15
  141. data/bin/setup +0 -8
  142. data/bin/with_framework +0 -7
  143. data/lib/atatus/metrics/vm.rb +0 -60
  144. data/lib/atatus/normalizers/action_controller.rb +0 -27
  145. data/lib/atatus/normalizers/action_mailer.rb +0 -26
  146. data/lib/atatus/normalizers/active_record.rb +0 -45
  147. data/lib/atatus/util/prefixed_logger.rb +0 -18
  148. data/vendor/.gitkeep +0 -0
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -6,10 +23,14 @@ module Atatus
6
23
  # @api private
7
24
  class MongoSpy
8
25
  def install
9
- ::Mongo::Monitoring::Global.subscribe(
10
- ::Mongo::Monitoring::COMMAND,
11
- Subscriber.new
12
- )
26
+ if defined?(::Mongo) && defined?(::Mongo::Monitoring) && defined?(::Mongo::Monitoring::Global)
27
+
28
+ ::Mongo::Monitoring::Global.subscribe(
29
+ ::Mongo::Monitoring::COMMAND,
30
+ Subscriber.new
31
+ )
32
+
33
+ end
13
34
  end
14
35
 
15
36
  # @api private
@@ -36,15 +57,21 @@ module Atatus
36
57
 
37
58
  private
38
59
 
39
- # rubocop:disable Metrics/MethodLength
40
60
  def push_event(event)
41
61
  return unless Atatus.current_transaction
42
62
  # Some MongoDB commands are not on collections but rather are db
43
63
  # admin commands. For these commands, the value at the `command_name`
44
64
  # key is the integer 1.
45
- unless event.command[event.command_name] == 1
46
- collection = event.command[event.command_name]
47
- end
65
+ # For getMore commands, the value at `command_name` is the cursor id
66
+ # and the collection name is at the key `collection`
67
+ collection =
68
+ if event.command[event.command_name] == 1 ||
69
+ event.command[event.command_name].is_a?(BSON::Int64)
70
+ event.command[:collection]
71
+ else
72
+ event.command[event.command_name]
73
+ end
74
+
48
75
  name = [event.database_name,
49
76
  collection,
50
77
  event.command_name].compact.join('.')
@@ -60,11 +87,10 @@ module Atatus
60
87
 
61
88
  @events[event.operation_id] = span
62
89
  end
63
- # rubocop:enable Metrics/MethodLength
64
90
 
65
91
  def pop_event(event)
66
- return unless (curr = Atatus.current_span)
67
92
  span = @events.delete(event.operation_id)
93
+ return unless (curr = Atatus.current_span)
68
94
 
69
95
  curr == span && Atatus.end_span
70
96
  end
@@ -76,6 +102,11 @@ module Atatus
76
102
  statement: event.command.to_s,
77
103
  type: 'mongodb',
78
104
  user: nil
105
+ },
106
+ destination: {
107
+ name: SUBTYPE,
108
+ resource: SUBTYPE,
109
+ type: TYPE
79
110
  }
80
111
  )
81
112
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -9,7 +26,6 @@ module Atatus
9
26
  TYPE = 'ext'
10
27
  SUBTYPE = 'net_http'
11
28
 
12
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
13
29
  class << self
14
30
  def disabled=(disabled)
15
31
  Thread.current[KEY] = disabled
@@ -30,41 +46,66 @@ module Atatus
30
46
  end
31
47
  end
32
48
 
49
+ # rubocop:disable Metrics/CyclomaticComplexity
33
50
  def install
34
51
  if defined?(::Net) && defined?(::Net::HTTP)
35
- ::Net::HTTP.class_eval do
52
+
53
+ Net::HTTP.class_eval do
36
54
  alias request_without_apm request
37
55
 
38
56
  def request(req, body = nil, &block)
39
57
  unless (transaction = Atatus.current_transaction)
40
58
  return request_without_apm(req, body, &block)
41
59
  end
60
+
42
61
  if Atatus::Spies::NetHTTPSpy.disabled?
43
62
  return request_without_apm(req, body, &block)
44
63
  end
45
64
 
46
- host, = req['host'] && req['host'].split(':')
47
- method = req.method
65
+ host = req['host']&.split(':')&.first || address
66
+ method = req.method.to_s.upcase
67
+ path, query = req.path.split('?')
68
+
69
+ url = use_ssl? ? +'https://' : +'http://'
70
+ url << host
71
+ url << ":#{port}" if port
72
+ url << path
73
+ url << "?#{query}" if query
74
+ uri = URI(url)
48
75
 
49
- host ||= address
76
+ destination =
77
+ Atatus::Span::Context::Destination.from_uri(uri)
50
78
 
51
- name = "#{method} #{host}"
79
+ context =
80
+ Atatus::Span::Context.new(
81
+ http: { url: uri, method: method },
82
+ destination: destination
83
+ )
52
84
 
53
85
  Atatus.with_span(
54
- name,
86
+ "#{method} #{host}",
55
87
  TYPE,
56
88
  subtype: SUBTYPE,
57
- action: method.to_s
89
+ action: method,
90
+ context: context
58
91
  ) do |span|
59
92
  trace_context = span&.trace_context || transaction.trace_context
60
- req['Atatus-Apm-Traceparent'] = trace_context.to_header
61
- request_without_apm(req, body, &block)
93
+ trace_context.apply_headers { |key, value| req[key] = value }
94
+
95
+ result = request_without_apm(req, body, &block)
96
+
97
+ if (http = span&.context&.http)
98
+ http.status_code = result.code
99
+ end
100
+
101
+ result
62
102
  end
63
103
  end
64
104
  end
105
+
65
106
  end
66
107
  end
67
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
108
+ # rubocop:enable Metrics/CyclomaticComplexity
68
109
  end
69
110
 
70
111
  register 'Net::HTTP', 'net/http', NetHTTPSpy.new
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -5,40 +22,42 @@ module Atatus
5
22
  module Spies
6
23
  # @api private
7
24
  class RakeSpy
8
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
9
25
  def install
10
- ::Rake::Task.class_eval do
11
- alias execute_without_apm execute
26
+ if defined?(::Rake) && defined?(::Rake::Task)
12
27
 
13
- def execute(*args)
14
- agent = Atatus.start
28
+ ::Rake::Task.class_eval do
29
+ alias execute_without_apm execute
15
30
 
16
- unless agent && agent.config.instrumented_rake_tasks.include?(name)
17
- return execute_without_apm(*args)
18
- end
31
+ def execute(*args)
32
+ agent = Atatus.start
19
33
 
20
- transaction =
21
- Atatus.start_transaction("Rake::Task[#{name}]", 'Rake')
34
+ unless agent && agent.config.instrumented_rake_tasks.include?(name)
35
+ return execute_without_apm(*args)
36
+ end
22
37
 
23
- begin
24
- result = execute_without_apm(*args)
38
+ transaction =
39
+ Atatus.start_transaction("Rake::Task[#{name}]", 'Rake')
25
40
 
26
- transaction.result = 'success' if transaction
27
- rescue StandardError => e
28
- transaction.result = 'error' if transaction
29
- Atatus.report(e)
41
+ begin
42
+ result = execute_without_apm(*args)
30
43
 
31
- raise
32
- ensure
33
- Atatus.end_transaction
34
- Atatus.stop
35
- end
44
+ transaction.result = 'success' if transaction
45
+ rescue StandardError => e
46
+ transaction.result = 'error' if transaction
47
+ Atatus.report(e)
36
48
 
37
- result
49
+ raise
50
+ ensure
51
+ Atatus.end_transaction
52
+ Atatus.stop
53
+ end
54
+
55
+ result
56
+ end
38
57
  end
58
+
39
59
  end
40
60
  end
41
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
42
61
  end
43
62
  register 'Rake::Task', 'rake', RakeSpy.new
44
63
  end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -0,0 +1,57 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ module Atatus
21
+ # @api private
22
+ module Spies
23
+ # @api private
24
+ class ResqueSpy
25
+ TYPE = 'Resque'
26
+
27
+ def install
28
+ install_perform_spy
29
+ end
30
+
31
+ def install_perform_spy
32
+ if defined?(::Resque) && defined?(::Resque::Job)
33
+
34
+ ::Resque::Job.class_eval do
35
+ alias :perform_without_atatus :perform
36
+
37
+ def perform
38
+ name = @payload && @payload['class']&.to_s
39
+ transaction = Atatus.start_transaction(name, TYPE)
40
+ perform_without_atatus
41
+ transaction.done 'success'
42
+ rescue ::Exception => e
43
+ Atatus.report(e, handled: false)
44
+ transaction.done 'error' if transaction
45
+ raise
46
+ ensure
47
+ Atatus.end_transaction
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
54
+
55
+ register 'Resque', 'resque', ResqueSpy.new
56
+ end
57
+ end
@@ -1,47 +1,84 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
- require 'atatus/sql_summarizer'
20
+ require 'atatus/sql'
4
21
 
5
22
  module Atatus
6
23
  # @api private
7
24
  module Spies
8
25
  # @api private
9
26
  class SequelSpy
10
- TYPE = 'db.sequel.sql'
27
+ TYPE = 'db'
28
+ ACTION = 'query'
11
29
 
12
30
  def self.summarizer
13
- @summarizer ||= SqlSummarizer.new
14
- end
15
-
16
- def self.build_context(sql, opts)
17
- Span::Context.new(
18
- db: { statement: sql, type: 'sql', user: opts[:user] }
19
- )
31
+ @summarizer ||= Sql.summarizer
20
32
  end
21
33
 
22
- # rubocop:disable Metrics/MethodLength
23
34
  def install
24
35
  require 'sequel/database/logging'
25
36
 
26
37
  if defined?(::Sequel) && defined?(::Sequel::Database)
38
+
27
39
  ::Sequel::Database.class_eval do
28
40
  alias log_connection_yield_without_apm log_connection_yield
29
41
 
30
- def log_connection_yield(sql, *args, &block)
42
+ def log_connection_yield(sql, connection, args = nil, &block)
31
43
  unless Atatus.current_transaction
32
- return log_connection_yield_without_apm(sql, *args, &block)
44
+ return log_connection_yield_without_apm(
45
+ sql, connection, args, &block
46
+ )
33
47
  end
34
48
 
35
- summarizer = Atatus::Spies::SequelSpy.summarizer
36
- name = summarizer.summarize sql
37
- context = Atatus::Spies::SequelSpy.build_context(sql, opts)
49
+ subtype = database_type.to_s
38
50
 
39
- Atatus.with_span(name, TYPE, context: context, &block)
51
+ name =
52
+ Atatus::Spies::SequelSpy.summarizer.summarize sql
53
+
54
+ context = Atatus::Span::Context.new(
55
+ db: { statement: sql, type: 'sql', user: opts[:user] },
56
+ destination: { name: subtype, resource: subtype, type: TYPE }
57
+ )
58
+
59
+ span = Atatus.start_span(
60
+ name,
61
+ TYPE,
62
+ subtype: subtype,
63
+ action: ACTION,
64
+ context: context
65
+ )
66
+ yield.tap do |result|
67
+ if name =~ /^(UPDATE|DELETE)/
68
+ if connection.respond_to?(:changes)
69
+ span.context.db.rows_affected = connection.changes
70
+ elsif result.is_a?(Integer)
71
+ span.context.db.rows_affected = result
72
+ end
73
+ end
74
+ end
75
+ ensure
76
+ Atatus.end_span
40
77
  end
41
78
  end
79
+
42
80
  end
43
81
  end
44
- # rubocop:enable Metrics/MethodLength
45
82
  end
46
83
 
47
84
  register 'Sequel', 'sequel', SequelSpy.new
@@ -0,0 +1,69 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ module Atatus
21
+ # @api private
22
+ module Spies
23
+ # @api private
24
+ class ShoryukenSpy
25
+ # @api private
26
+ class Middleware
27
+ def call(worker_instance, queue, sqs_msg, body)
28
+ transaction =
29
+ Atatus.start_transaction(
30
+ job_class(worker_instance, body),
31
+ 'shoryuken.job'
32
+ )
33
+
34
+ Atatus.set_label('shoryuken.id', sqs_msg.message_id)
35
+ Atatus.set_label('shoryuken.queue', queue)
36
+
37
+ yield
38
+
39
+ transaction&.done :success
40
+ rescue ::Exception => e
41
+ Atatus.report(e, handled: false)
42
+ transaction&.done :error
43
+ raise
44
+ ensure
45
+ Atatus.end_transaction
46
+ end
47
+
48
+ private
49
+
50
+ def job_class(worker_instance, body)
51
+ klass = body['job_class'] if body.is_a?(Hash)
52
+ klass || worker_instance.class.name
53
+ end
54
+ end
55
+
56
+ def install
57
+ if defined?(::Shoryuken)
58
+
59
+ ::Shoryuken.server_middleware do |chain|
60
+ chain.add Middleware
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+
67
+ register 'Shoryuken', 'shoryuken', ShoryukenSpy.new
68
+ end
69
+ end
@@ -1,3 +1,20 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
1
18
  # frozen_string_literal: true
2
19
 
3
20
  module Atatus
@@ -10,7 +27,6 @@ module Atatus
10
27
 
11
28
  # @api private
12
29
  class Middleware
13
- # rubocop:disable Metrics/MethodLength
14
30
  def call(_worker, job, queue)
15
31
  name = SidekiqSpy.name_for(job)
16
32
  transaction = Atatus.start_transaction(name, 'Sidekiq')
@@ -18,15 +34,14 @@ module Atatus
18
34
 
19
35
  yield
20
36
 
21
- transaction.done :success if transaction
37
+ transaction&.done :success
22
38
  rescue ::Exception => e
23
39
  Atatus.report(e, handled: false)
24
- transaction.done :error if transaction
40
+ transaction&.done :error
25
41
  raise
26
42
  ensure
27
43
  Atatus.end_transaction
28
44
  end
29
- # rubocop:enable Metrics/MethodLength
30
45
  end
31
46
 
32
47
  def self.name_for(job)
@@ -41,42 +56,48 @@ module Atatus
41
56
  end
42
57
 
43
58
  def install_middleware
44
- Sidekiq.configure_server do |config|
45
- config.server_middleware do |chain|
46
- chain.add Middleware
59
+ if defined?(::Sidekiq)
60
+
61
+ Sidekiq.configure_server do |config|
62
+ config.server_middleware do |chain|
63
+ chain.add Middleware
64
+ end
47
65
  end
66
+
48
67
  end
49
68
  end
50
69
 
51
- # rubocop:disable Metrics/MethodLength
52
70
  def install_processor
53
71
  require 'sidekiq/processor'
54
72
 
55
- Sidekiq::Processor.class_eval do
56
- alias start_without_apm start
57
- alias terminate_without_apm terminate
73
+ if defined?(::Sidekiq) && defined?(::Sidekiq::Processor)
58
74
 
59
- def start
60
- result = start_without_apm
75
+ Sidekiq::Processor.class_eval do
76
+ alias start_without_apm start
77
+ alias terminate_without_apm terminate
61
78
 
62
- # Already running from Railtie if Rails
63
- if Atatus.running?
64
- Atatus.agent.config.logger = Sidekiq.logger
65
- else
66
- Atatus.start
67
- end
79
+ def start
80
+ result = start_without_apm
68
81
 
69
- result
70
- end
82
+ # Already running from Railtie if Rails
83
+ if Atatus.running?
84
+ Atatus.agent.config.logger = Sidekiq.logger
85
+ else
86
+ Atatus.start
87
+ end
88
+
89
+ result
90
+ end
71
91
 
72
- def terminate
73
- terminate_without_apm
92
+ def terminate
93
+ terminate_without_apm
74
94
 
75
- Atatus.stop
95
+ Atatus.stop
96
+ end
76
97
  end
98
+
77
99
  end
78
100
  end
79
- # rubocop:enable Metrics/MethodLength
80
101
 
81
102
  def install
82
103
  install_processor