ddtrace 1.6.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -2
  3. data/README.md +2 -2
  4. data/ext/ddtrace_profiling_loader/extconf.rb +5 -2
  5. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +1 -1
  6. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +3 -2
  7. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +81 -47
  8. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +1 -1
  9. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +332 -125
  10. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.c +142 -0
  11. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.h +14 -0
  12. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +241 -0
  13. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.h +3 -0
  14. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +11 -13
  15. data/ext/ddtrace_profiling_native_extension/extconf.rb +22 -8
  16. data/ext/ddtrace_profiling_native_extension/helpers.h +5 -0
  17. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +8 -0
  18. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +111 -26
  19. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +9 -0
  20. data/ext/ddtrace_profiling_native_extension/profiling.c +205 -0
  21. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +86 -0
  22. data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +28 -6
  23. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +115 -0
  24. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +11 -0
  25. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +84 -35
  26. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +1 -0
  27. data/ext/ddtrace_profiling_native_extension/time_helpers.c +17 -0
  28. data/ext/ddtrace_profiling_native_extension/time_helpers.h +10 -0
  29. data/lib/datadog/appsec/assets/blocked.html +98 -3
  30. data/lib/datadog/appsec/assets/blocked.json +1 -0
  31. data/lib/datadog/appsec/assets/blocked.text +5 -0
  32. data/lib/datadog/appsec/assets/waf_rules/recommended.json +35 -46
  33. data/lib/datadog/appsec/assets/waf_rules/risky.json +1 -1
  34. data/lib/datadog/appsec/assets/waf_rules/strict.json +46 -1
  35. data/lib/datadog/appsec/assets.rb +2 -2
  36. data/lib/datadog/appsec/configuration/settings.rb +6 -0
  37. data/lib/datadog/appsec/configuration.rb +4 -0
  38. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +4 -8
  39. data/lib/datadog/appsec/contrib/rack/request.rb +17 -0
  40. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +2 -2
  41. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +2 -2
  42. data/lib/datadog/appsec/contrib/rails/patcher.rb +3 -6
  43. data/lib/datadog/appsec/contrib/sinatra/ext.rb +1 -0
  44. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +1 -1
  45. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +11 -8
  46. data/lib/datadog/appsec/extensions.rb +10 -0
  47. data/lib/datadog/appsec/processor.rb +18 -0
  48. data/lib/datadog/appsec/response.rb +54 -0
  49. data/lib/datadog/core/configuration/components.rb +27 -6
  50. data/lib/datadog/core/configuration/ext.rb +18 -0
  51. data/lib/datadog/core/configuration/settings.rb +14 -341
  52. data/lib/datadog/core/diagnostics/health.rb +4 -22
  53. data/lib/datadog/core/environment/variable_helpers.rb +58 -10
  54. data/lib/datadog/core/runtime/ext.rb +1 -1
  55. data/lib/datadog/core/utils.rb +0 -21
  56. data/lib/datadog/core.rb +21 -1
  57. data/lib/datadog/opentracer/distributed_headers.rb +7 -9
  58. data/lib/datadog/opentracer/rack_propagator.rb +0 -3
  59. data/lib/datadog/opentracer/text_map_propagator.rb +5 -7
  60. data/lib/datadog/profiling/collectors/cpu_and_wall_time.rb +10 -4
  61. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +20 -5
  62. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
  63. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
  64. data/lib/datadog/profiling/collectors/old_stack.rb +7 -0
  65. data/lib/datadog/profiling/exporter.rb +5 -0
  66. data/lib/datadog/profiling/old_recorder.rb +8 -0
  67. data/lib/datadog/profiling/profiler.rb +7 -0
  68. data/lib/datadog/profiling/scheduler.rb +4 -7
  69. data/lib/datadog/profiling/stack_recorder.rb +36 -0
  70. data/lib/datadog/profiling/tasks/setup.rb +0 -7
  71. data/lib/datadog/profiling.rb +2 -0
  72. data/lib/datadog/tracing/configuration/ext.rb +33 -3
  73. data/lib/datadog/tracing/configuration/settings.rb +433 -0
  74. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +4 -1
  75. data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
  76. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +4 -1
  77. data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
  78. data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +4 -0
  79. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +5 -1
  80. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +1 -0
  81. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +6 -1
  82. data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
  83. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +5 -1
  84. data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
  85. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +5 -1
  86. data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
  87. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +6 -1
  88. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +2 -1
  89. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +6 -12
  90. data/lib/datadog/tracing/contrib/grpc/distributed/fetcher.rb +27 -0
  91. data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +43 -0
  92. data/lib/datadog/tracing/contrib/grpc/ext.rb +1 -0
  93. data/lib/datadog/tracing/contrib/grpc/patcher.rb +0 -2
  94. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +6 -1
  95. data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +32 -0
  96. data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +38 -0
  97. data/lib/datadog/tracing/contrib/http/ext.rb +1 -0
  98. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +6 -1
  99. data/lib/datadog/tracing/contrib/httpclient/ext.rb +1 -0
  100. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +6 -1
  101. data/lib/datadog/tracing/contrib/httprb/ext.rb +1 -0
  102. data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +1 -0
  103. data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +1 -0
  104. data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +1 -0
  105. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +5 -1
  106. data/lib/datadog/tracing/contrib/mongodb/ext.rb +1 -0
  107. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +2 -0
  108. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +4 -1
  109. data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
  110. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -2
  111. data/lib/datadog/tracing/contrib/patcher.rb +3 -2
  112. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +4 -1
  113. data/lib/datadog/tracing/contrib/pg/ext.rb +1 -0
  114. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +12 -2
  115. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +4 -1
  116. data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
  117. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +1 -0
  118. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +10 -12
  119. data/lib/datadog/tracing/contrib/que/tracer.rb +2 -0
  120. data/lib/datadog/tracing/contrib/racecar/events/batch.rb +4 -1
  121. data/lib/datadog/tracing/contrib/racecar/events/message.rb +4 -1
  122. data/lib/datadog/tracing/contrib/rack/middlewares.rb +2 -0
  123. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +4 -1
  124. data/lib/datadog/tracing/contrib/redis/ext.rb +1 -0
  125. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +30 -21
  126. data/lib/datadog/tracing/contrib/redis/integration.rb +34 -2
  127. data/lib/datadog/tracing/contrib/redis/patcher.rb +18 -14
  128. data/lib/datadog/tracing/contrib/redis/quantize.rb +12 -9
  129. data/lib/datadog/tracing/contrib/redis/tags.rb +4 -6
  130. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +72 -0
  131. data/lib/datadog/tracing/contrib/resque/resque_job.rb +2 -0
  132. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +6 -1
  133. data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
  134. data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +2 -0
  135. data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +5 -0
  136. data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +5 -0
  137. data/lib/datadog/tracing/contrib/sneakers/tracer.rb +2 -0
  138. data/lib/datadog/{core → tracing}/diagnostics/ext.rb +1 -6
  139. data/lib/datadog/tracing/diagnostics/health.rb +40 -0
  140. data/lib/datadog/tracing/distributed/b3_multi.rb +66 -0
  141. data/lib/datadog/tracing/distributed/b3_single.rb +66 -0
  142. data/lib/datadog/tracing/distributed/datadog.rb +153 -0
  143. data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +1 -0
  144. data/lib/datadog/tracing/distributed/fetcher.rb +30 -0
  145. data/lib/datadog/tracing/distributed/headers/ext.rb +18 -16
  146. data/lib/datadog/tracing/distributed/helpers.rb +9 -7
  147. data/lib/datadog/tracing/distributed/none.rb +19 -0
  148. data/lib/datadog/tracing/distributed/propagation.rb +127 -0
  149. data/lib/datadog/tracing/distributed/trace_context.rb +369 -0
  150. data/lib/datadog/tracing/metadata/ext.rb +1 -1
  151. data/lib/datadog/tracing/propagation/http.rb +3 -106
  152. data/lib/datadog/tracing/sampling/priority_sampler.rb +11 -0
  153. data/lib/datadog/tracing/sampling/rate_sampler.rb +3 -3
  154. data/lib/datadog/tracing/span.rb +3 -19
  155. data/lib/datadog/tracing/span_operation.rb +5 -4
  156. data/lib/datadog/tracing/trace_digest.rb +75 -2
  157. data/lib/datadog/tracing/trace_operation.rb +5 -4
  158. data/lib/datadog/tracing/trace_segment.rb +1 -1
  159. data/lib/datadog/tracing/utils.rb +50 -0
  160. data/lib/ddtrace/transport/trace_formatter.rb +2 -5
  161. data/lib/ddtrace/version.rb +2 -2
  162. metadata +35 -15
  163. data/lib/datadog/tracing/distributed/headers/b3.rb +0 -55
  164. data/lib/datadog/tracing/distributed/headers/b3_single.rb +0 -67
  165. data/lib/datadog/tracing/distributed/headers/datadog.rb +0 -144
  166. data/lib/datadog/tracing/distributed/headers/parser.rb +0 -37
  167. data/lib/datadog/tracing/distributed/metadata/b3.rb +0 -55
  168. data/lib/datadog/tracing/distributed/metadata/b3_single.rb +0 -66
  169. data/lib/datadog/tracing/distributed/metadata/datadog.rb +0 -73
  170. data/lib/datadog/tracing/distributed/metadata/parser.rb +0 -34
  171. data/lib/datadog/tracing/propagation/grpc.rb +0 -98
