datadog 2.22.0 → 2.26.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 (245) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +140 -1
  3. data/ext/LIBDATADOG_DEVELOPMENT.md +1 -58
  4. data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +93 -23
  5. data/ext/datadog_profiling_native_extension/collectors_stack.c +21 -5
  6. data/ext/datadog_profiling_native_extension/crashtracking_runtime_stacks.c +239 -0
  7. data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +1 -1
  8. data/ext/datadog_profiling_native_extension/extconf.rb +9 -4
  9. data/ext/datadog_profiling_native_extension/heap_recorder.c +1 -1
  10. data/ext/datadog_profiling_native_extension/http_transport.c +1 -0
  11. data/ext/datadog_profiling_native_extension/private_vm_api_access.c +12 -0
  12. data/ext/datadog_profiling_native_extension/private_vm_api_access.h +4 -0
  13. data/ext/datadog_profiling_native_extension/profiling.c +2 -0
  14. data/ext/libdatadog_api/datadog_ruby_common.h +1 -1
  15. data/ext/libdatadog_api/feature_flags.c +554 -0
  16. data/ext/libdatadog_api/feature_flags.h +5 -0
  17. data/ext/libdatadog_api/init.c +2 -0
  18. data/ext/libdatadog_api/library_config.c +12 -11
  19. data/ext/libdatadog_extconf_helpers.rb +1 -1
  20. data/lib/datadog/ai_guard/api_client.rb +82 -0
  21. data/lib/datadog/ai_guard/component.rb +42 -0
  22. data/lib/datadog/ai_guard/configuration/ext.rb +17 -0
  23. data/lib/datadog/ai_guard/configuration/settings.rb +98 -0
  24. data/lib/datadog/ai_guard/configuration.rb +11 -0
  25. data/lib/datadog/ai_guard/evaluation/message.rb +25 -0
  26. data/lib/datadog/ai_guard/evaluation/no_op_result.rb +34 -0
  27. data/lib/datadog/ai_guard/evaluation/request.rb +81 -0
  28. data/lib/datadog/ai_guard/evaluation/result.rb +43 -0
  29. data/lib/datadog/ai_guard/evaluation/tool_call.rb +18 -0
  30. data/lib/datadog/ai_guard/evaluation.rb +72 -0
  31. data/lib/datadog/ai_guard/ext.rb +16 -0
  32. data/lib/datadog/ai_guard.rb +153 -0
  33. data/lib/datadog/appsec/api_security/route_extractor.rb +23 -6
  34. data/lib/datadog/appsec/api_security/sampler.rb +7 -4
  35. data/lib/datadog/appsec/assets/blocked.html +8 -0
  36. data/lib/datadog/appsec/assets/blocked.json +1 -1
  37. data/lib/datadog/appsec/assets/blocked.text +3 -1
  38. data/lib/datadog/appsec/assets.rb +1 -1
  39. data/lib/datadog/appsec/context.rb +2 -1
  40. data/lib/datadog/appsec/remote.rb +9 -12
  41. data/lib/datadog/appsec/response.rb +18 -4
  42. data/lib/datadog/appsec/security_engine/engine.rb +3 -3
  43. data/lib/datadog/appsec/security_engine/result.rb +2 -1
  44. data/lib/datadog/appsec/security_engine/runner.rb +2 -2
  45. data/lib/datadog/core/configuration/components.rb +37 -3
  46. data/lib/datadog/core/configuration/config_helper.rb +2 -2
  47. data/lib/datadog/core/configuration/deprecations.rb +2 -2
  48. data/lib/datadog/core/configuration/option_definition.rb +4 -2
  49. data/lib/datadog/core/configuration/options.rb +8 -5
  50. data/lib/datadog/core/configuration/settings.rb +28 -3
  51. data/lib/datadog/core/configuration/supported_configurations.rb +338 -302
  52. data/lib/datadog/core/ddsketch.rb +0 -2
  53. data/lib/datadog/core/environment/cgroup.rb +52 -25
  54. data/lib/datadog/core/environment/container.rb +140 -46
  55. data/lib/datadog/core/environment/ext.rb +7 -0
  56. data/lib/datadog/core/environment/process.rb +87 -0
  57. data/lib/datadog/core/error.rb +6 -6
  58. data/lib/datadog/core/feature_flags.rb +61 -0
  59. data/lib/datadog/core/pin.rb +4 -0
  60. data/lib/datadog/core/rate_limiter.rb +9 -1
  61. data/lib/datadog/core/remote/client/capabilities.rb +7 -0
  62. data/lib/datadog/core/remote/client.rb +14 -6
  63. data/lib/datadog/core/remote/component.rb +6 -4
  64. data/lib/datadog/core/remote/configuration/content.rb +15 -2
  65. data/lib/datadog/core/remote/configuration/digest.rb +14 -7
  66. data/lib/datadog/core/remote/configuration/repository.rb +1 -1
  67. data/lib/datadog/core/remote/configuration/target.rb +13 -6
  68. data/lib/datadog/core/remote/transport/config.rb +4 -25
  69. data/lib/datadog/core/remote/transport/http/config.rb +10 -50
  70. data/lib/datadog/core/remote/transport/http/negotiation.rb +14 -44
  71. data/lib/datadog/core/remote/transport/http.rb +15 -24
  72. data/lib/datadog/core/remote/transport/negotiation.rb +8 -33
  73. data/lib/datadog/core/remote/worker.rb +25 -37
  74. data/lib/datadog/core/runtime/metrics.rb +11 -1
  75. data/lib/datadog/core/semaphore.rb +1 -4
  76. data/lib/datadog/core/tag_builder.rb +0 -4
  77. data/lib/datadog/core/tag_normalizer.rb +84 -0
  78. data/lib/datadog/core/telemetry/component.rb +59 -16
  79. data/lib/datadog/core/telemetry/event/app_started.rb +88 -50
  80. data/lib/datadog/core/telemetry/event/synth_app_client_configuration_change.rb +27 -4
  81. data/lib/datadog/core/telemetry/logger.rb +2 -2
  82. data/lib/datadog/core/telemetry/logging.rb +2 -8
  83. data/lib/datadog/core/telemetry/metrics_manager.rb +9 -0
  84. data/lib/datadog/core/telemetry/request.rb +17 -3
  85. data/lib/datadog/core/telemetry/transport/http/telemetry.rb +3 -34
  86. data/lib/datadog/core/telemetry/transport/http.rb +21 -16
  87. data/lib/datadog/core/telemetry/transport/telemetry.rb +3 -11
  88. data/lib/datadog/core/telemetry/worker.rb +88 -32
  89. data/lib/datadog/core/transport/ext.rb +2 -0
  90. data/lib/datadog/core/transport/http/api/endpoint.rb +9 -4
  91. data/lib/datadog/core/transport/http/api/instance.rb +4 -21
  92. data/lib/datadog/core/transport/http/builder.rb +9 -5
  93. data/lib/datadog/core/transport/http/client.rb +80 -0
  94. data/lib/datadog/core/transport/http.rb +22 -19
  95. data/lib/datadog/core/transport/response.rb +12 -1
  96. data/lib/datadog/core/transport/transport.rb +90 -0
  97. data/lib/datadog/core/utils/array.rb +29 -0
  98. data/lib/datadog/{appsec/api_security → core/utils}/lru_cache.rb +10 -21
  99. data/lib/datadog/core/utils/network.rb +3 -1
  100. data/lib/datadog/core/utils/only_once_successful.rb +8 -2
  101. data/lib/datadog/core/utils/safe_dup.rb +2 -2
  102. data/lib/datadog/core/utils/sequence.rb +2 -0
  103. data/lib/datadog/core/utils/time.rb +1 -1
  104. data/lib/datadog/core/utils.rb +2 -0
  105. data/lib/datadog/core/workers/async.rb +10 -1
  106. data/lib/datadog/core/workers/interval_loop.rb +44 -3
  107. data/lib/datadog/core/workers/polling.rb +2 -0
  108. data/lib/datadog/core/workers/queue.rb +100 -1
  109. data/lib/datadog/data_streams/configuration/settings.rb +49 -0
  110. data/lib/datadog/data_streams/configuration.rb +11 -0
  111. data/lib/datadog/data_streams/ext.rb +11 -0
  112. data/lib/datadog/data_streams/extensions.rb +16 -0
  113. data/lib/datadog/data_streams/pathway_context.rb +169 -0
  114. data/lib/datadog/data_streams/processor.rb +509 -0
  115. data/lib/datadog/data_streams/transport/http/stats.rb +52 -0
  116. data/lib/datadog/data_streams/transport/http.rb +40 -0
  117. data/lib/datadog/data_streams/transport/stats.rb +46 -0
  118. data/lib/datadog/data_streams.rb +100 -0
  119. data/lib/datadog/di/boot.rb +4 -2
  120. data/lib/datadog/di/component.rb +0 -16
  121. data/lib/datadog/di/contrib/active_record.rb +30 -5
  122. data/lib/datadog/di/el/compiler.rb +8 -4
  123. data/lib/datadog/di/el/evaluator.rb +1 -1
  124. data/lib/datadog/di/error.rb +9 -0
  125. data/lib/datadog/di/instrumenter.rb +102 -37
  126. data/lib/datadog/di/logger.rb +2 -2
  127. data/lib/datadog/di/probe.rb +20 -0
  128. data/lib/datadog/di/probe_builder.rb +2 -1
  129. data/lib/datadog/di/probe_file_loader/railtie.rb +1 -1
  130. data/lib/datadog/di/probe_manager.rb +47 -33
  131. data/lib/datadog/di/probe_notification_builder.rb +77 -25
  132. data/lib/datadog/di/probe_notifier_worker.rb +5 -5
  133. data/lib/datadog/di/proc_responder.rb +32 -0
  134. data/lib/datadog/di/remote.rb +89 -84
  135. data/lib/datadog/di/transport/diagnostics.rb +8 -36
  136. data/lib/datadog/di/transport/http/diagnostics.rb +1 -33
  137. data/lib/datadog/di/transport/http/input.rb +1 -33
  138. data/lib/datadog/di/transport/http.rb +32 -17
  139. data/lib/datadog/di/transport/input.rb +67 -34
  140. data/lib/datadog/di.rb +61 -5
  141. data/lib/datadog/error_tracking/filters.rb +2 -2
  142. data/lib/datadog/kit/appsec/events/v2.rb +2 -3
  143. data/lib/datadog/open_feature/component.rb +60 -0
  144. data/lib/datadog/open_feature/configuration.rb +27 -0
  145. data/lib/datadog/open_feature/evaluation_engine.rb +70 -0
  146. data/lib/datadog/open_feature/exposures/batch_builder.rb +32 -0
  147. data/lib/datadog/open_feature/exposures/buffer.rb +43 -0
  148. data/lib/datadog/open_feature/exposures/deduplicator.rb +30 -0
  149. data/lib/datadog/open_feature/exposures/event.rb +60 -0
  150. data/lib/datadog/open_feature/exposures/reporter.rb +40 -0
  151. data/lib/datadog/open_feature/exposures/worker.rb +116 -0
  152. data/lib/datadog/open_feature/ext.rb +14 -0
  153. data/lib/datadog/open_feature/native_evaluator.rb +38 -0
  154. data/lib/datadog/open_feature/noop_evaluator.rb +26 -0
  155. data/lib/datadog/open_feature/provider.rb +141 -0
  156. data/lib/datadog/open_feature/remote.rb +67 -0
  157. data/lib/datadog/open_feature/resolution_details.rb +35 -0
  158. data/lib/datadog/open_feature/transport.rb +70 -0
  159. data/lib/datadog/open_feature.rb +19 -0
  160. data/lib/datadog/opentelemetry/api/baggage.rb +1 -1
  161. data/lib/datadog/opentelemetry/configuration/settings.rb +159 -0
  162. data/lib/datadog/opentelemetry/metrics.rb +117 -0
  163. data/lib/datadog/opentelemetry/sdk/configurator.rb +25 -1
  164. data/lib/datadog/opentelemetry/sdk/metrics_exporter.rb +35 -0
  165. data/lib/datadog/opentelemetry.rb +3 -0
  166. data/lib/datadog/profiling/collectors/code_provenance.rb +41 -7
  167. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +3 -2
  168. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  169. data/lib/datadog/profiling/collectors/info.rb +5 -4
  170. data/lib/datadog/profiling/component.rb +12 -11
  171. data/lib/datadog/profiling/ext/dir_monkey_patches.rb +18 -0
  172. data/lib/datadog/profiling/http_transport.rb +4 -1
  173. data/lib/datadog/profiling/profiler.rb +4 -0
  174. data/lib/datadog/profiling/tag_builder.rb +36 -3
  175. data/lib/datadog/profiling.rb +1 -2
  176. data/lib/datadog/single_step_instrument.rb +1 -1
  177. data/lib/datadog/tracing/configuration/ext.rb +9 -0
  178. data/lib/datadog/tracing/configuration/settings.rb +74 -0
  179. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +4 -4
  180. data/lib/datadog/tracing/contrib/action_pack/utils.rb +1 -2
  181. data/lib/datadog/tracing/contrib/active_job/log_injection.rb +21 -7
  182. data/lib/datadog/tracing/contrib/active_job/patcher.rb +5 -1
  183. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +4 -2
  184. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +4 -1
  185. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +11 -3
  186. data/lib/datadog/tracing/contrib/extensions.rb +10 -2
  187. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +11 -7
  188. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +7 -3
  189. data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +22 -17
  190. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +11 -3
  191. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +11 -3
  192. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +11 -3
  193. data/lib/datadog/tracing/contrib/kafka/instrumentation/consumer.rb +66 -0
  194. data/lib/datadog/tracing/contrib/kafka/instrumentation/producer.rb +66 -0
  195. data/lib/datadog/tracing/contrib/kafka/patcher.rb +14 -0
  196. data/lib/datadog/tracing/contrib/karafka/framework.rb +30 -0
  197. data/lib/datadog/tracing/contrib/karafka/monitor.rb +11 -0
  198. data/lib/datadog/tracing/contrib/karafka/patcher.rb +35 -4
  199. data/lib/datadog/tracing/contrib/rack/middlewares.rb +59 -27
  200. data/lib/datadog/tracing/contrib/rack/route_inference.rb +53 -0
  201. data/lib/datadog/tracing/contrib/rails/middlewares.rb +2 -2
  202. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +4 -1
  203. data/lib/datadog/tracing/contrib/roda/instrumentation.rb +3 -1
  204. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +3 -1
  205. data/lib/datadog/tracing/contrib/status_range_matcher.rb +9 -1
  206. data/lib/datadog/tracing/contrib/utils/quantization/hash.rb +3 -1
  207. data/lib/datadog/tracing/contrib/waterdrop/configuration/settings.rb +27 -0
  208. data/lib/datadog/tracing/contrib/waterdrop/distributed/propagation.rb +48 -0
  209. data/lib/datadog/tracing/contrib/waterdrop/ext.rb +17 -0
  210. data/lib/datadog/tracing/contrib/waterdrop/integration.rb +43 -0
  211. data/lib/datadog/tracing/contrib/waterdrop/middleware.rb +46 -0
  212. data/lib/datadog/tracing/contrib/waterdrop/patcher.rb +49 -0
  213. data/lib/datadog/tracing/contrib/waterdrop/producer.rb +50 -0
  214. data/lib/datadog/tracing/contrib/waterdrop.rb +41 -0
  215. data/lib/datadog/tracing/contrib.rb +1 -0
  216. data/lib/datadog/tracing/diagnostics/environment_logger.rb +1 -1
  217. data/lib/datadog/tracing/distributed/baggage.rb +3 -2
  218. data/lib/datadog/tracing/metadata/ext.rb +1 -1
  219. data/lib/datadog/tracing/remote.rb +1 -9
  220. data/lib/datadog/tracing/sampling/priority_sampler.rb +3 -1
  221. data/lib/datadog/tracing/span.rb +1 -1
  222. data/lib/datadog/tracing/span_event.rb +2 -2
  223. data/lib/datadog/tracing/span_operation.rb +20 -9
  224. data/lib/datadog/tracing/trace_operation.rb +44 -6
  225. data/lib/datadog/tracing/tracer.rb +42 -16
  226. data/lib/datadog/tracing/transport/http/client.rb +12 -26
  227. data/lib/datadog/tracing/transport/http/traces.rb +2 -50
  228. data/lib/datadog/tracing/transport/http.rb +15 -9
  229. data/lib/datadog/tracing/transport/io/client.rb +1 -1
  230. data/lib/datadog/tracing/transport/trace_formatter.rb +11 -0
  231. data/lib/datadog/tracing/transport/traces.rb +9 -71
  232. data/lib/datadog/tracing/workers/trace_writer.rb +5 -0
  233. data/lib/datadog/tracing/writer.rb +1 -0
  234. data/lib/datadog/version.rb +2 -2
  235. data/lib/datadog.rb +3 -0
  236. metadata +93 -23
  237. data/lib/datadog/core/remote/transport/http/api.rb +0 -53
  238. data/lib/datadog/core/remote/transport/http/client.rb +0 -49
  239. data/lib/datadog/core/telemetry/transport/http/api.rb +0 -43
  240. data/lib/datadog/core/telemetry/transport/http/client.rb +0 -49
  241. data/lib/datadog/core/transport/http/api/spec.rb +0 -36
  242. data/lib/datadog/di/transport/http/api.rb +0 -42
  243. data/lib/datadog/di/transport/http/client.rb +0 -47
  244. data/lib/datadog/opentelemetry/api/baggage.rbs +0 -26
  245. data/lib/datadog/tracing/transport/http/api.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 495f03c8c90a6786ec765ac781553fe5197d9511586a41964382b73bb69ccca9
