ddtrace 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (364) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +125 -1
  3. data/README.md +8 -10
  4. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +110 -18
  5. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +26 -3
  6. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +3 -0
  7. data/lib/datadog/appsec/component.rb +40 -6
  8. data/lib/datadog/appsec/configuration/settings.rb +20 -4
  9. data/lib/datadog/appsec/configuration.rb +8 -0
  10. data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -0
  11. data/lib/datadog/appsec/contrib/configuration/settings.rb +2 -0
  12. data/lib/datadog/appsec/contrib/integration.rb +2 -0
  13. data/lib/datadog/appsec/contrib/patcher.rb +2 -0
  14. data/lib/datadog/appsec/contrib/rack/configuration/settings.rb +2 -0
  15. data/lib/datadog/appsec/contrib/rack/gateway/request.rb +4 -15
  16. data/lib/datadog/appsec/contrib/rack/gateway/response.rb +1 -1
  17. data/lib/datadog/appsec/contrib/rack/patcher.rb +2 -0
  18. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +6 -0
  19. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +17 -4
  20. data/lib/datadog/appsec/contrib/rails/configuration/settings.rb +2 -0
  21. data/lib/datadog/appsec/contrib/rails/framework.rb +2 -0
  22. data/lib/datadog/appsec/contrib/rails/gateway/request.rb +1 -1
  23. data/lib/datadog/appsec/contrib/rails/request.rb +2 -0
  24. data/lib/datadog/appsec/contrib/rails/request_middleware.rb +2 -0
  25. data/lib/datadog/appsec/contrib/sinatra/configuration/settings.rb +2 -0
  26. data/lib/datadog/appsec/contrib/sinatra/framework.rb +2 -0
  27. data/lib/datadog/appsec/contrib/sinatra/gateway/route_params.rb +1 -1
  28. data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +2 -0
  29. data/lib/datadog/appsec/extensions.rb +2 -0
  30. data/lib/datadog/appsec/instrumentation/gateway/argument.rb +2 -4
  31. data/lib/datadog/appsec/processor/rule_loader.rb +63 -0
  32. data/lib/datadog/appsec/processor/rule_merger.rb +146 -0
  33. data/lib/datadog/appsec/processor.rb +15 -70
  34. data/lib/datadog/appsec/remote.rb +121 -0
  35. data/lib/datadog/appsec/utils/http.rb +2 -0
  36. data/lib/datadog/appsec/utils.rb +2 -0
  37. data/lib/datadog/appsec.rb +18 -4
  38. data/lib/datadog/ci/configuration/components.rb +2 -0
  39. data/lib/datadog/ci/configuration/settings.rb +2 -0
  40. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +2 -0
  41. data/lib/datadog/ci/contrib/cucumber/formatter.rb +2 -0
  42. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +2 -0
  43. data/lib/datadog/ci/contrib/cucumber/patcher.rb +2 -0
  44. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +2 -0
  45. data/lib/datadog/ci/contrib/rspec/patcher.rb +2 -0
  46. data/lib/datadog/ci/extensions.rb +2 -0
  47. data/lib/datadog/ci/flush.rb +2 -0
  48. data/lib/datadog/ci.rb +2 -0
  49. data/lib/datadog/core/buffer/cruby.rb +2 -0
  50. data/lib/datadog/core/buffer/random.rb +2 -0
  51. data/lib/datadog/core/buffer/thread_safe.rb +2 -0
  52. data/lib/datadog/core/chunker.rb +2 -0
  53. data/lib/datadog/core/configuration/agent_settings_resolver.rb +68 -17
  54. data/lib/datadog/core/configuration/components.rb +11 -14
  55. data/lib/datadog/core/configuration/dependency_resolver.rb +2 -0
  56. data/lib/datadog/core/configuration/option.rb +2 -0
  57. data/lib/datadog/core/configuration/option_definition.rb +2 -0
  58. data/lib/datadog/core/configuration/option_definition_set.rb +2 -0
  59. data/lib/datadog/core/configuration/option_set.rb +2 -0
  60. data/lib/datadog/core/configuration/settings.rb +70 -16
  61. data/lib/datadog/core/diagnostics/health.rb +2 -0
  62. data/lib/datadog/core/environment/class_count.rb +2 -0
  63. data/lib/datadog/core/environment/gc.rb +2 -0
  64. data/lib/datadog/core/environment/identity.rb +58 -0
  65. data/lib/datadog/core/environment/socket.rb +2 -0
  66. data/lib/datadog/core/environment/thread_count.rb +2 -0
  67. data/lib/datadog/core/environment/variable_helpers.rb +10 -2
  68. data/lib/datadog/core/environment/vm_cache.rb +2 -0
  69. data/lib/datadog/core/extensions.rb +2 -0
  70. data/lib/datadog/core/header_collection.rb +2 -0
  71. data/lib/datadog/core/metrics/helpers.rb +2 -0
  72. data/lib/datadog/core/metrics/metric.rb +2 -0
  73. data/lib/datadog/core/remote/client/capabilities.rb +57 -0
  74. data/lib/datadog/core/remote/client.rb +225 -0
  75. data/lib/datadog/core/remote/component.rb +158 -0
  76. data/lib/datadog/core/remote/configuration/content.rb +84 -0
  77. data/lib/datadog/core/remote/configuration/digest.rb +62 -0
  78. data/lib/datadog/core/remote/configuration/path.rb +90 -0
  79. data/lib/datadog/core/remote/configuration/repository.rb +292 -0
  80. data/lib/datadog/core/remote/configuration/target.rb +74 -0
  81. data/lib/datadog/core/remote/configuration.rb +18 -0
  82. data/lib/datadog/core/remote/dispatcher.rb +59 -0
  83. data/lib/datadog/core/remote/ext.rb +12 -0
  84. data/lib/datadog/core/remote/negotiation.rb +57 -0
  85. data/lib/datadog/core/remote/worker.rb +96 -0
  86. data/lib/datadog/core/remote.rb +24 -0
  87. data/lib/datadog/core/telemetry/collector.rb +8 -9
  88. data/lib/datadog/core/telemetry/heartbeat.rb +2 -0
  89. data/lib/datadog/core/telemetry/http/env.rb +2 -0
  90. data/lib/datadog/core/telemetry/http/transport.rb +2 -0
  91. data/lib/datadog/core/telemetry/v1/app_event.rb +2 -0
  92. data/lib/datadog/core/telemetry/v1/application.rb +7 -1
  93. data/lib/datadog/core/telemetry/v1/dependency.rb +7 -1
  94. data/lib/datadog/core/telemetry/v1/host.rb +9 -1
  95. data/lib/datadog/core/telemetry/v1/integration.rb +7 -1
  96. data/lib/datadog/core/telemetry/v1/product.rb +9 -1
  97. data/lib/datadog/core/telemetry/v1/telemetry_request.rb +7 -1
  98. data/lib/datadog/core/transport/config.rb +58 -0
  99. data/lib/datadog/core/transport/http/api/instance.rb +37 -0
  100. data/lib/datadog/core/transport/http/api/spec.rb +19 -0
  101. data/lib/datadog/core/transport/http/api.rb +57 -0
  102. data/lib/datadog/core/transport/http/builder.rb +217 -0
  103. data/lib/datadog/core/transport/http/client.rb +45 -0
  104. data/lib/datadog/core/transport/http/config.rb +268 -0
  105. data/lib/datadog/core/transport/http/negotiation.rb +144 -0
  106. data/lib/datadog/core/transport/http.rb +169 -0
  107. data/lib/datadog/core/transport/negotiation.rb +60 -0
  108. data/lib/datadog/core/utils/compression.rb +2 -0
  109. data/lib/datadog/core/utils/hash.rb +32 -0
  110. data/lib/datadog/core/utils/object_set.rb +2 -0
  111. data/lib/datadog/core/utils/safe_dup.rb +20 -2
  112. data/lib/datadog/core/utils/sequence.rb +2 -0
  113. data/lib/datadog/core/utils/time.rb +2 -0
  114. data/lib/datadog/core/worker.rb +2 -0
  115. data/lib/datadog/core/workers/async.rb +6 -2
  116. data/lib/datadog/core/workers/interval_loop.rb +7 -1
  117. data/lib/datadog/core/workers/queue.rb +2 -0
  118. data/lib/datadog/core/workers/runtime_metrics.rb +2 -0
  119. data/lib/datadog/kit.rb +2 -0
  120. data/lib/datadog/opentracer/binary_propagator.rb +2 -0
  121. data/lib/datadog/opentracer/carrier.rb +2 -0
  122. data/lib/datadog/opentracer/global_tracer.rb +2 -0
  123. data/lib/datadog/opentracer/propagator.rb +2 -0
  124. data/lib/datadog/opentracer/scope.rb +2 -0
  125. data/lib/datadog/opentracer/scope_manager.rb +2 -0
  126. data/lib/datadog/opentracer/span_context.rb +2 -0
  127. data/lib/datadog/opentracer/span_context_factory.rb +2 -0
  128. data/lib/datadog/opentracer/thread_local_scope.rb +2 -0
  129. data/lib/datadog/opentracer.rb +2 -0
  130. data/lib/datadog/profiling/backtrace_location.rb +2 -0
  131. data/lib/datadog/profiling/buffer.rb +2 -0
  132. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +19 -3
  133. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +2 -0
  134. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  135. data/lib/datadog/profiling/collectors/stack.rb +2 -0
  136. data/lib/datadog/profiling/collectors/thread_context.rb +2 -2
  137. data/lib/datadog/profiling/component.rb +103 -29
  138. data/lib/datadog/profiling/event.rb +2 -0
  139. data/lib/datadog/profiling/events/stack.rb +2 -0
  140. data/lib/datadog/profiling/ext.rb +28 -26
  141. data/lib/datadog/profiling/flush.rb +2 -0
  142. data/lib/datadog/profiling/native_extension.rb +2 -0
  143. data/lib/datadog/profiling/pprof/message_set.rb +2 -0
  144. data/lib/datadog/profiling/pprof/payload.rb +2 -0
  145. data/lib/datadog/profiling/pprof/string_table.rb +2 -0
  146. data/lib/datadog/profiling/preload.rb +2 -0
  147. data/lib/datadog/profiling/scheduler.rb +3 -1
  148. data/lib/datadog/profiling/stack_recorder.rb +0 -18
  149. data/lib/datadog/profiling/tag_builder.rb +2 -0
  150. data/lib/datadog/profiling/tasks/setup.rb +0 -26
  151. data/lib/datadog/profiling.rb +2 -1
  152. data/lib/datadog/tracing/analytics.rb +2 -0
  153. data/lib/datadog/tracing/configuration/ext.rb +7 -0
  154. data/lib/datadog/tracing/configuration/settings.rb +14 -0
  155. data/lib/datadog/tracing/context.rb +2 -0
  156. data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +2 -0
  157. data/lib/datadog/tracing/contrib/action_cable/event.rb +2 -0
  158. data/lib/datadog/tracing/contrib/action_cable/events.rb +2 -0
  159. data/lib/datadog/tracing/contrib/action_cable/patcher.rb +2 -0
  160. data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +2 -0
  161. data/lib/datadog/tracing/contrib/action_mailer/event.rb +2 -0
  162. data/lib/datadog/tracing/contrib/action_mailer/events.rb +2 -0
  163. data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +2 -0
  164. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +2 -24
  165. data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -0
  166. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +14 -1
  167. data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -0
  168. data/lib/datadog/tracing/contrib/action_view/event.rb +2 -0
  169. data/lib/datadog/tracing/contrib/action_view/events.rb +2 -0
  170. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +2 -0
  171. data/lib/datadog/tracing/contrib/active_job/event.rb +2 -0
  172. data/lib/datadog/tracing/contrib/active_job/events.rb +2 -0
  173. data/lib/datadog/tracing/contrib/active_job/log_injection.rb +2 -0
  174. data/lib/datadog/tracing/contrib/active_job/patcher.rb +2 -0
  175. data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +2 -0
  176. data/lib/datadog/tracing/contrib/active_model_serializers/event.rb +2 -0
  177. data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +2 -0
  178. data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +2 -0
  179. data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +8 -1
  180. data/lib/datadog/tracing/contrib/active_record/event.rb +2 -0
  181. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -1
  182. data/lib/datadog/tracing/contrib/active_record/events.rb +2 -0
  183. data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -0
  184. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +6 -2
  185. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +2 -0
  186. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -0
  187. data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +2 -0
  188. data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +2 -0
  189. data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +2 -0
  190. data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -0
  191. data/lib/datadog/tracing/contrib/analytics.rb +2 -0
  192. data/lib/datadog/tracing/contrib/auto_instrument.rb +2 -0
  193. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +9 -1
  194. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +8 -1
  195. data/lib/datadog/tracing/contrib/aws/patcher.rb +2 -0
  196. data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +2 -0
  197. data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +2 -0
  198. data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +2 -0
  199. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +2 -0
  200. data/lib/datadog/tracing/contrib/configurable.rb +2 -0
  201. data/lib/datadog/tracing/contrib/configuration/resolver.rb +2 -0
  202. data/lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb +2 -0
  203. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +8 -1
  204. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +4 -1
  205. data/lib/datadog/tracing/contrib/dalli/patcher.rb +2 -0
  206. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +2 -0
  207. data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +2 -0
  208. data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +2 -0
  209. data/lib/datadog/tracing/contrib/delayed_job/server_internal_tracer/worker.rb +2 -0
  210. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +8 -1
  211. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +4 -1
  212. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +8 -1
  213. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -3
  214. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +6 -2
  215. data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -0
  216. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +8 -1
  217. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -2
  218. data/lib/datadog/tracing/contrib/excon/patcher.rb +2 -0
  219. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +8 -1
  220. data/lib/datadog/tracing/contrib/faraday/connection.rb +2 -0
  221. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -2
  222. data/lib/datadog/tracing/contrib/faraday/rack_builder.rb +2 -0
  223. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +2 -0
  224. data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -0
  225. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +2 -0
  226. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +8 -1
  227. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +5 -2
  228. data/lib/datadog/tracing/contrib/grpc/intercept_with_datadog.rb +2 -0
  229. data/lib/datadog/tracing/contrib/grpc/patcher.rb +2 -0
  230. data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +2 -0
  231. data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +2 -0
  232. data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -0
  233. data/lib/datadog/tracing/contrib/hanami/plugin.rb +2 -0
  234. data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +2 -0
  235. data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +2 -0
  236. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +2 -0
  237. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +8 -1
  238. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -2
  239. data/lib/datadog/tracing/contrib/http/integration.rb +2 -0
  240. data/lib/datadog/tracing/contrib/http/patcher.rb +2 -0
  241. data/lib/datadog/tracing/contrib/http_annotation_helper.rb +2 -0
  242. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +2 -0
  243. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +2 -0
  244. data/lib/datadog/tracing/contrib/integration.rb +2 -0
  245. data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +2 -0
  246. data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +2 -0
  247. data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +2 -0
  248. data/lib/datadog/tracing/contrib/kafka/event.rb +2 -0
  249. data/lib/datadog/tracing/contrib/kafka/events.rb +2 -0
  250. data/lib/datadog/tracing/contrib/kafka/patcher.rb +2 -0
  251. data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +2 -0
  252. data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +2 -0
  253. data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -0
  254. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +2 -0
  255. data/lib/datadog/tracing/contrib/mongodb/instrumentation.rb +2 -0
  256. data/lib/datadog/tracing/contrib/mongodb/patcher.rb +2 -0
  257. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +2 -0
  258. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -0
  259. data/lib/datadog/tracing/contrib/mysql2/patcher.rb +2 -0
  260. data/lib/datadog/tracing/contrib/patchable.rb +2 -0
  261. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +2 -0
  262. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +2 -0
  263. data/lib/datadog/tracing/contrib/pg/patcher.rb +2 -0
  264. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +2 -0
  265. data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +2 -0
  266. data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +2 -0
  267. data/lib/datadog/tracing/contrib/qless/patcher.rb +2 -0
  268. data/lib/datadog/tracing/contrib/qless/tracer_cleaner.rb +2 -0
  269. data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +2 -0
  270. data/lib/datadog/tracing/contrib/racecar/event.rb +2 -0
  271. data/lib/datadog/tracing/contrib/racecar/events.rb +2 -0
  272. data/lib/datadog/tracing/contrib/racecar/patcher.rb +2 -0
  273. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +9 -2
  274. data/lib/datadog/tracing/contrib/rails/framework.rb +2 -0
  275. data/lib/datadog/tracing/contrib/rails/middlewares.rb +2 -0
  276. data/lib/datadog/tracing/contrib/rails/utils.rb +3 -1
  277. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +2 -0
  278. data/lib/datadog/tracing/contrib/rake/patcher.rb +2 -0
  279. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +2 -0
  280. data/lib/datadog/tracing/contrib/redis/tags.rb +2 -0
  281. data/lib/datadog/tracing/contrib/registerable.rb +2 -0
  282. data/lib/datadog/tracing/contrib/registry.rb +2 -0
  283. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +2 -0
  284. data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -0
  285. data/lib/datadog/tracing/contrib/resque/resque_job.rb +2 -0
  286. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +2 -0
  287. data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -0
  288. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +2 -0
  289. data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +34 -0
  290. data/lib/datadog/tracing/contrib/roda/ext.rb +18 -0
  291. data/lib/datadog/tracing/contrib/roda/instrumentation.rb +76 -0
  292. data/lib/datadog/tracing/contrib/roda/integration.rb +45 -0
  293. data/lib/datadog/tracing/contrib/roda/patcher.rb +30 -0
  294. data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +2 -0
  295. data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +3 -0
  296. data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -0
  297. data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +2 -0
  298. data/lib/datadog/tracing/contrib/sequel/dataset.rb +2 -0
  299. data/lib/datadog/tracing/contrib/sequel/patcher.rb +2 -0
  300. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +2 -0
  301. data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -0
  302. data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +2 -0
  303. data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +12 -3
  304. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +3 -0
  305. data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +38 -0
  306. data/lib/datadog/tracing/contrib/sidekiq/integration.rb +8 -0
  307. data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +16 -2
  308. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/heartbeat.rb +11 -4
  309. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/job_fetch.rb +2 -0
  310. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/redis_info.rb +2 -0
  311. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/scheduled_poller.rb +2 -0
  312. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/stop.rb +34 -0
  313. data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +18 -2
  314. data/lib/datadog/tracing/contrib/sidekiq/{tracing.rb → utils.rb} +3 -1
  315. data/lib/datadog/tracing/contrib/sinatra/headers.rb +2 -0
  316. data/lib/datadog/tracing/contrib/sinatra/patcher.rb +2 -0
  317. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +2 -0
  318. data/lib/datadog/tracing/contrib/span_attribute_schema.rb +28 -0
  319. data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +2 -0
  320. data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +2 -0
  321. data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +2 -0
  322. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  323. data/lib/datadog/tracing/contrib.rb +3 -0
  324. data/lib/datadog/tracing/correlation.rb +10 -10
  325. data/lib/datadog/tracing/diagnostics/health.rb +2 -0
  326. data/lib/datadog/tracing/distributed/trace_context.rb +22 -15
  327. data/lib/datadog/tracing/flush.rb +2 -0
  328. data/lib/datadog/tracing/metadata/analytics.rb +2 -0
  329. data/lib/datadog/tracing/metadata/errors.rb +2 -0
  330. data/lib/datadog/tracing/metadata/ext.rb +6 -0
  331. data/lib/datadog/tracing/metadata.rb +2 -0
  332. data/lib/datadog/tracing/pipeline/span_filter.rb +2 -0
  333. data/lib/datadog/tracing/pipeline/span_processor.rb +2 -0
  334. data/lib/datadog/tracing/propagation/http.rb +2 -0
  335. data/lib/datadog/tracing/runtime/metrics.rb +2 -0
  336. data/lib/datadog/tracing/sampling/all_sampler.rb +2 -0
  337. data/lib/datadog/tracing/sampling/matcher.rb +2 -0
  338. data/lib/datadog/tracing/sampling/priority_sampler.rb +2 -0
  339. data/lib/datadog/tracing/sampling/span/sampler.rb +2 -0
  340. data/lib/datadog/tracing/sync_writer.rb +2 -0
  341. data/lib/datadog/tracing/trace_digest.rb +2 -0
  342. data/lib/datadog/tracing/utils.rb +2 -0
  343. data/lib/datadog/tracing.rb +2 -0
  344. data/lib/ddtrace/auto_instrument.rb +2 -0
  345. data/lib/ddtrace/auto_instrument_base.rb +2 -0
  346. data/lib/ddtrace/transport/http/adapters/net.rb +12 -0
  347. data/lib/ddtrace/transport/http/adapters/registry.rb +2 -0
  348. data/lib/ddtrace/transport/http/api/endpoint.rb +2 -0
  349. data/lib/ddtrace/transport/http/api/fallbacks.rb +2 -0
  350. data/lib/ddtrace/transport/http/api/instance.rb +2 -0
  351. data/lib/ddtrace/transport/http/api/map.rb +2 -0
  352. data/lib/ddtrace/transport/http/api/spec.rb +2 -0
  353. data/lib/ddtrace/transport/http/env.rb +2 -0
  354. data/lib/ddtrace/transport/http/response.rb +2 -0
  355. data/lib/ddtrace/transport/io/response.rb +2 -0
  356. data/lib/ddtrace/transport/io/traces.rb +2 -0
  357. data/lib/ddtrace/transport/io.rb +2 -0
  358. data/lib/ddtrace/transport/parcel.rb +2 -0
  359. data/lib/ddtrace/transport/request.rb +3 -1
  360. data/lib/ddtrace/transport/statistics.rb +2 -0
  361. data/lib/ddtrace/transport/trace_formatter.rb +2 -0
  362. data/lib/ddtrace/version.rb +9 -5
  363. data/lib/ddtrace.rb +2 -0
  364. metadata +43 -6
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  module Configuration
@@ -5,6 +5,7 @@ require_relative 'ext'
5
5
  require_relative '../environment/ext'