@@ -1,9 +1,8 @@
1
1
  # typed: ignore
2
2
 
3
3
  require_relative '../../../../tracing'
4
- require_relative '../../../distributed/headers/ext'
5
4
  require_relative '../../../metadata/ext'
6
- require_relative '../../../propagation/grpc'
5
+ require_relative '../distributed/propagation'
7
6
  require_relative '../../analytics'
8
7
  require_relative '../ext'
9
8
  require_relative '../../ext'
@@ -45,7 +44,7 @@ module Datadog
45
44
  private
46
45
 
47
46
  def set_distributed_context!(metadata)
48
- Tracing.continue_trace!(Tracing::Propagation::GRPC.extract(metadata))
47
+ Tracing.continue_trace!(Distributed::Propagation::INSTANCE.extract(metadata))
49
48
  rescue StandardError => e
50
49
  Datadog.logger.debug(
51
50
  "unable to propagate GRPC metadata to context: #{e}"
@@ -54,11 +53,14 @@ module Datadog
54
53
 
55
54
  def annotate!(span, metadata)
56
55
  metadata.each do |header, value|
57
- next if reserved_headers.include?(header)
56
+ # Datadog propagation headers are considered internal implementation detail.
57
+ next if header.to_s.start_with?(Tracing::Distributed::Datadog::TAGS_PREFIX)
58
58
 
59
59
  span.set_tag(header, value)
60
60
  end
61
61
 
62
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_SERVER)
63
+
62
64
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
63
65
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_SERVICE)
64
66
 
