datadog 2.48.0 → 2.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -1
  3. data/ext/datadog_profiling_native_extension/collectors_stack.c +1 -1
  4. data/ext/datadog_profiling_native_extension/collectors_stack.h +4 -2
  5. data/ext/datadog_profiling_native_extension/extconf.rb +3 -0
  6. data/ext/datadog_profiling_native_extension/private_vm_api_access.c +13 -21
  7. data/ext/libdatadog_api/extconf.rb +2 -0
  8. data/ext/libdatadog_api/feature_flags.c +137 -0
  9. data/ext/libdatadog_api/process_discovery.c +3 -3
  10. data/ext/libdatadog_extconf_helpers.rb +1 -1
  11. data/lib/datadog/ai_guard/contrib/rack/patcher.rb +3 -5
  12. data/lib/datadog/ai_guard/contrib/rails/patcher.rb +7 -9
  13. data/lib/datadog/ai_guard/contrib/ruby_llm/patcher.rb +3 -5
  14. data/lib/datadog/ai_guard/metrics/telemetry.rb +2 -4
  15. data/lib/datadog/appsec/actions_handler.rb +5 -7
  16. data/lib/datadog/appsec/api_security/endpoint_collection/grape_route_serializer.rb +1 -3
  17. data/lib/datadog/appsec/api_security/endpoint_collection/rails_route_serializer.rb +1 -3
  18. data/lib/datadog/appsec/api_security/endpoint_collection/sinatra_route_serializer.rb +1 -3
  19. data/lib/datadog/appsec/assets.rb +8 -10
  20. data/lib/datadog/appsec/configuration.rb +1 -1
  21. data/lib/datadog/appsec/context.rb +63 -6
  22. data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +1 -3
  23. data/lib/datadog/appsec/contrib/active_record/patcher.rb +21 -24
  24. data/lib/datadog/appsec/contrib/aws_lambda/patcher.rb +3 -5
  25. data/lib/datadog/appsec/contrib/aws_lambda/waf_addresses.rb +9 -11
  26. data/lib/datadog/appsec/contrib/devise/configuration.rb +2 -4
  27. data/lib/datadog/appsec/contrib/devise/patcher.rb +3 -5
  28. data/lib/datadog/appsec/contrib/excon/patcher.rb +3 -5
  29. data/lib/datadog/appsec/contrib/faraday/patcher.rb +4 -6
  30. data/lib/datadog/appsec/contrib/graphql/patcher.rb +3 -5
  31. data/lib/datadog/appsec/contrib/rack/input_peeker.rb +3 -5
  32. data/lib/datadog/appsec/contrib/rack/patcher.rb +3 -5
  33. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +5 -4
  34. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +6 -7
  35. data/lib/datadog/appsec/contrib/rails/patcher.rb +19 -16
  36. data/lib/datadog/appsec/contrib/rails/patches/live_thread_patch.rb +33 -0
  37. data/lib/datadog/appsec/contrib/rest_client/patcher.rb +3 -5
  38. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +4 -6
  39. data/lib/datadog/appsec/default_header_tags.rb +2 -4
  40. data/lib/datadog/appsec/metrics/exporter.rb +4 -6
  41. data/lib/datadog/appsec/metrics/telemetry.rb +1 -3
  42. data/lib/datadog/appsec/metrics/telemetry_exporter.rb +2 -4
  43. data/lib/datadog/appsec/route_normalizer/route_text.rb +1 -3
  44. data/lib/datadog/appsec/route_normalizer.rb +4 -6
  45. data/lib/datadog/appsec/utils/http/body_reader.rb +3 -5
  46. data/lib/datadog/appsec/utils/http/url_encoded.rb +2 -4
  47. data/lib/datadog/core/borrowing_token_bucket.rb +60 -0
  48. data/lib/datadog/core/chunker.rb +1 -3
  49. data/lib/datadog/core/configuration/components.rb +48 -17
  50. data/lib/datadog/core/configuration/settings.rb +2 -1
  51. data/lib/datadog/core/configuration/supported_configurations.rb +2 -0
  52. data/lib/datadog/core/diagnostics/environment_logger.rb +1 -6
  53. data/lib/datadog/core/encoding.rb +8 -12
  54. data/lib/datadog/core/environment/cgroup.rb +3 -5
  55. data/lib/datadog/core/environment/container.rb +9 -11
  56. data/lib/datadog/core/environment/ext.rb +1 -6
  57. data/lib/datadog/core/environment/gc.rb +2 -4
  58. data/lib/datadog/core/environment/identity.rb +13 -15
  59. data/lib/datadog/core/environment/platform.rb +10 -12
  60. data/lib/datadog/core/environment/socket.rb +3 -5
  61. data/lib/datadog/core/environment/thread_count.rb +2 -4
  62. data/lib/datadog/core/environment/variable_helpers.rb +2 -6
  63. data/lib/datadog/core/environment/vm_cache.rb +5 -7
  64. data/lib/datadog/core/environment/yjit.rb +25 -24
  65. data/lib/datadog/core/logger.rb +5 -2
  66. data/lib/datadog/core/metrics/client.rb +8 -16
  67. data/lib/datadog/core/metrics/helpers.rb +3 -0
  68. data/lib/datadog/core/metrics/metric.rb +3 -1
  69. data/lib/datadog/core/rate_limiter.rb +9 -31
  70. data/lib/datadog/core/refillable_bucket.rb +72 -0
  71. data/lib/datadog/core/remote/client/capabilities.rb +4 -0
  72. data/lib/datadog/core/remote/client.rb +1 -5
  73. data/lib/datadog/core/remote/transport/http.rb +2 -4
  74. data/lib/datadog/core/tag_normalizer.rb +0 -2
  75. data/lib/datadog/core/telemetry/configuration_value.rb +1 -3
  76. data/lib/datadog/core/telemetry/transport/http.rb +2 -4
  77. data/lib/datadog/core/telemetry/worker.rb +30 -24
  78. data/lib/datadog/core/transport/http.rb +2 -4
  79. data/lib/datadog/core/utils/at_fork_monkey_patch.rb +2 -2
  80. data/lib/datadog/core/utils/forking.rb +1 -1
  81. data/lib/datadog/core/utils/lru_cache.rb +2 -2
  82. data/lib/datadog/core/utils/network.rb +1 -1
  83. data/lib/datadog/core/utils/time.rb +2 -2
  84. data/lib/datadog/core/utils/truncation.rb +1 -3
  85. data/lib/datadog/core/workers/async.rb +16 -14
  86. data/lib/datadog/core/workers/runtime_metrics.rb +1 -1
  87. data/lib/datadog/data_streams/transport/http.rb +1 -3
  88. data/lib/datadog/di/component.rb +14 -2
  89. data/lib/datadog/di/context.rb +50 -0
  90. data/lib/datadog/di/contrib.rb +2 -2
  91. data/lib/datadog/di/correlation_sampler/trace_budget.rb +75 -0
  92. data/lib/datadog/di/correlation_sampler/trace_budget_ledger/entry.rb +34 -0
  93. data/lib/datadog/di/correlation_sampler/trace_budget_ledger.rb +104 -0
  94. data/lib/datadog/di/correlation_sampler.rb +224 -0
  95. data/lib/datadog/di/guardrails_telemetry/reason.rb +8 -3
  96. data/lib/datadog/di/instrumenter.rb +294 -109
  97. data/lib/datadog/di/probe.rb +13 -2
  98. data/lib/datadog/di/probe_builder.rb +6 -8
  99. data/lib/datadog/di/probe_file_loader.rb +2 -2
  100. data/lib/datadog/di/probe_manager.rb +7 -30
  101. data/lib/datadog/di/probe_notification_builder.rb +42 -11
  102. data/lib/datadog/di/probe_notifier_worker.rb +11 -0
  103. data/lib/datadog/di/snapshot_pruner/node.rb +190 -0
  104. data/lib/datadog/di/snapshot_pruner/node_queue.rb +104 -0
  105. data/lib/datadog/di/snapshot_pruner/parser.rb +102 -0
  106. data/lib/datadog/di/snapshot_pruner.rb +128 -0
  107. data/lib/datadog/di/transport/input.rb +75 -15
  108. data/lib/datadog/di/utils.rb +3 -3
  109. data/lib/datadog/di.rb +29 -0
  110. data/lib/datadog/error_tracking/filters.rb +6 -8
  111. data/lib/datadog/open_feature/agentless/parser.rb +2 -4
  112. data/lib/datadog/open_feature/component.rb +24 -2
  113. data/lib/datadog/open_feature/configuration.rb +13 -0
  114. data/lib/datadog/open_feature/evaluation_engine.rb +5 -5
  115. data/lib/datadog/open_feature/exposure_hook.rb +146 -0
  116. data/lib/datadog/open_feature/exposures/event.rb +10 -8
  117. data/lib/datadog/open_feature/exposures/reporter.rb +34 -25
  118. data/lib/datadog/open_feature/ext.rb +12 -0
  119. data/lib/datadog/open_feature/flag_evaluation/aggregator.rb +10 -8
  120. data/lib/datadog/open_feature/flag_evaluation/writer.rb +9 -6
  121. data/lib/datadog/open_feature/hooks/exposure_logging_hook.rb +58 -0
  122. data/lib/datadog/open_feature/hooks/flag_eval_evp_hook.rb +4 -2
  123. data/lib/datadog/open_feature/hooks/flag_eval_metrics_hook.rb +3 -5
  124. data/lib/datadog/open_feature/hooks/span_enrichment_hook/codec.rb +3 -5
  125. data/lib/datadog/open_feature/native_evaluator.rb +30 -2
  126. data/lib/datadog/open_feature/noop_evaluator.rb +3 -1
  127. data/lib/datadog/open_feature/provider.rb +54 -4
  128. data/lib/datadog/open_feature/resolution_details.rb +1 -0
  129. data/lib/datadog/open_feature/split_features.rb +76 -0
  130. data/lib/datadog/opentelemetry/sdk/propagator.rb +5 -2
  131. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +28 -31
  132. data/lib/datadog/profiling/component.rb +31 -9
  133. data/lib/datadog/profiling/profiler.rb +6 -0
  134. data/lib/datadog/profiling/remote.rb +381 -0
  135. data/lib/datadog/profiling/worker_state.rb +65 -0
  136. data/lib/datadog/profiling.rb +1 -0
  137. data/lib/datadog/symbol_database/file_hash.rb +1 -3
  138. data/lib/datadog/tracing/component.rb +14 -16
  139. data/lib/datadog/tracing/configuration/settings.rb +2 -2
  140. data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +4 -6
  141. data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +4 -6
  142. data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +4 -6
  143. data/lib/datadog/tracing/contrib/action_cable/events.rb +3 -5
  144. data/lib/datadog/tracing/contrib/action_cable/patcher.rb +2 -4
  145. data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +5 -7
  146. data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +4 -6
  147. data/lib/datadog/tracing/contrib/action_mailer/events.rb +3 -5
  148. data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +2 -4
  149. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +2 -4
  150. data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -4
  151. data/lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb +2 -4
  152. data/lib/datadog/tracing/contrib/action_pack/action_dispatch/patcher.rb +2 -4
  153. data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -4
  154. data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +3 -5
  155. data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +3 -5
  156. data/lib/datadog/tracing/contrib/action_view/events.rb +3 -5
  157. data/lib/datadog/tracing/contrib/action_view/patcher.rb +3 -5
  158. data/lib/datadog/tracing/contrib/action_view/utils.rb +1 -3
  159. data/lib/datadog/tracing/contrib/active_job/events/discard.rb +3 -5
  160. data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +3 -5
  161. data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +3 -5
  162. data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +3 -5
  163. data/lib/datadog/tracing/contrib/active_job/events/perform.rb +3 -5
  164. data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +3 -5
  165. data/lib/datadog/tracing/contrib/active_job/events.rb +3 -5
  166. data/lib/datadog/tracing/contrib/active_job/patcher.rb +4 -6
  167. data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +4 -6
  168. data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +4 -6
  169. data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +3 -5
  170. data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +3 -5
  171. data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +4 -6
  172. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +3 -5
  173. data/lib/datadog/tracing/contrib/active_record/events.rb +3 -5
  174. data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -4
  175. data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +8 -10
  176. data/lib/datadog/tracing/contrib/active_support/cache/events.rb +3 -5
  177. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +5 -7
  178. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -6
  179. data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -4
  180. data/lib/datadog/tracing/contrib/analytics.rb +4 -6
  181. data/lib/datadog/tracing/contrib/aws/patcher.rb +5 -7
  182. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +5 -7
  183. data/lib/datadog/tracing/contrib/configuration/settings.rb +17 -0
  184. data/lib/datadog/tracing/contrib/dalli/patcher.rb +2 -4
  185. data/lib/datadog/tracing/contrib/dalli/quantize.rb +1 -3
  186. data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +4 -6
  187. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +3 -5
  188. data/lib/datadog/tracing/contrib/elasticsearch/quantize.rb +6 -8
  189. data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -4
  190. data/lib/datadog/tracing/contrib/excon/patcher.rb +3 -5
  191. data/lib/datadog/tracing/contrib/faraday/patcher.rb +4 -6
  192. data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -4
  193. data/lib/datadog/tracing/contrib/graphql/patcher.rb +4 -6
  194. data/lib/datadog/tracing/contrib/graphql/trace_patcher.rb +1 -3
  195. data/lib/datadog/tracing/contrib/graphql/tracing_patcher.rb +1 -3
  196. data/lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb +1 -3
  197. data/lib/datadog/tracing/contrib/grpc/patcher.rb +3 -5
  198. data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -4
  199. data/lib/datadog/tracing/contrib/http/patcher.rb +2 -4
  200. data/lib/datadog/tracing/contrib/httpclient/patcher.rb +2 -4
  201. data/lib/datadog/tracing/contrib/httprb/patcher.rb +2 -4
  202. data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +4 -6
  203. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +3 -5
  204. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +3 -5
  205. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +3 -5
  206. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/join_group.rb +2 -4
  207. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/leave_group.rb +2 -4
  208. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/sync_group.rb +2 -4
  209. data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +4 -6
  210. data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +4 -6
  211. data/lib/datadog/tracing/contrib/kafka/events.rb +3 -5
  212. data/lib/datadog/tracing/contrib/kafka/patcher.rb +4 -6
  213. data/lib/datadog/tracing/contrib/karafka/patcher.rb +2 -4
  214. data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -4
  215. data/lib/datadog/tracing/contrib/mongodb/parsers.rb +5 -7
  216. data/lib/datadog/tracing/contrib/mongodb/patcher.rb +3 -5
  217. data/lib/datadog/tracing/contrib/mysql2/patcher.rb +3 -5
  218. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +1 -3
  219. data/lib/datadog/tracing/contrib/opensearch/quantize.rb +5 -7
  220. data/lib/datadog/tracing/contrib/pg/patcher.rb +3 -5
  221. data/lib/datadog/tracing/contrib/presto/patcher.rb +1 -3
  222. data/lib/datadog/tracing/contrib/que/patcher.rb +2 -4
  223. data/lib/datadog/tracing/contrib/racecar/events/batch.rb +3 -5
  224. data/lib/datadog/tracing/contrib/racecar/events/consume.rb +3 -5
  225. data/lib/datadog/tracing/contrib/racecar/events/message.rb +3 -5
  226. data/lib/datadog/tracing/contrib/racecar/events.rb +3 -5
  227. data/lib/datadog/tracing/contrib/racecar/patcher.rb +2 -4
  228. data/lib/datadog/tracing/contrib/rack/patcher.rb +13 -19
  229. data/lib/datadog/tracing/contrib/rack/request_queue.rb +1 -3
  230. data/lib/datadog/tracing/contrib/rack/route_inference.rb +4 -6
  231. data/lib/datadog/tracing/contrib/rack/trace_proxy_middleware.rb +4 -6
  232. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -0
  233. data/lib/datadog/tracing/contrib/rails/ext.rb +2 -0
  234. data/lib/datadog/tracing/contrib/rails/framework.rb +6 -8
  235. data/lib/datadog/tracing/contrib/rails/log_injection.rb +1 -3
  236. data/lib/datadog/tracing/contrib/rails/patcher.rb +9 -11
  237. data/lib/datadog/tracing/contrib/rake/patcher.rb +3 -5
  238. data/lib/datadog/tracing/contrib/redis/patcher.rb +2 -4
  239. data/lib/datadog/tracing/contrib/redis/quantize.rb +7 -9
  240. data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -4
  241. data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -4
  242. data/lib/datadog/tracing/contrib/roda/patcher.rb +2 -4
  243. data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -4
  244. data/lib/datadog/tracing/contrib/sequel/patcher.rb +4 -6
  245. data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -4
  246. data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +7 -9
  247. data/lib/datadog/tracing/contrib/sinatra/env.rb +3 -5
  248. data/lib/datadog/tracing/contrib/sinatra/patcher.rb +5 -7
  249. data/lib/datadog/tracing/contrib/sneakers/patcher.rb +2 -4
  250. data/lib/datadog/tracing/contrib/stripe/patcher.rb +2 -4
  251. data/lib/datadog/tracing/contrib/stripe/request.rb +4 -6
  252. data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +1 -3
  253. data/lib/datadog/tracing/contrib/sucker_punch/instrumentation.rb +1 -3
  254. data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +3 -5
  255. data/lib/datadog/tracing/contrib/support.rb +1 -3
  256. data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +4 -0
  257. data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +2 -1
  258. data/lib/datadog/tracing/contrib/trilogy/patcher.rb +3 -5
  259. data/lib/datadog/tracing/contrib/utils/database.rb +1 -3
  260. data/lib/datadog/tracing/contrib/utils/quantization/hash_formatter.rb +8 -10
  261. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +11 -13
  262. data/lib/datadog/tracing/contrib/waterdrop/patcher.rb +3 -5
  263. data/lib/datadog/tracing/correlation.rb +3 -5
  264. data/lib/datadog/tracing/distributed/propagation.rb +2 -2
  265. data/lib/datadog/tracing/distributed/propagation_policy.rb +1 -3
  266. data/lib/datadog/tracing/distributed/trace_state/datadog.rb +5 -5
  267. data/lib/datadog/tracing/distributed/trace_state/open_telemetry.rb +2 -2
  268. data/lib/datadog/tracing/metadata/ext.rb +3 -9
  269. data/lib/datadog/tracing/remote.rb +1 -1
  270. data/lib/datadog/tracing/trace_operation.rb +11 -3
  271. data/lib/datadog/tracing/tracer.rb +9 -1
  272. data/lib/datadog/tracing/transport/http.rb +1 -3
  273. data/lib/datadog/tracing/transport/io.rb +2 -4
  274. data/lib/datadog/tracing/transport/traces.rb +1 -3
  275. data/lib/datadog/tracing/utils.rb +4 -6
  276. data/lib/datadog/version.rb +1 -1
  277. metadata +22 -6