6
6
  require_relative '../runtime/ext'
7
7
  require_relative '../telemetry/ext'
8
+ require_relative '../remote/ext'
8
9
  require_relative '../../profiling/ext'
9
10
 
10
11
  require_relative '../../tracing/configuration/settings'
@@ -202,9 +203,10 @@ module Datadog
202
203
  # @public_api
203
204
  settings :advanced do
204
205
  # This should never be reduced, as it can cause the resulting profiles to become biased.
205
- # The current default should be enough for most services, allowing 16 threads to be sampled around 30 times
206
+ # The default should be enough for most services, allowing 16 threads to be sampled around 30 times
206
207
  # per second for a 60 second period.
207
- # This setting is ignored when CPU Profiling 2.0 is in use.
208
+ #
209
+ # @deprecated This setting is ignored when CPU Profiling 2.0 is in use.
208
210
  option :max_events, default: 32768
209
211
 
210
212
  # Controls the maximum number of frames for each thread sampled. Can be tuned to avoid omitted frames in the
@@ -235,7 +237,7 @@ module Datadog
235
237
  # grouping and categorization of stack traces.
236
238
  option :code_provenance_enabled, default: true
237
239
 
238
- # No longer does anything, and will be removed on dd-trace-rb 2.0.
240
+ # @deprecated No longer does anything, and will be removed on dd-trace-rb 2.0.
239
241
  #