@@ -71,14 +73,6 @@ module Datadog
71
73
  Datadog.logger.debug("GRPC client trace failed: #{e}")
72
74
  end
73
75
 
74
- def reserved_headers
75
- [
76
- Tracing::Distributed::Headers::Ext::GRPC_METADATA_TRACE_ID,
77
- Tracing::Distributed::Headers::Ext::GRPC_METADATA_PARENT_ID,
78
- Tracing::Distributed::Headers::Ext::GRPC_METADATA_SAMPLING_PRIORITY
79
- ]
80
- end
81
-
82
76
  def format_resource(proto_method)
83
77
  proto_method
84
78
  .owner
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ require_relative '../../../distributed/fetcher'
5
+
6
+ module Datadog
7
+ module Tracing
8
+ module Contrib
9
+ module GRPC
10
+ module Distributed
11
+ # Retrieves values from the gRPC metadata.
12
+ # One metadata key can be associated with multiple values.
13
+ #
14
+ # @see https://github.com/grpc/grpc-go/blob/56ac86fa0f3940cb79946ce2c6e56f7ee7ecae84/Documentation/grpc-metadata.md#constructing-metadata
15
+ class Fetcher < Tracing::Distributed::Fetcher
16
+ def [](key)
17
+ # Metadata values are normally integrals but can also be
18
+ # arrays when multiple values are associated with the same key.
19
+ value = super(key)
20
+ value.is_a?(::Array) ? value[0] : value
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ require_relative 'fetcher'
5
+ require_relative '../../../distributed/b3_multi'
6
+ require_relative '../../../distributed/b3_single'
7
+ require_relative '../../../distributed/datadog'
8
+ require_relative '../../../distributed/none'
9
+ require_relative '../../../distributed/propagation'
10
+ require_relative '../../../distributed/trace_context'
11
+
12
+ module Datadog
13
+ module Tracing
14
+ module Contrib
15
+ module GRPC
16
+ module Distributed
17
+ # Extracts and injects propagation through gRPC metadata.
18
+ # @see https://github.com/grpc/grpc-go/blob/v1.50.1/Documentation/grpc-metadata.md
19
+ class Propagation < Tracing::Distributed::Propagation
20
+ def initialize
21
+ super(
22
+ propagation_styles: {
23
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER =>
24
+ Tracing::Distributed::B3Multi.new(fetcher: Fetcher),
25
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER =>
26
+ Tracing::Distributed::B3Single.new(fetcher: Fetcher),
27
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG =>
28
+ Tracing::Distributed::Datadog.new(fetcher: Fetcher),
29
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT =>
30
+ Tracing::Distributed::TraceContext.new(fetcher: Fetcher),
31
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_NONE => Tracing::Distributed::None.new
32
+ })
33
+ end
34
+
35
+ # DEV: Singleton kept until a larger refactor is performed.
36
+ # DEV: See {Datadog::Tracing::Distributed::Propagation#initialize} for more information.
37
+ INSTANCE = Propagation.new
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_GRPC_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_GRPC_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_GRPC_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_GRPC_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'grpc'.freeze
@@ -19,8 +19,6 @@ module Datadog
19
19
  end
