ddtrace 0.45.0 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +79 -0
  3. data/.rubocop.yml +250 -7
  4. data/.rubocop_todo.yml +396 -0
  5. data/Appraisals +15 -0
  6. data/CHANGELOG.md +68 -1
  7. data/Gemfile +38 -3
  8. data/Rakefile +5 -23
  9. data/ddtrace.gemspec +6 -36
  10. data/docs/DevelopmentGuide.md +28 -0
  11. data/docs/GettingStarted.md +8 -9
  12. data/integration/README.md +68 -0
  13. data/integration/apps/rack/.dockerignore +1 -0
  14. data/integration/apps/rack/.envrc.sample +1 -0
  15. data/integration/apps/rack/.gitignore +4 -0
  16. data/integration/apps/rack/.rspec +1 -0
  17. data/integration/apps/rack/Dockerfile +25 -0
  18. data/integration/apps/rack/Dockerfile-ci +11 -0
  19. data/integration/apps/rack/Gemfile +24 -0
  20. data/integration/apps/rack/README.md +93 -0
  21. data/integration/apps/rack/app/acme.rb +80 -0
  22. data/integration/apps/rack/app/datadog.rb +17 -0
  23. data/integration/apps/rack/bin/run +22 -0
  24. data/integration/apps/rack/bin/setup +17 -0
  25. data/integration/apps/rack/bin/test +24 -0
  26. data/integration/apps/rack/config.ru +6 -0
  27. data/integration/apps/rack/config/puma.rb +14 -0
  28. data/integration/apps/rack/config/unicorn.rb +23 -0
  29. data/integration/apps/rack/docker-compose.ci.yml +62 -0
  30. data/integration/apps/rack/docker-compose.yml +78 -0
  31. data/integration/apps/rack/script/build-images +38 -0
  32. data/integration/apps/rack/script/ci +50 -0
  33. data/integration/apps/rack/spec/integration/basic_spec.rb +10 -0
  34. data/integration/apps/rack/spec/spec_helper.rb +16 -0
  35. data/integration/apps/rack/spec/support/integration_helper.rb +22 -0
  36. data/integration/apps/rails-five/.dockerignore +1 -0
  37. data/integration/apps/rails-five/.env +3 -0
  38. data/integration/apps/rails-five/.envrc.sample +1 -0
  39. data/integration/apps/rails-five/.gitignore +30 -0
  40. data/integration/apps/rails-five/Dockerfile +25 -0
  41. data/integration/apps/rails-five/Dockerfile-ci +11 -0
  42. data/integration/apps/rails-five/Gemfile +104 -0
  43. data/integration/apps/rails-five/README.md +94 -0
  44. data/integration/apps/rails-five/Rakefile +6 -0
  45. data/integration/apps/rails-five/app/channels/application_cable/channel.rb +4 -0
  46. data/integration/apps/rails-five/app/channels/application_cable/connection.rb +4 -0
  47. data/integration/apps/rails-five/app/controllers/application_controller.rb +2 -0
  48. data/integration/apps/rails-five/app/controllers/basic_controller.rb +36 -0
  49. data/integration/apps/rails-five/app/controllers/concerns/.keep +0 -0
  50. data/integration/apps/rails-five/app/controllers/health_controller.rb +9 -0
  51. data/integration/apps/rails-five/app/controllers/jobs_controller.rb +12 -0
  52. data/integration/apps/rails-five/app/jobs/application_job.rb +2 -0
  53. data/integration/apps/rails-five/app/jobs/test_job.rb +12 -0
  54. data/integration/apps/rails-five/app/mailers/application_mailer.rb +4 -0
  55. data/integration/apps/rails-five/app/models/application_record.rb +3 -0
  56. data/integration/apps/rails-five/app/models/concerns/.keep +0 -0
  57. data/integration/apps/rails-five/app/models/test.rb +2 -0
  58. data/integration/apps/rails-five/app/views/layouts/mailer.html.erb +13 -0
  59. data/integration/apps/rails-five/app/views/layouts/mailer.text.erb +1 -0
  60. data/integration/apps/rails-five/bin/bundle +3 -0
  61. data/integration/apps/rails-five/bin/rails +9 -0
  62. data/integration/apps/rails-five/bin/rake +9 -0
  63. data/integration/apps/rails-five/bin/run +24 -0
  64. data/integration/apps/rails-five/bin/setup +27 -0
  65. data/integration/apps/rails-five/bin/spring +17 -0
  66. data/integration/apps/rails-five/bin/test +21 -0
  67. data/integration/apps/rails-five/bin/update +28 -0
  68. data/integration/apps/rails-five/config.ru +5 -0
  69. data/integration/apps/rails-five/config/application.rb +97 -0
  70. data/integration/apps/rails-five/config/boot.rb +4 -0
  71. data/integration/apps/rails-five/config/cable.yml +10 -0
  72. data/integration/apps/rails-five/config/credentials.yml.enc +1 -0
  73. data/integration/apps/rails-five/config/database.yml +28 -0
  74. data/integration/apps/rails-five/config/environment.rb +5 -0
  75. data/integration/apps/rails-five/config/environments/development.rb +51 -0
  76. data/integration/apps/rails-five/config/environments/production.rb +82 -0
  77. data/integration/apps/rails-five/config/environments/test.rb +43 -0
  78. data/integration/apps/rails-five/config/initializers/datadog.rb +18 -0
  79. data/integration/apps/rails-five/config/initializers/filter_parameter_logging.rb +4 -0
  80. data/integration/apps/rails-five/config/initializers/resque.rb +4 -0
  81. data/integration/apps/rails-five/config/initializers/rollbar.rb +5 -0
  82. data/integration/apps/rails-five/config/initializers/wrap_parameters.rb +14 -0
  83. data/integration/apps/rails-five/config/locales/en.yml +33 -0
  84. data/integration/apps/rails-five/config/puma.rb +24 -0
  85. data/integration/apps/rails-five/config/routes.rb +11 -0
  86. data/integration/apps/rails-five/config/spring.rb +6 -0
  87. data/integration/apps/rails-five/config/unicorn.rb +29 -0
  88. data/integration/apps/rails-five/db/migrate/20190927215052_create_tests.rb +11 -0
  89. data/integration/apps/rails-five/db/schema.rb +23 -0
  90. data/integration/apps/rails-five/db/seeds.rb +7 -0
  91. data/integration/apps/rails-five/docker-compose.ci.yml +98 -0
  92. data/integration/apps/rails-five/docker-compose.yml +100 -0
  93. data/integration/apps/rails-five/lib/tasks/.keep +0 -0
  94. data/integration/apps/rails-five/log/.keep +0 -0
  95. data/integration/apps/rails-five/public/robots.txt +1 -0
  96. data/integration/apps/rails-five/script/build-images +35 -0
  97. data/integration/apps/rails-five/script/ci +50 -0
  98. data/integration/apps/rails-five/spec/integration/basic_spec.rb +10 -0
  99. data/integration/apps/rails-five/spec/spec_helper.rb +16 -0
  100. data/integration/apps/rails-five/spec/support/integration_helper.rb +22 -0
  101. data/integration/apps/rails-five/storage/.keep +0 -0
  102. data/integration/apps/rails-five/tmp/.keep +0 -0
  103. data/integration/apps/rails-five/vendor/.keep +0 -0
  104. data/integration/apps/ruby/.dockerignore +1 -0
  105. data/integration/apps/ruby/.envrc.sample +1 -0
  106. data/integration/apps/ruby/.gitignore +2 -0
  107. data/integration/apps/ruby/Dockerfile +25 -0
  108. data/integration/apps/ruby/Dockerfile-ci +11 -0
  109. data/integration/apps/ruby/Gemfile +11 -0
  110. data/integration/apps/ruby/README.md +70 -0
  111. data/integration/apps/ruby/agent.yaml +3 -0
  112. data/integration/apps/ruby/app/datadog.rb +13 -0
  113. data/integration/apps/ruby/app/fibonacci.rb +58 -0
  114. data/integration/apps/ruby/bin/run +20 -0
  115. data/integration/apps/ruby/bin/setup +17 -0
  116. data/integration/apps/ruby/bin/test +21 -0
  117. data/integration/apps/ruby/docker-compose.ci.yml +51 -0
  118. data/integration/apps/ruby/docker-compose.yml +63 -0
  119. data/integration/apps/ruby/script/build-images +38 -0
  120. data/integration/apps/ruby/script/ci +50 -0
  121. data/integration/images/agent/Dockerfile +2 -0
  122. data/integration/images/agent/agent.yaml +3 -0
  123. data/integration/images/include/datadog/analyzer.rb +71 -0
  124. data/integration/images/include/datadog/demo_env.rb +101 -0
  125. data/integration/images/include/http-health-check +33 -0
  126. data/integration/images/ruby/2.0/Dockerfile +54 -0
  127. data/integration/images/ruby/2.1/Dockerfile +54 -0
  128. data/integration/images/ruby/2.2/Dockerfile +54 -0
  129. data/integration/images/ruby/2.3/Dockerfile +70 -0
  130. data/integration/images/ruby/2.4/Dockerfile +54 -0
  131. data/integration/images/ruby/2.5/Dockerfile +54 -0
  132. data/integration/images/ruby/2.6/Dockerfile +54 -0
  133. data/integration/images/ruby/2.7/Dockerfile +54 -0
  134. data/integration/images/ruby/3.0/Dockerfile +54 -0
  135. data/integration/images/wrk/Dockerfile +33 -0
  136. data/integration/images/wrk/scripts/entrypoint.sh +17 -0
  137. data/integration/images/wrk/scripts/scenarios/basic/default.lua +1 -0
  138. data/integration/images/wrk/scripts/scenarios/basic/fibonacci.lua +1 -0
  139. data/integration/script/build-images +43 -0
  140. data/lib/ddtrace.rb +0 -5
  141. data/lib/ddtrace/analytics.rb +2 -0
  142. data/lib/ddtrace/buffer.rb +4 -4
  143. data/lib/ddtrace/configuration.rb +1 -1
  144. data/lib/ddtrace/configuration/base.rb +1 -1
  145. data/lib/ddtrace/configuration/components.rb +2 -2
  146. data/lib/ddtrace/configuration/option_definition.rb +1 -3
  147. data/lib/ddtrace/configuration/options.rb +2 -3
  148. data/lib/ddtrace/configuration/settings.rb +17 -3
  149. data/lib/ddtrace/context.rb +5 -6
  150. data/lib/ddtrace/context_provider.rb +1 -0
  151. data/lib/ddtrace/contrib/action_cable/event.rb +1 -0
  152. data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +1 -3
  153. data/lib/ddtrace/contrib/action_view/event.rb +1 -1
  154. data/lib/ddtrace/contrib/action_view/utils.rb +1 -1
  155. data/lib/ddtrace/contrib/active_record/configuration/resolver.rb +17 -5
  156. data/lib/ddtrace/contrib/active_record/utils.rb +1 -0
  157. data/lib/ddtrace/contrib/active_support/notifications/event.rb +2 -1
  158. data/lib/ddtrace/contrib/active_support/notifications/subscriber.rb +1 -0
  159. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +9 -5
  160. data/lib/ddtrace/contrib/auto_instrument.rb +1 -0
  161. data/lib/ddtrace/contrib/aws/patcher.rb +1 -0
  162. data/lib/ddtrace/contrib/aws/services.rb +1 -0
  163. data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +1 -4
  164. data/lib/ddtrace/contrib/cucumber/configuration/settings.rb +0 -10
  165. data/lib/ddtrace/contrib/cucumber/ext.rb +0 -2
  166. data/lib/ddtrace/contrib/cucumber/formatter.rb +5 -11
  167. data/lib/ddtrace/contrib/dalli/patcher.rb +0 -38
  168. data/lib/ddtrace/contrib/delayed_job/plugin.rb +0 -1
  169. data/lib/ddtrace/contrib/elasticsearch/quantize.rb +3 -2
  170. data/lib/ddtrace/contrib/ethon/easy_patch.rb +5 -5
  171. data/lib/ddtrace/contrib/excon/middleware.rb +2 -6
  172. data/lib/ddtrace/contrib/extensions.rb +1 -0
  173. data/lib/ddtrace/contrib/faraday/middleware.rb +1 -3
  174. data/lib/ddtrace/contrib/faraday/patcher.rb +0 -36
  175. data/lib/ddtrace/contrib/grape/endpoint.rb +8 -15
  176. data/lib/ddtrace/contrib/grape/patcher.rb +0 -42
  177. data/lib/ddtrace/contrib/grpc/datadog_interceptor.rb +8 -8
  178. data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +1 -0
  179. data/lib/ddtrace/contrib/grpc/patcher.rb +0 -36
  180. data/lib/ddtrace/contrib/http/circuit_breaker.rb +1 -3
  181. data/lib/ddtrace/contrib/http/instrumentation.rb +5 -5
  182. data/lib/ddtrace/contrib/httpclient/instrumentation.rb +2 -3
  183. data/lib/ddtrace/contrib/httprb/instrumentation.rb +2 -3
  184. data/lib/ddtrace/contrib/mongodb/instrumentation.rb +2 -0
  185. data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -3
  186. data/lib/ddtrace/contrib/patcher.rb +1 -1
  187. data/lib/ddtrace/contrib/qless/qless_job.rb +1 -0
  188. data/lib/ddtrace/contrib/qless/tracer_cleaner.rb +1 -0
  189. data/lib/ddtrace/contrib/que/ext.rb +19 -19
  190. data/lib/ddtrace/contrib/que/tracer.rb +1 -1
  191. data/lib/ddtrace/contrib/racecar/event.rb +1 -0
  192. data/lib/ddtrace/contrib/rack/configuration/settings.rb +3 -3
  193. data/lib/ddtrace/contrib/rack/middlewares.rb +5 -10
  194. data/lib/ddtrace/contrib/rack/patcher.rb +1 -3
  195. data/lib/ddtrace/contrib/rake/instrumentation.rb +4 -2
  196. data/lib/ddtrace/contrib/redis/quantize.rb +1 -0
  197. data/lib/ddtrace/contrib/redis/vendor/LICENSE +20 -0
  198. data/lib/ddtrace/contrib/redis/vendor/resolver.rb +6 -7
  199. data/lib/ddtrace/contrib/registry.rb +2 -2
  200. data/lib/ddtrace/contrib/resque/resque_job.rb +2 -0
  201. data/lib/ddtrace/contrib/rest_client/request_patch.rb +1 -3
  202. data/lib/ddtrace/contrib/rspec/configuration/settings.rb +0 -10
  203. data/lib/ddtrace/contrib/rspec/example.rb +24 -10
  204. data/lib/ddtrace/contrib/rspec/ext.rb +0 -3
  205. data/lib/ddtrace/contrib/rspec/integration.rb +1 -1
  206. data/lib/ddtrace/contrib/rspec/patcher.rb +0 -2
  207. data/lib/ddtrace/contrib/sequel/utils.rb +5 -6
  208. data/lib/ddtrace/contrib/shoryuken/tracer.rb +0 -1
  209. data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +2 -7
  210. data/lib/ddtrace/contrib/sidekiq/tracing.rb +0 -1
  211. data/lib/ddtrace/contrib/sinatra/env.rb +1 -3
  212. data/lib/ddtrace/contrib/sinatra/headers.rb +1 -3
  213. data/lib/ddtrace/contrib/sinatra/tracer.rb +1 -3
  214. data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +3 -3
  215. data/lib/ddtrace/contrib/sneakers/ext.rb +11 -11
  216. data/lib/ddtrace/contrib/sneakers/tracer.rb +2 -4
  217. data/lib/ddtrace/contrib/status_code_matcher.rb +5 -3
  218. data/lib/ddtrace/correlation.rb +1 -0
  219. data/lib/ddtrace/diagnostics/environment_logger.rb +2 -1
  220. data/lib/ddtrace/distributed_tracing/headers/headers.rb +1 -0
  221. data/lib/ddtrace/distributed_tracing/headers/helpers.rb +1 -3
  222. data/lib/ddtrace/ext/ci.rb +2 -2
  223. data/lib/ddtrace/ext/distributed.rb +1 -1
  224. data/lib/ddtrace/ext/http.rb +1 -1
  225. data/lib/ddtrace/ext/runtime.rb +1 -1
  226. data/lib/ddtrace/forced_tracing.rb +2 -0
  227. data/lib/ddtrace/logger.rb +1 -1
  228. data/lib/ddtrace/metrics.rb +10 -6
  229. data/lib/ddtrace/opentracer/distributed_headers.rb +3 -0
  230. data/lib/ddtrace/opentracer/span.rb +2 -6
  231. data/lib/ddtrace/opentracer/thread_local_scope.rb +1 -0
  232. data/lib/ddtrace/patcher.rb +2 -3
  233. data/lib/ddtrace/pin.rb +3 -52
  234. data/lib/ddtrace/pipeline/span_filter.rb +1 -1
  235. data/lib/ddtrace/propagation/grpc_propagator.rb +1 -0
  236. data/lib/ddtrace/quantization/http.rb +1 -0
  237. data/lib/ddtrace/runtime/cgroup.rb +1 -1
  238. data/lib/ddtrace/runtime/container.rb +2 -2
  239. data/lib/ddtrace/sampler.rb +1 -1
  240. data/lib/ddtrace/sampling/rule_sampler.rb +1 -0
  241. data/lib/ddtrace/span.rb +7 -7
  242. data/lib/ddtrace/sync_writer.rb +7 -10
  243. data/lib/ddtrace/tracer.rb +1 -1
  244. data/lib/ddtrace/transport/http.rb +1 -3
  245. data/lib/ddtrace/transport/http/adapters/net.rb +9 -4
  246. data/lib/ddtrace/transport/http/adapters/registry.rb +1 -0
  247. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +2 -4
  248. data/lib/ddtrace/transport/http/builder.rb +2 -0
  249. data/lib/ddtrace/transport/http/traces.rb +2 -3
  250. data/lib/ddtrace/transport/io.rb +1 -1
  251. data/lib/ddtrace/transport/traces.rb +3 -0
  252. data/lib/ddtrace/utils/time.rb +25 -1
  253. data/lib/ddtrace/vendor/active_record/MIT-LICENSE +20 -0
  254. data/lib/ddtrace/version.rb +1 -1
  255. data/lib/ddtrace/workers.rb +5 -0
  256. data/lib/ddtrace/workers/async.rb +8 -0
  257. data/lib/ddtrace/workers/loop.rb +3 -0
  258. data/lib/ddtrace/workers/polling.rb +1 -0
  259. data/lib/ddtrace/workers/trace_writer.rb +9 -10
  260. data/lib/ddtrace/writer.rb +3 -3
  261. metadata +133 -400
  262. data/lib/ddtrace/augmentation.rb +0 -13
  263. data/lib/ddtrace/augmentation/method_wrapper.rb +0 -20
  264. data/lib/ddtrace/augmentation/method_wrapping.rb +0 -38
  265. data/lib/ddtrace/augmentation/shim.rb +0 -102
  266. data/lib/ddtrace/contrib/rspec/example_group.rb +0 -61
  267. data/lib/ddtrace/monkey.rb +0 -58
