ddtrace 0.29.1 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +4 -0
  3. data/CHANGELOG.md +18 -1
  4. data/lib/ddtrace/context.rb +26 -10
  5. data/lib/ddtrace/contrib/action_pack/action_controller/patcher.rb +3 -15
  6. data/lib/ddtrace/contrib/action_pack/patcher.rb +3 -9
  7. data/lib/ddtrace/contrib/action_view/event.rb +39 -0
  8. data/lib/ddtrace/contrib/action_view/events.rb +30 -0
  9. data/lib/ddtrace/contrib/action_view/events/render_partial.rb +40 -0
  10. data/lib/ddtrace/contrib/action_view/events/render_template.rb +43 -0
  11. data/lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb +4 -12
  12. data/lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb +6 -14
  13. data/lib/ddtrace/contrib/action_view/patcher.rb +19 -25
  14. data/lib/ddtrace/contrib/active_model_serializers/patcher.rb +3 -10
  15. data/lib/ddtrace/contrib/active_record/patcher.rb +3 -9
  16. data/lib/ddtrace/contrib/active_support/cache/patcher.rb +10 -24
  17. data/lib/ddtrace/contrib/active_support/patcher.rb +3 -9
  18. data/lib/ddtrace/contrib/aws/patcher.rb +7 -13
  19. data/lib/ddtrace/contrib/concurrent_ruby/patcher.rb +4 -11
  20. data/lib/ddtrace/contrib/dalli/patcher.rb +4 -10
  21. data/lib/ddtrace/contrib/delayed_job/patcher.rb +4 -10
  22. data/lib/ddtrace/contrib/elasticsearch/patcher.rb +8 -14
  23. data/lib/ddtrace/contrib/ethon/patcher.rb +7 -9
  24. data/lib/ddtrace/contrib/excon/patcher.rb +4 -11
  25. data/lib/ddtrace/contrib/faraday/patcher.rb +6 -12
  26. data/lib/ddtrace/contrib/grape/patcher.rb +7 -13
  27. data/lib/ddtrace/contrib/graphql/patcher.rb +5 -11
  28. data/lib/ddtrace/contrib/grpc/patcher.rb +7 -13
  29. data/lib/ddtrace/contrib/http/patcher.rb +3 -9
  30. data/lib/ddtrace/contrib/mongodb/patcher.rb +5 -11
  31. data/lib/ddtrace/contrib/mysql2/patcher.rb +3 -9
  32. data/lib/ddtrace/contrib/patcher.rb +38 -10
  33. data/lib/ddtrace/contrib/racecar/patcher.rb +4 -10
  34. data/lib/ddtrace/contrib/rack/patcher.rb +56 -21
  35. data/lib/ddtrace/contrib/rails/patcher.rb +4 -8
  36. data/lib/ddtrace/contrib/rake/patcher.rb +4 -10
  37. data/lib/ddtrace/contrib/redis/patcher.rb +8 -14
  38. data/lib/ddtrace/contrib/resque/patcher.rb +4 -10
  39. data/lib/ddtrace/contrib/rest_client/patcher.rb +5 -7
  40. data/lib/ddtrace/contrib/sequel/patcher.rb +4 -10
  41. data/lib/ddtrace/contrib/shoryuken/patcher.rb +4 -10
  42. data/lib/ddtrace/contrib/sidekiq/patcher.rb +12 -18
  43. data/lib/ddtrace/contrib/sinatra/patcher.rb +4 -10
  44. data/lib/ddtrace/contrib/sucker_punch/patcher.rb +7 -13
  45. data/lib/ddtrace/diagnostics/health.rb +9 -2
  46. data/lib/ddtrace/ext/diagnostics.rb +6 -0
  47. data/lib/ddtrace/ext/sampling.rb +13 -0
  48. data/lib/ddtrace/sampler.rb +49 -8
  49. data/lib/ddtrace/sampling.rb +2 -0
  50. data/lib/ddtrace/sampling/matcher.rb +57 -0
  51. data/lib/ddtrace/sampling/rate_limiter.rb +127 -0
  52. data/lib/ddtrace/sampling/rule.rb +61 -0
  53. data/lib/ddtrace/sampling/rule_sampler.rb +111 -0
  54. data/lib/ddtrace/span.rb +12 -0
  55. data/lib/ddtrace/tracer.rb +1 -0
  56. data/lib/ddtrace/version.rb +2 -2
  57. metadata +27 -4
@@ -12,19 +12,12 @@ module Datadog
12
12
 
13
13
  module_function
14
14
 
15
- def patched?
16
- done?(:active_model_serializers)
15
+ def target_version
16
+ Integration.version
17
17
  end
18
18
 
19
19
  def patch