@@ -70,26 +70,37 @@ module Datadog
70
70
  #
71
71
  # @api private
72
72
  class Instrumenter
73
- # Maximum number of capturing-probe snapshots admitted per second across the
74
- # whole process.
75
- GLOBAL_SNAPSHOT_RATE_LIMIT = 20
76
-
77
73
  # Maximum number of non-capturing probe emissions admitted per second across
78
74
  # the whole process.
79
75
  GLOBAL_LOG_RATE_LIMIT = 5000
80
76
 
81
- # Initializes the instrumenter.
77
+ # Canonical guardrails skip reason recorded for each correlation sampler
78
+ # drop decision.
79
+ # @return [Hash{Symbol => String}]
80
+ CORRELATION_DROP_SKIP_REASONS = {
81
+ own_rate_limit: GuardrailsTelemetry::Reason::RATE_LIMIT_PROBE,
82
+ global_budget: GuardrailsTelemetry::Reason::RATE_LIMIT_GLOBAL,
83
+ top_gate: GuardrailsTelemetry::Reason::RATE_LIMIT_GLOBAL,
84
+ trace_budget: GuardrailsTelemetry::Reason::RATE_LIMIT_TRACE_BUDGET,
85
+ }.freeze
86
+
87
+ # Initializes the instrumenter with its process-wide hard rate
88
+ # limiter and the coordination gate.
82
89
  #