@@ -56,6 +56,7 @@ module Datadog
56
56
 
57
57
  def auth_command?(command_args)
58
58
  return false unless command_args.is_a?(Array) && !command_args.empty?
59
+
59
60
  command_args.first.to_sym == :auth
60
61
  end
61
62
 
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ezra Zygmuntowicz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -56,11 +56,9 @@ module Datadog
56
56
  defaults = DEFAULTS.dup
57
57
  options = options.dup
58
58
 
59
- defaults.keys.each do |key|
59
+ defaults.each_key do |key|
60
60
  # Fill in defaults if needed
61
- if defaults[key].respond_to?(:call)
62
- defaults[key] = defaults[key].call
63
- end
61
+ defaults[key] = defaults[key].call if defaults[key].respond_to?(:call)
64
62
 
65
63
  # Symbolize only keys that are needed
66
64
  options[key] = options[key.to_s] if options.key?(key.to_s)
@@ -73,9 +71,10 @@ module Datadog
73
71
  if url
74
72
  uri = URI(url)
75
73
 
76
- if uri.scheme == 'unix'
74
+ case uri.scheme
75
+ when 'unix'
77
76
  defaults[:path] = uri.path
78
- elsif uri.scheme == 'redis' || uri.scheme == 'rediss'
77
+ when 'redis', 'rediss'
79
78
  defaults[:scheme] = uri.scheme