240
242
  # This was added as a temporary support option in case of issues with the new `Profiling::HttpTransport` class
241
243
  # but we're now confident it's working nicely so we've removed the old code path.
@@ -251,29 +253,44 @@ module Datadog
251
253
  # Forces enabling the new CPU Profiling 2.0 profiler (see ddtrace release notes for more details).
252
254
  #
253
255
  # Note that setting this to "false" (or not setting it) will not prevent the new profiler from
254
- # being automatically used in the future.
255
- # This option will be deprecated for removal once the new profiler gets enabled by default for all customers.
256
+ # being automatically used.
257
+ # This option will be deprecated for removal once the legacy profiler is removed.
258
+ #
259
+ # @default `DD_PROFILING_FORCE_ENABLE_NEW` environment variable, otherwise `false`
256
260
  option :force_enable_new_profiler do |o|
257
261
  o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_NEW', false) }
258
262
  o.lazy
259
263
  end
260
264
 
265
+ # Forces enabling the *legacy* (non-CPU Profiling 2.0 profiler) even when it would otherwise NOT be enabled.
266
+ #
267
+ # Temporarily added to ease migration to the new CPU Profiling 2.0 profiler, and will be removed soon.
268
+ # Do not use unless instructed to by support.
269
+ # This option will be deprecated for removal once the legacy profiler is removed.
270
+ #
271
+ # @default `DD_PROFILING_FORCE_ENABLE_LEGACY` environment variable, otherwise `false`
272
+ option :force_enable_legacy_profiler do |o|
273
+ o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_LEGACY', false) }
274
+ o.lazy
275
+ end
276
+
261
277
  # Forces enabling of profiling of time/resources spent in Garbage Collection.
