atatus 1.3.0 → 1.4.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 (147) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile +72 -22
  4. data/LICENSE +1 -1
  5. data/atatus.gemspec +2 -2
  6. data/lib/atatus.rb +76 -16
  7. data/lib/atatus/agent.rb +78 -29
  8. data/lib/atatus/central_config.rb +72 -27
  9. data/lib/atatus/central_config/cache_control.rb +18 -1
  10. data/lib/atatus/child_durations.rb +64 -0
  11. data/lib/atatus/collector/base.rb +61 -29
  12. data/lib/atatus/collector/builder.rb +46 -2
  13. data/lib/atatus/collector/hist.rb +54 -0
  14. data/lib/atatus/collector/transport.rb +41 -11
  15. data/lib/atatus/config.rb +129 -28
  16. data/lib/atatus/config/bytes.rb +17 -0
  17. data/lib/atatus/config/duration.rb +17 -0
  18. data/lib/atatus/config/options.rb +29 -9
  19. data/lib/atatus/config/regexp_list.rb +17 -0
  20. data/lib/atatus/config/wildcard_pattern_list.rb +64 -0
  21. data/lib/atatus/context.rb +32 -1
  22. data/lib/atatus/context/request.rb +17 -0
  23. data/lib/atatus/context/request/socket.rb +18 -1
  24. data/lib/atatus/context/request/url.rb +17 -0
  25. data/lib/atatus/context/response.rb +27 -2
  26. data/lib/atatus/context/user.rb +17 -0
  27. data/lib/atatus/context_builder.rb +19 -4
  28. data/lib/atatus/deprecations.rb +17 -0
  29. data/lib/atatus/error.rb +27 -0
  30. data/lib/atatus/error/exception.rb +24 -0
  31. data/lib/atatus/error/log.rb +17 -0
  32. data/lib/atatus/error_builder.rb +17 -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.rb +17 -0
  40. data/lib/atatus/metadata/process_info.rb +17 -0
  41. data/lib/atatus/metadata/service_info.rb +21 -6
  42. data/lib/atatus/metadata/system_info.rb +22 -3
  43. data/lib/atatus/metadata/system_info/container_info.rb +49 -10
  44. data/lib/atatus/metadata/system_info/hw_info.rb +1 -1
  45. data/lib/atatus/metrics.rb +69 -27
  46. data/lib/atatus/metrics/breakdown_set.rb +31 -0
  47. data/lib/atatus/metrics/{cpu_mem.rb → cpu_mem_set.rb} +110 -63
  48. data/lib/atatus/metrics/metric.rb +140 -0
  49. data/lib/atatus/metrics/set.rb +123 -0
  50. data/lib/atatus/metrics/span_scoped_set.rb +56 -0
  51. data/lib/atatus/metrics/transaction_set.rb +26 -0
  52. data/lib/atatus/metrics/vm_set.rb +58 -0
  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.rb +23 -9
  57. data/lib/atatus/normalizers/grape.rb +22 -0
  58. data/lib/atatus/normalizers/grape/endpoint_run.rb +65 -0
  59. data/lib/atatus/normalizers/rails.rb +27 -0
  60. data/lib/atatus/normalizers/rails/action_controller.rb +44 -0
  61. data/lib/atatus/normalizers/rails/action_mailer.rb +43 -0
  62. data/lib/atatus/normalizers/{action_view.rb → rails/action_view.rb} +17 -0
  63. data/lib/atatus/normalizers/rails/active_record.rb +80 -0
  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.rb +44 -15
  70. data/lib/atatus/span/context.rb +43 -28
  71. data/lib/atatus/span/context/db.rb +43 -0
  72. data/lib/atatus/span/context/destination.rb +77 -0
  73. data/lib/atatus/span/context/http.rb +43 -0
  74. data/lib/atatus/span_helpers.rb +18 -1
  75. data/lib/atatus/spies.rb +33 -15
  76. data/lib/atatus/spies/action_dispatch.rb +27 -6
  77. data/lib/atatus/spies/delayed_job.rb +26 -5
  78. data/lib/atatus/spies/dynamo_db.rb +62 -0
  79. data/lib/atatus/spies/elasticsearch.rb +53 -7
  80. data/lib/atatus/spies/faraday.rb +54 -20
  81. data/lib/atatus/spies/http.rb +36 -6
  82. data/lib/atatus/spies/json.rb +18 -0
  83. data/lib/atatus/spies/mongo.rb +41 -10
  84. data/lib/atatus/spies/net_http.rb +52 -11
  85. data/lib/atatus/spies/rake.rb +42 -23
  86. data/lib/atatus/spies/redis.rb +17 -0
  87. data/lib/atatus/spies/resque.rb +57 -0
  88. data/lib/atatus/spies/sequel.rb +54 -17
  89. data/lib/atatus/spies/shoryuken.rb +69 -0
  90. data/lib/atatus/spies/sidekiq.rb +46 -25
  91. data/lib/atatus/spies/sinatra.rb +20 -4
  92. data/lib/atatus/spies/sneakers.rb +74 -0
  93. data/lib/atatus/spies/sucker_punch.rb +58 -0
  94. data/lib/atatus/spies/tilt.rb +20 -1
  95. data/lib/atatus/sql.rb +36 -0
  96. data/lib/atatus/sql/signature.rb +169 -0
  97. data/lib/atatus/sql/tokenizer.rb +264 -0
  98. data/lib/atatus/sql/tokens.rb +63 -0
  99. data/lib/atatus/sql_summarizer.rb +24 -6
  100. data/lib/atatus/stacktrace.rb +17 -0
  101. data/lib/atatus/stacktrace/frame.rb +17 -3
  102. data/lib/atatus/stacktrace_builder.rb +23 -3
  103. data/lib/atatus/subscriber.rb +23 -4
  104. data/lib/atatus/trace_context.rb +84 -51
  105. data/lib/atatus/trace_context/traceparent.rb +111 -0
  106. data/lib/atatus/trace_context/tracestate.rb +148 -0
  107. data/lib/atatus/transaction.rb +74 -18
  108. data/lib/atatus/transport/base.rb +44 -27
  109. data/lib/atatus/transport/connection.rb +28 -72
  110. data/lib/atatus/transport/connection/http.rb +58 -35
  111. data/lib/atatus/transport/connection/proxy_pipe.rb +24 -5
  112. data/lib/atatus/transport/filters.rb +18 -1
  113. data/lib/atatus/transport/filters/hash_sanitizer.rb +77 -0
  114. data/lib/atatus/transport/filters/secrets_filter.rb +30 -55
  115. data/lib/atatus/transport/headers.rb +83 -0
  116. data/lib/atatus/transport/serializers.rb +17 -5
  117. data/lib/atatus/transport/serializers/context_serializer.rb +30 -3
  118. data/lib/atatus/transport/serializers/error_serializer.rb +17 -2
  119. data/lib/atatus/transport/serializers/metadata_serializer.rb +44 -22
  120. data/lib/atatus/transport/serializers/metricset_serializer.rb +34 -6
  121. data/lib/atatus/transport/serializers/span_serializer.rb +47 -12
  122. data/lib/atatus/transport/serializers/transaction_serializer.rb +18 -2
  123. data/lib/atatus/transport/user_agent.rb +48 -0
  124. data/lib/atatus/transport/worker.rb +31 -7
  125. data/lib/atatus/util.rb +18 -1
  126. data/lib/atatus/util/inflector.rb +17 -0
  127. data/lib/atatus/util/lru_cache.rb +17 -0
  128. data/lib/atatus/util/throttle.rb +17 -0
  129. data/lib/atatus/version.rb +19 -1
  130. metadata +46 -26
  131. data/Rakefile +0 -19
  132. data/bench/.gitignore +0 -2
  133. data/bench/app.rb +0 -53
  134. data/bench/benchmark.rb +0 -36
  135. data/bench/report.rb +0 -55
  136. data/bench/rubyprof.rb +0 -39
  137. data/bench/stackprof.rb +0 -23
  138. data/bin/build_docs +0 -5
  139. data/bin/console +0 -15
  140. data/bin/setup +0 -8
  141. data/bin/with_framework +0 -7
  142. data/lib/atatus/metrics/vm.rb +0 -60
  143. data/lib/atatus/normalizers/action_controller.rb +0 -27
  144. data/lib/atatus/normalizers/action_mailer.rb +0 -26
  145. data/lib/atatus/normalizers/active_record.rb +0 -45
  146. data/lib/atatus/util/prefixed_logger.rb +0 -18
  147. 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