20
20
 
21
21
  def patch
22
- require_relative '../../propagation/grpc'
23
- require_relative 'datadog_interceptor'
24
22
  require_relative 'intercept_with_datadog'
25
23
 
26
24
  prepend_interceptor
@@ -27,7 +27,12 @@ module Datadog
27
27
  end
28
28
 
29
29
  option :distributed_tracing, default: true
30
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
30
+
31
+ option :service_name do |o|
32
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
33
+ o.lazy
34
+ end
35
+
31
36
  option :split_by_domain, default: false
32
37
  end
33
38
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: false
2
+ # typed: false
3
+
4
+ require_relative '../../../distributed/fetcher'
5
+
6
+ module Datadog
7
+ module Tracing
8
+ module Contrib
9
+ module HTTP
10
+ module Distributed
11
+ # Retrieves Rack formatted headers from HTTP headers.
12
+ class Fetcher < Tracing::Distributed::Fetcher
13
+ # TODO: Don't assume Rack format.
14
+ # Make distributed tracing headers apathetic.
15
+ # DEV: Should we try to parse both verbatim an Rack-formatted headers,
16
+ # DEV: given Rack-formatted is the most common format in Ruby?
17
+ def [](name)
18
+ rack_header = "HTTP-#{name}"
19
+ rack_header.upcase!
20
+ rack_header.tr!('-'.freeze, '_'.freeze)
21
+
22
+ hdr = super(rack_header)
23
+
24
+ # Only return the value if it is not an empty string
25
+ hdr if hdr != ''
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ # typed: true
3
+
4
+ require_relative 'fetcher'
5
+ require_relative '../../../distributed/propagation'
6
+ require_relative '../../../distributed/b3_multi'
7
+ require_relative '../../../distributed/b3_single'
8
+ require_relative '../../../distributed/datadog'
9
+ require_relative '../../../distributed/none'
10
+ require_relative '../../../distributed/trace_context'
11
+
12
+ module Datadog
13
+ module Tracing
14
+ module Contrib
15
+ module HTTP
16
+ module Distributed
17
+ # Extracts and injects propagation through HTTP headers.
18
+ class Propagation < Tracing::Distributed::Propagation
19
+ def initialize
20
+ super(
21
+ propagation_styles: {
22
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_MULTI_HEADER =>
23
+ Tracing::Distributed::B3Multi.new(fetcher: Fetcher),
24
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER =>
25
+ Tracing::Distributed::B3Single.new(fetcher: Fetcher),
26
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG =>
27
+ Tracing::Distributed::Datadog.new(fetcher: Fetcher),
28
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_TRACE_CONTEXT =>
29
+ Tracing::Distributed::TraceContext.new(fetcher: Fetcher),
30
+ Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_NONE => Tracing::Distributed::None.new
31
+ })
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_HTTP_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_NET_HTTP_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_HTTP_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_HTTP_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'net/http'.freeze
@@ -27,7 +27,12 @@ module Datadog
27
27
  end
