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
@@ -22,51 +22,9 @@ module Datadog
22
22
  # Patch endpoints
23
23
  ::Grape::Endpoint.send(:include, Instrumentation)
24
24
 
25
- add_pin!
26
-
27
25
  # Subscribe to ActiveSupport events
28
26
  Datadog::Contrib::Grape::Endpoint.subscribe
29
27
  end
30
-
31
- def add_pin!
32
- # Attach a Pin object globally and set the service once
33
- pin = DeprecatedPin.new(
34
- get_option(:service_name),
35
- app: Ext::APP,
36
- app_type: Datadog::Ext::AppTypes::WEB,
37
- tracer: -> { get_option(:tracer) }
38
- )
39
- pin.onto(::Grape)
40
- end
41
-
42
- def get_option(option)
43
- Datadog.configuration[:grape].get_option(option)
44
- end
45
-
46
- # Implementation of deprecated Pin, which raises warnings when accessed.
47
- # To be removed when support for Datadog::Pin with Grape is removed.
48
- class DeprecatedPin < Datadog::Pin
49
- include Datadog::DeprecatedPin
50
-
51
- DEPRECATION_WARNING = %(
52
- Use of Datadog::Pin with Grape is DEPRECATED.
53
- Upgrade to the configuration API using the migration guide here:
54
- https://github.com/DataDog/dd-trace-rb/releases/tag/v0.11.0).freeze
55
-
56
- def tracer=(tracer)
57
- Datadog.configuration[:grape][:tracer] = tracer
58
- end
59
-
60
- def service_name=(service_name)
61
- Datadog.configuration[:grape][:service_name] = service_name
62
- end
63
-
64
- def log_deprecation_warning(method_name)
65
- do_once(method_name) do
66
- Datadog.logger.warn("#{method_name}:#{DEPRECATION_WARNING}")
67
- end
68
- end
69
- end
70
28
  end
71
29
  end
72
30
  end
@@ -15,20 +15,20 @@ module Datadog
15
15
  add_datadog_pin! { |c| yield(c) if block_given? }
16
16
  end
17
17
 
18
- def request_response(**keywords)
19
- trace(keywords) { yield }
18
+ def request_response(**keywords, &block)
19
+ trace(keywords, &block)
20
20
  end
21
21
 
22
- def client_streamer(**keywords)
23
- trace(keywords) { yield }
22
+ def client_streamer(**keywords, &block)
23
+ trace(keywords, &block)
24
24
  end
25
25
 
26
- def server_streamer(**keywords)
27
- trace(keywords) { yield }
26
+ def server_streamer(**keywords, &block)
27
+ trace(keywords, &block)
28
28
  end
29
29
 
30
- def bidi_streamer(**keywords)
31
- trace(keywords) { yield }
30
+ def bidi_streamer(**keywords, &block)
31
+ trace(keywords, &block)
32
32
  end
33
33
 
34
34
  private
@@ -44,6 +44,7 @@ module Datadog
44
44
  def annotate!(span, metadata)
45
45
  metadata.each do |header, value|
46
46
  next if reserved_headers.include?(header)
47
+
47
48
  span.set_tag(header, value)
48
49
  end
49
50
 
@@ -19,49 +19,13 @@ module Datadog
19
19
  require 'ddtrace/contrib/grpc/datadog_interceptor'
20
20
  require 'ddtrace/contrib/grpc/intercept_with_datadog'
21
21
 
22
- add_pin!
23
-
24
22
  prepend_interceptor
25
23
  end
26
24
 
27
- def add_pin!
28
- DeprecatedPin.new(
29
- get_option(:service_name),
30
- app: Ext::APP,
31
- app_type: Datadog::Ext::AppTypes::WEB,
32
- tracer: -> { get_option(:tracer) }
33
- ).onto(::GRPC)
34
- end
35
-
36
25
  def prepend_interceptor
37
26
  ::GRPC::InterceptionContext
38
27
  .send(:prepend, Datadog::Contrib::GRPC::InterceptWithDatadog)
39
28
  end
40
-
41
- def get_option(option)
42
- Datadog.configuration[:grpc].get_option(option)
43
- end
44
-
45
- # Implementation of deprecated Pin, which raises warnings when accessed.
46
- # To be removed when support for Datadog::Pin with GRPC is removed.
47
- class DeprecatedPin < Datadog::Pin
48
- include Datadog::DeprecatedPin
49
-
50
- DEPRECATION_WARNING = %(
51
- Use of Datadog::Pin with GRPC is DEPRECATED.
52
- Upgrade to the configuration API using the migration guide here:
53
- https://github.com/DataDog/dd-trace-rb/releases/tag/v0.11.0).freeze
54
-
55
- def service_name=(service_name)
56
- Datadog.configuration[:grpc][:service_name] = service_name
57
- end
58
-
59
- def log_deprecation_warning(method_name)
60
- do_once(method_name) do
61
- Datadog.logger.warn("#{method_name}:#{DEPRECATION_WARNING}")
62
- end
63
- end
64
- end
65
29
  end
66
30
  end
67
31
  end
@@ -27,9 +27,7 @@ module Datadog
27
27
  end
28
28
 
29
29
  def should_skip_distributed_tracing?(pin)
30
- if pin.config && pin.config.key?(:distributed_tracing)
31
- return !pin.config[:distributed_tracing]
32
- end
30
+ return !pin.config[:distributed_tracing] if pin.config && pin.config.key?(:distributed_tracing)
33
31
 
34
32
  !Datadog.configuration[:http][:distributed_tracing]
35
33
  end
@@ -19,7 +19,7 @@ module Datadog
19
19
 
20
20
  # Span hook invoked after request is completed.
21
21
  def self.after_request(&block)
22
- if block_given?
22
+ if block
23
23
  # Set hook
24
24
  @after_request = block
25
25
  else
@@ -32,15 +32,14 @@ module Datadog
32
32
  module InstanceMethods
33
33
  include Datadog::Contrib::HttpAnnotationHelper
34
34
 
35
- def request(req, body = nil, &block) # :yield: +response+
35
+ # :yield: +response+
36
+ def request(req, body = nil, &block)
36
37
  host, = host_and_port(req)
37
38
  request_options = datadog_configuration(host)
38
39
  pin = datadog_pin(request_options)
39
40
  return super(req, body, &block) unless pin && pin.tracer
40
41
 
41
- if Datadog::Contrib::HTTP.should_skip_tracing?(req, pin.tracer)
42
- return super(req, body, &block)
43
- end
42
+ return super(req, body, &block) if Datadog::Contrib::HTTP.should_skip_tracing?(req, pin.tracer)
44
43
 
45
44
  pin.tracer.trace(Ext::SPAN_REQUEST, on_error: method(:annotate_span_with_error!)) do |span|
46
45
  begin
@@ -108,6 +107,7 @@ module Datadog
108
107
 
109
108
  def set_analytics_sample_rate(span, request_options)
110
109
  return unless analytics_enabled?(request_options)
110
+
111
111
  Contrib::Analytics.set_sample_rate(span, analytics_sample_rate(request_options))
112
112
  end
113
113
 
@@ -134,15 +134,14 @@ module Datadog
134
134
  end
135
135
 
136
136
  def should_skip_distributed_tracing?(pin)
137
- if pin.config && pin.config.key?(:distributed_tracing)
138
- return !pin.config[:distributed_tracing]
139
- end
137
+ return !pin.config[:distributed_tracing] if pin.config && pin.config.key?(:distributed_tracing)
140
138
 
141
139
  !Datadog.configuration[:httpclient][:distributed_tracing]
142
140
  end
143
141
 
144
142
  def set_analytics_sample_rate(span, request_options)
145
143
  return unless analytics_enabled?(request_options)
144
+
146
145
  Contrib::Analytics.set_sample_rate(span, request_options[:analytics_sample_rate])
147
146
  end
148
147
  end
@@ -145,15 +145,14 @@ module Datadog
145
145
  end
146
146
 
147
147
  def should_skip_distributed_tracing?(pin)
148
- if pin.config && pin.config.key?(:distributed_tracing)
149
- return !pin.config[:distributed_tracing]
150
- end
148
+ return !pin.config[:distributed_tracing] if pin.config && pin.config.key?(:distributed_tracing)
151
149
 
152
150
  !Datadog.configuration[:httprb][:distributed_tracing]
153
151
  end
154
152
 
155
153
  def set_analytics_sample_rate(span, request_options)
156
154
  return unless analytics_enabled?(request_options)
155
+
157
156
  Contrib::Analytics.set_sample_rate(span, request_options[:analytics_sample_rate])
158
157
  end
159
158
  end
@@ -23,6 +23,7 @@ module Datadog
23
23
  return unless respond_to? :cluster
24
24
  return unless cluster.respond_to? :addresses
25
25
  return unless cluster.addresses.respond_to? :first
26
+
26
27
  Datadog::Pin.get_from(cluster.addresses.first)
27
28
  end
28
29
 
@@ -31,6 +32,7 @@ module Datadog
31
32
  return unless respond_to? :cluster
32
33
  return unless cluster.respond_to? :addresses
33
34
  return unless cluster.addresses.respond_to? :each
35
+
34
36
  # attach the PIN to all cluster addresses. One of them is used
35
37
  # when executing a Command and it is attached to the Monitoring
36
38
  # Event instance.
@@ -29,9 +29,7 @@ module Datadog
29
29
  span.set_tag(Datadog::Ext::Integration::TAG_PEER_SERVICE, span.service)
30
30
 
31
31
  # Set analytics sample rate
32
- if analytics_enabled?
33
- Contrib::Analytics.set_sample_rate(span, analytics_sample_rate)
34
- end
32
+ Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
35
33
 
36
34
  # add operation tags; the full query is stored and used as a resource,
37
35
  # since it has been quantized and reduced
@@ -92,6 +90,7 @@ module Datadog
92
90
 
93
91
  def clear_span(event)
94
92
  return if Thread.current[:datadog_mongo_span].nil?
93
+
95
94
  Thread.current[:datadog_mongo_span].delete(event.request_id)
96
95
  end
97
96
 
@@ -8,7 +8,7 @@ module Datadog
8
8
  base.send(:include, Datadog::Patcher)
9
9
 
10
10
  base.singleton_class.send(:prepend, CommonMethods)
11
- base.send(:prepend, CommonMethods) if base.class == Class
11
+ base.send(:prepend, CommonMethods) if base.instance_of?(Class)
12
12
  end
13
13
 
14
14
  # Prepended instance methods for all patchers
@@ -9,6 +9,7 @@ module Datadog
9
9
  module QlessJob
10
10
  def around_perform(job)
11
11
  return super unless datadog_configuration && tracer
12
+
12
13
  tracer.trace(Ext::SPAN_JOB, span_options) do |span|
13
14
  span.resource = job.klass_name
14
15
  span.span_type = Datadog::Ext::AppTypes::WORKER
@@ -16,6 +16,7 @@ module Datadog
16
16
  def forked?
17
17
  pin = Datadog::Pin.get_from(::Qless)
18
18
  return false unless pin
19
+
19
20
  pin.config[:forked] == true
20
21
  end
21
22
 
@@ -5,25 +5,25 @@ module Datadog
5
5
  module Que
6
6
  # Que integration constants
7
7
  module Ext
8
- APP = 'que'.freeze
9
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_QUE_ANALYTICS_ENABLED'.freeze
10
- ENV_ANALYTICS_ENABLED_OLD = 'DD_QUE_ANALYTICS_ENABLED'.freeze
11
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_QUE_ANALYTICS_SAMPLE_RATE'.freeze
12
- ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_QUE_ANALYTICS_SAMPLE_RATE'.freeze
13
- ENV_ENABLED = 'DD_TRACE_QUE_ENABLED'.freeze
14
- ENV_TAG_ARGS_ENABLED = 'DD_TRACE_QUE_TAG_ARGS_ENABLED'.freeze
15
- ENV_TAG_DATA_ENABLED = 'DD_TRACE_QUE_TAG_DATA_ENABLED'.freeze
16
- SERVICE_NAME = 'que'.freeze
17
- SPAN_JOB = 'que.job'.freeze
18
- TAG_JOB_ARGS = 'que.job.args'.freeze
19
- TAG_JOB_DATA = 'que.job.data'.freeze
20
- TAG_JOB_ERROR_COUNT = 'que.job.error_count'.freeze
21
- TAG_JOB_EXPIRED_AT = 'que.job.expired_at'.freeze
22
- TAG_JOB_FINISHED_AT = 'que.job.finished_at'.freeze
23
- TAG_JOB_ID = 'que.job.id'.freeze
24
- TAG_JOB_PRIORITY = 'que.job.priority'.freeze
25
- TAG_JOB_QUEUE = 'que.job.queue'.freeze
26
- TAG_JOB_RUN_AT = 'que.job.run_at'.freeze
8
+ APP = 'que'
9
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_QUE_ANALYTICS_ENABLED'
10
+ ENV_ANALYTICS_ENABLED_OLD = 'DD_QUE_ANALYTICS_ENABLED'
11
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_QUE_ANALYTICS_SAMPLE_RATE'
12
+ ENV_ANALYTICS_SAMPLE_RATE_OLD = 'DD_QUE_ANALYTICS_SAMPLE_RATE'
13
+ ENV_ENABLED = 'DD_TRACE_QUE_ENABLED'
14
+ ENV_TAG_ARGS_ENABLED = 'DD_TRACE_QUE_TAG_ARGS_ENABLED'
15
+ ENV_TAG_DATA_ENABLED = 'DD_TRACE_QUE_TAG_DATA_ENABLED'
16
+ SERVICE_NAME = 'que'
17
+ SPAN_JOB = 'que.job'
18
+ TAG_JOB_ARGS = 'que.job.args'
19
+ TAG_JOB_DATA = 'que.job.data'
20
+ TAG_JOB_ERROR_COUNT = 'que.job.error_count'
21
+ TAG_JOB_EXPIRED_AT = 'que.job.expired_at'
22
+ TAG_JOB_FINISHED_AT = 'que.job.finished_at'
23
+ TAG_JOB_ID = 'que.job.id'
24
+ TAG_JOB_PRIORITY = 'que.job.priority'
25
+ TAG_JOB_QUEUE = 'que.job.queue'
26
+ TAG_JOB_RUN_AT = 'que.job.run_at'
27
27
  end
28
28
  end
29
29
  end
@@ -9,7 +9,7 @@ module Datadog
9
9
  class Tracer
10
10
  def call(job)
11
11
  trace_options = {
12
- service: configuration[:service_name],
12
+ service: configuration[:service_name],
13
13
  span_type: Datadog::Ext::AppTypes::WORKER,
14
14
  on_error: configuration[:error_handler]
15
15
  }
@@ -66,6 +66,7 @@ module Datadog
66
66
  # preventing such a leak.
67
67
  def ensure_clean_context!
68
68
  return unless configuration[:tracer].call_context.current_span
69
+
69
70
  configuration[:tracer].provider.context = Context.new
70
71
  end
71
72
  end
@@ -8,9 +8,9 @@ module Datadog
8
8
  # Custom settings for the Rack integration
9
9
  class Settings < Contrib::Configuration::Settings
10
10
  DEFAULT_HEADERS = {
11
- response: [
12
- 'Content-Type',
13
- 'X-Request-ID'
11
+ response: %w[
12
+ Content-Type
13
+ X-Request-ID
14
14
  ]
15
15
  }.freeze
16
16
 
@@ -131,7 +131,8 @@ module Datadog
131
131
  end
132
132
 
133
133
  # rubocop:disable Metrics/AbcSize
134
- # rubocop:disable Metrics/MethodLength
134
+ # rubocop:disable Metrics/CyclomaticComplexity
135
+ # rubocop:disable Metrics/PerceivedComplexity
135
136
  def set_request_tags!(request_span, env, status, headers, response, original_env)
136
137
  # http://www.rubydoc.info/github/rack/rack/file/SPEC
137
138
  # The source of truth in Rack is the PATH_INFO key that holds the
@@ -199,9 +200,7 @@ module Datadog
199
200
 
200
201
  # detect if the status code is a 5xx and flag the request span as an error
201
202
  # unless it has been already set by the underlying framework
202
- if status.to_s.start_with?('5') && request_span.status.zero?
203
- request_span.status = 1
204
- end
203
+ request_span.status = 1 if status.to_s.start_with?('5') && request_span.status.zero?
205
204
  end
206
205
 
207
206
  private
@@ -258,9 +257,7 @@ module Datadog
258
257
  whitelist = configuration[:headers][:request] || []
259
258
  whitelist.each do |header|
260
259
  rack_header = header_to_rack_header(header)
261
- if env.key?(rack_header)
262
- result[Datadog::Ext::HTTP::RequestHeaders.to_tag(header)] = env[rack_header]
263
- end
260
+ result[Datadog::Ext::HTTP::RequestHeaders.to_tag(header)] = env[rack_header] if env.key?(rack_header)
264
261
  end
265
262
  end
266
263
  end
@@ -275,9 +272,7 @@ module Datadog
275
272
  # Try a case-insensitive lookup
276
273
  uppercased_header = header.to_s.upcase
277
274
  matching_header = headers.keys.find { |h| h.upcase == uppercased_header }
278
- if matching_header
279
- result[Datadog::Ext::HTTP::ResponseHeaders.to_tag(header)] = headers[matching_header]
280
- end
275
+ result[Datadog::Ext::HTTP::ResponseHeaders.to_tag(header)] = headers[matching_header] if matching_header
281
276
  end
282
277
  end
283
278
  end
@@ -53,9 +53,7 @@ module Datadog
53
53
  end
54
54
  end
55
55
 
56
- following = if middleware.instance_variable_defined?('@app')
57
- middleware.instance_variable_get('@app')
58
- end
56
+ following = (middleware.instance_variable_get('@app') if middleware.instance_variable_defined?('@app'))
59
57
 
60
58
  retain_middleware_name(following)
61
59
  end
@@ -16,7 +16,8 @@ module Datadog
16
16
  return super unless enabled?
17
17
 
18
18
  tracer.trace(Ext::SPAN_INVOKE, span_options) do |span|
19
- super.tap { annotate_invoke!(span, args) }
19
+ annotate_invoke!(span, args)
20
+ super
20
21
  end
21
22
  ensure
22
23
  shutdown_tracer!
@@ -26,7 +27,8 @@ module Datadog
26
27
  return super unless enabled?
27
28
 
28
29
  tracer.trace(Ext::SPAN_EXECUTE, span_options) do |span|
29
- super.tap { annotate_execute!(span, args) }
30
+ annotate_execute!(span, args)
31
+ super
30
32
  end
31
33
  ensure
32
34
  shutdown_tracer!