262
278
  #
263
279
  # Note that setting this to "false" (or not setting it) will not prevent the feature from being
264
280
  # being automatically enabled in the future.
265
281
  #
266
- # This toggle was added because, although this feature is safe and enabled by default on Ruby 2.x,
267
- # on Ruby 3.x it can break in applications that make use of Ractors due to two Ruby VM bugs:
268
- # https://bugs.ruby-lang.org/issues/19112 AND https://bugs.ruby-lang.org/issues/18464.
269
- #
270
- # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
271
- # feature is fully safe to enable and this toggle can be used to do so.
272
- #
273
- # Furthermore, currently this feature can add a lot of overhead for GC-heavy workloads.
282
+ # This feature defaults to off for two reasons:
283
+ # 1. Currently this feature can add a lot of overhead for GC-heavy workloads.
284
+ # 2. Although this feature is safe on Ruby 2.x, on Ruby 3.x it can break in applications that make use of
285
+ # Ractors due to two Ruby VM bugs:
286
+ # https://bugs.ruby-lang.org/issues/19112 AND https://bugs.ruby-lang.org/issues/18464.
287
+ # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
288
+ # feature is fully safe to enable and this toggle can be used to do so.
274
289
  #
275
290
  # We expect the once the above issues are overcome, we'll automatically enable the feature on fixed Ruby