83
- # @param settings [Datadog::Core::Configuration::Settings] tracer settings
84
- # @param serializer [Serializer] serializer for captured values
85
- # @param logger [DI::Logger] logger for instrumenter diagnostics
90
+ # @param settings [Datadog::Core::Configuration::Settings] active DI/core settings
91
+ # @param serializer [Datadog::DI::Serializer] serializes captured values into snapshots
92
+ # @param logger [Datadog::DI::Logger] DI logger used for diagnostic output
86
93
  # @param guardrails_telemetry [GuardrailsTelemetry] emitter for the canonical guardrail skip metrics
87
94
  # @param capture_expression_evaluator [CaptureExpressionEvaluator] evaluator for the probe's capture expressions
88
- # @param code_tracker [CodeTracker, nil] code tracker for line probe installation
89
- # @param telemetry [Datadog::Core::Telemetry::Component, nil] component instrumenter errors are reported through
95
+ # @param correlation_sampler [Datadog::DI::CorrelationSampler] coordinated
96
+ # sampling gate for capturing probes
97
+ # @param code_tracker [Datadog::DI::CodeTracker, nil] global code tracker, or nil when
98
+ # tracking is not active
99
+ # @param telemetry [Datadog::Core::Telemetry::Component, nil] telemetry sink, or nil
100
+ # when telemetry is disabled
90
101
  # @return [void]