4
- data.tar.gz: 81c46a4063b395a010ad1a028289b74c2d55bdaa6dff36ce61085d066a9b1a19
3
+ metadata.gz: cbf89a9582401ec9fcab36ed1c165ccd447e286085668c768c4df83b5dd27d81
4
+ data.tar.gz: 0c915a22c6ba56f7d39cd03a278466100e72769ac013bb26e9bd2204b4f280ee
5
5
  SHA512:
6
- metadata.gz: 2d4ab14bf55177e33f186c762b5156dd8cb8c17471c6277e1e0d1bce444212c98d221e00a2150fb3358203c898bb40fe431e9ebca0ef8fd22feec80758f8e922
7
- data.tar.gz: 505dd3f5f5a08a18a95aef5cb7ae979c63bee58b22d36b8d77b21b0b5998ef775ec8c437895633355664a5ac0c31a9c2624b73ef08b63fa4154712508411b172
6
+ metadata.gz: 1d2fefe85cab7cff7273196e57638a62da64b6ab0f84b0a350266b0adbc64ae57249d1ab6beb74bfe0d42a233f5b36855a4210ffeb69573fa4cafa2decc12820
7
+ data.tar.gz: 6b41c594384690eed2a84f1e8046046a72bb29c276e87d6cf048b34df2d24cf54725526f0d6eebed0a523f4334385a1f796cba8a6c1112e46e5d58787410611d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,95 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [2.26.0] - 2026-01-16
6
+
7
+ ### Added
8
+
9
+ * Core: Add process tags to runtime metrics when `DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED` is enabled. ([#5210][])
10
+ * SSI: Add experimental dependency injection validation.
11
+
12
+ ### Changed
13
+
14
+ * Profiling: Improve profiler error reporting. ([#5237][])
15
+ * SSI: Improve injection debug error reporting. ([#5238][])
16
+
17
+ ## [2.25.0] - 2026-01-13
18
+
19
+ ### Added
20
+
21
+ AI Guard: Add SDK for evaluating the safety of user messages and assistant commands for LLM session ([#5144][])
22
+
23
+ ### Changed
24
+
25
+ Core: Bump minimum version of `datadog-ruby_core_source` dependency ([#5215][])
26
+
27
+ ### Fixed
28
+
29
+ AppSec: Fix processing of numeric data for WAF and RASP checks ([#5222][])
30
+
31
+ ## [2.24.0] - 2026-01-08
32
+
33
+ ### Added
34
+
35
+ * Core: Add support for installing the gem on Ruby 4.0.x stable ([#5157][])
36
+ * Tracing: Add origin detection using extra headers and the `DD_EXTERNAL_ENV` variable. ([#5028][])
37
+ * Dynamic Instrumentation: Add one-click enablement support ([#5150][])
38
+ * SSI: Add support for Bundler deployment mode ([#5053][])
39
+ * SSI: Report UI-oriented injection results ([#5053][])
40
+ * SSI: Guard against Bundler global force_ruby_platform ([#5053][])
41
+ * SSI: Guard against Bundler 4.0 and Bundler 2.7 in 4.0 mode ([#5053][])
42
+ * SSI: Guard against Ruby 3.5+ ([#5053][])
43
+
44
+ ### Changed
45
+
46
+ * Profiling: Remove profiler warning related to the Ractor issue ([#5194][])
47
+ * Profiling: Disable heap profiling on Ruby 4 due to incompatibility ([#5148][])
48
+ * Dynamic Instrumentation: Stop using customer-provided time provider for method duration calculation ([#5153][])
49
+ * Live Debugger / Dynamic Instrumentation: Improve probe instrumentation ([#5165][])
50
+ * Live Debugger / Dynamic Instrumentation: Improve instrumentation reliability for probes ([#5169][])
51
+
52
+ ### Fixed
53
+
54
+ * Core: Improve reliability of worker shutdown ([#5176][])
55
+ * Core: Fix RDoc error when installing the `datadog` gem ([#5145][])
56
+ * Tracing: Ensure `Tracing.continue_from!` keeps the active trace for the full block duration. ([#4941][])
57
+ * Profiling: Fix and refine profiler thread state categorization for Ruby 4 ([#5197][])
58
+ * Profiling: Fix profiler error triggering `Bundler::PermissionError` ([#5146][])
59
+ * Live Debugger / Dynamic Instrumentation: Fix Live Debugger and Dynamic Instrumentation UI for forking web servers ([#5159][])
60
+ * Live Debugger / Dynamic Instrumentation: Fix method probe leak when a referenced class loads after the probe reaches the application ([#5168][])
61
+
62
+ ## [2.23.0] - 2025-12-11
63
+
64
+ ### Added
65
+
66
+ * Tracing: Add process tags to trace payloads with `DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED` environment variable ([#5033][])
67
+ * Tracing: Integrations: Add Data Streams Monitoring (DSM) instrumentation to Waterdrop producers ([#5031][])
68
+ * Tracing: Open Telemetry: Add OpenTelemetry metrics support with OTLP exporters using `DD_METRICS_OTEL_ENABLED` and standard OpenTelemetry environment variables ([#5021][])
69
+ * Tracing: Add `http.endpoint` tag which contains the route whenever routing info is available, and falls back to route inferred from the request path ([#4995][])
70
+ * Tracing: Add configuration of HTTP client and server error ranges via `DD_TRACE_HTTP_CLIENT_ERROR_STATUSES` and `DD_TRACE_HTTP_SERVER_ERROR_STATUSES` ([#4991][])
71
+ * Tracing: Integrations: Add Data Streams Monitoring for `ruby-kafka` and `karafka` consumers with optional manual instrumentation ([#4901][])
72
+ * Dynamic Instrumentation: Add support for Hash length operations in expression language ([#5019][])
73
+ * AppSec: Add unique security response identifier in the response body for blocked requests ([#5049][])
74
+ * AppSec: Add support for processor overrides and custom data scanners ([#5044][])
75
+ * Feature Flags: Add new component to support Open Feature SDK ([#5054][], [#5024][])
76
+
77
+ ### Changed
78
+
79
+ * Core: Update minimum `datadog-ruby_core_source` dependency to 3.4.2 ([#5122][])
80
+ * Core: Update `libdatadog` dependency to version 24.0.1 ([#5058][], [#5045][], [#5020][])
81
+ * Tracing: Treat IPs from `100.65.0.0/10` range as private. ([#4975][])
82
+
83
+ ### Fixed
84
+
85
+ * Live Debugger / Dynamic Instrumentation: Fix issues delivering large quantities of snapshots ([#5086][])
86
+ * Tracing: Integrations: Fix `NoMethodError` in GraphQL integration when error has no `locations`. ([#5025][])
87
+ * Tracing: Integrations: Fix `http.route` tag for Rack applications mounted inside Rails. ([#4988][])
88
+ * Profiling: Fix profiler support for Ruby 4.0.0-preview2 ([#5091][])
89
+ * Profiling: Fix profiler sleep and wait states not being categorized in timeline ([#5000][])
90
+ * Profiling: Fix profiler not identifying executables with gems they belong to ([#4999][])
91
+ * Stable Config: Fix potential segfault during configuration file parsing ([#5073][])
92
+ * AppSec: Fix route extraction error for Rails 8.1.1+. ([#5042][])
93
+
5
94
  ## [2.22.0] - 2025-10-15
6
95
 
7
96
  ### Added
@@ -3360,7 +3449,11 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1
3360
3449
  Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3361
3450
 
3362
3451
 
3363
- [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v2.22.0...master
3452
+ [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v2.26.0...master
3453
+ [2.26.0]: https://github.com/DataDog/dd-trace-rb/compare/v2.25.0...v2.26.0
3454
+ [2.25.0]: https://github.com/DataDog/dd-trace-rb/compare/v2.24.0...v2.25.0
3455
+ [2.24.0]: https://github.com/DataDog/dd-trace-rb/compare/v2.23.0...v2.24.0
3456
+ [2.23.0]: https://github.com/DataDog/dd-trace-rb/compare/v2.22.0...v2.23.0
3364
3457
  [2.22.0]: https://github.com/DataDog/dd-trace-rb/compare/v2.21.0...v2.22.0
3365
3458
  [2.21.0]: https://github.com/DataDog/dd-trace-rb/compare/v2.20.0...v2.21.0
3366
3459
  [2.20.0]: https://github.com/DataDog/dd-trace-rb/compare/v2.19.0...v2.20.0
@@ -4967,6 +5060,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
4967
5060
  [#4893]: https://github.com/DataDog/dd-trace-rb/issues/4893
4968
5061
  [#4894]: https://github.com/DataDog/dd-trace-rb/issues/4894
4969
5062
  [#4900]: https://github.com/DataDog/dd-trace-rb/issues/4900
5063
+ [#4901]: https://github.com/DataDog/dd-trace-rb/issues/4901
4970
5064
  [#4902]: https://github.com/DataDog/dd-trace-rb/issues/4902
4971
5065
  [#4906]: https://github.com/DataDog/dd-trace-rb/issues/4906
4972
5066
  [#4907]: https://github.com/DataDog/dd-trace-rb/issues/4907
@@ -4976,9 +5070,54 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
4976
5070
  [#4914]: https://github.com/DataDog/dd-trace-rb/issues/4914
4977
5071
  [#4918]: https://github.com/DataDog/dd-trace-rb/issues/4918
4978
5072
  [#4919]: https://github.com/DataDog/dd-trace-rb/issues/4919
5073
+ [#4941]: https://github.com/DataDog/dd-trace-rb/issues/4941
4979
5074
  [#4957]: https://github.com/DataDog/dd-trace-rb/issues/4957
4980
5075
  [#4965]: https://github.com/DataDog/dd-trace-rb/issues/4965
4981
5076
  [#4969]: https://github.com/DataDog/dd-trace-rb/issues/4969
5077
+ [#4975]: https://github.com/DataDog/dd-trace-rb/issues/4975
5078
+ [#4988]: https://github.com/DataDog/dd-trace-rb/issues/4988
5079
+ [#4991]: https://github.com/DataDog/dd-trace-rb/issues/4991
5080
+ [#4995]: https://github.com/DataDog/dd-trace-rb/issues/4995
5081
+ [#4999]: https://github.com/DataDog/dd-trace-rb/issues/4999
5082
+ [#5000]: https://github.com/DataDog/dd-trace-rb/issues/5000
5083
+ [#5019]: https://github.com/DataDog/dd-trace-rb/issues/5019
5084
+ [#5020]: https://github.com/DataDog/dd-trace-rb/issues/5020
5085
+ [#5021]: https://github.com/DataDog/dd-trace-rb/issues/5021
5086
+ [#5024]: https://github.com/DataDog/dd-trace-rb/issues/5024
5087
+ [#5025]: https://github.com/DataDog/dd-trace-rb/issues/5025
5088
+ [#5028]: https://github.com/DataDog/dd-trace-rb/issues/5028
5089
+ [#5031]: https://github.com/DataDog/dd-trace-rb/issues/5031
5090
+ [#5033]: https://github.com/DataDog/dd-trace-rb/issues/5033
5091
+ [#5042]: https://github.com/DataDog/dd-trace-rb/issues/5042
5092
+ [#5044]: https://github.com/DataDog/dd-trace-rb/issues/5044
5093
+ [#5045]: https://github.com/DataDog/dd-trace-rb/issues/5045
5094
+ [#5049]: https://github.com/DataDog/dd-trace-rb/issues/5049
5095
+ [#5053]: https://github.com/DataDog/dd-trace-rb/issues/5053
5096
+ [#5054]: https://github.com/DataDog/dd-trace-rb/issues/5054
5097
+ [#5058]: https://github.com/DataDog/dd-trace-rb/issues/5058
5098
+ [#5073]: https://github.com/DataDog/dd-trace-rb/issues/5073
5099
+ [#5086]: https://github.com/DataDog/dd-trace-rb/issues/5086
5100
+ [#5091]: https://github.com/DataDog/dd-trace-rb/issues/5091
5101
+ [#5122]: https://github.com/DataDog/dd-trace-rb/issues/5122
5102
+ [#5144]: https://github.com/DataDog/dd-trace-rb/issues/5144
5103
+ [#5145]: https://github.com/DataDog/dd-trace-rb/issues/5145
5104
+ [#5146]: https://github.com/DataDog/dd-trace-rb/issues/5146
5105
+ [#5148]: https://github.com/DataDog/dd-trace-rb/issues/5148
5106
+ [#5150]: https://github.com/DataDog/dd-trace-rb/issues/5150
5107
+ [#5153]: https://github.com/DataDog/dd-trace-rb/issues/5153
5108
+ [#5157]: https://github.com/DataDog/dd-trace-rb/issues/5157
5109
+ [#5159]: https://github.com/DataDog/dd-trace-rb/issues/5159
5110
+ [#5165]: https://github.com/DataDog/dd-trace-rb/issues/5165
5111
+ [#5168]: https://github.com/DataDog/dd-trace-rb/issues/5168
5112
+ [#5169]: https://github.com/DataDog/dd-trace-rb/issues/5169
5113
+ [#5176]: https://github.com/DataDog/dd-trace-rb/issues/5176
5114
+ [#5194]: https://github.com/DataDog/dd-trace-rb/issues/5194
5115
+ [#5197]: https://github.com/DataDog/dd-trace-rb/issues/5197
5116
+ [#5210]: https://github.com/DataDog/dd-trace-rb/issues/5210
5117
+ [#5215]: https://github.com/DataDog/dd-trace-rb/issues/5215
5118
+ [#5222]: https://github.com/DataDog/dd-trace-rb/issues/5222
5119
+ [#5237]: https://github.com/DataDog/dd-trace-rb/issues/5237
5120
+ [#5238]: https://github.com/DataDog/dd-trace-rb/issues/5238
4982
5121
  [@AdrianLC]: https://github.com/AdrianLC
4983
5122
  [@Azure7111]: https://github.com/Azure7111
4984
5123
  [@BabyGroot]: https://github.com/BabyGroot
@@ -1,60 +1,3 @@
1
1
  # Libdatadog development
2
2
 
3
- These instructions can quickly get outdated, so feel free to open an issue if they're not working (and/or ping @ivoanjo).
4
-
5
- ## Using libdatadog builds from CI or GitHub
6
-
7
- If you're developing inside docker/natively on Linux, you can use libdatadog builds from CI and GitHub.
8
-
9
- Here's what to do:
10
-
11
- 1. Create a folder for extracting libdatadog into based on your ruby platform (for instance inside the dd-trace-rb repo):
12
-
13
- ```bash
14
- export DD_RUBY_PLATFORM=`ruby -e 'puts Gem::Platform.local.to_s'`
15
- echo "Current ruby platform: $DD_RUBY_PLATFORM"
16
- mkdir -p my-libdatadog-build/$DD_RUBY_PLATFORM
17
- ```
18
-
19
- 2. Find a libdatadog build from CI or [GitHub releases](https://github.com/DataDog/libdatadog/releases). This should match the Ruby platform seen above.
20
- 3. Extract the libdatadog build into the folder:
21
-
22
- ```bash
23
- # In this example the build is in my downloads; notice the use of strip-components to get the correct folder structure
24
- tar zxvf ~/Downloads/libdatadog-x86_64-unknown-linux-gnu.tar.gz -C my-libdatadog-build/$DD_RUBY_PLATFORM/ --strip-components=1
25
- # Here's how it should look after
26
- ls my-libdatadog-build/$DD_RUBY_PLATFORM
27
- bin cmake include lib LICENSE LICENSE-3rdparty.yml NOTICE
28
- ```
29
-
30
- 6. Tell Ruby where to find libdatadog: ```export LIBDATADOG_VENDOR_OVERRIDE=`pwd`/my-libdatadog-build/``` (Notice no platform + use of pwd for full path here)
31
- 7. From dd-trace-rb, run `bundle exec rake clean compile`
32
- 8. For incremental builds, usually `bundle exec rake compile` is faster and `clean` is not needed
33
-
34
- If you additionally want to run the profiler test suite, also remember to `export DD_PROFILING_MACOS_TESTING=true` and re-run `rake clean compile`.
35
-
36
- ## Native development on macOS
37
-
38
- As of this writing (August 2025), the libdatadog builds on rubygems.org only support Linux.
39
-
40
- We don't officially support using libdatadog for Ruby on other platforms yet, but it is possible to use it for local development on macOS.
41
- (**Note that you don't need these instructions if you develop inside docker.**)
42
-
43
- Here's how you can do so:
44
-
45
- 1. [Install rust](https://www.rust-lang.org/tools/install)
46
- 2. Install `cbindgen`: `cargo install cbindgen`
47
- 3. Clone [libdatadog](https://github.com/datadog/libdatadog)
48
- 4. Create a folder for building into based on your ruby platform:
49
-
50
- ```bash
51
- export DD_RUBY_PLATFORM=`ruby -e 'puts Gem::Platform.local.to_s'`
52
- mkdir -p my-libdatadog-build/$DD_RUBY_PLATFORM
53
- ```
54
-
55
- 5. From inside of the libdatadog repo, build libdatadog into this folder: `./build-profiling-ffi.sh my-libdatadog-build/$DD_RUBY_PLATFORM`
56
- 6. Tell Ruby where to find libdatadog: `export LIBDATADOG_VENDOR_OVERRIDE=/adjust/this/to/be/the/full/path/to/my-libdatadog-build/` (Notice no platform here)
57
- 7. From dd-trace-rb, run `bundle exec rake clean compile`
58
- 8. For incremental builds, usually `bundle exec rake compile` is faster and `clean` is not needed
59
-
60
- If you additionally want to run the profiler test suite, also remember to `export DD_PROFILING_MACOS_TESTING=true` and re-run `rake clean compile`.
3
+ Moved to <../docs/LibdatadogDevelopment.md>!
@@ -76,8 +76,6 @@
76
76
  //
77
77
  // ---
78
78
 
79
- #define ERR_CLOCK_FAIL "failed to get clock time"
80
-
81
79
  // Maximum allowed value for an allocation weight. Attempts to use higher values will result in clamping.
82
80
  // See https://docs.google.com/document/d/1lWLB714wlLBBq6T4xZyAc4a5wtWhSmr4-hgiPKeErlA/edit#heading=h.ugp0zxcj5iqh
83
81
  // (Datadog-only link) for research backing the choice of this value.
@@ -117,6 +115,7 @@ typedef struct {
117
115
  // When something goes wrong during sampling, we record the Ruby exception here, so that it can be "re-raised" on
118
116
  // the CpuAndWallTimeWorker thread
119
117
  VALUE failure_exception;
118
+ const char *failure_exception_during_operation;
120
119
  // Used by `_native_stop` to flag the worker thread to start (see comment on `_native_sampling_loop`)
121
120
  VALUE stop_thread;
122
121
 
@@ -191,17 +190,17 @@ static VALUE _native_initialize(int argc, VALUE *argv, DDTRACE_UNUSED VALUE _sel
191
190
  static void cpu_and_wall_time_worker_typed_data_mark(void *state_ptr);
192
191
  static VALUE _native_sampling_loop(VALUE self, VALUE instance);
193
192
  static VALUE _native_stop(DDTRACE_UNUSED VALUE _self, VALUE self_instance, VALUE worker_thread);
194
- static VALUE stop(VALUE self_instance, VALUE optional_exception);
195
- static void stop_state(cpu_and_wall_time_worker_state *state, VALUE optional_exception);
193
+ static VALUE stop(VALUE self_instance, VALUE optional_exception, const char *optional_exception_during_operation);
194
+ static void stop_state(cpu_and_wall_time_worker_state *state, VALUE optional_exception, const char *optional_operation_name);
196
195
  static void handle_sampling_signal(DDTRACE_UNUSED int _signal, DDTRACE_UNUSED siginfo_t *_info, DDTRACE_UNUSED void *_ucontext);
197
196
  static void *run_sampling_trigger_loop(void *state_ptr);
198
197
  static void interrupt_sampling_trigger_loop(void *state_ptr);
199
198
  static void sample_from_postponed_job(DDTRACE_UNUSED void *_unused);
200
199
  static VALUE rescued_sample_from_postponed_job(VALUE self_instance);
201
- static VALUE handle_sampling_failure(VALUE self_instance, VALUE exception);
202
200
  static VALUE _native_current_sigprof_signal_handler(DDTRACE_UNUSED VALUE self);
203
201
  static VALUE release_gvl_and_run_sampling_trigger_loop(VALUE instance);
204
202
  static VALUE _native_is_running(DDTRACE_UNUSED VALUE self, VALUE instance);
203
+ static VALUE _native_failure_exception_during_operation(DDTRACE_UNUSED VALUE self, VALUE instance);
205
204
  static void testing_signal_handler(DDTRACE_UNUSED int _signal, DDTRACE_UNUSED siginfo_t *_info, DDTRACE_UNUSED void *_ucontext);
206
205
  static VALUE _native_install_testing_signal_handler(DDTRACE_UNUSED VALUE self);
207
206
  static VALUE _native_remove_testing_signal_handler(DDTRACE_UNUSED VALUE self);
@@ -209,7 +208,12 @@ static VALUE _native_trigger_sample(DDTRACE_UNUSED VALUE self);
209
208
  static VALUE _native_gc_tracepoint(DDTRACE_UNUSED VALUE self, VALUE instance);
210
209
  static void on_gc_event(VALUE tracepoint_data, DDTRACE_UNUSED void *unused);
211
210
  static void after_gc_from_postponed_job(DDTRACE_UNUSED void *_unused);
212
- static VALUE safely_call(VALUE (*function_to_call_safely)(VALUE), VALUE function_to_call_safely_arg, VALUE instance);
211
+ static VALUE safely_call(
212
+ VALUE (*function_to_call_safely)(VALUE),
213
+ VALUE function_to_call_safely_arg,
214
+ VALUE instance,
215
+ VALUE (*handle_sampling_failure)(VALUE, VALUE)
216
+ );
213
217
  static VALUE _native_simulate_handle_sampling_signal(DDTRACE_UNUSED VALUE self);
214
218
  static VALUE _native_simulate_sample_from_postponed_job(DDTRACE_UNUSED VALUE self);
215
219
  static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE instance);
@@ -226,6 +230,7 @@ static void disable_tracepoints(cpu_and_wall_time_worker_state *state);
226
230
  static VALUE _native_with_blocked_sigprof(DDTRACE_UNUSED VALUE self);
227
231
  static VALUE rescued_sample_allocation(VALUE tracepoint_data);
228
232
  static void delayed_error(cpu_and_wall_time_worker_state *state, const char *error);
233
+ static void delayed_error_clock_failure(cpu_and_wall_time_worker_state *state);
229
234
  static VALUE _native_delayed_error(DDTRACE_UNUSED VALUE self, VALUE instance, VALUE error_msg);
230
235
  static VALUE _native_hold_signals(DDTRACE_UNUSED VALUE self);
231
236
  static VALUE _native_resume_signals(DDTRACE_UNUSED VALUE self);
@@ -235,6 +240,10 @@ static void after_gvl_running_from_postponed_job(DDTRACE_UNUSED void *_unused);
235
240
  #endif
236
241
  static VALUE rescued_after_gvl_running_from_postponed_job(VALUE self_instance);
237
242
  static VALUE _native_gvl_profiling_hook_active(DDTRACE_UNUSED VALUE self, VALUE instance);
243
+ static VALUE handle_sampling_failure_rescued_sample_from_postponed_job(VALUE self_instance, VALUE exception);
244
+ static VALUE handle_sampling_failure_thread_context_collector_sample_after_gc(VALUE self_instance, VALUE exception);
245
+ static VALUE handle_sampling_failure_rescued_sample_allocation(VALUE self_instance, VALUE exception);
246
+ static VALUE handle_sampling_failure_rescued_after_gvl_running_from_postponed_job(VALUE self_instance, VALUE exception);
238
247
  static inline void during_sample_enter(cpu_and_wall_time_worker_state* state);
239
248
  static inline void during_sample_exit(cpu_and_wall_time_worker_state* state);
240
249
 
@@ -262,6 +271,7 @@ static inline void during_sample_exit(cpu_and_wall_time_worker_state* state);
262
271
  // (e.g. signal handler) where it's impossible or just awkward to pass it as an argument.
263
272
  static VALUE active_sampler_instance = Qnil;
264
273
  static cpu_and_wall_time_worker_state *active_sampler_instance_state = NULL;
274
+ static VALUE clock_failure_exception_class = Qnil;
265
275
 
266
276
  // See handle_sampling_signal for details on what this does
267
277
  #ifdef NO_POSTPONED_TRIGGER
@@ -299,6 +309,8 @@ void collectors_cpu_and_wall_time_worker_init(VALUE profiling_module) {
299
309
  VALUE collectors_cpu_and_wall_time_worker_class = rb_define_class_under(collectors_module, "CpuAndWallTimeWorker", rb_cObject);
300
310
  // Hosts methods used for testing the native code using RSpec
301
311
  VALUE testing_module = rb_define_module_under(collectors_cpu_and_wall_time_worker_class, "Testing");
312
+ clock_failure_exception_class = rb_define_class_under(collectors_cpu_and_wall_time_worker_class, "ClockFailure", rb_eRuntimeError);
313
+ rb_gc_register_mark_object(clock_failure_exception_class);
302
314
 
303
315
  // Instances of the CpuAndWallTimeWorker class are "TypedData" objects.
304
316
  // "TypedData" objects are special objects in the Ruby VM that can wrap C structs.
@@ -318,6 +330,7 @@ void collectors_cpu_and_wall_time_worker_init(VALUE profiling_module) {
318
330
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_stats_reset_not_thread_safe", _native_stats_reset_not_thread_safe, 1);
319
331
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_allocation_count", _native_allocation_count, 0);
320
332
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_is_running?", _native_is_running, 1);
333
+ rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_failure_exception_during_operation", _native_failure_exception_during_operation, 1);
321
334
  rb_define_singleton_method(testing_module, "_native_current_sigprof_signal_handler", _native_current_sigprof_signal_handler, 0);
322
335
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_hold_signals", _native_hold_signals, 0);
323
336
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_resume_signals", _native_resume_signals, 0);
@@ -370,6 +383,7 @@ static VALUE _native_new(VALUE klass) {
370
383
 
371
384
  atomic_init(&state->should_run, false);
372
385
  state->failure_exception = Qnil;
386
+ state->failure_exception_during_operation = NULL;
373
387
  state->stop_thread = Qnil;
374
388
 
375
389
  during_sample_exit(state);
@@ -554,22 +568,24 @@ static VALUE _native_stop(DDTRACE_UNUSED VALUE _self, VALUE self_instance, VALUE
554
568
 
555
569
  state->stop_thread = worker_thread;
556
570
 
557
- return stop(self_instance, /* optional_exception: */ Qnil);
571
+ return stop(self_instance, Qnil, NULL);
558
572
  }
559
573
 
560
- static void stop_state(cpu_and_wall_time_worker_state *state, VALUE optional_exception) {
574
+ // When providing an `optional_exception`, `optional_exception_during_operation` should be provided as well
575
+ static void stop_state(cpu_and_wall_time_worker_state *state, VALUE optional_exception, const char *optional_exception_during_operation) {
561
576
  atomic_store(&state->should_run, false);
562
577
  state->failure_exception = optional_exception;
578
+ state->failure_exception_during_operation = optional_exception_during_operation;
563
579
 
564
580
  // Disable the tracepoints as soon as possible, so the VM doesn't keep on calling them
565
581
  disable_tracepoints(state);
566
582
  }
567
583
 
568
- static VALUE stop(VALUE self_instance, VALUE optional_exception) {
584
+ static VALUE stop(VALUE self_instance, VALUE optional_exception, const char *optional_exception_during_operation) {
569
585
  cpu_and_wall_time_worker_state *state;
570
586
  TypedData_Get_Struct(self_instance, cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
571
587
 
572
- stop_state(state, optional_exception);
588
+ stop_state(state, optional_exception, optional_exception_during_operation);
573
589
 
574
590
  return Qtrue;
575
591
  }
@@ -726,7 +742,12 @@ static void sample_from_postponed_job(DDTRACE_UNUSED void *_unused) {
726
742
  during_sample_enter(state);
727
743
 
728
744
  // Rescue against any exceptions that happen during sampling
729
- safely_call(rescued_sample_from_postponed_job, state->self_instance, state->self_instance);
745
+ safely_call(
746
+ rescued_sample_from_postponed_job,
747
+ state->self_instance,
748
+ state->self_instance,
749
+ handle_sampling_failure_rescued_sample_from_postponed_job
750
+ );
730
751
 
731
752
  during_sample_exit(state);
732
753
  }
@@ -763,11 +784,6 @@ static VALUE rescued_sample_from_postponed_job(VALUE self_instance) {
763
784
  return Qnil;
764
785
  }
765
786
 
766
- static VALUE handle_sampling_failure(VALUE self_instance, VALUE exception) {
767
- stop(self_instance, exception);
768
- return Qnil;
769
- }
770
-
771
787
  // This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
772
788
  // It SHOULD NOT be used for other purposes.
773
789
  static VALUE _native_current_sigprof_signal_handler(DDTRACE_UNUSED VALUE self) {
@@ -844,6 +860,15 @@ static VALUE _native_is_running(DDTRACE_UNUSED VALUE self, VALUE instance) {
844
860
  return (state != NULL && is_thread_alive(state->owner_thread) && state->self_instance == instance) ? Qtrue : Qfalse;
845
861
  }
846
862
 
863
+ static VALUE _native_failure_exception_during_operation(DDTRACE_UNUSED VALUE self, VALUE instance) {
864
+ cpu_and_wall_time_worker_state *state;
865
+ TypedData_Get_Struct(instance, cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
866
+
867
+ if (state->failure_exception_during_operation == NULL) return Qnil;
868
+
869
+ return rb_str_new_cstr(state->failure_exception_during_operation);
870
+ }
871
+
847
872
  static void testing_signal_handler(DDTRACE_UNUSED int _signal, DDTRACE_UNUSED siginfo_t *_info, DDTRACE_UNUSED void *_ucontext) {
848
873
  /* Does nothing on purpose */
849
874
  }
@@ -936,14 +961,24 @@ static void after_gc_from_postponed_job(DDTRACE_UNUSED void *_unused) {
936
961
 
937
962
  during_sample_enter(state);
938
963
 
939
- safely_call(thread_context_collector_sample_after_gc, state->thread_context_collector_instance, state->self_instance);
964
+ safely_call(
965
+ thread_context_collector_sample_after_gc,
966
+ state->thread_context_collector_instance,
967
+ state->self_instance,
968
+ handle_sampling_failure_thread_context_collector_sample_after_gc
969
+ );
940
970
 
941
971
  during_sample_exit(state);
942
972
  }
943
973
 
944
974
  // Equivalent to Ruby begin/rescue call, where we call a C function and jump to the exception handler if an
945
975
  // exception gets raised within
946
- static VALUE safely_call(VALUE (*function_to_call_safely)(VALUE), VALUE function_to_call_safely_arg, VALUE instance) {
976
+ static VALUE safely_call(
977
+ VALUE (*function_to_call_safely)(VALUE),
978
+ VALUE function_to_call_safely_arg,
979
+ VALUE instance,
980
+ VALUE (*handle_sampling_failure)(VALUE, VALUE)
981
+ ) {
947
982
  VALUE exception_handler_function_arg = instance;
948
983
  return rb_rescue2(
949
984
  function_to_call_safely,
@@ -1119,7 +1154,7 @@ static VALUE _native_allocation_count(DDTRACE_UNUSED VALUE self) {
1119
1154
  #define HANDLE_CLOCK_FAILURE(call) ({ \
1120
1155
  long _result = (call); \
1121
1156
  if (_result == 0) { \
1122
- delayed_error(state, ERR_CLOCK_FAIL); \
1157
+ delayed_error_clock_failure(state); \
1123
1158
  return; \
1124
1159
  } \
1125
1160
  _result; \
@@ -1203,12 +1238,17 @@ static void on_newobj_event(DDTRACE_UNUSED VALUE unused1, DDTRACE_UNUSED void *u
1203
1238
  during_sample_enter(state);
1204
1239
 
1205
1240
  // Rescue against any exceptions that happen during sampling
1206
- safely_call(rescued_sample_allocation, Qnil, state->self_instance);
1241
+ safely_call(
1242
+ rescued_sample_allocation,
1243
+ Qnil,
1244
+ state->self_instance,
1245
+ handle_sampling_failure_rescued_sample_allocation
1246
+ );
1207
1247
 
1208
1248
  if (state->dynamic_sampling_rate_enabled) {
1209
1249
  long now = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
1210
1250
  if (now == 0) {
1211
- delayed_error(state, ERR_CLOCK_FAIL);
1251
+ delayed_error_clock_failure(state);
1212
1252
  // NOTE: Not short-circuiting here to make sure cleanup happens
1213
1253
  }
1214
1254
  uint64_t sampling_time_ns = discrete_dynamic_sampler_after_sample(&state->allocation_sampler, now);
@@ -1284,7 +1324,12 @@ static VALUE rescued_sample_allocation(DDTRACE_UNUSED VALUE unused) {
1284
1324
 
1285
1325
  static void delayed_error(cpu_and_wall_time_worker_state *state, const char *error) {
1286
1326
  // If we can't raise an immediate exception at the calling site, use the asynchronous flow through the main worker loop.
1287
- stop_state(state, rb_exc_new_cstr(rb_eRuntimeError, error));
1327
+ stop_state(state, rb_exc_new_cstr(rb_eRuntimeError, error), "delayed_error");
1328
+ }
1329
+
1330
+ static void delayed_error_clock_failure(cpu_and_wall_time_worker_state *state) {
1331
+ // If we can't raise an immediate exception at the calling site, use the asynchronous flow through the main worker loop.
1332
+ stop_state(state, rb_exc_new_cstr(clock_failure_exception_class, "failed to get clock time"), "delayed_error_clock_failure");
1288
1333
  }
1289
1334
 
1290
1335
  static VALUE _native_delayed_error(DDTRACE_UNUSED VALUE self, VALUE instance, VALUE error_msg) {
@@ -1365,7 +1410,12 @@ static VALUE _native_resume_signals(DDTRACE_UNUSED VALUE self) {
1365
1410
  during_sample_enter(state);
1366
1411
 
1367
1412
  // Rescue against any exceptions that happen during sampling
1368
- safely_call(rescued_after_gvl_running_from_postponed_job, state->self_instance, state->self_instance);
1413
+ safely_call(
1414
+ rescued_after_gvl_running_from_postponed_job,
1415
+ state->self_instance,
1416
+ state->self_instance,
1417
+ handle_sampling_failure_rescued_after_gvl_running_from_postponed_job
1418
+ );
1369
1419
 
1370
1420
  during_sample_exit(state);
1371
1421
  }
@@ -1404,6 +1454,26 @@ static VALUE _native_resume_signals(DDTRACE_UNUSED VALUE self) {
1404
1454
  }
1405
1455
  #endif
1406
1456
 
1457
+ static VALUE handle_sampling_failure_rescued_sample_from_postponed_job(VALUE self_instance, VALUE exception) {
1458
+ stop(self_instance, exception, "rescued_sample_from_postponed_job");
1459
+ return Qnil;
1460
+ }
1461
+
1462
+ static VALUE handle_sampling_failure_thread_context_collector_sample_after_gc(VALUE self_instance, VALUE exception) {
1463
+ stop(self_instance, exception, "thread_context_collector_sample_after_gc");
1464
+ return Qnil;
1465
+ }
1466
+
1467
+ static VALUE handle_sampling_failure_rescued_sample_allocation(VALUE self_instance, VALUE exception) {
1468
+ stop(self_instance, exception, "rescued_sample_allocation");
1469
+ return Qnil;
1470
+ }
1471
+
1472
+ static VALUE handle_sampling_failure_rescued_after_gvl_running_from_postponed_job(VALUE self_instance, VALUE exception) {
1473
+ stop(self_instance, exception, "rescued_after_gvl_running_from_postponed_job");
1474
+ return Qnil;
1475
+ }
1476
+
1407
1477
  static inline void during_sample_enter(cpu_and_wall_time_worker_state* state) {
1408
1478
  // Tell the compiler it's not allowed to reorder the `during_sample` flag with anything that happens after.
1409
1479
  //
@@ -347,13 +347,19 @@ void sample_thread(
347
347
  } else if (CHARSLICE_EQUALS("select", name_slice)) { // Expected to be Kernel.select
348
348
  state_label->str = DDOG_CHARSLICE_C("waiting");
349
349
  } else if (
350
- CHARSLICE_EQUALS("synchronize", name_slice) || // Expected to be Monitor/Mutex#synchronize
351
- CHARSLICE_EQUALS("lock", name_slice) || // Expected to be Mutex#lock
350
+ CHARSLICE_EQUALS("synchronize", name_slice) || // Expected to be Monitor/Mutex#synchronize on Ruby 2 & 3, and Monitor#synchronize on 4 (Mutex becomes <internal:thread_sync>)
351
+ #ifdef NO_PRIMITIVE_MUTEX_AND_CONDITION_VARIABLE // Ruby < 4
352
+ CHARSLICE_EQUALS("lock", name_slice) || // Expected to be Mutex#lock
353
+ #endif
352
354
  CHARSLICE_EQUALS("join", name_slice) // Expected to be Thread#join
353
355
  ) {
354
356
  state_label->str = DDOG_CHARSLICE_C("blocked");
355
357
  } else if (CHARSLICE_EQUALS("wait_readable", name_slice)) { // Expected to be IO#wait_readable
356
358
  state_label->str = DDOG_CHARSLICE_C("network");
359
+ } else if (CHARSLICE_EQUALS("_native_idle_sampling_loop", name_slice)) { // Expected to be Datadog::Profiler::Collectors::IdleSamplingHelper#_native_idle_sampling_loop
360
+ state_label->str = DDOG_CHARSLICE_C("waiting");
361
+ } else if (CHARSLICE_EQUALS("_native_sampling_loop", name_slice)) { // Expected to be Datadog::Profiler::Collectors::CpuAndWallTimeWorker#_native_sampling_loop
362
+ state_label->str = DDOG_CHARSLICE_C("sleeping");
357
363
  }
358
364
  #ifdef NO_PRIMITIVE_POP // Ruby < 3.2
359
365
  else if (CHARSLICE_EQUALS("pop", name_slice)) { // Expected to be Queue/SizedQueue#pop
@@ -362,9 +368,19 @@ void sample_thread(
362
368
  #endif
363
369
  } else {
364
370
  #ifndef NO_PRIMITIVE_POP // Ruby >= 3.2
365
- // Unlike the above, Ruby actually treats this one specially and gives it a nice file name we can match on!
366
- if (CHARSLICE_EQUALS("pop", name_slice) && CHARSLICE_EQUALS("<internal:thread_sync>", filename_slice)) { // Expected to be Queue/SizedQueue#pop
367
- state_label->str = DDOG_CHARSLICE_C("waiting");
371
+ if (CHARSLICE_EQUALS("<internal:thread_sync>", filename_slice)) {
372
+ if (CHARSLICE_EQUALS("pop", name_slice)) { // Expected to be Queue/SizedQueue#pop
373
+ state_label->str = DDOG_CHARSLICE_C("waiting");
374
+ }
375
+ #ifndef NO_PRIMITIVE_MUTEX_AND_CONDITION_VARIABLE // Ruby >= 4
376
+ else if (CHARSLICE_EQUALS("synchronize", name_slice) || CHARSLICE_EQUALS("lock", name_slice)) { // Expected to be Mutex#lock/synchronize
377
+ state_label->str = DDOG_CHARSLICE_C("blocked");
378
+ } else if (CHARSLICE_EQUALS("sleep", name_slice)) { // Expected to be Mutex#sleep
379
+ state_label->str = DDOG_CHARSLICE_C("sleeping");
380
+ } else if (CHARSLICE_EQUALS("wait", name_slice)) { // Expected to be ConditionVariable#wait
381
+ state_label->str = DDOG_CHARSLICE_C("waiting");
382
+ }
383
+ #endif
368
384
  }
369
385
  #endif
370
386
  }