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
@@ -96,6 +96,7 @@ module Datadog
96
96
  # @return [Hash]
97
97
  def self.default_connection_config
98
98
  return @default_connection_config if instance_variable_defined?(:@default_connection_config)
99
+
99
100
  current_connection_name = if ::ActiveRecord::Base.respond_to?(:connection_specification_name)
100
101
  ::ActiveRecord::Base.connection_specification_name
101
102
  else
@@ -20,7 +20,8 @@ module Datadog
20
20
  module ClassMethods
21
21
  DEFAULT_TRACER = -> { Datadog.tracer }
22
22
 
23
- def subscribe!
23
+ # Publicly exposes protected method `subscribe!`
24
+ def subscribe! # rubocop:disable Lint/UselessMethodDefinition
24
25
  super
25
26
  end
26
27
 
@@ -36,6 +36,7 @@ module Datadog
36
36
  # Should be triggered by the inheriting class.
37
37
  def subscribe!
38
38
  return subscribed? if subscribed? || on_subscribe_block.nil?
39
+
39
40
  on_subscribe_block.call
40
41
  @subscribed = true
41
42
  end
@@ -9,7 +9,8 @@ module Datadog
9
9
  :options
10
10
 
11
11
  def initialize(tracer, span_name, options, &block)
12
- raise ArgumentError, 'Must be given a block!' unless block_given?
12
+ raise ArgumentError, 'Must be given a block!' unless block
13
+
13
14
  @tracer = tracer
14
15
  @span_name = span_name
15
16
  @options = options
@@ -38,21 +39,23 @@ module Datadog
38
39
  end
39
40
 
40
41
  def before_trace(&block)
41
- callbacks.add(:before_trace, &block) if block_given?
42
+ callbacks.add(:before_trace, &block) if block
42
43
  end
43
44
 
44
45
  def after_trace(&block)
45
- callbacks.add(:after_trace, &block) if block_given?
46
+ callbacks.add(:after_trace, &block) if block
46
47
  end
47
48
 
48
49
  def subscribe(pattern)
49
50
  return false if subscribers.key?(pattern)
51
+
50
52
  subscribers[pattern] = ::ActiveSupport::Notifications.subscribe(pattern, self)
51
53
  true
52
54
  end
53
55
 
54
56
  def unsubscribe(pattern)
55
57
  return false unless subscribers.key?(pattern)
58
+
56
59
  ::ActiveSupport::Notifications.unsubscribe(subscribers[pattern])
57
60
  subscribers.delete(pattern)
58
61
  true
@@ -60,7 +63,8 @@ module Datadog
60
63
 
61
64
  def unsubscribe_all
62
65
  return false if subscribers.empty?
63
- subscribers.keys.each { |pattern| unsubscribe(pattern) }
66
+
67
+ subscribers.each_key { |pattern| unsubscribe(pattern) }
64
68
  true
65
69
  end
66
70
 
@@ -131,7 +135,7 @@ module Datadog
131
135
  end
132
136
 
133
137
  def add(key, &block)
134
- blocks_for(key) << block if block_given?
138
+ blocks_for(key) << block if block
135
139
  end
136
140
 
137
141
  def run(event, key, *args)
@@ -32,6 +32,7 @@ module Datadog
32
32
  # cause undesirable service naming, so we exclude them based their auto_instrument? setting.
33
33
  # we also don't want to mix rspec/cucumber integration in as rspec is env we run tests in.
34
34
  next unless integration.klass.auto_instrument?
35
+
35
36
  integrations << integration.name
36
37
  end
37
38
 
@@ -35,6 +35,7 @@ module Datadog
35
35
 
36
36
  available_services.each_with_object([]) do |service, constants|
37
37
  next if ::Aws.autoload?(service)
38
+
38
39
  constants << ::Aws.const_get(service, false).const_get(:Client, false) rescue next
39
40
  end
40
41
  end
@@ -52,6 +52,7 @@ module Datadog
52
52
  ElasticLoadBalancingV2
53
53
  ElasticTranscoder
54
54
  ElasticsearchService
55
+ EventBridge
55
56
  Firehose