80
79
  defaults[:host] = uri.host if uri.host
81
80
  defaults[:port] = uri.port if uri.port
@@ -90,7 +89,7 @@ module Datadog
90
89
  end
91
90
 
92
91
  # Use default when option is not specified or nil
93
- defaults.keys.each do |key|
92
+ defaults.each_key do |key|
94
93
  options[key] = defaults[key] if options[key].nil?
95
94
  end
96
95
 
@@ -17,9 +17,9 @@ module Datadog
17
17
  end
18
18
  end
19
19
 
20
- def each
20
+ def each(&block)
21
21
  @mutex.synchronize do
22
- @data.each { |_, entry| yield(entry) }
22
+ @data.each_value(&block)
23
23
  end
24
24
  end
25
25
 
@@ -44,6 +44,7 @@ module Datadog
44
44
  def forked?
45
45
  pin = Datadog::Pin.get_from(::Resque)
46
46
  return false unless pin
47
+
47
48
  pin.config[:forked] == true
48
49
  end
49
50
 
@@ -76,5 +77,6 @@ Resque.after_fork do
76
77
 
77
78
  # Clean the state so no CoW happens
78
79
  next if configuration[:tracer].nil?
80
+
79
81
  configuration[:tracer].provider.context = nil
80
82
  end
@@ -54,9 +54,7 @@ module Datadog
54
54
  yield(span).tap do |response|
