ddtrace 1.12.1 → 1.13.1

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/CHANGELOG.md +129 -9
  3. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +97 -14
  4. data/ext/ddtrace_profiling_native_extension/extconf.rb +6 -0
  5. data/ext/ddtrace_profiling_native_extension/http_transport.c +19 -6
  6. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -1
  7. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +41 -2
  8. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +6 -0
  9. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +6 -10
  10. data/ext/ddtrace_profiling_native_extension/time_helpers.c +40 -4
  11. data/ext/ddtrace_profiling_native_extension/time_helpers.h +14 -0
  12. data/lib/datadog/appsec/component.rb +9 -0
  13. data/lib/datadog/appsec/configuration/settings.rb +104 -195
  14. data/lib/datadog/appsec/configuration.rb +0 -79
  15. data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -4
  16. data/lib/datadog/appsec/contrib/devise/event.rb +57 -0
  17. data/lib/datadog/appsec/contrib/devise/ext.rb +13 -0
  18. data/lib/datadog/appsec/contrib/devise/integration.rb +42 -0
  19. data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +76 -0
  20. data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +52 -0
  21. data/lib/datadog/appsec/contrib/devise/patcher.rb +45 -0
  22. data/lib/datadog/appsec/contrib/devise/resource.rb +35 -0
  23. data/lib/datadog/appsec/contrib/devise/tracking.rb +49 -0
  24. data/lib/datadog/appsec/contrib/rack/ext.rb +2 -1
  25. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +1 -1
  26. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +1 -1
  27. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +1 -1
  28. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +12 -7
  29. data/lib/datadog/appsec/contrib/rails/ext.rb +3 -2
  30. data/lib/datadog/appsec/contrib/rails/framework.rb +1 -3
  31. data/lib/datadog/appsec/contrib/rails/patcher.rb +8 -8
  32. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +1 -1
  33. data/lib/datadog/appsec/contrib/sinatra/ext.rb +2 -1
  34. data/lib/datadog/appsec/contrib/sinatra/framework.rb +1 -3
  35. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +1 -1
  36. data/lib/datadog/appsec/event.rb +1 -1
  37. data/lib/datadog/appsec/extensions.rb +1 -130
  38. data/lib/datadog/appsec/monitor/reactive/set_user.rb +1 -1
  39. data/lib/datadog/appsec/processor.rb +1 -1
  40. data/lib/datadog/appsec/rate_limiter.rb +1 -1
  41. data/lib/datadog/appsec/remote.rb +1 -1
  42. data/lib/datadog/appsec.rb +1 -2
  43. data/lib/datadog/ci/configuration/settings.rb +6 -8
  44. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +7 -5
  45. data/lib/datadog/ci/contrib/cucumber/ext.rb +10 -8
  46. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +35 -0
  47. data/lib/datadog/ci/contrib/minitest/ext.rb +21 -0
  48. data/lib/datadog/ci/contrib/minitest/integration.rb +49 -0
  49. data/lib/datadog/ci/contrib/minitest/patcher.rb +27 -0
  50. data/lib/datadog/ci/contrib/minitest/test_helper.rb +68 -0
  51. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +7 -5
  52. data/lib/datadog/ci/contrib/rspec/ext.rb +9 -7
  53. data/lib/datadog/ci.rb +1 -0
  54. data/lib/datadog/core/backport.rb +51 -0
  55. data/lib/datadog/core/configuration/agent_settings_resolver.rb +9 -5
  56. data/lib/datadog/core/configuration/base.rb +5 -5
  57. data/lib/datadog/core/configuration/components.rb +6 -1
  58. data/lib/datadog/core/configuration/ext.rb +7 -5
  59. data/lib/datadog/core/configuration/option.rb +269 -19
  60. data/lib/datadog/core/configuration/option_definition.rb +76 -11
  61. data/lib/datadog/core/configuration/options.rb +22 -10
  62. data/lib/datadog/core/configuration/settings.rb +139 -61
  63. data/lib/datadog/core/environment/execution.rb +55 -0
  64. data/lib/datadog/core/environment/ext.rb +13 -11
  65. data/lib/datadog/core/environment/yjit.rb +58 -0
  66. data/lib/datadog/core/git/ext.rb +24 -22
  67. data/lib/datadog/core/logging/ext.rb +3 -1
  68. data/lib/datadog/core/metrics/ext.rb +7 -5
  69. data/lib/datadog/core/remote/client/capabilities.rb +5 -0
  70. data/lib/datadog/core/remote/client.rb +3 -0
  71. data/lib/datadog/core/remote/component.rb +25 -34
  72. data/lib/datadog/core/remote/configuration/content.rb +28 -1
  73. data/lib/datadog/core/remote/configuration/repository.rb +3 -1
  74. data/lib/datadog/core/remote/ext.rb +1 -1
  75. data/lib/datadog/core/remote/negotiation.rb +17 -4
  76. data/lib/datadog/core/runtime/ext.rb +22 -12
  77. data/lib/datadog/core/runtime/metrics.rb +43 -0
  78. data/lib/datadog/core/telemetry/client.rb +12 -2
  79. data/lib/datadog/core/telemetry/emitter.rb +4 -2
  80. data/lib/datadog/core/telemetry/event.rb +19 -4
  81. data/lib/datadog/core/telemetry/ext.rb +4 -1
  82. data/lib/datadog/core/telemetry/heartbeat.rb +2 -4
  83. data/lib/datadog/core/telemetry/http/ext.rb +10 -8
  84. data/lib/datadog/core/telemetry/http/transport.rb +1 -0
  85. data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +41 -0
  86. data/lib/datadog/core/telemetry/v2/request.rb +29 -0
  87. data/lib/datadog/core/transport/http/client.rb +1 -1
  88. data/lib/datadog/core/transport/http/config.rb +10 -0
  89. data/lib/datadog/core/utils/duration.rb +52 -0
  90. data/lib/datadog/core/utils/hash.rb +47 -0
  91. data/lib/datadog/core/utils/network.rb +1 -1
  92. data/lib/datadog/core/utils/safe_dup.rb +27 -20
  93. data/lib/datadog/core/utils.rb +1 -1
  94. data/lib/datadog/core/workers/async.rb +2 -2
  95. data/lib/datadog/kit/appsec/events.rb +139 -89
  96. data/lib/datadog/kit/identity.rb +80 -65
  97. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +3 -0
  98. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -0
  99. data/lib/datadog/profiling/collectors/thread_context.rb +9 -2
  100. data/lib/datadog/profiling/component.rb +41 -9
  101. data/lib/datadog/profiling/exporter.rb +5 -1
  102. data/lib/datadog/profiling/flush.rb +9 -2
  103. data/lib/datadog/profiling/http_transport.rb +13 -3
  104. data/lib/datadog/profiling/load_native_extension.rb +7 -1
  105. data/lib/datadog/profiling.rb +11 -1
  106. data/lib/datadog/tracing/component.rb +58 -6
  107. data/lib/datadog/tracing/configuration/dynamic/option.rb +71 -0
  108. data/lib/datadog/tracing/configuration/dynamic.rb +64 -0
  109. data/lib/datadog/tracing/configuration/ext.rb +35 -32
  110. data/lib/datadog/tracing/configuration/http.rb +74 -0
  111. data/lib/datadog/tracing/configuration/settings.rb +106 -92
  112. data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +9 -6
  113. data/lib/datadog/tracing/contrib/action_cable/ext.rb +20 -18
  114. data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +9 -6
  115. data/lib/datadog/tracing/contrib/action_mailer/ext.rb +20 -18
  116. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +8 -6
  117. data/lib/datadog/tracing/contrib/action_pack/ext.rb +10 -8
  118. data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +9 -6
  119. data/lib/datadog/tracing/contrib/action_view/ext.rb +12 -10
  120. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +13 -7
  121. data/lib/datadog/tracing/contrib/active_job/ext.rb +25 -23
  122. data/lib/datadog/tracing/contrib/active_job/log_injection.rb +1 -1
  123. data/lib/datadog/tracing/contrib/active_job/patcher.rb +1 -1
  124. data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +9 -6
  125. data/lib/datadog/tracing/contrib/active_model_serializers/ext.rb +12 -10
  126. data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +9 -7
  127. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +0 -8
  128. data/lib/datadog/tracing/contrib/active_record/ext.rb +17 -15
  129. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +0 -5
  130. data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +9 -7
  131. data/lib/datadog/tracing/contrib/active_support/ext.rb +18 -16
  132. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +14 -7
  133. data/lib/datadog/tracing/contrib/aws/ext.rb +37 -24
  134. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +9 -5
  135. data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +3 -2
  136. data/lib/datadog/tracing/contrib/concurrent_ruby/ext.rb +4 -2
  137. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +14 -7
  138. data/lib/datadog/tracing/contrib/dalli/ext.rb +19 -11
  139. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +8 -6
  140. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +13 -7
  141. data/lib/datadog/tracing/contrib/delayed_job/ext.rb +16 -14
  142. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +14 -7
  143. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +21 -15
  144. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +8 -5
  145. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +16 -9
  146. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +43 -3
  147. data/lib/datadog/tracing/contrib/ethon/ext.rb +19 -11
  148. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +0 -5
  149. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +19 -10
  150. data/lib/datadog/tracing/contrib/excon/ext.rb +16 -8
  151. data/lib/datadog/tracing/contrib/excon/middleware.rb +20 -5
  152. data/lib/datadog/tracing/contrib/ext.rb +23 -1
  153. data/lib/datadog/tracing/contrib/extensions.rb +32 -0
  154. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +20 -10
  155. data/lib/datadog/tracing/contrib/faraday/ext.rb +16 -8
  156. data/lib/datadog/tracing/contrib/faraday/middleware.rb +16 -5
  157. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +8 -6
  158. data/lib/datadog/tracing/contrib/grape/ext.rb +16 -14
  159. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +8 -6
  160. data/lib/datadog/tracing/contrib/graphql/ext.rb +7 -5
  161. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +19 -9
  162. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +29 -20
  163. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +21 -20
  164. data/lib/datadog/tracing/contrib/grpc/ext.rb +16 -13
  165. data/lib/datadog/tracing/contrib/grpc/formatting.rb +127 -0
  166. data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +3 -2
  167. data/lib/datadog/tracing/contrib/hanami/ext.rb +10 -8
  168. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +4 -7
  169. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +33 -11
  170. data/lib/datadog/tracing/contrib/http/ext.rb +16 -9
  171. data/lib/datadog/tracing/contrib/http/instrumentation.rb +22 -7
  172. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +33 -11
  173. data/lib/datadog/tracing/contrib/httpclient/ext.rb +17 -9
  174. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +17 -5
  175. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +33 -11
  176. data/lib/datadog/tracing/contrib/httprb/ext.rb +16 -9
  177. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +17 -5
  178. data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +9 -6
  179. data/lib/datadog/tracing/contrib/kafka/ext.rb +42 -39
  180. data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +3 -2
  181. data/lib/datadog/tracing/contrib/lograge/ext.rb +3 -1
  182. data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +1 -0
  183. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +14 -7
  184. data/lib/datadog/tracing/contrib/mongodb/ext.rb +20 -16
  185. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +9 -5
  186. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +17 -14
  187. data/lib/datadog/tracing/contrib/mysql2/ext.rb +15 -10
  188. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +9 -5
  189. data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +52 -0
  190. data/lib/datadog/tracing/contrib/opensearch/ext.rb +37 -0
  191. data/lib/datadog/tracing/contrib/opensearch/integration.rb +44 -0
  192. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +128 -0
  193. data/lib/datadog/tracing/contrib/opensearch/quantize.rb +81 -0
  194. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +17 -14
  195. data/lib/datadog/tracing/contrib/pg/ext.rb +22 -19
  196. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +9 -5
  197. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +14 -7
  198. data/lib/datadog/tracing/contrib/presto/ext.rb +25 -20
  199. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +9 -5
  200. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +12 -10
  201. data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +12 -8
  202. data/lib/datadog/tracing/contrib/qless/ext.rb +14 -12
  203. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +21 -12
  204. data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +9 -7
  205. data/lib/datadog/tracing/contrib/racecar/event.rb +0 -5
  206. data/lib/datadog/tracing/contrib/racecar/ext.rb +20 -18
  207. data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +16 -12
  208. data/lib/datadog/tracing/contrib/rack/ext.rb +18 -16
  209. data/lib/datadog/tracing/contrib/rack/header_collection.rb +3 -0
  210. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +53 -0
  211. data/lib/datadog/tracing/contrib/rack/middlewares.rb +8 -49
  212. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +15 -11
  213. data/lib/datadog/tracing/contrib/rails/ext.rb +7 -5
  214. data/lib/datadog/tracing/contrib/rails/log_injection.rb +7 -10
  215. data/lib/datadog/tracing/contrib/rails/patcher.rb +10 -41
  216. data/lib/datadog/tracing/contrib/rails/railtie.rb +3 -3
  217. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +12 -9
  218. data/lib/datadog/tracing/contrib/rake/ext.rb +14 -12
  219. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +17 -9
  220. data/lib/datadog/tracing/contrib/redis/ext.rb +22 -15
  221. data/lib/datadog/tracing/contrib/redis/tags.rb +9 -5
  222. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +13 -7
  223. data/lib/datadog/tracing/contrib/resque/ext.rb +9 -7
  224. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +16 -9
  225. data/lib/datadog/tracing/contrib/rest_client/ext.rb +15 -8
  226. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +20 -5
  227. data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +9 -6
  228. data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +3 -2
  229. data/lib/datadog/tracing/contrib/semantic_logger/ext.rb +3 -1
  230. data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +1 -0
  231. data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +9 -6
  232. data/lib/datadog/tracing/contrib/sequel/ext.rb +10 -8
  233. data/lib/datadog/tracing/contrib/sequel/utils.rb +2 -7
  234. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +14 -8
  235. data/lib/datadog/tracing/contrib/shoryuken/ext.rb +14 -12
  236. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +18 -11
  237. data/lib/datadog/tracing/contrib/sidekiq/ext.rb +32 -30
  238. data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +11 -9
  239. data/lib/datadog/tracing/contrib/sinatra/env.rb +0 -17
  240. data/lib/datadog/tracing/contrib/sinatra/ext.rb +21 -19
  241. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +3 -14
  242. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +14 -8
  243. data/lib/datadog/tracing/contrib/sneakers/ext.rb +1 -0
  244. data/lib/datadog/tracing/contrib/sneakers/tracer.rb +1 -1
  245. data/lib/datadog/tracing/contrib/span_attribute_schema.rb +74 -10
  246. data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +9 -6
  247. data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +9 -6
  248. data/lib/datadog/tracing/contrib/sucker_punch/ext.rb +15 -13
  249. data/lib/datadog/tracing/contrib/utils/database.rb +5 -3
  250. data/lib/datadog/tracing/contrib.rb +1 -0
  251. data/lib/datadog/tracing/correlation.rb +9 -12
  252. data/lib/datadog/tracing/diagnostics/ext.rb +21 -19
  253. data/lib/datadog/tracing/distributed/b3_multi.rb +2 -2
  254. data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
  255. data/lib/datadog/tracing/distributed/trace_context.rb +52 -17
  256. data/lib/datadog/tracing/metadata/ext.rb +9 -6
  257. data/lib/datadog/tracing/remote.rb +78 -0
  258. data/lib/datadog/tracing/sampling/rule_sampler.rb +29 -0
  259. data/lib/datadog/tracing/span_operation.rb +3 -15
  260. data/lib/datadog/tracing/trace_operation.rb +16 -3
  261. data/lib/datadog/tracing/trace_segment.rb +5 -2
  262. data/lib/datadog/tracing/tracer.rb +10 -1
  263. data/lib/ddtrace/transport/ext.rb +15 -9
  264. data/lib/ddtrace/transport/trace_formatter.rb +9 -0
  265. data/lib/ddtrace/version.rb +8 -11
  266. metadata +36 -7
  267. data/lib/datadog/tracing/contrib/sinatra/headers.rb +0 -35