276
291
  # versions.
292
+ #
293
+ # @default `DD_PROFILING_FORCE_ENABLE_GC` environment variable, otherwise `false`
277
294
  option :force_enable_gc_profiling do |o|
278
295
  o.default { env_to_bool('DD_PROFILING_FORCE_ENABLE_GC', false) }
279
296
  o.lazy
@@ -287,11 +304,26 @@ module Datadog
287
304
  #
288
305
  # If you use Ruby 3.x and your application does not use Ractors (or if your Ruby has been patched), the
289
306
  # feature is fully safe to enable and this toggle can be used to do so.
307
+ #
308
+ # @default `true` on Ruby 2.x, `false` on Ruby 3.x
290
309
  option :allocation_counting_enabled, default: RUBY_VERSION.start_with?('2.')
310
+
311
+ # Can be used to disable checking which version of `libmysqlclient` is being used by the `mysql2` gem.
312
+ #
313
+ # This setting is only used when the `mysql2` gem is installed.
314
+ #
315
+ # @default `DD_PROFILING_SKIP_MYSQL2_CHECK` environment variable, otherwise `false`
316
+ option :skip_mysql2_check do |o|
317
+ o.default { env_to_bool('DD_PROFILING_SKIP_MYSQL2_CHECK', false) }
318
+ o.lazy
319
+ end
291
320
  end
