ddtrace 1.14.0 → 1.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +165 -2
  3. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +3 -5
  4. data/ext/ddtrace_profiling_native_extension/clock_id.h +0 -3
  5. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +0 -22
  6. data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +0 -1
  7. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +41 -6
  8. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +3 -0
  9. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +76 -24
  10. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +1 -1
  11. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +207 -32
  12. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.h +1 -1
  13. data/ext/ddtrace_profiling_native_extension/extconf.rb +8 -2
  14. data/ext/ddtrace_profiling_native_extension/http_transport.c +26 -10
  15. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.c +42 -0
  16. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +6 -0
  17. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -16
  18. data/ext/ddtrace_profiling_native_extension/pid_controller.c +57 -0
  19. data/ext/ddtrace_profiling_native_extension/pid_controller.h +45 -0
  20. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +17 -12
  21. data/ext/ddtrace_profiling_native_extension/profiling.c +0 -2
  22. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +74 -37
  23. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +13 -3
  24. data/lib/datadog/appsec/assets/waf_rules/processors.json +92 -0
  25. data/lib/datadog/appsec/assets/waf_rules/recommended.json +698 -75
  26. data/lib/datadog/appsec/assets/waf_rules/scanners.json +114 -0
  27. data/lib/datadog/appsec/assets/waf_rules/strict.json +98 -8
  28. data/lib/datadog/appsec/assets.rb +8 -0
  29. data/lib/datadog/appsec/component.rb +9 -2
  30. data/lib/datadog/appsec/configuration/settings.rb +61 -2
  31. data/lib/datadog/appsec/contrib/rack/gateway/request.rb +6 -2
  32. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
  33. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +2 -7
  34. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +2 -5
  35. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +2 -5
  36. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
  37. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +24 -10
  38. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
  39. data/lib/datadog/appsec/contrib/rails/patcher.rb +9 -3
  40. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +2 -5
  41. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
  42. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
  43. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +2 -5
  44. data/lib/datadog/appsec/event.rb +106 -50
  45. data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
  46. data/lib/datadog/appsec/monitor/reactive/set_user.rb +2 -5
  47. data/lib/datadog/appsec/processor/actions.rb +49 -0
  48. data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
  49. data/lib/datadog/appsec/processor.rb +34 -6
  50. data/lib/datadog/appsec/remote.rb +4 -1
  51. data/lib/datadog/appsec/response.rb +82 -4
  52. data/lib/datadog/appsec/sample_rate.rb +21 -0
  53. data/lib/datadog/appsec.rb +2 -2
  54. data/lib/datadog/core/configuration/agent_settings_resolver.rb +29 -24
  55. data/lib/datadog/core/configuration/base.rb +1 -11
  56. data/lib/datadog/core/configuration/components.rb +7 -2
  57. data/lib/datadog/core/configuration/ext.rb +21 -0
  58. data/lib/datadog/core/configuration/option.rb +2 -4
  59. data/lib/datadog/core/configuration/option_definition.rb +17 -41
  60. data/lib/datadog/core/configuration/options.rb +5 -5
  61. data/lib/datadog/core/configuration/settings.rb +47 -45
  62. data/lib/datadog/core/environment/execution.rb +47 -9
  63. data/lib/datadog/core/environment/variable_helpers.rb +0 -69
  64. data/lib/datadog/core/error.rb +1 -0
  65. data/lib/datadog/core/git/ext.rb +2 -0
  66. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  67. data/lib/datadog/core/remote/component.rb +2 -2
  68. data/lib/datadog/core/remote/negotiation.rb +2 -2
  69. data/lib/datadog/core/remote/transport/config.rb +60 -0
  70. data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
  71. data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
  72. data/lib/datadog/core/remote/transport/http/api.rb +58 -0
  73. data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
  74. data/lib/datadog/core/remote/transport/http/client.rb +48 -0
  75. data/lib/datadog/core/remote/transport/http/config.rb +280 -0
  76. data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
  77. data/lib/datadog/core/remote/transport/http.rb +179 -0
  78. data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
  79. data/lib/datadog/core/remote/worker.rb +3 -1
  80. data/lib/datadog/core/telemetry/collector.rb +3 -2
  81. data/lib/datadog/core/telemetry/http/transport.rb +2 -1
  82. data/lib/datadog/core/transport/ext.rb +47 -0
  83. data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
  84. data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
  85. data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
  86. data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
  87. data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
  88. data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
  89. data/lib/datadog/core/transport/http/api/map.rb +18 -0
  90. data/lib/datadog/core/transport/http/env.rb +62 -0
  91. data/lib/datadog/core/transport/http/response.rb +60 -0
  92. data/lib/datadog/core/transport/parcel.rb +22 -0
  93. data/lib/datadog/core/transport/request.rb +17 -0
  94. data/lib/datadog/core/transport/response.rb +64 -0
  95. data/lib/datadog/core/workers/polling.rb +2 -2
  96. data/lib/datadog/opentelemetry/api/context.rb +10 -3
  97. data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
  98. data/lib/datadog/opentelemetry/sdk/span_processor.rb +14 -2
  99. data/lib/datadog/opentelemetry/sdk/trace/span.rb +68 -0
  100. data/lib/datadog/opentelemetry/trace.rb +58 -0
  101. data/lib/datadog/opentelemetry.rb +1 -0
  102. data/lib/datadog/opentracer.rb +9 -0
  103. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +14 -19
  104. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  105. data/lib/datadog/profiling/collectors/thread_context.rb +9 -1
  106. data/lib/datadog/profiling/component.rb +24 -99
  107. data/lib/datadog/profiling/ext.rb +0 -12
  108. data/lib/datadog/profiling/flush.rb +0 -3
  109. data/lib/datadog/profiling/http_transport.rb +6 -3
  110. data/lib/datadog/profiling/native_extension.rb +0 -21
  111. data/lib/datadog/profiling/profiler.rb +36 -13
  112. data/lib/datadog/profiling/scheduler.rb +16 -9
  113. data/lib/datadog/profiling.rb +8 -81
  114. data/lib/datadog/tracing/component.rb +10 -4
  115. data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
  116. data/lib/datadog/tracing/configuration/ext.rb +4 -2
  117. data/lib/datadog/tracing/configuration/settings.rb +14 -7
  118. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -1
  119. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -1
  120. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
  121. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +106 -197
  122. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
  123. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +7 -0
  124. data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +14 -14
  125. data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +3 -10
  126. data/lib/datadog/tracing/contrib/concurrent_ruby/integration.rb +2 -1
  127. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +8 -1
  128. data/lib/datadog/tracing/contrib/concurrent_ruby/promises_future_patch.rb +22 -0
  129. data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
  130. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -0
  131. data/lib/datadog/tracing/contrib/dalli/ext.rb +7 -0
  132. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +9 -2
  133. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -1
  134. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +5 -0
  135. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -0
  136. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +8 -0
  137. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -0
  138. data/lib/datadog/tracing/contrib/ext.rb +3 -0
  139. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
  140. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -0
  141. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +21 -1
  142. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +11 -1
  143. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +18 -0
  144. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
  145. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +3 -3
  146. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -0
  147. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -0
  148. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -0
  149. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +7 -0
  150. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +13 -3
  151. data/lib/datadog/tracing/contrib/opensearch/integration.rb +2 -2
  152. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +7 -0
  153. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +5 -0
  154. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +5 -0
  155. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
  156. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -1
  157. data/lib/datadog/tracing/contrib/racecar/event.rb +5 -0
  158. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +14 -4
  159. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -4
  160. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -1
  161. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +1 -1
  162. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +3 -38
  163. data/lib/datadog/tracing/contrib/redis/tags.rb +7 -2
  164. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +46 -33
  165. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -1
  166. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -0
  167. data/lib/datadog/tracing/contrib/sequel/utils.rb +5 -0
  168. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -1
  169. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -1
  170. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -1
  171. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  172. data/lib/datadog/tracing/diagnostics/environment_logger.rb +6 -0
  173. data/lib/datadog/tracing/distributed/propagation.rb +13 -33
  174. data/lib/datadog/tracing/metadata/tagging.rb +3 -3
  175. data/lib/datadog/tracing/sync_writer.rb +3 -3
  176. data/lib/datadog/tracing/tracer.rb +2 -0
  177. data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
  178. data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
  179. data/lib/datadog/tracing/transport/http/api.rb +43 -0
  180. data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
  181. data/lib/datadog/tracing/transport/http/client.rb +57 -0
  182. data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
  183. data/lib/datadog/tracing/transport/http/traces.rb +152 -0
  184. data/lib/datadog/tracing/transport/http.rb +124 -0
  185. data/lib/datadog/tracing/transport/io/client.rb +89 -0
  186. data/lib/datadog/tracing/transport/io/response.rb +27 -0
  187. data/lib/datadog/tracing/transport/io/traces.rb +101 -0
  188. data/lib/datadog/tracing/transport/io.rb +30 -0
  189. data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
  190. data/lib/datadog/tracing/transport/statistics.rb +77 -0
  191. data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
  192. data/lib/datadog/tracing/transport/traces.rb +224 -0
  193. data/lib/datadog/tracing/workers/trace_writer.rb +5 -3
  194. data/lib/datadog/tracing/workers.rb +3 -2
  195. data/lib/datadog/tracing/writer.rb +5 -2
  196. data/lib/ddtrace/transport/ext.rb +17 -15
  197. data/lib/ddtrace/version.rb +2 -2
  198. data/lib/ddtrace.rb +1 -1
  199. metadata +73 -96
  200. data/lib/datadog/ci/configuration/components.rb +0 -32
  201. data/lib/datadog/ci/configuration/settings.rb +0 -51
  202. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -35
  203. data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -22
  204. data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
  205. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
  206. data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
  207. data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
  208. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +0 -35
  209. data/lib/datadog/ci/contrib/minitest/ext.rb +0 -21
  210. data/lib/datadog/ci/contrib/minitest/integration.rb +0 -49
  211. data/lib/datadog/ci/contrib/minitest/patcher.rb +0 -27
  212. data/lib/datadog/ci/contrib/minitest/test_helper.rb +0 -68
  213. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -35
  214. data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
  215. data/lib/datadog/ci/contrib/rspec/ext.rb +0 -21
  216. data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
  217. data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
  218. data/lib/datadog/ci/ext/app_types.rb +0 -9
  219. data/lib/datadog/ci/ext/environment.rb +0 -575
  220. data/lib/datadog/ci/ext/settings.rb +0 -10
  221. data/lib/datadog/ci/ext/test.rb +0 -35
  222. data/lib/datadog/ci/extensions.rb +0 -19
  223. data/lib/datadog/ci/flush.rb +0 -38
  224. data/lib/datadog/ci/test.rb +0 -81
  225. data/lib/datadog/ci.rb +0 -21
  226. data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
  227. data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
  228. data/lib/datadog/core/configuration/option_set.rb +0 -10
  229. data/lib/datadog/core/transport/config.rb +0 -58
  230. data/lib/datadog/core/transport/http/api.rb +0 -57
  231. data/lib/datadog/core/transport/http/client.rb +0 -45
  232. data/lib/datadog/core/transport/http/config.rb +0 -278
  233. data/lib/datadog/core/transport/http/negotiation.rb +0 -144
  234. data/lib/datadog/core/transport/http.rb +0 -169
  235. data/lib/datadog/core/utils/object_set.rb +0 -43
  236. data/lib/datadog/core/utils/string_table.rb +0 -47
  237. data/lib/datadog/profiling/backtrace_location.rb +0 -34
  238. data/lib/datadog/profiling/buffer.rb +0 -43
  239. data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
  240. data/lib/datadog/profiling/encoding/profile.rb +0 -41
  241. data/lib/datadog/profiling/event.rb +0 -15
  242. data/lib/datadog/profiling/events/stack.rb +0 -82
  243. data/lib/datadog/profiling/old_recorder.rb +0 -107
  244. data/lib/datadog/profiling/pprof/builder.rb +0 -125
  245. data/lib/datadog/profiling/pprof/converter.rb +0 -102
  246. data/lib/datadog/profiling/pprof/message_set.rb +0 -16
  247. data/lib/datadog/profiling/pprof/payload.rb +0 -20
  248. data/lib/datadog/profiling/pprof/pprof.proto +0 -212
  249. data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
  250. data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
  251. data/lib/datadog/profiling/pprof/string_table.rb +0 -12
  252. data/lib/datadog/profiling/pprof/template.rb +0 -118
  253. data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
  254. data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
  255. data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
  256. data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
  257. data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
  258. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
  259. data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
  260. data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
  261. data/lib/ddtrace/transport/http/api/instance.rb +0 -35
  262. data/lib/ddtrace/transport/http/api/map.rb +0 -16
  263. data/lib/ddtrace/transport/http/api/spec.rb +0 -17
  264. data/lib/ddtrace/transport/http/api.rb +0 -39
  265. data/lib/ddtrace/transport/http/builder.rb +0 -176
  266. data/lib/ddtrace/transport/http/client.rb +0 -52
  267. data/lib/ddtrace/transport/http/env.rb +0 -58
  268. data/lib/ddtrace/transport/http/response.rb +0 -58
  269. data/lib/ddtrace/transport/http/statistics.rb +0 -43
  270. data/lib/ddtrace/transport/http/traces.rb +0 -144
  271. data/lib/ddtrace/transport/http.rb +0 -117
  272. data/lib/ddtrace/transport/io/client.rb +0 -85
  273. data/lib/ddtrace/transport/io/response.rb +0 -25
  274. data/lib/ddtrace/transport/io/traces.rb +0 -99
  275. data/lib/ddtrace/transport/io.rb +0 -28
  276. data/lib/ddtrace/transport/parcel.rb +0 -20
  277. data/lib/ddtrace/transport/request.rb +0 -15
  278. data/lib/ddtrace/transport/response.rb +0 -60
  279. data/lib/ddtrace/transport/serializable_trace.rb +0 -122
  280. data/lib/ddtrace/transport/statistics.rb +0 -75
  281. data/lib/ddtrace/transport/trace_formatter.rb +0 -207
  282. data/lib/ddtrace/transport/traces.rb +0 -216