@@ -12,18 +12,21 @@ module Datadog
12
12
  # @public_api
13
13
  class Settings < Contrib::Configuration::Settings
14
14
  option :enabled do |o|
15
- o.default { env_to_bool(Ext::ENV_ENABLED, true) }
16
- o.lazy
15
+ o.type :bool
16
+ o.env Ext::ENV_ENABLED
17
+ o.default true
17
18
  end
18
19
 
19
20
  option :analytics_enabled do |o|
20
- o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }
21
- o.lazy
21
+ o.type :bool
22
+ o.env Ext::ENV_ANALYTICS_ENABLED
23
+ o.default false
22
24
  end
23
25
 
24
26
  option :analytics_sample_rate do |o|
25
- o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }
26
- o.lazy
27
+ o.type :float
28
+ o.env Ext::ENV_ANALYTICS_SAMPLE_RATE
29
+ o.default 1.0
27
30
  end
28
31
 
29
32
  option :service_name do |o|
@@ -33,7 +36,11 @@ module Datadog
33
36
  Ext::DEFAULT_PEER_SERVICE_NAME
34
37
  )
35
38
  end
36
- o.lazy
39
+ end
40
+
41
+ option :peer_service do |o|
42
+ o.type :string, nilable: true
43
+ o.env Ext::ENV_PEER_SERVICE
37
44
  end