56
57
  GameLift
57
58
  Glacier
@@ -11,7 +11,7 @@ module Datadog
11
11
  return if patterns.empty?
12
12
 
13
13
  # Try to find a matching pattern
14
- matching_pattern = patterns.find do |pattern|
14
+ patterns.find do |pattern|
15
15
  if pattern.is_a?(Proc)
16
16
  (pattern === name)
17
17
  else
@@ -19,9 +19,6 @@ module Datadog
19
19
  (pattern == name) # Only required during configuration time.
20
20
  end
21
21
  end
22
-
23
- # Return match or default
24
- matching_pattern
25
22
  end
26
23
 
27
24
  def add(pattern)
@@ -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
@@ -4,8 +4,6 @@ module Datadog
4
4
  # Cucumber integration constants
5
5
  module Ext
6
6
  APP = 'cucumber'.freeze
7
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_CUCUMBER_ANALYTICS_ENABLED'.freeze
8
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_CUCUMBER_ANALYTICS_SAMPLE_RATE'.freeze
9
7
  ENV_ENABLED = 'DD_TRACE_CUCUMBER_ENABLED'.freeze
10
8
  ENV_OPERATION_NAME = 'DD_TRACE_CUCUMBER_OPERATION_NAME'.freeze
11
9
  FRAMEWORK = 'cucumber'.freeze
@@ -9,10 +9,8 @@ module Datadog
9
9
  module Cucumber
10
10
  # Defines collection of instrumented Cucumber events
11
11
  class Formatter
12
- attr_reader :config
12
+ attr_reader :config, :current_feature_span, :current_step_span
13
13
  private :config
14
-
15
- attr_reader :current_feature_span, :current_step_span
16
14
  private :current_feature_span, :current_step_span
17
15
 
18
16
  def initialize(config)
@@ -43,17 +41,13 @@ module Datadog
43
41
  @current_feature_span.set_tag(Datadog::Ext::Test::TAG_TYPE, Ext::TEST_TYPE)
44
42
  @current_feature_span.set_tag(Datadog::Ext::Test::TAG_SPAN_KIND, Datadog::Ext::AppTypes::TEST)
45
43
 
46
- # Set analytics sample rate
47
- if Datadog::Contrib::Analytics.enabled?(configuration[:analytics_enabled])
48
- Datadog::Contrib::Analytics.set_sample_rate(@current_feature_span, configuration[:analytics_sample_rate])
49
- end
50
-
51
44
  # Measure service stats
52
45
  Contrib::Analytics.set_measured(@current_feature_span)
53
46
  end
54
47
 
55
48
  def on_test_case_finished(event)
56
49
  return if @current_feature_span.nil?
50
+
57
51
  @current_feature_span.status = 1 if event.result.failed?
58
52
  @current_feature_span.set_tag(Datadog::Ext::Test::TAG_STATUS, status_from_result(event.result))
59
53
  @current_feature_span.finish
@@ -69,9 +63,8 @@ module Datadog
69
63
 
70
64
  def on_test_step_finished(event)
71
65
  return if @current_step_span.nil?
72
- unless event.result.passed?
73
- @current_step_span.set_error event.result.exception
74
- end
66
+
67
+ @current_step_span.set_error event.result.exception unless event.result.passed?
75
68
  @current_step_span.set_tag(Datadog::Ext::Test::TAG_STATUS, status_from_result(event.result))
76
69
  @current_step_span.finish
77
70
  end
@@ -84,6 +77,7 @@ module Datadog
84
77
  elsif result.ok?
85
78
  return Datadog::Ext::Test::Status::PASS
86
79
  end
80
+
87
81
  Datadog::Ext::Test::Status::FAIL
88
82
  end
89
83
 
@@ -17,46 +17,8 @@ module Datadog
17
17
  end
18
18
 
19
19
  def patch
20
- add_pin!
21
20
  ::Dalli::Server.send(:include, Instrumentation)
22
21
  end