@@ -16,8 +33,6 @@ module Atatus
16
33
  end
17
34
  end
18
35
 
19
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
20
- # rubocop:disable Metrics/BlockLength, Metrics/PerceivedComplexity
21
36
  # rubocop:disable Metrics/CyclomaticComplexity
22
37
  def install
23
38
  if defined?(::Faraday) && defined?(::Faraday::Connection)
@@ -30,42 +45,61 @@ module Atatus
30
45
  return run_request_without_apm(method, url, body, headers, &block)
31
46
  end
32
47
 
33
- host = if url_prefix.is_a?(URI) && url_prefix.host
34
- url_prefix.host
35
- elsif url.nil?
36
- tmp_request = build_request(method) do |req|
37
- yield(req) if block_given?
38
- end
39
- URI(tmp_request.path).host
40
- else
41
- URI(url).host
42
- end
48
+ uri = URI(build_url(url))
49
+
50
+ # If url is set inside block it isn't available until yield,
51
+ # so we temporarily build the request to yield. This could be a
52
+ # problem if the block has side effects as it will be yielded twice
53
+ # ~mikker
54
+ unless uri.host
55
+ tmp_request = build_request(method) do |req|
56
+ yield(req) if block_given?
57
+ end
58
+ uri = URI(tmp_request.path)
59
+ end
60
+
61
+ host = uri.host
43
62
 