38
45
  end
39
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Tracing
3
5
  module Contrib
@@ -5,18 +7,24 @@ module Datadog
5
7
  # Dalli integration constants
6
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
7
9
  module Ext
8
- ENV_ENABLED = 'DD_TRACE_DALLI_ENABLED'.freeze
9
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_DALLI_ANALYTICS_ENABLED'.freeze
10
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_DALLI_ANALYTICS_SAMPLE_RATE'.freeze
11
- ENV_SERVICE_NAME = 'DD_TRACE_DALLI_SERVICE_NAME'.freeze
10
+ ENV_ENABLED = 'DD_TRACE_DALLI_ENABLED'
11
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_DALLI_ANALYTICS_ENABLED'
12
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_DALLI_ANALYTICS_SAMPLE_RATE'
13
+ ENV_SERVICE_NAME = 'DD_TRACE_DALLI_SERVICE_NAME'
14
+ ENV_PEER_SERVICE = 'DD_TRACE_DALLI_PEER_SERVICE'
15
+
12
16
  QUANTIZE_MAX_CMD_LENGTH = 100
13
- DEFAULT_PEER_SERVICE_NAME = 'memcached'.freeze
14
- SPAN_COMMAND = 'memcached.command'.freeze
15
- SPAN_TYPE_COMMAND = 'memcached'.freeze
16
- TAG_COMMAND = 'memcached.command'.freeze
17
- TAG_COMPONENT = 'dalli'.freeze
18
- TAG_OPERATION_COMMAND = 'command'.freeze
19
- TAG_SYSTEM = 'memcached'.freeze
17
+ DEFAULT_PEER_SERVICE_NAME = 'memcached'
18
+ SPAN_COMMAND = 'memcached.command'
19
+ SPAN_TYPE_COMMAND = 'memcached'
20
+ TAG_COMMAND = 'memcached.command'
21
+ TAG_COMPONENT = 'dalli'
22
+ TAG_OPERATION_COMMAND = 'command'
23
+ TAG_SYSTEM = 'memcached'
24
+ PEER_SERVICE_SOURCES = Array[
25
+ Tracing::Metadata::Ext::TAG_PEER_HOSTNAME,
26
+ Tracing::Metadata::Ext::NET::TAG_DESTINATION_NAME,
27
+ Tracing::Metadata::Ext::NET::TAG_TARGET_HOST,].freeze
20
28
  end