28
28
 
29
29
  option :distributed_tracing, default: true
30
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
30
+
31
+ option :service_name do |o|
32
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
33
+ o.lazy
34
+ end
35
+
31
36
  option :split_by_domain, default: false
32
37
  end
33
38
  end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_HTTPCLIENT_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_HTTPCLIENT_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_HTTPCLIENT_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_HTTPCLIENT_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'httpclient'.freeze
@@ -27,7 +27,12 @@ module Datadog
27
27
  end
28
28
 
29
29
  option :distributed_tracing, default: true
30
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
30
+
31
+ option :service_name do |o|
32
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
33
+ o.lazy
34
+ end
35
+
31
36
  option :split_by_domain, default: false
32
37
  end
33
38
  end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_HTTPRB_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_HTTPRB_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_HTTPRB_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_EHTTPRB_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'httprb'.freeze
@@ -10,6 +10,7 @@ module Datadog
10
10
  super
11
11
 
12
12
  span.set_tag(Ext::TAG_GROUP, payload[:group_id])
13
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CONSUMER)
13
14
  end
14
15
  end
15
16
  end
@@ -20,6 +20,7 @@ module Datadog
20
20
 
21
21
  span.set_tag(Ext::TAG_MESSAGE_COUNT, payload[:message_count]) if payload.key?(:message_count)
22
22
  span.set_tag(Ext::TAG_SENT_MESSAGE_COUNT, payload[:sent_message_count]) if payload.key?(:sent_message_count)
23
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_PRODUCER)
23
24
  end
24
25
 
25
26
  module_function
@@ -23,6 +23,7 @@ module Datadog
23
23
  if payload.key?(:delivered_message_count)
24
24
  span.set_tag(Ext::TAG_DELIVERED_MESSAGE_COUNT, payload[:delivered_message_count])
25
25
  end
26
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_PRODUCER)
26
27
  end
27
28
 
28
29
  module_function
@@ -29,7 +29,11 @@ module Datadog
29
29
  end
30
30
 
31
31
  option :quantize, default: DEFAULT_QUANTIZE
32
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
32
+
33
+ option :service_name do |o|
34
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
35
+ o.lazy
36
+ end
33
37
  end
34
38
  end
35
39
  end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_MONGO_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_MONGO_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_MONGO_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_MONGO_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'mongodb'.freeze
@@ -33,6 +33,8 @@ module Datadog
33
33
 
34
34
  span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)
35
35
 
36
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
37
+
36
38
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
37
39
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_COMMAND)
38
40
 
@@ -28,7 +28,10 @@ module Datadog
28
28
  o.lazy
29
29
  end
30
30
 
31
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
31
+ option :service_name do |o|
32
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
33
+ o.lazy
34
+ end
32
35
 
33
36
  option :comment_propagation do |o|
34
37
  o.default do
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_MYSQL2_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_MYSQL2_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_MYSQL2_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_MYSQL2_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'mysql2'.freeze
@@ -22,7 +22,7 @@ module Datadog
22
22
  def query(sql, options = {})
23
23
  service = Datadog.configuration_for(self, :service_name) || datadog_configuration[:service_name]
24
24
 
25
- Tracing.trace(Ext::SPAN_QUERY, service: service) do |span|
25
+ Tracing.trace(Ext::SPAN_QUERY, service: service) do |span, trace_op|
26
26
  span.resource = sql
27
27
  span.span_type = Tracing::Metadata::Ext::SQL::TYPE
28
28
 
@@ -46,7 +46,7 @@ module Datadog
46
46
  propagation_mode = Contrib::Propagation::SqlComment::Mode.new(comment_propagation)
47
47
 
48
48
  Contrib::Propagation::SqlComment.annotate!(span, propagation_mode)
49
- sql = Contrib::Propagation::SqlComment.prepend_comment(sql, span, propagation_mode)
49
+ sql = Contrib::Propagation::SqlComment.prepend_comment(sql, span, trace_op, propagation_mode)
50
50
 
51
51
  super(sql, options)
52
52
  end
@@ -66,14 +66,15 @@ module Datadog
66
66
  Datadog.health_metrics.error_instrumentation_patch(1, tags: tags)
67
67
  end
68
68
 
69
- private
70
-
71
69
  def default_tags