@@ -11,18 +11,12 @@ module Datadog
11
11
 
12
12
  attr_reader \
13
13
  :default,
14
- # experimental_default_proc is used when we want to store a block as part of the option value.
15
- # Since this new option is experimental and we might not need it in the near future, I gave it a name that is
16
- # clear to the reader that they should not rely on it and that is subject to change.
17
- # Currently is only use internally.
18
- :experimental_default_proc,
14
+ :default_proc,
19
15
  :env,
20
16
  :deprecated_env,
21
17
  :env_parser,
22
- :delegate_to,
23
- :depends_on,
24
18
  :name,
25
- :on_set,
19
+ :after_set,
26
20
  :resetter,
27
21
  :setter,
28
22
  :type,
@@ -30,14 +24,12 @@ module Datadog
30
24
 
31
25
  def initialize(name, meta = {}, &block)
32
26
  @default = meta[:default]
33
- @experimental_default_proc = meta[:experimental_default_proc]
27
+ @default_proc = meta[:default_proc]
34
28
  @env = meta[:env]
35
29
  @deprecated_env = meta[:deprecated_env]
36
30
  @env_parser = meta[:env_parser]
37
- @delegate_to = meta[:delegate_to]
38
- @depends_on = meta[:depends_on] || []
39
31
  @name = name.to_sym