21
29
  end
22
30
  end
@@ -22,16 +22,17 @@ module Datadog
22
22
  span.service = datadog_configuration[:service_name]
23
23
  span.span_type = Ext::SPAN_TYPE_COMMAND
24
24
 
25
+ if datadog_configuration[:peer_service]
26
+ span.set_tag(
27
+ Tracing::Metadata::Ext::TAG_PEER_SERVICE,
28
+ datadog_configuration[:peer_service]
29
+ )
30
+ end
31
+
25
32
  span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
26
33
 
27
34
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
28
35
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_COMMAND)
29
-
30
- # Tag as an external peer service
31
- if Contrib::SpanAttributeSchema.default_span_attribute_schema?
32
- span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
33
- end
34
-
35
36
  span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, hostname)
36
37
 
37
38
  # Set analytics sample rate
@@ -47,6 +48,7 @@ module Datadog
47
48
  cmd = Quantize.format_command(op, args)
48
49
  span.set_tag(Ext::TAG_COMMAND, cmd)
49
50
 
51
+ Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
50
52
  super
51
53
  end
52
54
  end
@@ -13,23 +13,29 @@ module Datadog
13
13
  # @public_api
14
14
  class Settings < Contrib::Configuration::Settings
15
15
  option :enabled do |o|
16
- o.default { env_to_bool(Ext::ENV_ENABLED, true) }
17
- o.lazy
16
+ o.type :bool
17
+ o.env Ext::ENV_ENABLED
18
+ o.default true
18
19
  end
19
20
 
20
21
  option :analytics_enabled do |o|
21
- o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }
22
- o.lazy
22
+ o.type :bool
23
+ o.env Ext::ENV_ANALYTICS_ENABLED
24
+ o.default false
23
25
  end
24
26
 
25
27
  option :analytics_sample_rate do |o|