20
- do_once(:active_model_serializers) do
21
- begin
22
- # Subscribe to ActiveModelSerializers events
23
- Events.subscribe!
24
- rescue StandardError => e
25
- Datadog::Tracer.log.error("Unable to apply ActiveModelSerializers integration: #{e}")
26
- end
27
- end
20
+ Events.subscribe!
28
21
  end
29
22
 
30
23
  def get_option(option)
@@ -10,18 +10,12 @@ module Datadog
10
10
 
11
11
  module_function
12
12
 
13
- def patched?
14
- done?(:active_record)
13
+ def target_version
14
+ Integration.version
15
15
  end
16
16
 
17
17
  def patch
18
- do_once(:active_record) do
19
- begin
20
- Events.subscribe!
21
- rescue StandardError => e
22
- Datadog::Tracer.log.error("Unable to apply Active Record integration: #{e}")
23
- end
24
- end
18
+ Events.subscribe!
25
19
  end
26
20
  end
27
21
  end
@@ -11,21 +11,15 @@ module Datadog
11
11
 
12
12
  module_function
13
13
 
14
- def patched?
15
- done?(:cache)
14
+ def target_version
15
+ Integration.version
16
16
  end
17
17
 
18
18
  def patch
19
- do_once(:cache) do
20
- begin
21
- patch_cache_store_read
22
- patch_cache_store_fetch
23
- patch_cache_store_write
24
- patch_cache_store_delete
25
- rescue StandardError => e
26
- Datadog::Tracer.log.error("Unable to apply Active Support cache integration: #{e}")
27
- end
28
- end
19
+ patch_cache_store_read
20
+ patch_cache_store_fetch
21
+ patch_cache_store_write
22
+ patch_cache_store_delete
29
23
  end
30
24
 
31
25
  def cache_store_class(meth)
@@ -33,27 +27,19 @@ module Datadog
33
27
  end
34
28
 
35
29
  def patch_cache_store_read
36
- do_once(:patch_cache_store_read) do
37
- cache_store_class(:read).send(:prepend, Cache::Instrumentation::Read)
38
- end
30
+ cache_store_class(:read).send(:prepend, Cache::Instrumentation::Read)
39
31
  end
40
32
 
41
33
  def patch_cache_store_fetch
42
- do_once(:patch_cache_store_fetch) do
43
- cache_store_class(:fetch).send(:prepend, Cache::Instrumentation::Fetch)
44
- end
34
+ cache_store_class(:fetch).send(:prepend, Cache::Instrumentation::Fetch)
45
35
  end
46
36
 
47
37
  def patch_cache_store_write
48
- do_once(:patch_cache_store_write) do
49
- cache_store_class(:write).send(:prepend, Cache::Instrumentation::Write)
50
- end
38
+ cache_store_class(:write).send(:prepend, Cache::Instrumentation::Write)
51
39
  end
52
40
 
53
41
  def patch_cache_store_delete
54
- do_once(:patch_cache_store_delete) do
55
- cache_store_class(:delete).send(:prepend, Cache::Instrumentation::Delete)
56
- end
42
+ cache_store_class(:delete).send(:prepend, Cache::Instrumentation::Delete)
57
43
  end
58
44
  end
59
45
  end
@@ -10,18 +10,12 @@ module Datadog
10
10
 
11
11
  module_function
12
12
 
13
- def patched?
14
- done?(:active_support)
13
+ def target_version
14
+ Integration.version
15
15
  end
16
16
 
17
17
  def patch
18
- do_once(:active_support) do
19
- begin
20
- Cache::Patcher.patch
21
- rescue StandardError => e
22
- Datadog::Tracer.log.error("Unable to apply Active Support integration: #{e}")
23
- end
24
- end
18
+ Cache::Patcher.patch
25
19
  end
26
20
  end
27
21
  end
@@ -11,22 +11,16 @@ module Datadog
11
11
 
12
12
  module_function
13
13
 
14
- def patched?
15
- done?(:aws)
14
+ def target_version
15
+ Integration.version
16
16
  end
17
17
 
18
18
  def patch
19
- do_once(:aws) do
20
- begin
21
- require 'ddtrace/contrib/aws/parsed_context'
22
- require 'ddtrace/contrib/aws/instrumentation'
23
- require 'ddtrace/contrib/aws/services'
24
-
25
- add_plugin(Seahorse::Client::Base, *loaded_constants)
26
- rescue StandardError => e
27
- Datadog::Tracer.log.error("Unable to apply AWS integration: #{e}")
28
- end
29
- end
19
+ require 'ddtrace/contrib/aws/parsed_context'
20
+ require 'ddtrace/contrib/aws/instrumentation'
21
+ require 'ddtrace/contrib/aws/services'
22
+
23
+ add_plugin(Seahorse::Client::Base, *loaded_constants)
30
24
  end
31
25
 
32
26
  def add_plugin(*targets)
@@ -9,20 +9,13 @@ module Datadog
9
9
 