40
- @on_set = meta[:on_set]
32
+ @after_set = meta[:after_set]
41
33
  @resetter = meta[:resetter]
42
34
  @setter = meta[:setter] || block || IDENTITY
43
35
  @type = meta[:type]
@@ -62,12 +54,10 @@ module Datadog
62
54
  @deprecated_env = nil
63
55
  @env_parser = nil
64
56
  @default = nil
65
- @experimental_default_proc = nil
66
- @delegate_to = nil
67
- @depends_on = []
57
+ @default_proc = nil
68
58
  @helpers = {}
69
59
  @name = name.to_sym
70
- @on_set = nil
60
+ @after_set = nil
71
61
  @resetter = nil
72
62
  @setter = OptionDefinition::IDENTITY
73
63
  @type = nil
@@ -81,10 +71,6 @@ module Datadog
81
71
  validate_options!
82
72
  end
83
73
 
84
- def depends_on(*values)
85
- @depends_on = values.flatten
86
- end
87
-
88
74
  def env(value)
89
75
  @env = value
90
76
  end
@@ -101,12 +87,8 @@ module Datadog
101
87
  @default = block || value
102
88
  end
103
89
 
104
- def experimental_default_proc(&block)
105
- @experimental_default_proc = block
106
- end
107
-
108
- def delegate_to(&block)
109
- @delegate_to = block
90
+ def default_proc(&block)
91
+ @default_proc = block
110
92
  end