26
- o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }
27
- o.lazy
28
+ o.type :float
29
+ o.env Ext::ENV_ANALYTICS_SAMPLE_RATE
30
+ o.default 1.0
28
31
  end
29
32
 
30
33
  option :service_name
31
34
  option :client_service_name
32
- option :error_handler, default: Tracing::SpanOperation::Events::DEFAULT_ON_ERROR
35
+ option :error_handler do |o|
36
+ o.type :proc
37
+ o.experimental_default_proc(&Tracing::SpanOperation::Events::DEFAULT_ON_ERROR)
38
+ end
33
39
  end
34
40
  end
35
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Tracing
3
5
  module Contrib
@@ -5,20 +7,20 @@ module Datadog
5
7
  # DelayedJob integration constants
6
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
7
9
  module Ext
8
- ENV_ENABLED = 'DD_TRACE_DELAYED_JOB_ENABLED'.freeze
9
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_DELAYED_JOB_ANALYTICS_ENABLED'.freeze
10
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_DELAYED_JOB_ANALYTICS_SAMPLE_RATE'.freeze
11
- SPAN_JOB = 'delayed_job'.freeze
12
- SPAN_ENQUEUE = 'delayed_job.enqueue'.freeze
13
- SPAN_RESERVE_JOB = 'delayed_job.reserve_job'.freeze
14
- TAG_ATTEMPTS = 'delayed_job.attempts'.freeze
15
- TAG_ID = 'delayed_job.id'.freeze
16
- TAG_PRIORITY = 'delayed_job.priority'.freeze
17
- TAG_QUEUE = 'delayed_job.queue'.freeze
18
- TAG_COMPONENT = 'delayed_job'.freeze
19
- TAG_OPERATION_ENQUEUE = 'enqueue'.freeze
20
- TAG_OPERATION_JOB = 'job'.freeze
21
- TAG_OPERATION_RESERVE_JOB = 'reserve_job'.freeze
10
+ ENV_ENABLED = 'DD_TRACE_DELAYED_JOB_ENABLED'
11
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_DELAYED_JOB_ANALYTICS_ENABLED'
12
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_DELAYED_JOB_ANALYTICS_SAMPLE_RATE'
13
+ SPAN_JOB = 'delayed_job'
14
+ SPAN_ENQUEUE = 'delayed_job.enqueue'
15
+ SPAN_RESERVE_JOB = 'delayed_job.reserve_job'
16
+ TAG_ATTEMPTS = 'delayed_job.attempts'
17
+ TAG_ID = 'delayed_job.id'
18
+ TAG_PRIORITY = 'delayed_job.priority'
19
+ TAG_QUEUE = 'delayed_job.queue'
20
+ TAG_COMPONENT = 'delayed_job'
21
+ TAG_OPERATION_ENQUEUE = 'enqueue'
22
+ TAG_OPERATION_JOB = 'job'
23
+ TAG_OPERATION_RESERVE_JOB = 'reserve_job'
22
24
  end
23
25
  end
24
26
  end
@@ -12,18 +12,21 @@ module Datadog
12
12
  # @public_api
13
13
  class Settings < Contrib::Configuration::Settings
14
14
  option :enabled do |o|
15
- o.default { env_to_bool(Ext::ENV_ENABLED, true) }
16
- o.lazy
15
+ o.type :bool
16
+ o.env Ext::ENV_ENABLED
17
+ o.default true
17
18
  end
18
19
 
19
20
  option :analytics_enabled do |o|
20
- o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }
21
- o.lazy
21
+ o.type :bool
22
+ o.env Ext::ENV_ANALYTICS_ENABLED
23
+ o.default false
22
24
  end
23
25
 
24
26
  option :analytics_sample_rate do |o|
25
- o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }
26
- o.lazy
27
+ o.type :float
28
+ o.env Ext::ENV_ANALYTICS_SAMPLE_RATE
29
+ o.default 1.0
27
30
  end
28
31
 
29
32
  option :quantize, default: {}
@@ -35,7 +38,11 @@ module Datadog
35
38
  Ext::DEFAULT_PEER_SERVICE_NAME
36
39
  )
37
40
  end
38
- o.lazy
41
+ end
42
+
43
+ option :peer_service do |o|
44
+ o.type :string, nilable: true
45
+ o.env Ext::ENV_PEER_SERVICE
39
46
  end
40
47
  end
41
48
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Tracing
3
5
  module Contrib
@@ -5,21 +7,25 @@ module Datadog
5
7
  # Elasticsearch integration constants
6
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
7
9
  module Ext