292
321
 
293
322
  # @public_api
294
323
  settings :upload do
324
+ # Network timeout for reporting profiling data to Datadog.
325
+ #
326
+ # @default `DD_PROFILING_UPLOAD_TIMEOUT` environment variable, otherwise `30.0`
295
327
  option :timeout_seconds do |o|
296
328
  o.setter { |value| value.nil? ? 30.0 : value.to_f }
297
329
  o.default { env_to_float(Profiling::Ext::ENV_UPLOAD_TIMEOUT, 30.0) }
@@ -436,11 +468,33 @@ module Datadog
436
468
  settings :telemetry do
437
469
  # Enable telemetry collection. This allows telemetry events to be emitted to the telemetry API.
438
470
  #
439
- # @default `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment variable, otherwise `false`. In a future release,
440
- # this value will be changed to `true` by default as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection).
471
+ # @default `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment variable, otherwise `true`.
472
+ # Can be disabled as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection).
473
+ # @return [Boolean]
474
+ option :enabled do |o|
475
+ o.default { env_to_bool(Core::Telemetry::Ext::ENV_ENABLED, true) }
476
+ o.lazy
477
+ end
478
+ end
479
+
480
+ # Remote configuration
481
+ # @public_api
482
+ settings :remote do
483
+ # Enable remote configuration. This allows fetching of remote configuration for live updates.
484
+ #
485
+ # @default `DD_REMOTE_CONFIGURATION_ENABLED` environment variable, otherwise `true`.
441
486
  # @return [Boolean]
442
487
  option :enabled do |o|
443
- o.default { env_to_bool(Core::Telemetry::Ext::ENV_ENABLED, false) }
488
+ o.default { env_to_bool(Core::Remote::Ext::ENV_ENABLED, true) }
489
+ o.lazy
490
+ end
491
+
492
+ # Tune remote configuration polling interval.
493
+ #
494
+ # @default `DD_REMOTE_CONFIGURATION_POLL_INTERVAL_SECONDS` environment variable, otherwise `5.0` seconds.
495
+ # @return [Float]
496
+ option :poll_interval_seconds do |o|
497
+ o.default { env_to_float(Core::Remote::Ext::ENV_POLL_INTERVAL_SECONDS, 5.0) }
444
498
  o.lazy
445
499
  end
446
500
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../metrics/client'
2
4
  require_relative '../../tracing/diagnostics/health'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  module Environment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  module Environment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
 
3
5
  require_relative 'ext'
@@ -47,9 +49,65 @@ module Datadog
47
49
  Core::Environment::Ext::LANG_VERSION
48
50
  end
49
51
 
52
+ # Returns tracer version, rubygems-style
50
53
  def tracer_version
51
54
  Core::Environment::Ext::TRACER_VERSION
52
55
  end