111
93
 
112
94
  def helper(name, *_args, &block)
@@ -123,8 +105,8 @@ module Datadog
123
105
  end
124
106
  end
125
107
 
126
- def on_set(&block)
127
- @on_set = block
108
+ def after_set(&block)
109
+ @after_set = block
128
110
  end
129
111
 
130
112
  def resetter(&block)
@@ -143,24 +125,20 @@ module Datadog
143
125
  end
144
126
 
145
127
  # For applying options for OptionDefinition
146
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
147
128
  def apply_options!(options = {})
148
129
  return if options.nil? || options.empty?
149
130
 
150
131
  default(options[:default]) if options.key?(:default)
151
- experimental_default_proc(&options[:experimental_default_proc]) if options.key?(:experimental_default_proc)
132
+ default_proc(&options[:default_proc]) if options.key?(:default_proc)
152
133
  env(options[:env]) if options.key?(:env)
153
134
  deprecated_env(options[:deprecated_env]) if options.key?(:deprecated_env)
154
135
  env_parser(&options[:env_parser]) if options.key?(:env_parser)
155
- delegate_to(&options[:delegate_to]) if options.key?(:delegate_to)
156
- depends_on(*options[:depends_on]) if options.key?(:depends_on)
157
136
  lazy(options[:lazy]) if options.key?(:lazy)
158
- on_set(&options[:on_set]) if options.key?(:on_set)
137
+ after_set(&options[:after_set]) if options.key?(:after_set)
159
138
  resetter(&options[:resetter]) if options.key?(:resetter)
160
139
  setter(&options[:setter]) if options.key?(:setter)
161
140
  type(options[:type], **(options[:type_options] || {})) if options.key?(:type)
162
141
  end
163
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
164
142
 
165
143
  def to_definition
166
144
  OptionDefinition.new(@name, meta)
@@ -169,13 +147,11 @@ module Datadog
169
147
  def meta