8
- ENV_ENABLED = 'DD_TRACE_ELASTICSEARCH_ENABLED'.freeze
9
- ENV_SERVICE_NAME = 'DD_TRACE_ELASTICSEARCH_SERVICE_NAME'.freeze
10
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_ELASTICSEARCH_ANALYTICS_ENABLED'.freeze
11
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ELASTICSEARCH_ANALYTICS_SAMPLE_RATE'.freeze
12
- DEFAULT_PEER_SERVICE_NAME = 'elasticsearch'.freeze
13
- SPAN_QUERY = 'elasticsearch.query'.freeze
14
- SPAN_TYPE_QUERY = 'elasticsearch'.freeze
15
- TAG_BODY = 'elasticsearch.body'.freeze
16
- TAG_METHOD = 'elasticsearch.method'.freeze
17
- TAG_PARAMS = 'elasticsearch.params'.freeze
18
- TAG_URL = 'elasticsearch.url'.freeze
19
- TAG_COMPONENT = 'elasticsearch'.freeze
20
- TAG_OPERATION_QUERY = 'query'.freeze
21
-
22
- TAG_SYSTEM = 'elasticsearch'.freeze
10
+ ENV_ENABLED = 'DD_TRACE_ELASTICSEARCH_ENABLED'
11
+ ENV_SERVICE_NAME = 'DD_TRACE_ELASTICSEARCH_SERVICE_NAME'
12
+ ENV_PEER_SERVICE = 'DD_TRACE_ELASTICSEARCH_PEER_SERVICE'
13
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_ELASTICSEARCH_ANALYTICS_ENABLED'
14
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ELASTICSEARCH_ANALYTICS_SAMPLE_RATE'
15
+ DEFAULT_PEER_SERVICE_NAME = 'elasticsearch'
16
+ SPAN_QUERY = 'elasticsearch.query'
17
+ SPAN_TYPE_QUERY = 'elasticsearch'
18
+ TAG_BODY = 'elasticsearch.body'
19
+ TAG_METHOD = 'elasticsearch.method'
20
+ TAG_PARAMS = 'elasticsearch.params'
21
+ TAG_URL = 'elasticsearch.url'
22
+ TAG_COMPONENT = 'elasticsearch'
23
+ TAG_OPERATION_QUERY = 'query'
24
+ TAG_SYSTEM = 'elasticsearch'
25
+ PEER_SERVICE_SOURCES = Array[
26
+ Tracing::Metadata::Ext::TAG_PEER_HOSTNAME,
27
+ Tracing::Metadata::Ext::NET::TAG_DESTINATION_NAME,
28
+ Tracing::Metadata::Ext::NET::TAG_TARGET_HOST,].freeze
23
29
  end
24
30
  end
25
31
  end
@@ -77,6 +77,13 @@ module Datadog
77
77
  host = connection.host[:host] if connection
78
78
  port = connection.host[:port] if connection
79
79
 
80
+ if datadog_configuration[:peer_service]
81
+ span.set_tag(
82
+ Tracing::Metadata::Ext::TAG_PEER_SERVICE,
83
+ datadog_configuration[:peer_service]
84
+ )
85
+ end
86
+
80
87
  span.span_type = Datadog::Tracing::Contrib::Elasticsearch::Ext::SPAN_TYPE_QUERY
81
88
 
82
89
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
@@ -89,11 +96,6 @@ module Datadog
89
96
  params = JSON.generate(params) if params && !params.is_a?(String)
90
97
  body = JSON.generate(body) if body && !body.is_a?(String)
91
98
 
92
- # Tag as an external peer service
93
- if Contrib::SpanAttributeSchema.default_span_attribute_schema?
94
- span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
95
- end
96
-
97
99
  span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, host) if host
98
100
 
99
101
  # Set analytics sample rate
@@ -117,6 +119,7 @@ module Datadog
117
119
 
118
120
  quantized_url = Datadog::Tracing::Contrib::Elasticsearch::Quantize.format_url(url)
119
121
  span.resource = "#{method} #{quantized_url}"
122
+ Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
120
123
  rescue StandardError => e
121
124
  Datadog.logger.error(e.message)
122
125
  ensure
@@ -12,23 +12,26 @@ module Datadog
12
12
  # @public_api
13
13
  class Settings < Contrib::Configuration::Settings
14
14
  option :enabled do |o|
15
- o.default { env_to_bool(Ext::ENV_ENABLED, true) }
16
- o.lazy
15
+ o.type :bool
16
+ o.env Ext::ENV_ENABLED
17
+ o.default true
17
18
  end
18
19
 
19
20
  option :analytics_enabled do |o|
20
- o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }
21
- o.lazy
21
+ o.type :bool
22
+ o.env Ext::ENV_ANALYTICS_ENABLED
23
+ o.default false
22
24
  end
23
25
 
24
26
  option :analytics_sample_rate do |o|
25
- o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }
26
- o.lazy
27
+ o.type :float
28
+ o.env Ext::ENV_ANALYTICS_SAMPLE_RATE
29
+ o.default 1.0
27
30
  end
28
31
 
29
- option :distributed_tracing, default: true
32
+ option :distributed_tracing, default: true, type: :bool
30
33
 
31
- option :split_by_domain, default: false
34
+ option :split_by_domain, default: false, type: :bool
32
35
 
33
36
  option :service_name do |o|
34
37
  o.default do
@@ -37,7 +40,11 @@ module Datadog
37
40
  Ext::DEFAULT_PEER_SERVICE_NAME
38
41
  )
39
42
  end
40
- o.lazy
43
+ end
44
+
45
+ option :peer_service do |o|
46
+ o.type :string, nilable: true
47
+ o.env Ext::ENV_PEER_SERVICE
41
48
  end
42
49
  end
43
50
  end
@@ -1,5 +1,6 @@
1
1
  require 'uri'
2
2
 
3
+ require_relative '../../../core/utils/hash'
3
4
  require_relative '../../metadata/ext'
4
5
  require_relative '../../propagation/http'
5
6
  require_relative 'ext'
@@ -58,6 +59,12 @@ module Datadog
58
59
  set_span_error_message("Request has failed with HTTP error: #{response_code}")
59
60
  end
60
61
  end
62
+
63
+ @datadog_span.set_tags(
64
+ Datadog.configuration.tracing.header_tags.response_tags(
65
+ Core::Utils::Hash::CaseInsensitiveWrapper.new(parse_response_headers)
66
+ )
67
+ )
61
68
  ensure