55
55
  # Verify return value is a response
56
56
  # If so, add additional tags.
57
- if response.is_a?(::RestClient::Response)
58
- span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.code)
59
- end
57
+ span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.code) if response.is_a?(::RestClient::Response)
60
58
  end
61
59
  rescue ::RestClient::ExceptionWithResponse => e
62
60
  span.set_error(e) if Datadog::Ext::HTTP::ERROR_RANGE.cover?(e.http_code)
@@ -12,16 +12,6 @@ module Datadog
12
12
  o.lazy
13
13
  end
14
14
 
15
- option :analytics_enabled do |o|
16
- o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, true) }
17
- o.lazy
18
- end
19
-
20
- option :analytics_sample_rate do |o|
21
- o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }
22
- o.lazy
23
- end
24
-
25
15
  option :service_name do |o|
26
16
  o.default { Datadog.configuration.service || Ext::SERVICE_NAME }
27
17
  o.lazy
@@ -10,30 +10,29 @@ module Datadog
10
10
  # Instance methods for configuration
11
11
  module InstanceMethods
12
12
  def run(example_group_instance, reporter)
13
- configuration = Datadog.configuration[:rspec]
14
13
  return super unless configuration[:enabled]
15
14
 
16
- test_name = "#{example_group.description}::#{description}"
15
+ test_name = full_description.strip
16
+ if metadata[:description].empty?
17
+ # for unnamed it blocks this appends something like "example at ./spec/some_spec.rb:10"
18
+ test_name += " #{description}"
19
+ end
20
+
17
21
  trace_options = {
18
22
  app: Ext::APP,
19
23
  resource: test_name,
20
24
  service: configuration[:service_name],
21
25
  span_type: Datadog::Ext::AppTypes::TEST,
22
- tags: example_group.instance_variable_get(:@tags).merge(Datadog.configuration.tags)
26
+ tags: tags.merge(Datadog.configuration.tags)
23
27
  }