170
148
  {
171
149
  default: @default,
172
- experimental_default_proc: @experimental_default_proc,
150
+ default_proc: @default_proc,
173
151
  env: @env,
174
152
  deprecated_env: @deprecated_env,
175
153
  env_parser: @env_parser,
176
- delegate_to: @delegate_to,
177
- depends_on: @depends_on,
178
- on_set: @on_set,
154
+ after_set: @after_set,
179
155
  resetter: @resetter,
180
156
  setter: @setter,
181
157
  type: @type,
@@ -186,10 +162,10 @@ module Datadog
186
162
  private
187
163
 
188
164
  def validate_options!
189
- if !@default.nil? && @experimental_default_proc
165
+ if !@default.nil? && @default_proc
190
166
  raise InvalidOptionError,
191
- 'Using `default` and `experimental_default_proc` is not allowed. Please use one or the other.' \
192
- 'If you want to store a block as the default value use `experimental_default_proc`'\
167
+ 'Using `default` and `default_proc` is not allowed. Please use one or the other.' \
168
+ 'If you want to store a block as the default value use `default_proc`'\
193
169
  ' otherwise use `default`'
194
170
  end
195
171
  end
@@ -1,6 +1,6 @@
1
- require_relative 'option_set'
1
+ # frozen_string_literal: true
2
+
2
3
  require_relative 'option_definition'
3
- require_relative 'option_definition_set'
4
4
 
5
5
  module Datadog
6
6
  module Core
@@ -18,7 +18,7 @@ module Datadog
18
18
  module ClassMethods
19
19
  def options
20
20
  # Allows for class inheritance of option definitions
21
- @options ||= superclass <= Options ? superclass.options.dup : OptionDefinitionSet.new
21
+ @options ||= superclass <= Options ? superclass.options.dup : {}
22
22
  end
23
23
 
24
24
  protected
@@ -64,7 +64,7 @@ module Datadog
64
64
  # @public_api
65
65
  module InstanceMethods
66
66
  def options
67
- @options ||= OptionSet.new
67
+ @options ||= {}
68
68
  end
69
69
 
70
70
  def set_option(name, value, precedence: Configuration::Option::Precedence::PROGRAMMATIC)
@@ -101,7 +101,7 @@ module Datadog
101
101
  end
102
102
 
103
103
  def reset_options!
104
- options.values.each(&:reset)
104
+ options.each_value(&:reset)
105
105
  end
106
106
 
107
107
  private
@@ -103,13 +103,12 @@ module Datadog
103
103
  o.env Datadog::Core::Configuration::Ext::Diagnostics::ENV_DEBUG_ENABLED
104
104
  o.default false
105
105
  o.type :bool
106
- o.on_set do |enabled|
106
+ o.after_set do |enabled|
107
107
  # Enable rich debug print statements.
108
108
  # We do not need to unnecessarily load 'pp' unless in debugging mode.
109
109
  require 'pp' if enabled
110
110
  end
111
111
  end
112
-
113
112
  # Internal {Datadog::Statsd} metrics collection.
114
113
  #
115
114
  # @public_api
@@ -177,7 +176,7 @@ module Datadog
177
176
  #
178
177
  # @return Logger::Severity
179
178
  option :instance do |o|
180
- o.on_set { |value| set_option(:level, value.level) unless value.nil? }
179
+ o.after_set { |value| set_option(:level, value.level) unless value.nil? }
181
180
  end
182
181
 
183
182
  # Log level for `Datadog.logger`.
@@ -208,21 +207,16 @@ module Datadog
208
207
 
209
208
  # @public_api
210
209
  settings :advanced do
211
- # @deprecated This setting is ignored when CPU Profiling 2.0 is in use, and will be removed on dd-trace-rb 2.0.
210
+ # @deprecated No longer does anything, and will be removed on dd-trace-rb 2.0.
212
211
  #
213
- # This should never be reduced, as it can cause the resulting profiles to become biased.
214
- # The default should be enough for most services, allowing 16 threads to be sampled around 30 times
215
- # per second for a 60 second period.
212
+ # This was used prior to the GA of the new CPU Profiling 2.0 profiler. The CPU Profiling 2.0 profiler does not
213
+ # use or need this setting and thus it doesn't do anything.
216
214
  option :max_events do |o|
217
- o.default 32768
218
- o.on_set do |value|
219
- if value != 32768
220
- Datadog.logger.warn(
221
- 'The profiling.advanced.max_events setting has been deprecated for removal. It no longer does ' \
222
- 'anything unless you the `force_enable_legacy_profiler` option is in use. ' \
223
- 'Please remove it from your Datadog.configure block.'
224
- )
225
- end
215
+ o.after_set do
216
+ Datadog.logger.warn(
217
+ 'The profiling.advanced.max_events setting has been deprecated for removal and no ' \
218
+ 'longer does anything. Please remove it from your Datadog.configure block.'
219
+ )
226
220
  end
227
221
  end
228
222
 
@@ -261,7 +255,7 @@ module Datadog
261
255
  # This was added as a temporary support option in case of issues with the new `Profiling::HttpTransport` class
262
256
  # but we're now confident it's working nicely so we've removed the old code path.
263
257
  option :legacy_transport_enabled do |o|
264
- o.on_set do
258
+ o.after_set do
265
259
  Datadog.logger.warn(
266
260
  'The profiling.advanced.legacy_transport_enabled setting has been deprecated for removal and no ' \
267
261
  'longer does anything. Please remove it from your Datadog.configure block.'
@@ -274,7 +268,7 @@ module Datadog
274
268
  # This was used prior to the GA of the new CPU Profiling 2.0 profiler. Using CPU Profiling 2.0 is now the
275
269
  # default and this doesn't do anything.
276
270
  option :force_enable_new_profiler do |o|
277
- o.on_set do
271
+ o.after_set do
278
272
  Datadog.logger.warn(
279
273
  'The profiling.advanced.force_enable_new_profiler setting has been deprecated for removal and no ' \
280
274
  'longer does anything. Please remove it from your Datadog.configure block.'
@@ -282,26 +276,16 @@ module Datadog
282
276
  end
283
277
  end
284
278
 
285
- # @deprecated Will be removed for dd-trace-rb 2.0.
286
- #
287
- # Forces enabling the *legacy* non-CPU Profiling 2.0 profiler.
288
- # Do not use unless instructed to by support.
279
+ # @deprecated No longer does anything, and will be removed on dd-trace-rb 2.0.
289
280
  #
290
- # @default `DD_PROFILING_FORCE_ENABLE_LEGACY` environment variable, otherwise `false`
281
+ # This was used prior to the GA of the new CPU Profiling 2.0 profiler. Using CPU Profiling 2.0 is now the
282
+ # default and this doesn't do anything.
291
283
  option :force_enable_legacy_profiler do |o|
292
- o.env 'DD_PROFILING_FORCE_ENABLE_LEGACY'
293
- o.default false
294
- o.type :bool
295
- o.on_set do |value|
296
- if value
297
- Datadog.logger.warn(
298
- 'The profiling.advanced.force_enable_legacy_profiler setting has been deprecated for removal. ' \
299
- 'Do not use unless instructed to by support. ' \
300
- 'If you needed to use it due to incompatibilities with the CPU Profiling 2.0 profiler, consider ' \
301
- 'using the profiling.advanced.no_signals_workaround_enabled setting instead. ' \
302
- 'See <https://dtdg.co/ruby-profiler-troubleshooting> for details.'
303
- )
304
- end
284
+ o.after_set do
285
+ Datadog.logger.warn(
286
+ 'The profiling.advanced.force_enable_legacy_profiler setting has been deprecated for removal and no ' \
287
+ 'longer does anything. Please remove it from your Datadog.configure block.'
288
+ )
305
289
  end
306
290
  end
307
291
 
@@ -330,15 +314,33 @@ module Datadog
330
314
 
331
315
  # Can be used to enable/disable the Datadog::Profiling.allocation_count feature.
332
316
  #
333
- # This feature is safe and enabled by default on Ruby 2.x, but
334
- # on Ruby 3.x it can break in applications that make use of Ractors due to two Ruby VM bugs:
335
- # https://bugs.ruby-lang.org/issues/19112 AND https://bugs.ruby-lang.org/issues/18464.
317
+ # This feature is safe and enabled by default on Ruby 2.x, but has a few caveats on Ruby 3.x.
318
+ #
319
+ # Caveat 1 (severe):
320
+ # On Ruby versions 3.0 (all), 3.1.0 to 3.1.3, and 3.2.0 to 3.2.2 this is disabled by default because it
321
+ # can trigger a VM bug that causes a segmentation fault during garbage collection of Ractors
322
+ # (https://bugs.ruby-lang.org/issues/18464). We don't recommend using this feature on such Rubies.
323
+ # This bug is fixed on Ruby versions 3.1.4, 3.2.3 and 3.3.0.
324
+ #
325
+ # Caveat 2 (annoyance):
326
+ # On all known versions of Ruby 3.x, due to https://bugs.ruby-lang.org/issues/19112, when a ractor gets
327
+ # garbage collected, Ruby will disable all active tracepoints, which this feature internally relies on.
328
+ # Thus this feature is only usable if you're not using Ractors.
336
329
  #
337
- # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
338
- # feature is fully safe to enable and this toggle can be used to do so.
330
+ # Caveat 3 (severe):
331
+ # Ruby 3.2.0 to 3.2.2 have a bug in the newobj tracepoint (https://bugs.ruby-lang.org/issues/19482,
332
+ # https://github.com/ruby/ruby/pull/7464) so that's an extra reason why it's not safe on those Rubies.
333
+ # This bug is fixed on Ruby versions 3.2.3 and 3.3.0.
339
334
  #
340
- # @default `true` on Ruby 2.x, `false` on Ruby 3.x
341
- option :allocation_counting_enabled, default: RUBY_VERSION.start_with?('2.')
335
+ # @default `true` on Ruby 2.x and 3.1.4+, 3.2.3+ and 3.3.0+; `false` for Ruby 3.0 and unpatched Rubies.
336
+ option :allocation_counting_enabled do |o|
337
+ o.default do
338
+ RUBY_VERSION.start_with?('2.') ||
339
+ (RUBY_VERSION.start_with?('3.1.') && RUBY_VERSION >= '3.1.4') ||
340
+ (RUBY_VERSION.start_with?('3.2.') && RUBY_VERSION >= '3.2.3') ||
341
+ RUBY_VERSION >= '3.3.'
342
+ end
343
+ end
342
344
 
343
345
  # Can be used to disable checking which version of `libmysqlclient` is being used by the `mysql2` gem.
344
346
  #
@@ -527,10 +529,10 @@ module Datadog
527
529
  # @default `->{ Time.now }`
528
530
  # @return [Proc<Time>]
529
531
  option :time_now_provider do |o|
530
- o.experimental_default_proc { ::Time.now }
532
+ o.default_proc { ::Time.now }
531
533
  o.type :proc
532
534
 
533
- o.on_set do |time_provider|
535
+ o.after_set do |time_provider|
534
536
  Core::Utils::Time.now_provider = time_provider
535
537
  end
536
538
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'set'
4
+
3
5
  module Datadog
4
6
  module Core
5
7
  module Environment
@@ -10,14 +12,29 @@ module Datadog
10
12
  # This can be used to make decisions about when to enable
11
13
  # background systems like worker threads or telemetry.
12
14
  def development?
13
- !!(repl? || test? || rails_development?)
15
+ !!(webmock_enabled? || repl? || test? || rails_development?)
16
+ end
17
+
18
+ # WebMock stores the reference to `Net::HTTP` with constant `OriginalNetHTTP`, and when WebMock enables,
19
+ # the adapter swaps `Net::HTTP` reference to its mock object, @webMockNetHTTP.
20
+ #
21
+ # Hence, we can detect by
22
+ # 1. Checking if `Net::HTTP` is referring to mock object
23
+ # => ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP))
24
+ #
25
+ # 2. Checking if `Net::HTTP` is referring to the original one
26
+ # => ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter::OriginalNetHTTP)
27
+ def webmock_enabled?
28
+ defined?(::WebMock::HttpLibAdapters::NetHttpAdapter) &&
29
+ defined?(::Net::HTTP) &&
30
+ ::Net::HTTP.equal?(::WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP))
14
31
  end
15
32
 
16
33
  private
17
34
 
18
35
  # Is this process running a test?
19
36
  def test?
20
- rspec? || minitest?
37
+ rspec? || minitest? || cucumber?
21
38
  end
22
39
 
23
40
  # Is this process running inside on a Read–eval–print loop?
@@ -49,14 +66,35 @@ module Datadog
49
66
  ::Minitest::Unit.class_variable_get(:@@installed_at_exit))
50
67
  end
51
68
 
52
- # A Rails Spring Ruby process is a bit peculiar: the process is agnostic
53
- # whether the application is running as a console or server.
54
- # Luckily, the Spring gem *must not* be installed in a production environment so
55
- # detecting its presence is enough to deduct if this is a development environment.
56
- #
57
- # @see https://github.com/rails/spring/blob/48b299348ace2188444489a0c216a6f3e9687281/README.md?plain=1#L204-L207
69
+ # Check if we are running from `bin/cucumber` or `cucumber/rake/task`.
70
+ def cucumber?
71
+ defined?(::Cucumber::Cli)
72
+ end
73
+
74
+ # If this is a Rails application, use different heuristics to detect
75
+ # whether this is a development environment or not.
58
76
  def rails_development?
59
- defined?(::Spring)
77
+ # A Rails Spring Ruby process is a bit peculiar: the process is agnostic
78
+ # whether the application is running as a console or server.
79
+ # Luckily, the Spring gem *must not* be installed in a production environment so
80
+ # detecting its presence is enough to deduct if this is a development environment.
81
+ #
82
+ # @see https://github.com/rails/spring/blob/48b299348ace2188444489a0c216a6f3e9687281/README.md?plain=1#L204-L207
83
+ defined?(::Spring) || rails_env_development?
84
+ end
85
+
86
+ RAILS_ENV_DEVELOPMENT = Set['development', 'test'].freeze
87
+ private_constant :RAILS_ENV_DEVELOPMENT
88
+
89
+ # By default, every Rails application has three environments: `development`, `test`, and `production`.
90
+ # This has been the case since Rails 3.0.0:
91
+ # https://github.com/rails/rails/blob/3e48484ff16ea07ffe5db232bf43c14992e273c1/railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt#L144
92
+ #
93
+ # Instead of checking for "not production", we instead check for "development" and "test" because
94
+ # it's common to have a custom "staging" environment, and such environment normally want to run as close
95
+ # to production as possible.
96
+ def rails_env_development?
97
+ defined?(::Rails.env) && RAILS_ENV_DEVELOPMENT.include?(::Rails.env)
60
98
  end
61
99
  end
62
100
  end
@@ -29,75 +29,6 @@ module Datadog
29
29
  end
30
30
  end
31
31
 
32
- # Reads an environment variable as an Integer.
33
- #
34
- # @param [String] var environment variable
35
- # @param [Array<String>] var list of environment variables
36
- # @param [Integer] default the default value if the keys in `var` are not present in the environment
37
- # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
38
- # the first key in `var` is not used.
39
- # @return [Integer] if the environment value is a valid Integer
40
- # @return [default] if the environment value is not found
41
- def env_to_int(var, default = nil, deprecation_warning: true)
42
- var = decode_array(var, deprecation_warning)
43
- var && ENV.key?(var) ? ENV[var].to_i : default
44
- end
45
-
46
- # Reads an environment variable as a Float.
47
- #
48
- # @param [String] var environment variable
49
- # @param [Array<String>] var list of environment variables
50
- # @param [Float] default the default value if the keys in `var` are not present in the environment
51
- # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
52
- # the first key in `var` is not used.
53
- # @return [Float] if the environment value is a valid Float
54
- # @return [default] if the environment value is not found
55
- def env_to_float(var, default = nil, deprecation_warning: true)
56
- var = decode_array(var, deprecation_warning)
57
- var && ENV.key?(var) ? ENV[var].to_f : default
58
- end
59
-
60
- # Parses comma- or space-separated lists.
61
- #
62
- # If a comma is present, then the list is considered comma-separated.
63
- # Otherwise, it is considered space-separated.
64
- #
65
- # After the entries are separated, commas and whitespaces that are
66
- # either trailing or leading are trimmed.
67
- #
68
- # Empty entries, after trimmed, are also removed from the result.
69
- #
70
- # @param [String] var environment variable
71
- # @param [Array<String>] var list of environment variables
72
- # @param [Array<Object>] default the default value if the keys in `var` are not present in the environment
73
- # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
74
- # the first key in `var` is not used.
75
- # @return [Array<Object>] if the environment value is a valid list
76
- # @return [default] if the environment value is not found
77
- def env_to_list(var, default = [], comma_separated_only:, deprecation_warning: true)
78
- var = decode_array(var, deprecation_warning)
79
- if var && ENV.key?(var)
80
- value = ENV[var]
81
-
82
- values = if value.include?(',') || comma_separated_only
83
- value.split(',')
84
- else
85
- value.split(' ') # rubocop:disable Style/RedundantArgument
86
- end
87
-
88
- values.map! do |v|
89
- v.gsub!(/\A[\s,]*|[\s,]*\Z/, '')
90
-
91
- v.empty? ? nil : v
92
- end
93
-
94
- values.compact!
95
- values
96
- else
97
- default
98
- end
99
- end
100
-
101
32
  private
102
33
 
103
34
  def decode_array(var, deprecation_warning)
@@ -15,6 +15,7 @@ module Datadog
15
15
  when Array then new(*value)
16
16
  when Exception then new(value.class, value.message, full_backtrace(value))
17
17
  when ContainsMessage then new(value.class, value.message)
18
+ when String then new(nil, value)
18
19
  else BlankError
19
20
  end
20
21
  end
@@ -5,6 +5,8 @@ module Datadog
5
5
  module Git
6
6
  # Defines constants for Git tags
7
7
  module Ext
8
+ GIT_SHA_LENGTH = 40
9
+
8
10
  TAG_BRANCH = 'git.branch'
9
11
  TAG_REPOSITORY_URL = 'git.repository_url'
10
12
  TAG_TAG = 'git.tag'
@@ -7,7 +7,7 @@ module Datadog
7
7
  module Core
8
8
  module Remote
9
9
  class Client
10
- # Capbailities
10
+ # Capabilities
11
11
  class Capabilities
12
12
  attr_reader :products, :capabilities, :receivers, :base64_capabilities
13
13
 
@@ -3,7 +3,7 @@
3
3
  require_relative 'worker'
4
4
  require_relative 'client/capabilities'
5
5
  require_relative 'client'
6
- require_relative '../transport/http'
6
+ require_relative 'transport/http'
7
7
  require_relative '../remote'
8
8
  require_relative 'negotiation'
9
9
 
@@ -22,7 +22,7 @@ module Datadog
22
22
  transport_options[:agent_settings] = agent_settings if agent_settings
23
23
 
24
24
  negotiation = Negotiation.new(settings, agent_settings)
25
- transport_v7 = Datadog::Core::Transport::HTTP.v7(**transport_options.dup)
25
+ transport_v7 = Datadog::Core::Remote::Transport::HTTP.v7(**transport_options.dup)
26
26
 
27
27
  @barrier = Barrier.new(BARRIER_TIMEOUT)
28
28
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../transport/http'
3
+ require_relative 'transport/http'
4
4
 
5
5
  module Datadog
6
6
  module Core
@@ -11,7 +11,7 @@ module Datadog
11
11
  transport_options = {}
12
12
  transport_options[:agent_settings] = agent_settings if agent_settings
13
13
 
14
- @transport_root = Datadog::Core::Transport::HTTP.root(**transport_options.dup)
14
+ @transport_root = Datadog::Core::Remote::Transport::HTTP.root(**transport_options.dup)
15
15
  @logged = {}
16
16
  end
17
17
 
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../core/transport/request'
4
+ require_relative '../../../core/transport/parcel'
5
+
6
+ module Datadog
7
+ module Core
8
+ module Remote
9
+ module Transport
10
+ module Config
11
+ # Data transfer object for encoded traces
12
+ class EncodedParcel
13
+ include Datadog::Core::Transport::Parcel
14
+
15
+ def count
16
+ data.length
17
+ end
18
+ end
19
+
20
+ # Config request
21
+ class Request < Datadog::Core::Transport::Request
22
+ end
23
+
24
+ # Config response
25
+ module Response
26
+ attr_reader :roots, :targets, :target_files, :client_configs
27
+
28
+ def empty?
29
+ @empty
30
+ end
31
+ end
32
+
33
+ # Config transport
34
+ class Transport
35
+ attr_reader :client, :apis, :default_api, :current_api_id
36
+
37
+ def initialize(apis, default_api)
38
+ @apis = apis
39
+
40
+ @client = HTTP::Client.new(current_api)
41
+ end
42
+
43
+ ##### there is only one transport! it's negotiation!
44
+ def send_config(payload)
45
+ json = JSON.dump(payload)
46
+ parcel = EncodedParcel.new(json)
47
+ request = Request.new(parcel)
48
+
49
+ @client.send_config_payload(request)
50
+ end
51
+
52
+ def current_api
53
+ @apis[HTTP::API::V7]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Core
5
+ module Remote
6
+ module Transport
7
+ module HTTP
8
+ module API
9
+ # An API configured with adapter and routes
10
+ class Instance
11
+ attr_reader \
12
+ :adapter,
13
+ :headers,
14
+ :spec
15
+
16
+ def initialize(spec, adapter, options = {})
17
+ @spec = spec
18
+ @adapter = adapter
19
+ @headers = options.fetch(:headers, {})
20
+ end
21
+
22
+ def encoder
23
+ spec.encoder
24
+ end
25
+
26
+ def call(env)
27
+ # Add headers to request env, unless empty.
28
+ env.headers.merge!(headers) unless headers.empty?
29
+
30
+ # Send request env to the adapter.
31
+ adapter.call(env)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end