62
69
  @datadog_span.finish
63
70
  @datadog_span = nil
@@ -122,10 +129,13 @@ module Datadog
122
129
  method = @datadog_method.to_s if instance_variable_defined?(:@datadog_method) && !@datadog_method.nil?
123
130
  span.resource = method
124
131
 
125
- if Contrib::SpanAttributeSchema.default_span_attribute_schema?
126
- # Tag as an external peer service
127
- span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
132
+ if datadog_configuration[:peer_service]
133
+ span.set_tag(
134
+ Tracing::Metadata::Ext::TAG_PEER_SERVICE,
135
+ datadog_configuration[:peer_service]
136
+ )
128
137
  end
138
+
129
139
  # Set analytics sample rate
130
140
  Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
131
141
 
@@ -142,6 +152,16 @@ module Datadog
142
152
  span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, uri.host)
143
153
  span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, uri.port)
144
154
  span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, uri.host)
155
+
156
+ if @datadog_original_headers
157
+ span.set_tags(
158
+ Datadog.configuration.tracing.header_tags.request_tags(
159
+ Core::Utils::Hash::CaseInsensitiveWrapper.new(@datadog_original_headers)
160
+ )
161
+ )
162
+ end
163
+
164
+ Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
145
165
  end
146
166
 
147
167
  def set_span_error_message(message)
@@ -168,6 +188,26 @@ module Datadog
168
188
  def analytics_sample_rate
169
189
  datadog_configuration[:analytics_sample_rate]
170
190
  end
191
+
192
+ # `#response_headers` returns a "\n" concatenated String containing:
193
+ # * The HTTP Status-Line.
194
+ # * The response headers.
195
+ # * A trailing "\n".
196
+ #
197
+ # This method extracts only the headers from it.
198
+ def parse_response_headers
199
+ return {} if response_headers.empty?
200
+
201
+ lines = response_headers.split("\n")
202
+
203
+ lines = lines[1..(lines.size - 1)] # Remove Status-Line and trailing whitespace.
204
+
205
+ # Find only well-behaved HTTP headers.
206
+ lines.map do |line|
207
+ header = line.split(':', 2)
208
+ header.size != 2 ? nil : header
209
+ end.compact.to_h
210
+ end
171
211
  end
172
212
  end
173
213
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Tracing
3
5
  module Contrib
@@ -5,17 +7,23 @@ module Datadog
5
7
  # Ethon integration constants
6
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
7
9
  module Ext
8
- ENV_ENABLED = 'DD_TRACE_ETHON_ENABLED'.freeze
9
- ENV_SERVICE_NAME = 'DD_TRACE_ETHON_SERVICE_NAME'.freeze
10
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_ETHON_ANALYTICS_ENABLED'.freeze
11
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ETHON_ANALYTICS_SAMPLE_RATE'.freeze
12
- DEFAULT_PEER_SERVICE_NAME = 'ethon'.freeze
13
- SPAN_REQUEST = 'ethon.request'.freeze
14
- SPAN_MULTI_REQUEST = 'ethon.multi.request'.freeze
15
- NOT_APPLICABLE_METHOD = 'N/A'.freeze
16
- TAG_COMPONENT = 'ethon'.freeze
17
- TAG_OPERATION_REQUEST = 'request'.freeze
18
- TAG_OPERATION_MULTI_REQUEST = 'multi.request'.freeze
10
+ ENV_ENABLED = 'DD_TRACE_ETHON_ENABLED'
11
+ ENV_SERVICE_NAME = 'DD_TRACE_ETHON_SERVICE_NAME'
12
+ ENV_PEER_SERVICE = 'DD_TRACE_ETHON_PEER_SERVICE'
13
+
14
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_ETHON_ANALYTICS_ENABLED'
15
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_ETHON_ANALYTICS_SAMPLE_RATE'
16
+ DEFAULT_PEER_SERVICE_NAME = 'ethon'
17
+ SPAN_REQUEST = 'ethon.request'
18
+ SPAN_MULTI_REQUEST = 'ethon.multi.request'
19
+ NOT_APPLICABLE_METHOD = 'N/A'
20
+ TAG_COMPONENT = 'ethon'
21
+ TAG_OPERATION_REQUEST = 'request'
22
+ TAG_OPERATION_MULTI_REQUEST = 'multi.request'
23
+ PEER_SERVICE_SOURCES = Array[
24
+ Tracing::Metadata::Ext::TAG_PEER_HOSTNAME,
25
+ Tracing::Metadata::Ext::NET::TAG_DESTINATION_NAME,
26
+ Tracing::Metadata::Ext::NET::TAG_TARGET_HOST,].freeze
19
27
  end
20
28
  end
21
29
  end
@@ -69,11 +69,6 @@ module Datadog
69
69
 
70
70
  @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
71
71
 
72
- if Contrib::SpanAttributeSchema.default_span_attribute_schema?
73
- # Tag as an external peer service
74
- @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, @datadog_multi_span.service)
75
- end
76
-
77
72
  # Set analytics sample rate
78
73
  Contrib::Analytics.set_sample_rate(@datadog_multi_span, analytics_sample_rate) if analytics_enabled?
79
74
 
@@ -12,23 +12,28 @@ module Datadog
12
12
  # @public_api
13
13
  class Settings < Contrib::Configuration::Settings
14
14
  option :enabled do |o|
15
- o.default { env_to_bool(Ext::ENV_ENABLED, true) }
16
- o.lazy
15
+ o.type :bool
16
+ o.env Ext::ENV_ENABLED
17
+ o.default true
17
18
  end