72
70
  ["patcher:#{patch_name}"].tap do |tags|
73
71
  tags << "target_version:#{target_version}" if respond_to?(:target_version) && !target_version.nil?
72
+ super.each { |t| tags << t } if defined?(super)
74
73
  end
75
74
  end
76
75
 
76
+ private
77
+
77
78
  def patch_only_once
78
79
  # NOTE: This is not thread-safe
79
80
  @patch_only_once ||= Core::Utils::OnlyOnce.new
@@ -28,7 +28,10 @@ module Datadog
28
28
  o.lazy
29
29
  end
30
30
 
31
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
31
+ option :service_name do |o|
32
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
33
+ o.lazy
34
+ end
32
35
 
33
36
  option :comment_propagation do |o|
34
37
  o.default do
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_PG_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_PG_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_PG_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_PG_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'pg'.freeze
@@ -80,7 +80,12 @@ module Datadog
80
80
  service = Datadog.configuration_for(self, :service_name) || datadog_configuration[:service_name]
81
81
  resource = statement_name || sql
82
82
 
83
- Tracing.trace(name, service: service, resource: resource, type: Tracing::Metadata::Ext::SQL::TYPE) do |span|
83
+ Tracing.trace(
84
+ name,
85
+ service: service,
86
+ resource: resource,
87
+ type: Tracing::Metadata::Ext::SQL::TYPE
88
+ ) do |span, trace_op|
84
89
  annotate_span_with_query!(span, service)
85
90
  # Set analytics sample rate
86
91
  Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
@@ -88,7 +93,12 @@ module Datadog
88
93
  if sql
89
94
  propagation_mode = Contrib::Propagation::SqlComment::Mode.new(comment_propagation)
90
95
  Contrib::Propagation::SqlComment.annotate!(span, propagation_mode)
91
- propagated_sql_statement = Contrib::Propagation::SqlComment.prepend_comment(sql, span, propagation_mode)
96
+ propagated_sql_statement = Contrib::Propagation::SqlComment.prepend_comment(
97
+ sql,
98
+ span,
99
+ trace_op,
100
+ propagation_mode
101
+ )
92
102
  end
93
103
 
94
104
  result = yield(propagated_sql_statement)
@@ -26,7 +26,10 @@ module Datadog
26
26
  o.lazy
27
27
  end
28
28
 
29
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
29
+ option :service_name do |o|
30
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
31
+ o.lazy
32
+ end
30
33
  end
31
34
  end
32
35
  end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_PRESTO_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_PRESTO_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_PRESTO_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_PRESTO_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  DEFAULT_PEER_SERVICE_NAME = 'presto'.freeze
@@ -24,6 +24,7 @@ module Datadog
24
24
  KEY_ENVIRONMENT = 'dde'.freeze
25
25
  KEY_PARENT_SERVICE = 'ddps'.freeze
26
26
  KEY_VERSION = 'ddpv'.freeze
27
+ KEY_TRACEPARENT = 'traceparent'.freeze
27
28
  end
28
29
  end
29
30
  end
@@ -3,6 +3,8 @@
3
3
  require_relative 'sql_comment/comment'
4
4
  require_relative 'sql_comment/ext'
5
5
 
6
+ require_relative '../../distributed/trace_context'
7
+
6
8
  module Datadog
7
9
  module Tracing
8
10
  module Contrib
@@ -12,11 +14,12 @@ module Datadog
12
14
  def self.annotate!(span_op, mode)
13
15
  return unless mode.enabled?
14
16
 
15
- # PENDING: Until `traceparent`` implementation in `full` mode
16
- # span_op.set_tag(Ext::TAG_DBM_TRACE_INJECTED, true) if mode.full?
17
+ span_op.set_tag(Ext::TAG_DBM_TRACE_INJECTED, true) if mode.full?
17
18
  end
18
19
 
19
- def self.prepend_comment(sql, span_op, mode)
20
+ # Inject span_op and trace_op instead of TraceDigest to improve memory usage
21
+ # for `disabled` and `service` mode
22
+ def self.prepend_comment(sql, span_op, trace_op, mode)
20
23
  return sql unless mode.enabled?
21
24
 
22
25
  tags = {
@@ -26,8 +29,10 @@ module Datadog
26
29
  Ext::KEY_VERSION => datadog_configuration.version
27
30
  }