24
28
 
25
- configuration[:tracer].trace(configuration[:operation_name], trace_options) do |span|
29
+ tracer.trace(configuration[:operation_name], trace_options) do |span|
26
30
  span.set_tag(Datadog::Ext::Test::TAG_FRAMEWORK, Ext::FRAMEWORK)
27
31
  span.set_tag(Datadog::Ext::Test::TAG_NAME, test_name)
28
- span.set_tag(Datadog::Ext::Test::TAG_SUITE, example_group.file_path)
32
+ span.set_tag(Datadog::Ext::Test::TAG_SUITE, file_path)
29
33
  span.set_tag(Datadog::Ext::Test::TAG_TYPE, Ext::TEST_TYPE)
30
34
  span.set_tag(Datadog::Ext::Test::TAG_SPAN_KIND, Datadog::Ext::AppTypes::TEST)
31
35
 
32
- # Set analytics sample rate
33
- if Datadog::Contrib::Analytics.enabled?(configuration[:analytics_enabled])
34
- Datadog::Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
35
- end
36
-
37
36
  # Measure service stats
38
37
  Contrib::Analytics.set_measured(span)
39
38
 
@@ -51,9 +50,24 @@ module Datadog
51
50
  span.set_tag(Datadog::Ext::Test::TAG_STATUS, Datadog::Ext::Test::Status::SKIP)