18
19
 
19
20
  option :analytics_enabled do |o|
20
- o.default { env_to_bool(Ext::ENV_ANALYTICS_ENABLED, false) }
21
- o.lazy
21
+ o.type :bool
22
+ o.env Ext::ENV_ANALYTICS_ENABLED
23
+ o.default false
22
24
  end
23
25
 
24
26
  option :analytics_sample_rate do |o|
25
- o.default { env_to_float(Ext::ENV_ANALYTICS_SAMPLE_RATE, 1.0) }
26
- o.lazy
27
+ o.type :float
28
+ o.env Ext::ENV_ANALYTICS_SAMPLE_RATE
29
+ o.default 1.0
27
30
  end
28
31
 
29
- option :distributed_tracing, default: true
30
- option :error_handler
31
- option :split_by_domain, default: false
32
+ option :distributed_tracing, default: true, type: :bool
33
+ option :error_handler do |o|
34
+ o.type :proc, nilable: true
35
+ end
36
+ option :split_by_domain, default: false, type: :bool
32
37
 
33
38
  option :service_name do |o|
34
39
  o.default do
@@ -37,7 +42,11 @@ module Datadog
37
42
  Ext::DEFAULT_PEER_SERVICE_NAME
38
43
  )
39
44
  end
40
- o.lazy
45
+ end
46
+
47
+ option :peer_service do |o|
48
+ o.type :string, nilable: true
49
+ o.env Ext::ENV_PEER_SERVICE
41
50
  end
42
51
  end
43
52
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Tracing
3
5
  module Contrib
@@ -5,14 +7,20 @@ module Datadog
5
7
  # Excon integration constants
6
8
  # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
7
9
  module Ext
8
- ENV_ENABLED = 'DD_TRACE_EXCON_ENABLED'.freeze
9
- ENV_SERVICE_NAME = 'DD_TRACE_EXCON_SERVICE_NAME'.freeze
10
- ENV_ANALYTICS_ENABLED = 'DD_TRACE_EXCON_ANALYTICS_ENABLED'.freeze
11
- ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_EXCON_ANALYTICS_SAMPLE_RATE'.freeze
12
- DEFAULT_PEER_SERVICE_NAME = 'excon'.freeze
13
- SPAN_REQUEST = 'excon.request'.freeze
14
- TAG_COMPONENT = 'excon'.freeze
15
- TAG_OPERATION_REQUEST = 'request'.freeze
10
+ ENV_ENABLED = 'DD_TRACE_EXCON_ENABLED'
11
+ ENV_SERVICE_NAME = 'DD_TRACE_EXCON_SERVICE_NAME'
12
+ ENV_PEER_SERVICE = 'DD_TRACE_EXCON_PEER_SERVICE'
13
+
14
+ ENV_ANALYTICS_ENABLED = 'DD_TRACE_EXCON_ANALYTICS_ENABLED'
15
+ ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_EXCON_ANALYTICS_SAMPLE_RATE'
16
+ DEFAULT_PEER_SERVICE_NAME = 'excon'
17
+ SPAN_REQUEST = 'excon.request'
18
+ TAG_COMPONENT = 'excon'
19
+ TAG_OPERATION_REQUEST = 'request'
20
+ PEER_SERVICE_SOURCES = Array[
21
+ Tracing::Metadata::Ext::TAG_PEER_HOSTNAME,
22
+ Tracing::Metadata::Ext::NET::TAG_DESTINATION_NAME,
23
+ Tracing::Metadata::Ext::NET::TAG_TARGET_HOST,].freeze
16
24
  end
17
25
  end
18
26
  end
@@ -114,16 +114,18 @@ module Datadog
114
114
  span.service = service_name(datum[:host], @options)
115
115
  span.span_type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
116
116
 
117
+ if @options[:peer_service]
118
+ span.set_tag(
119
+ Tracing::Metadata::Ext::TAG_PEER_SERVICE,
120
+ @options[:peer_service]
121
+ )
122
+ end
123
+
117
124
  span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
118
125
 
119
126
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
120
127
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
121
128
 
122
- if Contrib::SpanAttributeSchema.default_span_attribute_schema?
123
- # Tag as an external peer service
124
- span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, span.service)
125
- end
126
-
127
129
  span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, datum[:host])
128
130
 
129
131
  # Set analytics sample rate
@@ -133,6 +135,13 @@ module Datadog
133
135
  span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_METHOD, datum[:method].to_s.upcase)
134
136
  span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, datum[:host])
135
137
  span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, datum[:port])
138
+ span.set_tags(
139
+ Datadog.configuration.tracing.header_tags.request_tags(
140
+ Core::Utils::Hash::CaseInsensitiveWrapper.new(datum[:headers])
141
+ )
142
+ )
143
+
144
+ Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
136
145
  end
137
146
 
138
147
  def handle_response(datum)
@@ -144,6 +153,12 @@ module Datadog
144
153
  response = datum[:response]
145
154
  span.set_error(["Error #{response[:status]}", response[:body]]) if error_handler.call(response)
146
155
  span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE, response[:status])
156
+
157
+ span.set_tags(
158
+ Datadog.configuration.tracing.header_tags.response_tags(
159
+ Core::Utils::Hash::CaseInsensitiveWrapper.new(response[:headers])
160
+ )
161
+ )
147
162
  end
148
163
  span.set_error(datum[:error]) if datum.key?(:error)
149
164
  span.finish