91
102
  def initialize(settings, serializer, logger, guardrails_telemetry:, capture_expression_evaluator:,
92
- code_tracker: nil, telemetry: nil)
103
+ correlation_sampler:, code_tracker: nil, telemetry: nil)
93
104
  @settings = settings
94
105
  @serializer = serializer
95
106
  @logger = logger
@@ -97,8 +108,8 @@ module Datadog
97
108
  @guardrails_telemetry = guardrails_telemetry
98
109
  @capture_expression_evaluator = capture_expression_evaluator
99
110
  @code_tracker = code_tracker
100
- @global_snapshot_rate_limiter = Datadog::Core::TokenBucket.new(GLOBAL_SNAPSHOT_RATE_LIMIT)
101
111
  @global_log_rate_limiter = Datadog::Core::TokenBucket.new(GLOBAL_LOG_RATE_LIMIT)
112
+ @correlation_sampler = correlation_sampler
102
113
 
103
114
  @lock = Mutex.new
104
115
  end
@@ -114,6 +125,8 @@ module Datadog
114
125
  # @return [CaptureExpressionEvaluator]
115
126
  attr_reader :capture_expression_evaluator
116
127
  attr_reader :code_tracker
128
+ # @return [Datadog::DI::CorrelationSampler]
129
+ attr_reader :correlation_sampler
117
130
 
118
131
  # The code tracker is a global singleton created lazily by
119
132
  # DI.activate_tracking. When DI is enabled after boot via remote
@@ -121,23 +134,48 @@ module Datadog
121
134
  # Component#start! assigns the now-current tracker here.
122
135
  attr_writer :code_tracker
123
136
 
124
- # Process-wide snapshot rate limiter.
125
- # @return [Datadog::Core::TokenBucket]
126
- attr_reader :global_snapshot_rate_limiter
127
137
  # Process-wide log rate limiter.
128
138
  # @return [Datadog::Core::TokenBucket]
129
139
  attr_reader :global_log_rate_limiter
130
140
 
131
- # Returns the process-wide rate limiter for the probe.
141
+ # Decides whether a condition-evaluation-failure notification may
142
+ # emit, after the probe's own condition-error limiter admitted it. A
143
+ # capturing probe's notification inside an active trace takes the
144
+ # correlation sampler's coordinated decision, consuming the trace's
145
+ # per-trace budget; every other notification, one with no active
146
+ # trace or from a non-capturing probe, consumes one GLOBAL token.
147
+ # Denials record the canonical rate-limit skip metric. A gate error
148
+ # fails open; the probe's condition-error limiter is the remaining
149
+ # throttle.
132
150
  #