52
51
  end
53
52
  end
53
+
54
54
  result
55
55
  end
56
56
  end
57
+
58
+ private
59
+
60
+ def configuration
61
+ Datadog.configuration[:rspec]
62
+ end
63
+
64
+ def tracer
65
+ configuration[:tracer]
66
+ end
67
+
68
+ def tags
69
+ @tags ||= Datadog::Ext::CI.tags(ENV)
70
+ end
57
71
  end
58
72
  end
59
73
  end
@@ -4,13 +4,10 @@ module Datadog
4
4
  # RSpec integration constants
5
5
  module Ext
6
6
  APP = 'rspec'.freeze
7
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_RSPEC_ANALYTICS_ENABLED'.freeze
8
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_RSPEC_ANALYTICS_SAMPLE_RATE'.freeze
9
7
  ENV_ENABLED = 'DD_TRACE_RSPEC_ENABLED'.freeze
10
8
  ENV_OPERATION_NAME = 'DD_TRACE_RSPEC_OPERATION_NAME'.freeze
11
9
  FRAMEWORK = 'rspec'.freeze
12
10
  OPERATION_NAME = 'rspec.example'.freeze
13
- EXAMPLE_GROUP_OPERATION_NAME = 'rspec.example_group'.freeze
14
11
  SERVICE_NAME = 'rspec'.freeze
15
12
  TEST_TYPE = 'test'.freeze
16
13
  end
@@ -21,7 +21,7 @@ module Datadog
21
21
 
22
22
  def self.loaded?
23
23
  !defined?(::RSpec).nil? && !defined?(::RSpec::Core).nil? && \
24
- !defined?(::RSpec::Core::Example).nil? && !defined?(::RSpec::Core::ExampleGroup).nil?
24
+ !defined?(::RSpec::Core::Example).nil?
25
25
  end
26
26
 
27
27
  def self.compatible?
@@ -1,6 +1,5 @@
1
1
  require 'ddtrace/contrib/patcher'
2
2
  require 'ddtrace/contrib/rspec/example'
3
- require 'ddtrace/contrib/rspec/example_group'
4
3
 
5
4
  module Datadog
6
5
  module Contrib
@@ -17,7 +16,6 @@ module Datadog
17
16
 
18
17
  def patch
19
18
  ::RSpec::Core::Example.send(:include, Example)
20
- ::RSpec::Core::ExampleGroup.send(:include, ExampleGroup)
21
19
  end
22
20
  end
23
21
  end
@@ -30,12 +30,11 @@ module Datadog
30
30
 
31
31
  def parse_opts(sql, opts, db_opts, dataset = nil)
32
32
  # Prepared statements don't provide their sql query in the +sql+ parameter.
33
- unless sql.is_a?(String)
34
- if dataset && dataset.respond_to?(:prepared_sql) && (resolved_sql = dataset.prepared_sql)
35
- # The dataset contains the resolved SQL query and prepared statement name.
36
- prepared_name = dataset.prepared_statement_name
37
- sql = resolved_sql
38
- end
33
+ if !sql.is_a?(String) && (dataset && dataset.respond_to?(:prepared_sql) &&
34
+ (resolved_sql = dataset.prepared_sql))
35
+ # The dataset contains the resolved SQL query and prepared statement name.
36
+ prepared_name = dataset.prepared_statement_name
37
+ sql = resolved_sql
39
38
  end
40
39
 