23
-
24
- # DEPRECATED: Only kept for users still using `Dalli.datadog_pin` to configure.
25
- # Replaced by configuration API, i.e. `c.use :dalli`.
26
- def add_pin!
27
- DeprecatedPin
28
- .new(
29
- get_option(:service_name),
30
- app: Ext::APP,
31
- app_type: Datadog::Ext::AppTypes::CACHE,
32
- tracer: -> { get_option(:tracer) }
33
- ).onto(::Dalli)
34
- end
35
-
36
- def get_option(option)
37
- Datadog.configuration[:dalli].get_option(option)
38
- end
39
-
40
- # Implementation of deprecated Pin, which raises warnings when accessed.
41
- # To be removed when support for Datadog::Pin with Dalli is removed.
42
- class DeprecatedPin < Datadog::Pin
43
- include Datadog::DeprecatedPin
44
-
45
- DEPRECATION_WARNING = %(
46
- Use of Datadog::Pin with Dalli is DEPRECATED.
47
- Upgrade to the configuration API using the migration guide here:
48
- https://github.com/DataDog/dd-trace-rb/releases/tag/v0.11.0).freeze
49
-
50
- def service_name=(service_name)
51
- Datadog.configuration[:dalli][:service_name] = service_name
52
- end
53
-
54
- def log_deprecation_warning(method_name)
55
- do_once(method_name) do
56
- Datadog.logger.warn("#{method_name}:#{DEPRECATION_WARNING}")
57
- end
58
- end
59
- end
60
22
  end
61
23
  end
62
24
  end
@@ -12,7 +12,6 @@ module Datadog
12
12
 
13
13
  tracer.trace(Ext::SPAN_JOB, service: configuration[:service_name], resource: job_name(job),
14
14
  on_error: configuration[:error_handler]) do |span|
15
-
16
15
  set_sample_rate(span)
17
16
 
18
17
  # Measure service stats
@@ -17,7 +17,7 @@ module Datadog
17
17
 
18
18
  def format_url(url)
19
19
  sanitize_fragment_with_id(url)
20
- .gsub(/(?:[\d]+)/, PLACEHOLDER)
20
+ .gsub(/(?:\d+)/, PLACEHOLDER)
21
21
  end
22
22
 
23
23
  def format_body(body, options = {})
@@ -60,6 +60,7 @@ module Datadog
60
60
  # If JSON parsing fails, it prints fail_value.
61
61
  def reserialize_json(string, fail_value = PLACEHOLDER)
62
62
  return string unless block_given?
63
+
63
64
  begin
64
65
  JSON.dump(yield(JSON.parse(string)))
65
66
  rescue JSON::ParserError
@@ -72,7 +73,7 @@ module Datadog
72
73
  # This is meant as simple heuristic that attempts to detect if particular fragment
73
74
  # represents document Id. This is meant to reduce the cardinality in most frequent cases.
74
75
  def sanitize_fragment_with_id(url)
75
- url.gsub(%r{^(/?[^/]*/[^/]*/)(?:[^\?/\d]*[\d]+[^\?/]*)}, ID_PLACEHOLDER)
76
+ url.gsub(%r{^(/?[^/]*/[^/]*/)(?:[^?/\d]*\d+[^?/]*)}, ID_PLACEHOLDER)
76
77
  end
77
78
  end
78
79
  end
@@ -13,8 +13,8 @@ module Datadog
13
13
  def self.included(base)
14
14
  base.send(:prepend, InstanceMethods)
15
15
  end
16
+
16
17
  # InstanceMethods - implementing instrumentation
17
- # rubocop:disable Metrics/ModuleLength
18
18
  module InstanceMethods
19
19
  include Datadog::Contrib::HttpAnnotationHelper
20
20
 
@@ -36,12 +36,14 @@ module Datadog
36
36
  def perform
37
37
  load_datadog_configuration_for(url)
38
38
  return super unless tracer_enabled?
39
+
39
40
  datadog_before_request
40
41
  super
41
42
  end
42
43
 
43
44
  def complete
44
45
  return super unless tracer_enabled?
46
+
45
47
  begin
46
48
  response_options = mirror.options
47
49
  response_code = (response_options[:response_code] || response_options[:code]).to_i
@@ -100,9 +102,7 @@ module Datadog
100
102
  def datadog_tag_request
101
103
  span = @datadog_span
102
104
  method = Ext::NOT_APPLICABLE_METHOD
103
- if instance_variable_defined?(:@datadog_method) && !@datadog_method.nil?
104
- method = @datadog_method.to_s
105
- end
105
+ method = @datadog_method.to_s if instance_variable_defined?(:@datadog_method) && !@datadog_method.nil?
106
106
  span.resource = method
107
107
  # Tag as an external peer service
108
108
  span.set_tag(Datadog::Ext::Integration::TAG_PEER_SERVICE, span.service)
@@ -111,6 +111,7 @@ module Datadog
111
111
 
112
112
  this_uri = uri
113
113
  return unless this_uri
114
+
114
115
  span.set_tag(Datadog::Ext::HTTP::URL, this_uri.path)
115
116
  span.set_tag(Datadog::Ext::HTTP::METHOD, method)
116
117
  span.set_tag(Datadog::Ext::NET::TARGET_HOST, this_uri.host)
@@ -125,7 +126,6 @@ module Datadog
125
126
 
126
127
  def uri
127
128
  URI.parse(url)
128
- # rubocop:disable Lint/HandleExceptions
129
129
  rescue URI::InvalidURIError
130
130
  end
131
131
 
@@ -119,9 +119,7 @@ module Datadog
119
119
  span.set_tag(Datadog::Ext::Integration::TAG_PEER_SERVICE, span.service)
120
120
 
121
121
  # Set analytics sample rate
122
- if analytics_enabled?
123
- Contrib::Analytics.set_sample_rate(span, analytics_sample_rate)
124
- end
122
+ Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
125
123
 
126
124
  span.set_tag(Datadog::Ext::HTTP::URL, datum[:path])
127
125
  span.set_tag(Datadog::Ext::HTTP::METHOD, datum[:method].to_s.upcase)
@@ -136,9 +134,7 @@ module Datadog
136
134
 
137
135
  if datum.key?(:response)
138
136
  response = datum[:response]
139
- if error_handler.call(response)
140
- span.set_error(["Error #{response[:status]}", response[:body]])
141
- end
137
+ span.set_error(["Error #{response[:status]}", response[:body]]) if error_handler.call(response)
142
138
  span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response[:status])