28
31
 
29
- # PENDING: Until `traceparent`` implementation in `full` mode
30
- # tags.merge!(trace_context(span_op)) if mode.full?
32
+ if mode.full?
33
+ tags[Ext::KEY_TRACEPARENT] =
34
+ Tracing::Distributed::TraceContext.new(fetcher: nil).send(:build_traceparent, trace_op.to_digest)
35
+ end
31
36
 
32
37
  "#{Comment.new(tags)} #{sql}"
33
38
  end
@@ -35,13 +40,6 @@ module Datadog
35
40
  def self.datadog_configuration
36
41
  Datadog.configuration
37
42
  end
38
-
39
- # TODO: Derive from trace
40
- def self.trace_context(_)
41
- {
42
- # traceparent: '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01'
43
- }.freeze
44
- end
45
43
  end
46
44
  end
47
45
  end
@@ -33,6 +33,8 @@ module Datadog
33
33
  request_span.set_tag(Ext::TAG_JOB_ARGS, job.que_attrs[:args]) if configuration[:tag_args]
34
34
  request_span.set_tag(Ext::TAG_JOB_DATA, job.que_attrs[:data]) if configuration[:tag_data]
35
35
 
36
+ request_span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CONSUMER)
37
+
36
38
  set_sample_rate(request_span)
37
39
  Contrib::Analytics.set_measured(request_span)
38
40
 
@@ -25,7 +25,10 @@ module Datadog
25
25
  end
26
26
 
27
27
  def span_options
28
- super.merge(tags: { Tracing::Metadata::Ext::TAG_OPERATION => Ext::TAG_OPERATION_BATCH })
28
+ super.merge(
29
+ tags: { Tracing::Metadata::Ext::TAG_OPERATION => Ext::TAG_OPERATION_BATCH,
30
+ Tracing::Metadata::Ext::TAG_KIND => Tracing::Metadata::Ext::SpanKind::TAG_CONSUMER }
31
+ )
29
32
  end
30
33
  end
31
34
  end
@@ -25,7 +25,10 @@ module Datadog
25
25
  end
26
26
 
27
27
  def span_options
28
- super.merge(tags: { Tracing::Metadata::Ext::TAG_OPERATION => Ext::TAG_OPERATION_MESSAGE })
28
+ super.merge(
29
+ tags: { Tracing::Metadata::Ext::TAG_OPERATION => Ext::TAG_OPERATION_MESSAGE,
30
+ Tracing::Metadata::Ext::TAG_KIND => Tracing::Metadata::Ext::SpanKind::TAG_CONSUMER }
31
+ )
29
32
  end
30
33
  end
31
34
  end
@@ -45,6 +45,7 @@ module Datadog
45
45
  # Tag this span as belonging to Rack
46
46
  frontend_span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
47
47
  frontend_span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_HTTP_SERVER_QUEUE)
48
+ frontend_span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_SERVER)
48
49
 
49
50
  # Set peer service (so its not believed to belong to this app)
50
51
  frontend_span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, configuration[:web_service_name])
@@ -157,6 +158,7 @@ module Datadog
157
158
 
158
159
  request_span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
159
160
  request_span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
161
+ request_span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_SERVER)
160
162
 
161
163
  # Set analytics sample rate
162
164
  if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
@@ -31,7 +31,10 @@ module Datadog
31
31
  o.lazy
32
32
  end
33
33
 
34
- option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
34
+ option :service_name do |o|
35
+ o.default { ENV.fetch(Ext::ENV_SERVICE_NAME, Ext::DEFAULT_PEER_SERVICE_NAME) }
36
+ o.lazy
37
+ end
35
38
  end
36
39
  end
37
40
  end
@@ -8,6 +8,7 @@ module Datadog
8
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
9
  module Ext
10
10
  ENV_ENABLED = 'DD_TRACE_REDIS_ENABLED'.freeze
11
+ ENV_SERVICE_NAME = 'DD_TRACE_REDIS_SERVICE_NAME'.freeze
11
12
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_REDIS_ANALYTICS_ENABLED'.freeze
12
13
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_REDIS_ANALYTICS_SAMPLE_RATE'.freeze
13
14
  ENV_COMMAND_ARGS = 'DD_REDIS_COMMAND_ARGS'.freeze