41
40
  {
@@ -14,7 +14,6 @@ module Datadog
14
14
  def call(worker_instance, queue, sqs_msg, body)
15
15
  @tracer.trace(Ext::SPAN_JOB, service: @shoryuken_service, span_type: Datadog::Ext::AppTypes::WORKER,
16
16
  on_error: @error_handler) do |span|
17
-
18
17
  # Set analytics sample rate
19
18
  if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
20
19
  Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
@@ -22,7 +22,6 @@ module Datadog
22
22
 
23
23
  @tracer.trace(Ext::SPAN_JOB, service: service, span_type: Datadog::Ext::AppTypes::WORKER,
24
24
  on_error: @error_handler) do |span|
25
-
26
25
  span.resource = resource
27
26
  # Set analytics sample rate
28
27
  if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
@@ -38,9 +37,7 @@ module Datadog
38
37
  span.set_tag(Ext::TAG_JOB_QUEUE, job['queue'])
39
38
  span.set_tag(Ext::TAG_JOB_WRAPPER, job['class']) if job['wrapped']
40
39
  span.set_tag(Ext::TAG_JOB_DELAY, 1000.0 * (Time.now.utc.to_f - job['enqueued_at'].to_f))
41
- if tag_args && !job['args'].nil? && !job['args'].empty?
42
- span.set_tag(Ext::TAG_JOB_ARGS, job['args'])
43
- end
40
+ span.set_tag(Ext::TAG_JOB_ARGS, job['args']) if tag_args && !job['args'].nil? && !job['args'].empty?
44
41
 
45
42
  yield
46
43
  end
@@ -60,9 +57,7 @@ module Datadog
60
57
  nil
61
58
  end
62
59
 
63
- if worker_klass.respond_to?(:datadog_tracer_config)
64
- worker_klass.datadog_tracer_config[key]
65
- end
60
+ worker_klass.datadog_tracer_config[key] if worker_klass.respond_to?(:datadog_tracer_config)
66
61
  end
67
62
  end
68
63
  end
@@ -31,7 +31,6 @@ module Datadog
31
31
  job['class'].to_s
32
32
  end
33
33
 
34
- #
35
34
  def delay_extension_class(job)
36
35
  clazz, method = YAML.parse(job['args'].first).children.first.children
37
36
 
@@ -23,9 +23,7 @@ module Datadog
23
23
  {}.tap do |result|
24
24
  headers.each do |header|
25
25
  rack_header = header_to_rack_header(header)
26
- if env.key?(rack_header)
27
- result[Datadog::Ext::HTTP::RequestHeaders.to_tag(header)] = env[rack_header]
28
- end
26
+ result[Datadog::Ext::HTTP::RequestHeaders.to_tag(header)] = env[rack_header] if env.key?(rack_header)
29
27
  end
30
28
  end
31
29
  end
@@ -18,9 +18,7 @@ module Datadog
18
18
  # Try a case-insensitive lookup
19
19
  uppercased_header = header.to_s.upcase
20
20
  matching_header = headers.keys.find { |h| h.upcase == uppercased_header }
21
- if matching_header
22
- result[Datadog::Ext::HTTP::ResponseHeaders.to_tag(header)] = headers[matching_header]
23
- end
21
+ result[Datadog::Ext::HTTP::ResponseHeaders.to_tag(header)] = headers[matching_header] if matching_header
24
22
  end
25
23
  end
26
24
  end
@@ -110,9 +110,7 @@ module Datadog
110
110
 
111
111
  span.set_tag(Ext::TAG_APP_NAME, settings.name || settings.superclass.name)
112
112
  span.set_tag(Ext::TAG_ROUTE_PATH, @datadog_route)
113
- if request.script_name && !request.script_name.empty?
114
- span.set_tag(Ext::TAG_SCRIPT_NAME, request.script_name)
115
- end
113
+ span.set_tag(Ext::TAG_SCRIPT_NAME, request.script_name) if request.script_name && !request.script_name.empty?
116
114
 
117
115
  rack_request_span = env[Datadog::Contrib::Rack::TraceMiddleware::RACK_REQUEST_SPAN]
118
116
  rack_request_span.resource = span.resource if rack_request_span
@@ -15,6 +15,8 @@ module Datadog
15
15
 
16
16
  # rubocop:disable Metrics/AbcSize
17
17
  # rubocop:disable Metrics/MethodLength
18
+ # rubocop:disable Metrics/CyclomaticComplexity
19
+ # rubocop:disable Metrics/PerceivedComplexity
18
20
  def call(env)
19
21
  # Set the trace context (e.g. distributed tracing)
20
22
  if configuration[:distributed_tracing] && tracer.provider.context.trace_id.nil?
@@ -40,9 +42,7 @@ module Datadog
40
42
  request = ::Sinatra::Request.new(env)
41
43
  span.set_tag(Datadog::Ext::HTTP::URL, request.path)
42
44
  span.set_tag(Datadog::Ext::HTTP::METHOD, request.request_method)
43
- if request.script_name && !request.script_name.empty?
44
- span.set_tag(Ext::TAG_SCRIPT_NAME, request.script_name)
45
- end
45
+ span.set_tag(Ext::TAG_SCRIPT_NAME, request.script_name) if request.script_name && !request.script_name.empty?
46
46
 
47
47
  span.set_tag(Ext::TAG_APP_NAME, @app_instance.settings.name)
48
48
 
@@ -5,17 +5,17 @@ module Datadog
5
5
  module Sneakers
6
6
  # Sneakers integration constants
7
7
  module Ext
8
- APP = 'sneakers'.freeze
9
- ENV_ENABLED = 'DD_TRACE_SNEAKERS_ENABLED'.freeze
10
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_SNEAKERS_ANALYTICS_ENABLED'.freeze
11
- ENV_ANALYTICS_ENABLED_OLD = 'DD_SNEAKERS_ANALYTICS_ENABLED'.freeze
12
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_SNEAKERS_ANALYTICS_SAMPLE_RATE'.freeze
13
- ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_SNEAKERS_ANALYTICS_SAMPLE_RATE'.freeze
14
- SERVICE_NAME = 'sneakers'.freeze
15
- SPAN_JOB = 'sneakers.job'.freeze
16
- TAG_JOB_ROUTING_KEY = 'sneakers.routing_key'.freeze
17
- TAG_JOB_QUEUE = 'sneakers.queue'.freeze
18
- TAG_JOB_BODY = 'sneakers.body'.freeze
8
+ APP = 'sneakers'
9
+ ENV_ENABLED = 'DD_TRACE_SNEAKERS_ENABLED'
10
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_SNEAKERS_ANALYTICS_ENABLED'
11
+ ENV_ANALYTICS_ENABLED_OLD = 'DD_SNEAKERS_ANALYTICS_ENABLED'
12
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_SNEAKERS_ANALYTICS_SAMPLE_RATE'
13
+ ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_SNEAKERS_ANALYTICS_SAMPLE_RATE'
14
+ SERVICE_NAME = 'sneakers'
15
+ SPAN_JOB = 'sneakers.job'
16
+ TAG_JOB_ROUTING_KEY = 'sneakers.routing_key'
17
+ TAG_JOB_QUEUE = 'sneakers.queue'
18
+ TAG_JOB_BODY = 'sneakers.body'
19
19
  end
20
20
  end
21
21
  end
@@ -14,7 +14,7 @@ module Datadog
14
14
 
15
15
  def call(deserialized_msg, delivery_info, metadata, handler)
16
16
  trace_options = {
17
- service: configuration[:service_name],
17
+ service: configuration[:service_name],
18
18
  span_type: Datadog::Ext::AppTypes::WORKER,
19
19
  on_error: configuration[:error_handler]
20
20
  }
@@ -32,9 +32,7 @@ module Datadog
32
32
  request_span.set_tag(Ext::TAG_JOB_ROUTING_KEY, delivery_info.routing_key)
33
33
  request_span.set_tag(Ext::TAG_JOB_QUEUE, delivery_info.consumer.queue.name)
34
34
 
35
- if configuration[:tag_body]
36
- request_span.set_tag(Ext::TAG_JOB_BODY, deserialized_msg)
37
- end
35
+ request_span.set_tag(Ext::TAG_JOB_BODY, deserialized_msg) if configuration[:tag_body]
38
36
 
39
37
  @app.call(deserialized_msg, delivery_info, metadata, handler)
40
38
  end
@@ -5,7 +5,7 @@ module Datadog
5
5
  module Contrib
6
6
  # Contains methods helpful for tracing/annotating HTTP request libraries
7
7
  class StatusCodeMatcher
8
- REGEX_PARSER = /^\d{3}(?:-\d{3})?(?:,\d{3}(?:-\d{3})?)*$/
8
+ REGEX_PARSER = /^\d{3}(?:-\d{3})?(?:,\d{3}(?:-\d{3})?)*$/.freeze
9
9
 
10
10
  def initialize(range)
11
11
  @error_response_range = range
@@ -27,9 +27,10 @@ module Datadog
27
27
  set = Set.new
28
28
  handle_statuses.each do |statuses|
29
29
  status = statuses.to_s.split('-')
30
- if status.length == 1
30
+ case status.length
31
+ when 1
31
32
  set.add(Integer(status[0]))
32
- elsif status.length == 2
33
+ when 2
33
34
  min, max = status.minmax
34
35
  Array(min..max).each do |i|
35
36
  set.add(Integer(i))
@@ -43,6 +44,7 @@ module Datadog
43
44
 
44
45
  def error_responses
45
46
  return @error_response_range if @error_response_range.is_a?(String) && !@error_response_range.nil?
47
+
46
48
  @error_response_range.join(',') if @error_response_range.is_a?(Array) && !@error_response_range.empty?
47
49
  end
48
50
 
@@ -32,6 +32,7 @@ module Datadog
32
32
  # Produces a CorrelationIdentifier from the Context provided
33
33
  def identifier_from_context(context)
34
34
  return Identifier.new.freeze if context.nil?
35
+
35
36
  Identifier.new(context.trace_id, context.span_id).freeze
36
37
  end
37
38
  end