10
10
  module_function
11
11
 
12
- def patched?
13
- done?(:concurrent_ruby)
12
+ def target_version
13
+ Integration.version
14
14
  end
15
15
 
16
16
  def patch
17
- do_once(:concurrent_ruby) do
18
- begin
19
- require 'ddtrace/contrib/concurrent_ruby/future_patch'
20
-
21
- patch_future
22
- rescue StandardError => e
23
- Datadog::Tracer.log.error("Unable to apply Future integration: #{e}")
24
- end
25
- end
17
+ require 'ddtrace/contrib/concurrent_ruby/future_patch'
18
+ patch_future
26
19
  end
27
20
 
28
21
  # Propagate tracing context in Concurrent::Future
@@ -12,19 +12,13 @@ module Datadog
12
12
 
13
13
  module_function
14
14
 
15
- def patched?
16
- done?(:dalli)
15
+ def target_version
16
+ Integration.version
17
17
  end
18
18
 
19
19
  def patch
20
- do_once(:dalli) do
21
- begin
22
- add_pin!
23
- ::Dalli::Server.send(:include, Instrumentation)
24
- rescue StandardError => e
25
- Datadog::Tracer.log.error("Unable to apply Dalli integration: #{e}")
26
- end
27
- end
20
+ add_pin!
21
+ ::Dalli::Server.send(:include, Instrumentation)
28
22
  end
29
23
 
30
24
  # DEPRECATED: Only kept for users still using `Dalli.datadog_pin` to configure.
@@ -10,19 +10,13 @@ module Datadog
10
10
 
11
11
  module_function
12
12
 
13
- def patched?
14
- done?(:delayed_job)
13
+ def target_version
14
+ Integration.version
15
15
  end
16
16
 
17
17
  def patch
18
- do_once(:delayed_job) do
19
- begin
20
- require 'ddtrace/contrib/delayed_job/plugin'
21
- add_instrumentation(::Delayed::Worker)
22
- rescue StandardError => e
23
- Datadog::Tracer.log.error("Unable to apply DelayedJob integration: #{e}")
24
- end
25
- end
18
+ require 'ddtrace/contrib/delayed_job/plugin'
19
+ add_instrumentation(::Delayed::Worker)
26
20
  end
27
21
 
28
22
  def add_instrumentation(klass)
@@ -13,23 +13,17 @@ module Datadog
13
13
 
14
14
  module_function
15
15
 
16
- def patched?
17
- done?(:elasticsearch)
16
+ def target_version
17
+ Integration.version
18
18
  end
19
19
 
20
20
  def patch
21
- do_once(:elasticsearch) do
22
- begin
23
- require 'uri'
24
- require 'json'
25
- require 'ddtrace/pin'
26
- require 'ddtrace/contrib/elasticsearch/quantize'
27
-
28
- patch_elasticsearch_transport_client
29
- rescue StandardError => e
30
- Datadog::Tracer.log.error("Unable to apply Elasticsearch integration: #{e}")
31
- end
32
- end
21
+ require 'uri'
22
+ require 'json'
23
+ require 'ddtrace/pin'
24
+ require 'ddtrace/contrib/elasticsearch/quantize'
25
+
26
+ patch_elasticsearch_transport_client
33
27
  end
34
28
 
35
29
  # rubocop:disable Metrics/MethodLength
@@ -7,19 +7,17 @@ module Datadog
7
7
 
8
8
  module_function
9
9
 
10
- def patched?
11
- done?(:ethon)
10
+ def target_version
11
+ Integration.version
12
12
  end
13
13
 
14
14
  def patch
15
- do_once(:ethon) do
16
- require 'ddtrace/ext/app_types'
17
- require 'ddtrace/contrib/ethon/easy_patch'
18
- require 'ddtrace/contrib/ethon/multi_patch'
15
+ require 'ddtrace/ext/app_types'
16
+ require 'ddtrace/contrib/ethon/easy_patch'
17
+ require 'ddtrace/contrib/ethon/multi_patch'
19
18
 
20
- ::Ethon::Easy.send(:include, EasyPatch)
21
- ::Ethon::Multi.send(:include, MultiPatch)
22
- end
19
+ ::Ethon::Easy.send(:include, EasyPatch)
20
+ ::Ethon::Multi.send(:include, MultiPatch)
23
21
  end
24
22
  end
25
23
  end
@@ -9,20 +9,13 @@ module Datadog
9
9
 
10
10
  module_function
11
11
 
12
- def patched?
13
- done?(:excon)
12
+ def target_version
13
+ Integration.version
14
14
  end
15
15
 
16
16
  def patch
17
- do_once(:excon) do
18
- begin
19
- require 'ddtrace/contrib/excon/middleware'
20
-
21
- add_middleware
22
- rescue StandardError => e
23
- Datadog::Tracer.log.error("Unable to apply Excon integration: #{e}")
24
- end
25
- end
17
+ require 'ddtrace/contrib/excon/middleware'
18
+ add_middleware
26
19
  end