56
+
57
+ # Returns tracer version, comforming to https://semver.org/spec/v2.0.0.html
58
+ def tracer_version_semver2
59
+ # from ddtrace/version.rb, we have MAJOR.MINOR.PATCH plus optional .PRE and .BUILD
60
+ # - transform .PRE to -PRE if present
61
+ # - transform .BUILD to +BUILD if present
62
+ # - keep triplet segments before that
63
+
64
+ m = SEMVER2_RE.match(tracer_version)
65
+
66
+ pre = "-#{m[:pre]}" if m[:pre]
67
+ build = "+gha#{m[:gha_run_id]}.g#{m[:git_sha]}.#{m[:branch].tr('.', '-')}" if m[:build]
68
+
69
+ "#{m[:major]}.#{m[:minor]}.#{m[:patch]}#{pre}#{build}"
70
+ end
71
+
72
+ SEMVER2_RE = /
73
+ ^
74
+ # mandatory segments
75
+ (?<major>\d+)
76
+ \.
77
+ (?<minor>\d+)
78
+ \.
79
+ (?<patch>\d+)
80
+
81
+ # pre segments start with a value
82
+ # - containing at least one alpha
83
+ # - that is not part of our build segments expected values
84
+ # and stop with a value that is not part of our build segments expected values
85
+ (?:
86
+ \.
87
+ (?<pre>
88
+ (?!gha)
89
+ [a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*
90
+ (?:
91
+ \.
92
+ (?!gha)
93
+ [a-zA-Z0-9]+
94
+ )*
95
+ )
96
+ )?
97
+
98
+ # build segments: ours include CI info (`gha`), then git (`g`), then branch name
99
+ (?:
100
+ \.
101
+ (?<build>
102
+ gha(?<gha_run_id>\d+)
103
+ \.
104
+ g(?<git_sha>[a-f0-9]+)
105
+ \.
106
+ (?<branch>(?:[a-zA-Z0-9.])+)
107
+ )
108
+ )?
109
+ $
110
+ /xm.freeze
53
111
  end
54
112
  end
55
113
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'socket'
2
4
  require_relative '../utils/forking'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  module Environment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  # Namespace for handling application environment
@@ -14,11 +16,17 @@ module Datadog
14
16
  # @param [Boolean] default the default value if the keys in `var` are not present in the environment
15
17
  # @param [Boolean] deprecation_warning when `var` is a list, record a deprecation log when
16
18
  # the first key in `var` is not used.
17
- # @return [Boolean] if the environment value is the string `true`
19
+ # @return [Boolean] if the environment value is the string `true` or `1`
18
20
  # @return [default] if the environment value is not found
19
21
  def env_to_bool(var, default = nil, deprecation_warning: true)
20
22
  var = decode_array(var, deprecation_warning)
21
- var && ENV.key?(var) ? ENV[var].to_s.strip.downcase == 'true' : default
23
+ if var && ENV.key?(var)
24
+ value = ENV[var].to_s.strip
25
+ value.downcase!
26
+ value == 'true' || value == '1' # rubocop:disable Style/MultipleComparison
27
+ else
28
+ default
29
+ end
22
30
  end
23
31
 
24
32
  # Reads an environment variable as an Integer.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  module Environment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'configuration'
2
4
 
3
5
  # Global namespace that includes all Datadog functionality.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  # A some-what abstract class representing a collection of headers.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  module Metrics
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Datadog
2
4
  module Core
3
5
  module Metrics
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../../appsec/remote'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Remote
8
+ class Client
9
+ # Capbailities
10
+ class Capabilities
11
+ attr_reader :products, :capabilities, :receivers, :base64_capabilities
12
+
13
+ def initialize(settings)
14
+ @capabilities = []
15
+ @products = []
16
+ @receivers = []
17
+
18
+ register(settings)
19
+
20
+ @base64_capabilities = capabilities_to_base64
21
+ end
22
+
23
+ private
24
+
25
+ def register(settings)
26
+ if settings.appsec.enabled
27
+ register_capabilities(Datadog::AppSec::Remote.capabilities)
28
+ register_products(Datadog::AppSec::Remote.products)
29
+ register_receivers(Datadog::AppSec::Remote.receivers)
30
+ end
31
+ end
32
+
33
+ def register_capabilities(capabilities)
34
+ @capabilities.concat(capabilities)
35
+ end
36
+
37
+ def register_receivers(receivers)
38
+ @receivers.concat(receivers)
39
+ end
40
+
41
+ def register_products(products)
42
+ @products.concat(products)
43
+ end
44
+
45
+ def capabilities_to_base64
46
+ return '' if capabilities.empty?
47
+
48
+ cap_to_hexs = capabilities.reduce(:|).to_s(16).tap { |s| s.size.odd? && s.prepend('0') }.scan(/\h\h/)
49
+ binary = cap_to_hexs.each_with_object([]) { |hex, acc| acc << hex }.map { |e| e.to_i(16) }.pack('C*')
50
+
51
+ Base64.encode64(binary).chomp
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,225 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ require_relative 'configuration'
6
+ require_relative 'dispatcher'
7
+
8
+ module Datadog
9
+ module Core
10
+ module Remote
11
+ # Client communicates with the agent and sync remote configuration
12
+ class Client
13
+ class SyncError < StandardError; end
14
+
15
+ attr_reader :transport, :repository, :id, :dispatcher
16
+
17
+ def initialize(transport, capabilities, repository: Configuration::Repository.new)
18
+ @transport = transport
19
+
20
+ @repository = repository
21
+ @id = SecureRandom.uuid
22
+ @dispatcher = Dispatcher.new
23
+ @capabilities = capabilities
24
+
25
+ @capabilities.receivers.each do |receiver|
26
+ dispatcher.receivers << receiver
27
+ end
28
+ end
29
+
30
+ # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity
31
+ def sync
32
+ # TODO: Skip sync if no capabilities are registered
33
+ response = transport.send_config(payload)
34
+
35
+ if response.ok?
36
+ # when response is completely empty, do nothing as in: leave as is
37
+ if response.empty?
38
+ Datadog.logger.debug { 'remote: empty response => NOOP' }
39
+
40
+ return
41
+ end
42
+
43
+ begin
44
+ paths = response.client_configs.map do |path|
45
+ Configuration::Path.parse(path)
46
+ end
47
+
48
+ targets = Configuration::TargetMap.parse(response.targets)
49
+
50
+ contents = Configuration::ContentList.parse(response.target_files)
51
+ rescue Remote::Configuration::Path::ParseError => e
52
+ raise SyncError, e.message
53
+ end
54
+
55
+ # To make sure steep does not complain
56
+ return unless paths && targets && contents
57
+
58
+ # TODO: sometimes it can strangely be so that paths.empty?
59
+ # TODO: sometimes it can strangely be so that targets.empty?
60
+
61
+ changes = repository.transaction do |current, transaction|
62
+ # paths to be removed: previously applied paths minus ingress paths
63
+ (current.paths - paths).each { |p| transaction.delete(p) }
64
+
65
+ # go through each ingress path
66
+ paths.each do |path|
67
+ # match target with path
68
+ target = targets[path]
69
+
70
+ # abort entirely if matching target not found
71
+ raise SyncError, "no target for path '#{path}'" if target.nil?
72
+
73
+ # new paths are not in previously applied paths
74
+ new = !current.paths.include?(path)
75
+
76
+ # updated paths are in previously applied paths
77
+ # but the content hash changed
78
+ changed = current.paths.include?(path) && !current.contents.find_content(path, target)
79
+
80
+ # skip if unchanged
81
+ same = !new && !changed
82
+
83
+ next if same
84
+
85
+ # match content with path and target
86
+ content = contents.find_content(path, target)
87
+
88
+ # abort entirely if matching content not found
89
+ raise SyncError, "no valid content for target at path '#{path}'" if content.nil?
90
+
91
+ # to be added or updated << config
92
+ # TODO: metadata (hash, version, etc...)
93
+ transaction.insert(path, target, content) if new
94
+ transaction.update(path, target, content) if changed
95
+ end
96
+
97
+ # save backend opaque backend state
98
+ transaction.set(opaque_backend_state: targets.opaque_backend_state)
99
+ transaction.set(targets_version: targets.version)
100
+
101
+ # upon transaction end, new list of applied config + metadata (add, change, remove) will be saved
102
+ # TODO: also remove stale config (matching removed) from cache (client configs is exhaustive list of paths)
103
+ end
104
+
105
+ if changes.empty?
106
+ Datadog.logger.debug { 'remote: no changes' }
107
+ else
108
+ dispatcher.dispatch(changes, repository)
109
+ end
110
+ end
111
+ end
112
+ # rubocop:enable Metrics/AbcSize,Metrics/PerceivedComplexity,Metrics/MethodLength,Metrics/CyclomaticComplexity
113
+
114
+ private
115
+
116
+ def payload # rubocop:disable Metrics/MethodLength
117
+ state = repository.state
118
+
119
+ client_tracer_tags = [
120
+ "platform:#{native_platform}", # native platform
121
+ # "asm.config.rules:#{}", # TODO: defined|undefined
122
+ # "asm.config.enabled:#{}", # TODO: true|false|undefined
123
+ "ruby.tracer.version:#{Core::Environment::Identity.tracer_version}",
124
+ "ruby.runtime.platform:#{RUBY_PLATFORM}",
125
+ "ruby.runtime.version:#{RUBY_VERSION}",
126
+ "ruby.runtime.engine.name:#{RUBY_ENGINE}",
127
+ "ruby.runtime.engine.version:#{ruby_engine_version}",
128
+ "ruby.rubygems.platform.local:#{Gem::Platform.local}",
129
+ "ruby.gem.libddwaf.version:#{gem_spec('libddwaf').version}",
130
+ "ruby.gem.libddwaf.platform:#{gem_spec('libddwaf').platform}",
131
+ "ruby.gem.libdatadog.version:#{gem_spec('libdatadog').version}",
132
+ "ruby.gem.libdatadog.platform:#{gem_spec('libdatadog').platform}",
133
+ ]
134
+
135
+ client_tracer = {
136
+ runtime_id: Core::Environment::Identity.id,
137
+ language: Core::Environment::Identity.lang,
138
+ tracer_version: tracer_version_semver2,
139
+ service: Datadog.configuration.service,
140
+ env: Datadog.configuration.env,
141
+ tags: client_tracer_tags,
142
+ }
143
+
144
+ app_version = Datadog.configuration.version
145
+
146
+ client_tracer[:app_version] = app_version if app_version
147
+
148
+ {
149
+ client: {
150
+ state: {
151
+ root_version: state.root_version,
152
+ targets_version: state.targets_version,
153
+ config_states: state.config_states,
154
+ has_error: state.has_error,
155
+ error: state.error,
156
+ backend_client_state: state.opaque_backend_state,
157
+ },
158
+ id: id,
159
+ products: @capabilities.products,
160
+ is_tracer: true,
161
+ is_agent: false,
162
+ client_tracer: client_tracer,
163
+ # base64 is needed otherwise the Go agent fails with an unmarshal error
164
+ capabilities: @capabilities.base64_capabilities
165
+ },
166
+ cached_target_files: state.cached_target_files,
167
+ }
168
+ end
169
+
170
+ def tracer_version_semver2
171
+ @tracer_version_semver2 ||= Core::Environment::Identity.tracer_version_semver2
172
+ end
173
+
174
+ def ruby_engine_version
175
+ @ruby_engine_version ||= defined?(RUBY_ENGINE_VERSION) ? RUBY_ENGINE_VERSION : RUBY_VERSION
176
+ end
177
+
178
+ def gem_spec(name)
179
+ (@gem_specs ||= {})[name] ||= ::Gem.loaded_specs[name] || GemSpecificationFallback.new(nil, nil)
180
+ end
181
+
182
+ def native_platform
183
+ return @native_platform unless @native_platform.nil?
184
+
185
+ os = if RUBY_ENGINE == 'jruby'
186
+ os_name = java.lang.System.get_property('os.name')
187
+
188
+ case os_name
189
+ when /linux/i then 'linux'
190
+ when /mac/i then 'darwin'
191
+ else os_name
192
+ end
193
+ else
194
+ Gem::Platform.local.os
195
+ end
196
+
197
+ version = if os != 'linux'
198
+ nil
199
+ elsif RUBY_PLATFORM =~ /linux-(.+)$/
200
+ # Old rubygems don't handle non-gnu linux correctly
201
+ Regexp.last_match(1)
202
+ else
203
+ 'gnu'
204
+ end
205
+
206
+ cpu = if RUBY_ENGINE == 'jruby'
207
+ os_arch = java.lang.System.get_property('os.arch')
208
+
209
+ case os_arch
210
+ when 'amd64' then 'x86_64'
211
+ when 'aarch64' then os == 'darwin' ? 'arm64' : 'aarch64'
212
+ else os_arch
213
+ end
214
+ else
215
+ Gem::Platform.local.cpu
216
+ end
217
+
218
+ @native_platform = [cpu, os, version].compact.join('-')
219
+ end
220
+
221
+ GemSpecificationFallback = _ = Struct.new(:version, :platform) # rubocop:disable Naming/ConstantName
222
+ end
223
+ end
224
+ end
225
+ end