143
139
  end
144
140
  span.set_error(datum[:error]) if datum.key?(:error)
@@ -30,6 +30,7 @@ module Datadog
30
30
  reduce_verbosity = target.respond_to?(:reduce_verbosity?) ? target.reduce_verbosity? : false
31
31
  target.integrations_pending_activation.each do |integration|
32
32
  next unless integration.respond_to?(:patch)
33
+
33
34
  # integration.patch returns either true or a hash of details on why patching failed
34
35
  patch_results = integration.patch
35
36
 
@@ -57,9 +57,7 @@ module Datadog
57
57
  end
58
58
 
59
59
  def handle_response(span, env, options)
60
- if options.fetch(:error_handler).call(env)
61
- span.set_error(["Error #{env[:status]}", env[:body]])
62
- end
60
+ span.set_error(["Error #{env[:status]}", env[:body]]) if options.fetch(:error_handler).call(env)
63
61
 
64
62
  span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, env[:status])
65
63
  end
@@ -20,21 +20,10 @@ module Datadog
20
20
  def patch
21
21
  require 'ddtrace/contrib/faraday/middleware'
22
22
 
23
- add_pin!
24
23
  register_middleware!
25
24
  add_default_middleware!
26
25
  end
27
26
 
28
- def add_pin!
29
- DeprecatedPin
30
- .new(
31
- get_option(:service_name),
32
- app: Ext::APP,
33
- app_type: Datadog::Ext::HTTP::TYPE_OUTBOUND,
34
- tracer: -> { get_option(:tracer) }
35
- ).onto(::Faraday)
36
- end
37
-
38
27
  def register_middleware!
39
28
  ::Faraday::Middleware.register_middleware(ddtrace: Middleware)
40
29
  end
@@ -58,31 +47,6 @@ module Datadog
58
47
  ::Faraday::RackBuilder.send(:prepend, RackBuilder)