27
20
 
28
21
  def add_middleware
@@ -12,22 +12,16 @@ module Datadog
12
12
 
13
13
  module_function
14
14
 
15
- def patched?
16
- done?(:faraday)
15
+ def target_version
16
+ Integration.version
17
17
  end
18
18
 
19
19
  def patch
20
- do_once(:faraday) do
21
- begin
22
- require 'ddtrace/contrib/faraday/middleware'
20
+ require 'ddtrace/contrib/faraday/middleware'
23
21
 
24
- add_pin!
25
- register_middleware!
26
- add_default_middleware!
27
- rescue StandardError => e
28
- Datadog::Tracer.log.error("Unable to apply Faraday integration: #{e}")
29
- end
30
- end
22
+ add_pin!
23
+ register_middleware!
24
+ add_default_middleware!
31
25
  end
32
26
 
33
27
  def add_pin!
@@ -14,24 +14,18 @@ module Datadog
14
14
 
15
15
  module_function
16
16
 
17
- def patched?
18
- done?(:grape)
17
+ def target_version
18
+ Integration.version
19
19
  end
20
20
 
21
21
  def patch
22
- do_once(:grape) do
23
- begin
24
- # Patch endpoints
25
- ::Grape::Endpoint.send(:include, Instrumentation)
22
+ # Patch endpoints
23
+ ::Grape::Endpoint.send(:include, Instrumentation)
26
24
 
27
- add_pin!
25
+ add_pin!
28
26
 
29
- # Subscribe to ActiveSupport events
30
- Datadog::Contrib::Grape::Endpoint.subscribe
31
- rescue StandardError => e
32
- Datadog::Tracer.log.error("Unable to apply Grape integration: #{e}")
33
- end
34
- end
27
+ # Subscribe to ActiveSupport events
28
+ Datadog::Contrib::Grape::Endpoint.subscribe
35
29
  end
36
30
 
37
31
  def add_pin!
@@ -9,22 +9,16 @@ module Datadog
9
9
 
10
10
  module_function
11
11
 
12
- def patched?
13
- done?(:graphql)
12
+ def target_version
13
+ Integration.version
14
14
  end
15
15
 
16
16
  def patch
17
17
  return if get_option(:schemas).nil?
18
18
 
19
- do_once(:graphql) do
20
- begin
21
- require 'ddtrace/ext/app_types'
22
- require 'ddtrace/ext/http'
23
- get_option(:schemas).each { |s| patch_schema!(s) }
24
- rescue StandardError => e
25
- Datadog::Tracer.log.error("Unable to apply GraphQL integration: #{e}")
26
- end
27
- end
19
+ require 'ddtrace/ext/app_types'
20
+ require 'ddtrace/ext/http'
21
+ get_option(:schemas).each { |s| patch_schema!(s) }
28
22
  end
29
23
 
30
24
  def patch_schema!(schema)
@@ -10,24 +10,18 @@ module Datadog
10
10
 
11
11
  module_function
12
12
 
13
- def patched?
14
- done?(:grpc)
13
+ def target_version
14
+ Integration.version
15
15
  end
16
16
 
17
17
  def patch
18
- do_once(:grpc) do
19
- begin
20
- require 'ddtrace/propagation/grpc_propagator'
21
- require 'ddtrace/contrib/grpc/datadog_interceptor'
22
- require 'ddtrace/contrib/grpc/intercept_with_datadog'
18
+ require 'ddtrace/propagation/grpc_propagator'
19
+ require 'ddtrace/contrib/grpc/datadog_interceptor'
20
+ require 'ddtrace/contrib/grpc/intercept_with_datadog'
23
21
 
24
- add_pin!
22
+ add_pin!
25
23
 
26
- prepend_interceptor
27
- rescue StandardError => e
28
- Datadog::Tracer.log.error("Unable to apply gRPC integration: #{e}")
29
- end
30
- end
24
+ prepend_interceptor
31
25
  end
32
26
 
33
27
  def add_pin!
@@ -12,19 +12,13 @@ module Datadog
12
12
 
13
13
  module_function
14
14
 
15
- def patched?
16
- done?(:http)
15
+ def target_version
16
+ Integration.version
17
17
  end
18
18
 
19
19
  # patch applies our patch if needed
20
20
  def patch
21
- do_once(:http) do
22
- begin
23
- ::Net::HTTP.send(:include, Instrumentation)
24
- rescue StandardError => e
25
- Datadog::Tracer.log.error("Unable to apply net/http integration: #{e}")
26
- end
27
- end
21
+ ::Net::HTTP.send(:include, Instrumentation)
28
22
  end
29
23
  end
30
24
  end