44
- name = "#{method.upcase} #{host}"
63
+ upcased_method = method.to_s.upcase
64
+
65
+ destination = Atatus::Span::Context::Destination.from_uri(uri)
66
+
67
+ context =
68
+ Atatus::Span::Context.new(
69
+ http: { url: uri, method: upcased_method },
70
+ destination: destination
71
+ )
45
72
 
46
73
  Atatus.with_span(
47
- name,
74
+ "#{upcased_method} #{host}",
48
75
  TYPE,
49
76
  subtype: SUBTYPE,
50
- action: method.to_s
77
+ action: upcased_method,
78
+ context: context
51
79
  ) do |span|
52
80
  Atatus::Spies::FaradaySpy.without_net_http do
53
81
  trace_context = span&.trace_context || transaction.trace_context
54
82
 
55
- run_request_without_apm(method, url, body, headers) do |req|
56
- req['Atatus-Apm-Traceparent'] = trace_context.to_header
83
+ result =
84
+ run_request_without_apm(method, url, body, headers) do |req|
85
+ trace_context.apply_headers { |k, v| req[k] = v }
86
+
87
+ yield req if block_given?
88
+ end
57
89
 
58
- yield req if block_given?
90
+ if (http = span&.context&.http)
91
+ http.status_code = result.status.to_s
59
92
  end
93
+
94
+ result
60
95
  end
61
96
  end
62
97
  end
63
98
  end
99
+
64
100
  end
65
101
  end
66
102
  # rubocop:enable Metrics/CyclomaticComplexity
67
- # rubocop:enable Metrics/BlockLength, Metrics/PerceivedComplexity
68
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
69
103
  end
70
104
 
71
105
  register 'Faraday', 'faraday', FaradaySpy.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
@@ -7,8 +24,6 @@ module Atatus
7
24
  class HTTPSpy
8
25
  TYPE = 'ext'
9
26
  SUBTYPE = 'http_rb'
10
-
11
- # rubocop:disable Metrics/MethodLength
12
27
  def install
13
28
  if defined?(::HTTP) && defined?(::HTTP::Client)
14
29
 
@@ -23,23 +38,38 @@ module Atatus
23
38
  method = req.verb.to_s.upcase
24
39
  host = req.uri.host
25
40
 
41
+ destination =
42
+ Atatus::Span::Context::Destination.from_uri(req.uri)
43
+ context = Atatus::Span::Context.new(
44
+ http: { url: req.uri, method: method },
45
+ destination: destination
46
+ )
47
+
26
48
  name = "#{method} #{host}"
27
49
 
28
50
  Atatus.with_span(
29
51
  name,
30
52
  TYPE,
31
53
  subtype: SUBTYPE,
32
- action: method
54
+ action: method,
55
+ context: context
33
56
  ) do |span|
34
57
  trace_context = span&.trace_context || transaction.trace_context
35
- req['Atatus-Apm-Traceparent'] = trace_context.to_header
36
- perform_without_apm(req, options)
58
+ trace_context.apply_headers { |key, value| req[key] = value }
59
+
60
+ result = perform_without_apm(req, options)
61
+
62
+ if (http = span&.context&.http)
63
+ http.status_code = result.status.to_s
64
+ end
65
+
66
+ result
37
67
  end
38
68
  end
39
69
  end
70
+
40
71
  end
41
72
  end
42
- # rubocop:enable Metrics/MethodLength
43
73
  end
44
74
 
45
75
  register 'HTTP', 'http', HTTPSpy.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
  require 'atatus/span_helpers'
@@ -16,6 +33,7 @@ module Atatus
16
33
  span_class_method :parse!, 'JSON#parse!', 'json.parse'
17
34
  span_class_method :generate, 'JSON#generate', 'json.generate'
18
35
  end
36
+
19
37
  end
20
38
  end
21
39
  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
@@ -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