133
- # @param probe [Probe] the probe whose invocation is being rate limited
134
- # @return [Datadog::Core::TokenBucket] the shared limiter for the probe's category
135
- def probe_global_rate_limiter(probe)
136
- if probe.capturing?
137
- global_snapshot_rate_limiter
138
- else
139
- global_log_rate_limiter
151
+ # @param probe [Datadog::DI::Probe] the probe whose condition evaluation failed
152
+ # @return [Boolean] true when the notification may emit
153
+ def admit_condition_error_snapshot?(probe)
154
+ begin
155
+ trace = current_trace
156
+ if trace && probe.capturing?
157
+ admitted, drop_reason = correlation_sampler.emit_with_reason?(probe, trace)
158
+ else
159
+ admitted = correlation_sampler.admit_process_wide_snapshot?
160
+ drop_reason = :global_budget
161
+ end
162
+ rescue Exception => exc # standard:disable Lint/RescueException
163
+ reraise_per_policy(exc)
164
+
165
+ logger.debug { "[di-correlation] gate error, failing open to the probe's condition-error limiter: #{exc.class}: #{exc.message}" }
166
+ telemetry&.report(exc, description: "Error in DI correlation gate")
167
+ return true
140
168
  end
169
+
170
+ unless admitted
171
+ # A denial always carries its drop decision; Steep cannot infer
172
+ # the pairing between the returned tuple's elements.
173
+ # @type var drop_reason: Symbol
174
+ record_rate_limit_skip(CORRELATION_DROP_SKIP_REASONS.fetch(drop_reason), probe)
175
+ return false
176
+ end
177
+
178
+ true
141
179
  end
142
180
 
143
181
  # Emits the canonical rate-limit skip metric for a probe.
@@ -146,9 +184,9 @@ module Datadog
146
184
  # @param reason [String] a GuardrailsTelemetry::Reason constant for the rejecting limit
147
185
  # @return [void]
148
186
  def record_rate_limit_skip(reason, probe)
187
+ limit = rate_limit_skip_limit(reason)
149
188
  logger.trace do
150
- "di: #{probe.type} probe #{probe.id}: skipping due to " \
151
- "#{(reason == GuardrailsTelemetry::Reason::RATE_LIMIT_PROBE) ? "per-probe" : "global"} rate limit" \
189
+ "di: #{probe.type} probe #{probe.id}: skipping due to #{limit}" \
152
190
  " (#{reason})"
153
191
  end
154
192
  guardrails_telemetry.skipped(
@@ -158,6 +196,24 @@ module Datadog
158
196
  nil
159
197
  end
160
198
 
199
+ # Names the rejecting limit each rate-limit skip reason reports.
200
+ #
201
+ # @param reason [String] a GuardrailsTelemetry::Reason rate-limit constant
202
+ # @return [String] the limit the reason names
203
+ # @raise [ArgumentError] when the reason is no known rate-limit constant
204
+ private def rate_limit_skip_limit(reason)
205
+ case reason
206
+ when GuardrailsTelemetry::Reason::RATE_LIMIT_PROBE
207
+ "per-probe rate limit"
208
+ when GuardrailsTelemetry::Reason::RATE_LIMIT_GLOBAL
209
+ "global rate limit"
210
+ when GuardrailsTelemetry::Reason::RATE_LIMIT_TRACE_BUDGET
211
+ "per-trace snapshot budget"
212
+ else
213
+ raise ArgumentError, "Unknown rate limit skip reason: #{reason}"
214
+ end
215
+ end
216
+
161
217
  # This is a substitute for Thread::Backtrace::Location
162
218
  # which does not have a public constructor.
163
219
  # Used for the fabricated stack frame for the method itself
@@ -500,6 +556,124 @@ module Datadog
500
556
 
501
557
  attr_reader :lock
502
558
 
559
+ # Decides whether a probe hit is admitted for emission. A capturing
560
+ # hit delegates the whole decision to the correlation sampler, and
561
+ # every denial is recorded as the canonical rate-limit skip metric.
562
+ # A gate error fails open to the probe's own rate limiter. A
563
+ # non-capturing hit consults the probe's own rate limiter and then
564
+ # the process-wide log rate limiter.
565
+ #
566
+ # An admitted hit yields the active trace for the snapshot envelope:
567
+ # the gate's own resolution for a capturing hit, reused by the
568
+ # envelope capture, and a fresh resolution for a non-capturing hit or
569
+ # for a gate error that failed open.
570
+ #
571
+ # @param probe [Datadog::DI::Probe] the probe whose hit is being gated
572
+ # @yieldparam trace [Datadog::Tracing::TraceOperation, nil] the trace
573
+ # active when the hit was admitted
574
+ # @return [Boolean]
575
+ def emit?(probe)
576
+ if probe.capturing?
577
+ begin
578
+ trace = current_trace
579
+ admitted, drop_reason = correlation_sampler.emit_with_reason?(probe, trace)
580
+ rescue Exception => exc # standard:disable Lint/RescueException
581
+ reraise_per_policy(exc)
582
+
583
+ logger.debug { "[di-correlation] gate error, failing open to per-probe rate limit: #{exc.class}: #{exc.message}" }
584
+ telemetry&.report(exc, description: "Error in DI correlation gate")
585
+ unless probe.own_rate_limit_allows?
586
+ record_rate_limit_skip(GuardrailsTelemetry::Reason::RATE_LIMIT_PROBE, probe)
587
+ return false
588
+ end
589
+
590
+ yield(active_trace_at_admission) if block_given?
591
+ return true
592
+ end
593
+
594
+ unless admitted
595
+ # A denial always carries its drop decision; Steep cannot infer
596
+ # the pairing between the returned tuple's elements.
597
+ # @type var drop_reason: Symbol
598
+ record_rate_limit_skip(CORRELATION_DROP_SKIP_REASONS.fetch(drop_reason), probe)
599
+ return false
600
+ end
601
+
602
+ yield(trace) if block_given?
603
+ else
604
+ unless probe.own_rate_limit_allows?
605
+ record_rate_limit_skip(GuardrailsTelemetry::Reason::RATE_LIMIT_PROBE, probe)
606
+ return false
607
+ end
608
+
609
+ return false unless global_rate_limit_allows?(probe)
610
+
611
+ yield(active_trace_at_admission) if block_given?
612
+ end
613
+ true
614
+ end
615
+
616
+ # The active APM trace, or nil when no trace is active.
617
+ #
618
+ # @return [Datadog::Tracing::TraceOperation, nil]
619
+ def current_trace
620
+ Datadog::DI.active_trace
621
+ end
622
+
623
+ # Returns the trace active when the gate admitted a hit, for the
624
+ # snapshot envelope, or nil when resolution fails.
625
+ #
626
+ # @return [Datadog::Tracing::TraceOperation, nil]
627
+ def active_trace_at_admission
628
+ current_trace
629
+ rescue Exception => exc # standard:disable Lint/RescueException
630
+ reraise_per_policy(exc)
631
+
632
+ logger.debug { "[di-correlation] admission trace capture failed: #{exc.class}: #{exc.message}" }
633
+ nil
634
+ end
635
+
636
+ # Returns the span active when the gate admitted a hit, for the
637
+ # snapshot envelope, or nil when resolution fails.
638
+ #
639
+ # @return [Datadog::Tracing::SpanOperation, nil]
640
+ def active_span_at_admission
641
+ Datadog::DI.active_span
642
+ rescue Exception => exc # standard:disable Lint/RescueException
643
+ reraise_per_policy(exc)
644
+
645
+ logger.debug { "[di-correlation] admission span capture failed: #{exc.class}: #{exc.message}" }
646
+ nil
647
+ end
648
+
649
+ # Re-raises a gate error: fatal exceptions always, every exception
650
+ # when the customer opted into propagation. Called from rescue blocks
651
+ # only.
652
+ #
653
+ # @param exc [Exception] the in-flight exception
654
+ # @return [void]
655
+ def reraise_per_policy(exc)
656
+ Datadog::DI.reraise_if_fatal(exc)
657
+ raise exc if settings.dynamic_instrumentation.internal.propagate_all_exceptions
658
+ end
659
+
660
+ # Consults the process-wide hard rate limiter bounding non-capturing
661
+ # hits. Capturing hits draw their process-wide bound from the
662
+ # correlation sampler's GLOBAL budget, which traced and untraced
663
+ # traffic share; a hard cap at the same rate would drop the snapshots
664
+ # already admitted under a trace's GLOBAL deficit.
665
+ #
666
+ # @param probe [Datadog::DI::Probe] the probe whose hit is being gated
667
+ # @return [Boolean] true when the hard limiter admits the hit
668
+ def global_rate_limit_allows?(probe)
669
+ unless global_log_rate_limiter.allow?
670
+ record_rate_limit_skip(GuardrailsTelemetry::Reason::RATE_LIMIT_GLOBAL, probe)
671
+ return false
672
+ end
673
+
674
+ true
675
+ end
676
+
503
677
  # Body of the method probe wrapper. Extracted from the define_method
504
678
  # block in #hook_method so the begin/ensure structure can use normal
505
679
  # indentation. The original method is invoked with yield, calling the
@@ -539,6 +713,16 @@ module Datadog
539
713
  return yield unless probe.enabled?
540
714
 
541
715
  DI.enter_probe
716
+ # The trace is captured at admission, before the customer method
717
+ # runs: a method that finishes the active trace or starts a new one
718
+ # must not relabel the snapshot away from the trace whose budget the
719
+ # gate consumed, nor pair that trace with a span of the replacement
720
+ # trace. The gate passes its own resolution to the block, so an
721
+ # admitted capturing hit resolves the trace once. The declaration sits
722
+ # above the begin/ensure body: steep drops @type var annotations
723
+ # inside a body that has an ensure clause.
724
+ # @type var admission_trace: Datadog::Tracing::TraceOperation?
725
+ admission_trace = nil
542
726
  begin
543
727
  di_start_time = Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID)