59
48
  end
60
49
  end
61
-
62
- def get_option(option)
63
- Datadog.configuration[:faraday].get_option(option)
64
- end
65
-
66
- # Implementation of deprecated Pin, which raises warnings when accessed.
67
- # To be removed when support for Datadog::Pin with Faraday is removed.
68
- class DeprecatedPin < Datadog::Pin
69
- include Datadog::DeprecatedPin
70
-
71
- DEPRECATION_WARNING = %(
72
- Use of Datadog::Pin with Faraday is DEPRECATED.
73
- Upgrade to the configuration API using the migration guide here:
74
- https://github.com/DataDog/dd-trace-rb/releases/tag/v0.11.0).freeze
75
-
76
- def service_name=(service_name)
77
- Datadog.configuration[:faraday][:service_name] = service_name
78
- end
79
-
80
- def log_deprecation_warning(method_name)
81
- do_once(method_name) do
82
- Datadog.logger.warn("#{method_name}:#{DEPRECATION_WARNING}")
83
- end
84
- end
85
- end
86
50
  end
87
51
  end
88
52
  end
@@ -51,6 +51,7 @@ module Datadog
51
51
 
52
52
  def endpoint_run(name, start, finish, id, payload)
53
53
  return unless Thread.current[KEY_RUN]
54
+
54
55
  Thread.current[KEY_RUN] = false
55
56
 
56
57
  return unless enabled?
@@ -76,18 +77,14 @@ module Datadog
76
77
  end
77
78
 
78
79
  # Set analytics sample rate
79
- if analytics_enabled?
80
- Contrib::Analytics.set_sample_rate(span, analytics_sample_rate)
81
- end
80
+ Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
82
81
 
83
82
  # Measure service stats
84
83
  Contrib::Analytics.set_measured(span)
85
84
 
86
85
  # catch thrown exceptions
87
86
 
88
- if exception_is_error?(payload[:exception_object])
89
- span.set_error(payload[:exception_object])
90
- end
87
+ span.set_error(payload[:exception_object]) if exception_is_error?(payload[:exception_object])
91
88
 
92
89
  # override the current span with this notification values
93
90
  span.set_tag(Ext::TAG_ROUTE_ENDPOINT, api_view) unless api_view.nil?
@@ -122,6 +119,7 @@ module Datadog
122
119
 
123
120
  def endpoint_render(name, start, finish, id, payload)
124
121
  return unless Thread.current[KEY_RENDER]
122
+
125
123
  Thread.current[KEY_RENDER] = false
126
124
 
127
125
  return unless enabled?
@@ -134,9 +132,7 @@ module Datadog
134
132
  # Measure service stats
135
133
  Contrib::Analytics.set_measured(span)
136
134
 
137
- if exception_is_error?(payload[:exception_object])
138
- span.set_error(payload[:exception_object])
139
- end
135
+ span.set_error(payload[:exception_object]) if exception_is_error?(payload[:exception_object])
140
136
  ensure
141
137
  span.start(start)
142
138
  span.finish(finish)
@@ -163,17 +159,13 @@ module Datadog
163
159
 
164
160
  begin
165
161
  # Set analytics sample rate
166
- if analytics_enabled?
167
- Contrib::Analytics.set_sample_rate(span, analytics_sample_rate)
168
- end
162
+ Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
169
163
 
170
164
  # Measure service stats
171
165
  Contrib::Analytics.set_measured(span)
172
166
 
173
167
  # catch thrown exceptions
174
- if exception_is_error?(payload[:exception_object])
175
- span.set_error(payload[:exception_object])
176
- end
168
+ span.set_error(payload[:exception_object]) if exception_is_error?(payload[:exception_object])
177
169
 
178
170
  span.set_tag(Ext::TAG_FILTER_TYPE, type.to_s)
179
171
  ensure
@@ -226,6 +218,7 @@ module Datadog
226
218
  return false unless exception
227
219
  return true unless matcher
228
220
  return true unless exception.respond_to?('status')
221
+
229
222
  matcher.include?(exception.status)
230
223
  end
231
224