544
728
 
@@ -594,16 +778,8 @@ module Datadog
594
778
  end
595
779
  end
596
780
 
597
- rate_limiter = probe.rate_limiter
598
- admitted = continue
599
- if continue && rate_limiter && !rate_limiter.allow?
600
- admitted = false
601
- record_rate_limit_skip(GuardrailsTelemetry::Reason::RATE_LIMIT_PROBE, probe)
602
- end
603
- if admitted && !probe_global_rate_limiter(probe).allow?
604
- admitted = false
605
- record_rate_limit_skip(GuardrailsTelemetry::Reason::RATE_LIMIT_GLOBAL, probe)
606
- end
781
+ admitted = continue && emit?(probe) { |trace| admission_trace = trace }
782
+ admission_span = active_span_at_admission if admitted
607
783
  if admitted
608
784
  # Arguments may be mutated by the method, therefore
609
785
  # they need to be serialized prior to method invocation.
@@ -703,6 +879,8 @@ module Datadog
703
879
  entry_capture_expressions: entry_capture_expressions,
704
880
  entry_capture_evaluation_errors: entry_capture_evaluation_errors,
705
881
  caller_locations: caller_locs,
882
+ admission_trace: admission_trace,
883
+ admission_span: admission_span,
706
884
  return_value: rv, duration: duration, exception: exc)
707
885
 
708
886
  begin
@@ -794,8 +972,8 @@ module Datadog
794
972
  end
795
973
 
796
974
  # Trace point callback for a line probe hit. Evaluates the probe's
797
- # condition, applies the per-probe rate limiter and the global rate
798
- # limiter, then invokes the responder with the built context.
975
+ # condition, applies the emission admission gate, then invokes the
976
+ # responder with the built context.
799
977
  #
800
978
  # @param probe [Probe] the probe the trace point was installed for.
801
979
  # @param iseq [RubyVM::InstructionSequence, nil] instruction sequence of
@@ -821,90 +999,97 @@ module Datadog
821
999
  )
822
1000
  end
823
1001
 
824
- # We set the trace point on :return to be able to instrument
825
- # 'end' lines. This also causes the trace point to be invoked on
826
- # non-'end' lines when a line raises an exception, since the
827
- # exception causes the method to stop executing and stack unwends.
828
- # We do not want two invocations of the trace point.
829
- # Therefore, if a trace point is invoked with a :line event,
830
- # mark it as such and ignore subsequent :return events.
831
- if probe.executed_on_line?
832
- return unless tp.event == :line
833
- else
834
- _ = 42 # stop standard from changing this code
1002
+ # Re-entrancy guard, mirroring the method-probe wrapper: the
1003
+ # processing below dispatches interceptable stdlib methods
1004
+ # (Kernel#send, Mutex#synchronize, WeakRef methods), and a nested
1005
+ # method-probe firing during this callback must short-circuit
1006
+ # instead of consuming rate-limit tokens and snapshotting
1007
+ # DI-internal arguments. The prior guard state is restored so a
1008
+ # hit nested inside other DI processing does not clear the outer
1009
+ # guard. The guard starts after the untargeted match check above:
1010
+ # an untargeted trace point invokes this callback for every line
1011
+ # executed in the process, so the unmatched-line return would
1012
+ # otherwise run the fiber-local guard round trip on each of them.
1013
+ was_in_probe = DI.in_probe?
1014
+ DI.enter_probe unless was_in_probe
1015
+ begin
1016
+ # We set the trace point on :return to be able to instrument
1017
+ # 'end' lines. This also causes the trace point to be invoked on
1018
+ # non-'end' lines when a line raises an exception, since the
1019
+ # exception causes the method to stop executing and stack unwends.
1020
+ # We do not want two invocations of the trace point.
1021
+ # Therefore, if a trace point is invoked with a :line event,
1022
+ # mark it as such and ignore subsequent :return events.
1023
+ if probe.executed_on_line?
1024
+ return unless tp.event == :line
1025
+ else
1026
+ _ = 42 # stop standard from changing this code
835
1027
 
836
- if tp.event == :line
837
- probe.executed_on_line!
1028
+ if tp.event == :line
1029
+ probe.executed_on_line!
1030
+ end
838
1031
  end
839
- end
840
1032
 
841
- if condition = probe.condition
842
- begin
843
- context = build_trace_point_context(probe, tp)
844
- return unless condition.satisfied?(context,
845
- evaluation_deadline: serializer.evaluation_deadline)
846
- rescue Exception => exc # standard:disable Lint/RescueException
847
- Datadog::DI.reraise_if_fatal(exc)
848
- # Evaluation error exception can be raised for "expected"
849
- # errors, we probably need another setting to control whether
850
- # these exceptions are propagated.
851
- raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions &&
852
- !exc.is_a?(DI::Error::ExpressionEvaluationError)
853
-
854
- # An evaluation timeout is an internal budget abort, so it
855
- # stays contained even under propagate_all_exceptions.
856
- record_condition_evaluation_timeout(probe, exc)
857
-
858
- if context
859
- # We want to report evaluation errors for conditions
860
- # as probe snapshots. However, if we failed to create
861
- # the context, we won't be able to report anything as
862
- # the probe notifier builder requires a context.
863
- begin
864
- responder.probe_condition_evaluation_failed_callback(context, condition, exc)
865
- rescue Exception => nested_exc # standard:disable Lint/RescueException
866
- Datadog::DI.reraise_if_fatal(nested_exc)
867
- raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions
1033
+ if condition = probe.condition
1034
+ begin
1035
+ context = build_trace_point_context(probe, tp)
1036
+ return unless condition.satisfied?(context,
1037
+ evaluation_deadline: serializer.evaluation_deadline)
1038
+ rescue Exception => exc # standard:disable Lint/RescueException
1039
+ Datadog::DI.reraise_if_fatal(exc)
1040
+ # Evaluation error exception can be raised for "expected"
1041
+ # errors, we probably need another setting to control whether
1042
+ # these exceptions are propagated.
1043
+ raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions &&
1044
+ !exc.is_a?(DI::Error::ExpressionEvaluationError)
868
1045
 
869
- logger.debug { "di: error in probe condition evaluation failed callback: #{nested_exc.class}: #{nested_exc.message}" }
870
- telemetry&.report(nested_exc, description: "Error in probe condition evaluation failed callback")
871
- end
1046
+ # An evaluation timeout is an internal budget abort, so it
1047
+ # stays contained even under propagate_all_exceptions.
1048
+ record_condition_evaluation_timeout(probe, exc)
872
1049
 
873
- return
874
- else
875
- _ = 42 # stop standard from wrecking this code
1050
+ if context
1051
+ # We want to report evaluation errors for conditions
1052
+ # as probe snapshots. However, if we failed to create
1053
+ # the context, we won't be able to report anything as
1054
+ # the probe notifier builder requires a context.
1055
+ begin
1056
+ responder.probe_condition_evaluation_failed_callback(context, condition, exc)
1057
+ rescue Exception => nested_exc # standard:disable Lint/RescueException
1058
+ Datadog::DI.reraise_if_fatal(nested_exc)
1059
+ raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions
876
1060
 
877
- raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions
1061
+ logger.debug { "di: error in probe condition evaluation failed callback: #{nested_exc.class}: #{nested_exc.message}" }
1062
+ telemetry&.report(nested_exc, description: "Error in probe condition evaluation failed callback")
1063
+ end
1064
+
1065
+ return
1066
+ else
1067
+ _ = 42 # stop standard from wrecking this code
878
1068
 
879
- logger.debug { "di: error evaluating condition without context (tracer bug?): #{exc.class}: #{exc.message}" }
880
- telemetry&.report(exc, description: "Error evaluating condition without context")
881
- # If execution gets here, there is probably a bug in the tracer.
1069
+ raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions
1070
+
1071
+ logger.debug { "di: error evaluating condition without context (tracer bug?): #{exc.class}: #{exc.message}" }
1072
+ telemetry&.report(exc, description: "Error evaluating condition without context")
1073
+ # If execution gets here, there is probably a bug in the tracer.
1074
+ end
882
1075
  end
883
1076
  end
884
- end
885
1077
 
886
- # In practice we should always have a rate limiter, but be safe
887
- # and check that it is in fact set.
888
- if probe.rate_limiter && !probe.rate_limiter.allow?
889
- record_rate_limit_skip(GuardrailsTelemetry::Reason::RATE_LIMIT_PROBE, probe)
890
- return
891
- end
1078
+ return unless emit?(probe)
892
1079
 
893
- unless probe_global_rate_limiter(probe).allow?
894
- record_rate_limit_skip(GuardrailsTelemetry::Reason::RATE_LIMIT_GLOBAL, probe)
895
- return
896
- end
1080
+ # The context creation is relatively expensive and we don't
1081
+ # want to run it if the callback won't be executed due to the
1082
+ # rate limit.
1083
+ # Thus the copy-paste of the creation call here.
1084
+ context ||= build_trace_point_context(probe, tp)
897
1085
 
898
- # The context creation is relatively expensive and we don't
899
- # want to run it if the callback won't be executed due to the
900
- # rate limit.
901
- # Thus the copy-paste of the creation call here.
902
- context ||= build_trace_point_context(probe, tp)
1086
+ responder.probe_executed_callback(context)
903
1087
 
904
- responder.probe_executed_callback(context)
905
-
906
- check_and_disable_if_exceeded(probe, responder, di_start_time)
907
- nil
1088
+ check_and_disable_if_exceeded(probe, responder, di_start_time)
1089
+ nil
1090
+ ensure
1091
+ DI.leave_probe unless was_in_probe
1092
+ end
908
1093
  rescue Exception => exc # standard:disable Lint/RescueException
909
1094
  Datadog::DI.reraise_if_fatal(exc)
910
1095
  raise if settings.dynamic_instrumentation.internal.propagate_all_exceptions
@@ -978,7 +1163,7 @@ module Datadog
978
1163
  else
979
1164
  # Expensive suffix check.
980
1165
  suffix = Utils.normalize_windows_separators(probe.file)
981
- found = nil #: ::String?
1166
+ found = nil #: String?
982
1167
  [false, true].each do |case_insensitive|
983
1168
  working_suffix = suffix.dup
984
1169
  loop do
@@ -143,6 +143,8 @@ module Datadog
143
143
  attr_reader :evaluate_at
144
144
 
145
145
  # Rate limit in effect, in invocations per second. Always present.
146
+ #
147
+ # @return [Integer]
146
148
  attr_reader :rate_limit
147
149
 
148
150
  # Rate limiter object. For internal DI use only.
@@ -158,6 +160,15 @@ module Datadog
158
160
  # probe rate limit for the errors).
159
161
  attr_reader :condition_evaluation_failed_rate_limiter
160
162
 
163
+ # Consumes one token from the probe's own rate limiter and reports
164
+ # whether this probe hit is admitted; a probe with no rate limiter is
165
+ # admitted.
166
+ #
167
+ # @return [Boolean]
168
+ def own_rate_limit_allows?
169
+ rate_limiter.nil? || rate_limiter.allow?
170
+ end
171
+
161
172
  def capture_snapshot?
162
173
  @capture_snapshot
163
174
  end
@@ -166,8 +177,8 @@ module Datadog
166
177
  !@capture_expressions.empty?
167
178
  end
168
179
 
169
- # Whether this probe captures user data, either as a full snapshot
170
- # or via capture expressions.
180
+ # Whether the probe captures data: a full snapshot, or at least one
181
+ # capture expression.
171
182
  #
172
183
  # @return [Boolean]
173
184
  def capturing?
@@ -27,8 +27,6 @@ module Datadog
27
27
  "LOG_PROBE" => :log,
28
28
  }.freeze
29
29
 
30
- module_function
31
-
32
30
  CAPTURE_EXPRESSION_NAME_PATTERN = /\A[a-zA-Z0-9_?]+\z/
33
31
 
34
32
  EVALUATE_AT_STRINGS = {
@@ -37,7 +35,7 @@ module Datadog
37
35
  "DEFAULT" => :exit,
38
36
  }.freeze
39
37
 
40
- def build_from_remote_config(config, logger:)
38
+ def self.build_from_remote_config(config, logger:)
41
39
  # The validations here are not yet comprehensive.
42
40
  type = config.fetch("type")
43
41
  type_symbol = PROBE_TYPES[type] or raise ArgumentError, "Unrecognized probe type: #{type}"
@@ -82,7 +80,7 @@ module Datadog
82
80
  raise ArgumentError, "Malformed remote configuration entry for probe: #{exc.class}: #{exc.message}: #{config}"
83
81
  end
84
82
 
85
- def build_capture_expressions(raw)
83
+ def self.build_capture_expressions(raw)
86
84
  return [] if raw.nil?
87
85
  unless Array === raw
88
86
  raise ArgumentError, "captureExpressions must be an array, got: #{raw.class}"
@@ -107,7 +105,7 @@ module Datadog
107
105
  end
108
106
  end
109
107
 
110
- def dedup_capture_expressions(capture_expressions, probe_id, logger)
108
+ def self.dedup_capture_expressions(capture_expressions, probe_id, logger)
111
109
  return capture_expressions if capture_expressions.size < 2
112
110
  by_name = {}
113
111
  capture_expressions.each do |capture_expression|
@@ -120,7 +118,7 @@ module Datadog
120
118
  by_name.values
121
119
  end
122
120
 
123
- def build_capture_limits(raw)
121
+ def self.build_capture_limits(raw)
124
122
  return nil if raw.nil?
125
123
  unless Hash === raw
126
124
  raise ArgumentError, "capture-expression entry capture must be a hash, got: #{raw.class}"
@@ -133,7 +131,7 @@ module Datadog
133
131
  )
134
132
  end
135
133
 
136
- def parse_evaluate_at(raw, probe_id, logger)
134
+ def self.parse_evaluate_at(raw, probe_id, logger)
137
135
  return :exit if raw.nil?
138
136
  EVALUATE_AT_STRINGS[raw] || begin
139
137
  logger.debug do
@@ -143,7 +141,7 @@ module Datadog
143
141
  end
144
142
  end
145
143
 
146
- def build_template_segments(segments)
144
+ def self.build_template_segments(segments)
147
145
  segments&.map do |segment|
148
146
  if Hash === segment
149
147
  if str = segment["str"]
@@ -7,7 +7,7 @@ require_relative "fatal_exceptions"
7
7
  module Datadog
8
8
  module DI
9
9
  module ProbeFileLoader
10
- module_function def load_now_or_later
10
+ def self.load_now_or_later
11
11
  if Datadog::Core::Contrib::Rails::Utils.railtie_supported?
12
12
  Datadog.logger.debug("di: loading probe_file_loader/railtie")
13
13
  require_relative "probe_file_loader/railtie"
@@ -19,7 +19,7 @@ module Datadog
19
19
  # This method can be called more than once, to attempt to load
20
20
  # DI components that depend on third-party libraries after additional
21
21
  # dependencies are loaded (or potentially loaded).
22
- module_function def load_now
22
+ def self.load_now
23
23
  should_propagate = false
24
24
 
25
25
  probe_file_path = DATADOG_ENV["DD_DYNAMIC_INSTRUMENTATION_PROBE_FILE"]