ddtrace 1.14.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +178 -2
  3. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +3 -5
  4. data/ext/ddtrace_profiling_native_extension/clock_id.h +0 -3
  5. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +0 -22
  6. data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +0 -1
  7. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +41 -6
  8. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +3 -0
  9. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +76 -24
  10. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +1 -1
  11. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +207 -32
  12. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.h +1 -1
  13. data/ext/ddtrace_profiling_native_extension/extconf.rb +8 -2
  14. data/ext/ddtrace_profiling_native_extension/http_transport.c +26 -10
  15. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.c +42 -0
  16. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +6 -0
  17. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -16
  18. data/ext/ddtrace_profiling_native_extension/pid_controller.c +57 -0
  19. data/ext/ddtrace_profiling_native_extension/pid_controller.h +45 -0
  20. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +17 -12
  21. data/ext/ddtrace_profiling_native_extension/profiling.c +0 -2
  22. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +74 -37
  23. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +13 -3
  24. data/lib/datadog/appsec/assets/waf_rules/processors.json +92 -0
  25. data/lib/datadog/appsec/assets/waf_rules/recommended.json +698 -75
  26. data/lib/datadog/appsec/assets/waf_rules/scanners.json +114 -0
  27. data/lib/datadog/appsec/assets/waf_rules/strict.json +98 -8
  28. data/lib/datadog/appsec/assets.rb +8 -0
  29. data/lib/datadog/appsec/component.rb +9 -2
  30. data/lib/datadog/appsec/configuration/settings.rb +61 -2
  31. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
  32. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +2 -7
  33. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +2 -5
  34. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +2 -5
  35. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
  36. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +23 -9
  37. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
  38. data/lib/datadog/appsec/contrib/rails/patcher.rb +9 -3
  39. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +2 -5
  40. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
  41. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
  42. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +2 -5
  43. data/lib/datadog/appsec/event.rb +106 -50
  44. data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
  45. data/lib/datadog/appsec/monitor/reactive/set_user.rb +2 -5
  46. data/lib/datadog/appsec/processor/actions.rb +49 -0
  47. data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
  48. data/lib/datadog/appsec/processor.rb +34 -6
  49. data/lib/datadog/appsec/remote.rb +4 -1
  50. data/lib/datadog/appsec/response.rb +82 -4
  51. data/lib/datadog/appsec/sample_rate.rb +21 -0
  52. data/lib/datadog/appsec.rb +2 -2
  53. data/lib/datadog/core/configuration/agent_settings_resolver.rb +29 -24
  54. data/lib/datadog/core/configuration/base.rb +1 -11
  55. data/lib/datadog/core/configuration/components.rb +7 -2
  56. data/lib/datadog/core/configuration/ext.rb +21 -0
  57. data/lib/datadog/core/configuration/option.rb +2 -4
  58. data/lib/datadog/core/configuration/option_definition.rb +17 -41
  59. data/lib/datadog/core/configuration/options.rb +5 -5
  60. data/lib/datadog/core/configuration/settings.rb +47 -45
  61. data/lib/datadog/core/environment/execution.rb +47 -9
  62. data/lib/datadog/core/environment/variable_helpers.rb +0 -69
  63. data/lib/datadog/core/error.rb +1 -0
  64. data/lib/datadog/core/git/ext.rb +2 -0
  65. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  66. data/lib/datadog/core/remote/component.rb +2 -2
  67. data/lib/datadog/core/remote/negotiation.rb +2 -2
  68. data/lib/datadog/core/remote/transport/config.rb +60 -0
  69. data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
  70. data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
  71. data/lib/datadog/core/remote/transport/http/api.rb +58 -0
  72. data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
  73. data/lib/datadog/core/remote/transport/http/client.rb +48 -0
  74. data/lib/datadog/core/remote/transport/http/config.rb +280 -0
  75. data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
  76. data/lib/datadog/core/remote/transport/http.rb +179 -0
  77. data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
  78. data/lib/datadog/core/telemetry/collector.rb +3 -2
  79. data/lib/datadog/core/telemetry/http/transport.rb +2 -1
  80. data/lib/datadog/core/transport/ext.rb +47 -0
  81. data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
  82. data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
  83. data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
  84. data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
  85. data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
  86. data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
  87. data/lib/datadog/core/transport/http/api/map.rb +18 -0
  88. data/lib/datadog/core/transport/http/env.rb +62 -0
  89. data/lib/datadog/core/transport/http/response.rb +60 -0
  90. data/lib/datadog/core/transport/parcel.rb +22 -0
  91. data/lib/datadog/core/transport/request.rb +17 -0
  92. data/lib/datadog/core/transport/response.rb +64 -0
  93. data/lib/datadog/core/workers/polling.rb +2 -2
  94. data/lib/datadog/opentelemetry/api/context.rb +10 -3
  95. data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
  96. data/lib/datadog/opentelemetry/sdk/span_processor.rb +14 -2
  97. data/lib/datadog/opentelemetry/sdk/trace/span.rb +68 -0
  98. data/lib/datadog/opentelemetry/trace.rb +58 -0
  99. data/lib/datadog/opentelemetry.rb +1 -0
  100. data/lib/datadog/opentracer.rb +9 -0
  101. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +12 -18
  102. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  103. data/lib/datadog/profiling/collectors/thread_context.rb +9 -1
  104. data/lib/datadog/profiling/component.rb +24 -99
  105. data/lib/datadog/profiling/ext.rb +0 -12
  106. data/lib/datadog/profiling/flush.rb +0 -3
  107. data/lib/datadog/profiling/http_transport.rb +6 -3
  108. data/lib/datadog/profiling/native_extension.rb +0 -21
  109. data/lib/datadog/profiling/profiler.rb +11 -12
  110. data/lib/datadog/profiling.rb +8 -81
  111. data/lib/datadog/tracing/component.rb +10 -4
  112. data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
  113. data/lib/datadog/tracing/configuration/ext.rb +4 -2
  114. data/lib/datadog/tracing/configuration/settings.rb +14 -7
  115. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -1
  116. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -1
  117. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
  118. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +104 -197
  119. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
  120. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +7 -0
  121. data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
  122. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -0
  123. data/lib/datadog/tracing/contrib/dalli/ext.rb +7 -0
  124. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +9 -2
  125. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -1
  126. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +5 -0
  127. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -0
  128. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +8 -0
  129. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -0
  130. data/lib/datadog/tracing/contrib/ext.rb +3 -0
  131. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
  132. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -0
  133. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +21 -1
  134. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +11 -1
  135. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +18 -0
  136. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
  137. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +3 -3
  138. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -0
  139. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -0
  140. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -0
  141. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +7 -0
  142. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +13 -3
  143. data/lib/datadog/tracing/contrib/opensearch/integration.rb +2 -2
  144. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +7 -0
  145. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +5 -0
  146. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +5 -0
  147. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
  148. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -1
  149. data/lib/datadog/tracing/contrib/racecar/event.rb +5 -0
  150. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +14 -4
  151. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -4
  152. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -1
  153. data/lib/datadog/tracing/contrib/redis/tags.rb +5 -0
  154. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -1
  155. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -0
  156. data/lib/datadog/tracing/contrib/sequel/utils.rb +5 -0
  157. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -1
  158. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -1
  159. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -1
  160. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  161. data/lib/datadog/tracing/distributed/propagation.rb +13 -33
  162. data/lib/datadog/tracing/metadata/tagging.rb +3 -3
  163. data/lib/datadog/tracing/sync_writer.rb +3 -3
  164. data/lib/datadog/tracing/tracer.rb +2 -0
  165. data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
  166. data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
  167. data/lib/datadog/tracing/transport/http/api.rb +43 -0
  168. data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
  169. data/lib/datadog/tracing/transport/http/client.rb +57 -0
  170. data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
  171. data/lib/datadog/tracing/transport/http/traces.rb +152 -0
  172. data/lib/datadog/tracing/transport/http.rb +124 -0
  173. data/lib/datadog/tracing/transport/io/client.rb +89 -0
  174. data/lib/datadog/tracing/transport/io/response.rb +27 -0
  175. data/lib/datadog/tracing/transport/io/traces.rb +101 -0
  176. data/lib/datadog/tracing/transport/io.rb +30 -0
  177. data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
  178. data/lib/datadog/tracing/transport/statistics.rb +77 -0
  179. data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
  180. data/lib/datadog/tracing/transport/traces.rb +224 -0
  181. data/lib/datadog/tracing/workers/trace_writer.rb +5 -3
  182. data/lib/datadog/tracing/workers.rb +3 -2
  183. data/lib/datadog/tracing/writer.rb +5 -2
  184. data/lib/ddtrace/transport/ext.rb +17 -15
  185. data/lib/ddtrace/version.rb +1 -1
  186. data/lib/ddtrace.rb +1 -1
  187. metadata +72 -96
  188. data/lib/datadog/ci/configuration/components.rb +0 -32
  189. data/lib/datadog/ci/configuration/settings.rb +0 -51
  190. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -35
  191. data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -22
  192. data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
  193. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
  194. data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
  195. data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
  196. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +0 -35
  197. data/lib/datadog/ci/contrib/minitest/ext.rb +0 -21
  198. data/lib/datadog/ci/contrib/minitest/integration.rb +0 -49
  199. data/lib/datadog/ci/contrib/minitest/patcher.rb +0 -27
  200. data/lib/datadog/ci/contrib/minitest/test_helper.rb +0 -68
  201. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -35
  202. data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
  203. data/lib/datadog/ci/contrib/rspec/ext.rb +0 -21
  204. data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
  205. data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
  206. data/lib/datadog/ci/ext/app_types.rb +0 -9
  207. data/lib/datadog/ci/ext/environment.rb +0 -575
  208. data/lib/datadog/ci/ext/settings.rb +0 -10
  209. data/lib/datadog/ci/ext/test.rb +0 -35
  210. data/lib/datadog/ci/extensions.rb +0 -19
  211. data/lib/datadog/ci/flush.rb +0 -38
  212. data/lib/datadog/ci/test.rb +0 -81
  213. data/lib/datadog/ci.rb +0 -21
  214. data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
  215. data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
  216. data/lib/datadog/core/configuration/option_set.rb +0 -10
  217. data/lib/datadog/core/transport/config.rb +0 -58
  218. data/lib/datadog/core/transport/http/api.rb +0 -57
  219. data/lib/datadog/core/transport/http/client.rb +0 -45
  220. data/lib/datadog/core/transport/http/config.rb +0 -278
  221. data/lib/datadog/core/transport/http/negotiation.rb +0 -144
  222. data/lib/datadog/core/transport/http.rb +0 -169
  223. data/lib/datadog/core/utils/object_set.rb +0 -43
  224. data/lib/datadog/core/utils/string_table.rb +0 -47
  225. data/lib/datadog/profiling/backtrace_location.rb +0 -34
  226. data/lib/datadog/profiling/buffer.rb +0 -43
  227. data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
  228. data/lib/datadog/profiling/encoding/profile.rb +0 -41
  229. data/lib/datadog/profiling/event.rb +0 -15
  230. data/lib/datadog/profiling/events/stack.rb +0 -82
  231. data/lib/datadog/profiling/old_recorder.rb +0 -107
  232. data/lib/datadog/profiling/pprof/builder.rb +0 -125
  233. data/lib/datadog/profiling/pprof/converter.rb +0 -102
  234. data/lib/datadog/profiling/pprof/message_set.rb +0 -16
  235. data/lib/datadog/profiling/pprof/payload.rb +0 -20
  236. data/lib/datadog/profiling/pprof/pprof.proto +0 -212
  237. data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
  238. data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
  239. data/lib/datadog/profiling/pprof/string_table.rb +0 -12
  240. data/lib/datadog/profiling/pprof/template.rb +0 -118
  241. data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
  242. data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
  243. data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
  244. data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
  245. data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
  246. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
  247. data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
  248. data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
  249. data/lib/ddtrace/transport/http/api/instance.rb +0 -35
  250. data/lib/ddtrace/transport/http/api/map.rb +0 -16
  251. data/lib/ddtrace/transport/http/api/spec.rb +0 -17
  252. data/lib/ddtrace/transport/http/api.rb +0 -39
  253. data/lib/ddtrace/transport/http/builder.rb +0 -176
  254. data/lib/ddtrace/transport/http/client.rb +0 -52
  255. data/lib/ddtrace/transport/http/env.rb +0 -58
  256. data/lib/ddtrace/transport/http/response.rb +0 -58
  257. data/lib/ddtrace/transport/http/statistics.rb +0 -43
  258. data/lib/ddtrace/transport/http/traces.rb +0 -144
  259. data/lib/ddtrace/transport/http.rb +0 -117
  260. data/lib/ddtrace/transport/io/client.rb +0 -85
  261. data/lib/ddtrace/transport/io/response.rb +0 -25
  262. data/lib/ddtrace/transport/io/traces.rb +0 -99
  263. data/lib/ddtrace/transport/io.rb +0 -28
  264. data/lib/ddtrace/transport/parcel.rb +0 -20
  265. data/lib/ddtrace/transport/request.rb +0 -15
  266. data/lib/ddtrace/transport/response.rb +0 -60
  267. data/lib/ddtrace/transport/serializable_trace.rb +0 -122
  268. data/lib/ddtrace/transport/statistics.rb +0 -75
  269. data/lib/ddtrace/transport/trace_formatter.rb +0 -207
  270. data/lib/ddtrace/transport/traces.rb +0 -216
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae7238650b45da9d8bf8f5834af2a29153081e798c2c8733c9bffb8768b6c430
4
- data.tar.gz: b9bc8f36d37b91d18754892bd8dbc92cd515b9e38caf8561e23b665f14ee5e9e
3
+ metadata.gz: 18896f24a83a74a5ea6f4adfb3baad9fec922f0d3c3e8d087d28805744584d40
4
+ data.tar.gz: 173d93233e49670ed94a9d3cd7501f50c596ceb7624293e4c1992513e6121fa6
5
5
  SHA512:
6
- metadata.gz: 4b4cdffa9d4ee39e6763be4a87dbdf3e351fd29915d4eaea45dc9c800543c65c8eb21375138422280cfed5715d8f23e95e58190752af6631c14453d39b29b263
7
- data.tar.gz: fbc970e48e5e5038775368618e672ab7b2405cd6ea9b899136b34e9ae776f26a92436087fb0810ef7d66574c2f694cdea03197cf980b08dc35a9defcf4c3dc74
6
+ metadata.gz: 174e727aad6f68b2873e88ac71b5a563075c501f4fbd75cad563735c765962d5753f6025a0a75c257f12a7a89fc83713e3ff249f2e2815803786ed709e35daff
7
+ data.tar.gz: bc2bbcc9d601473e871dee51e53745045b37204bb902dd2f29deac2ea4c94bdc7aa6c016eecfd2648ccac13393b612400c9167bdbd115271893e561fcb12a8ce
data/CHANGELOG.md CHANGED
@@ -2,6 +2,135 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [1.15.0] - 2023-10-09
6
+
7
+ ### Highlights
8
+
9
+ #### Timeline view for Profiler beta
10
+
11
+ As of ddtrace 1.15.0, the Profiler now supports gathering data for the new
12
+ [Timeline view](https://docs.datadoghq.com/profiler/profile_visualizations/#timeline-view).
13
+
14
+ The Timeline view allows you to look at time-based patterns and work distribution over the period of a single profile: you can look at what individual threads were doing, and when 🎉
15
+
16
+ You can use the timeline view both when looking at individual profiles, as well as when scoped to a given trace.
17
+
18
+ You can enable it:
19
+
20
+ * Using an environment variable by setting `DD_PROFILING_EXPERIMENTAL_TIMELINE_ENABLED=true`
21
+ * Or via code by adding to your `Datadog.configure` block:
22
+
23
+ ```ruby
24
+ Datadog.configure do |c|
25
+ # … existing configuration …
26
+ c.profiling.advanced.experimental_timeline_enabled = true
27
+ end
28
+ ```
29
+
30
+ Give it a try, let us know what you think!
31
+
32
+ (Note: We do not recommend enabling this feature prior to 1.15.0!)
33
+
34
+ #### google-protobuf dependency is no longer needed by the Profiler
35
+
36
+ As of ddtrace version 1.15.0, the `google-protobuf` gem is no longer needed to enable the Profiler.
37
+
38
+ If you've added this gem to your `Gemfile`/`gems.rb` file as part of enabling the Profiler, you can
39
+ remove it now. (If you're curious, we've internally replaced this dependency with the `libdatadog` gem.)
40
+
41
+ #### Configure blocking responses for AppSec via configuration or Remote Configuration
42
+
43
+ As of dd-trace-rb 1.15.0, AppSec supports configuring the blocking response.
44
+
45
+ You can configure the blocking response via:
46
+ - Using the ENV variables: `DD_APPSEC_HTTP_BLOCKED_TEMPLATE_HTML=#{file_name}`, and `DD_APPSEC_HTTP_BLOCKED_TEMPLATE_JSON=#{file_name}`
47
+ - Via code by adding to your `Datadog.configure` block:
48
+
49
+ ```ruby
50
+ Datadog.configure do |c|
51
+ # … existing configuration …
52
+ c.appsec.block.templates.html = "#{file_name}"
53
+ c.appsec.block.templates.json = "#{file_name}"
54
+ end
55
+ ```
56
+
57
+ - Using the Remote configuration UI. This option allow you to configure the status code and the blocking behaviour. You can redirect malicious attacker to custome pages.
58
+ You can find more information on the [official documentation](https://docs.datadoghq.com/security/application_security/threats/protection/#customize-protection-behavior)
59
+
60
+ #### Configure agentless mode for CI visibility
61
+
62
+ If you are using CI visibility with a cloud CI provider without access to the underlying worker nodes, such as GitHub Actions or CircleCI, configure the library to use the Agentless mode.
63
+
64
+ For this, set the following environment variables:
65
+ - DD_CIVISIBILITY_AGENTLESS_ENABLED=true
66
+ - DD_API_KEY=<your_api_key>
67
+
68
+ Additionally, configure which Datadog site you want to send your data to:
69
+ - DD_SITE (default: datadoghq.com)
70
+
71
+ You can also enable agentless mode with `Datadog.configure` block:
72
+
73
+ ```ruby
74
+ Datadog.configure do |c|
75
+ # … existing configuration …
76
+ c.ci.agentless_mode_enabled = true
77
+ # don't forget to set DD_API_KEY env variable!
78
+ end
79
+ ```
80
+
81
+ ### Added
82
+ * Profiling: Import java-profiler PID controller and port it to C ([#3190][])
83
+ * Tracing: Support Opensearch 3 ([#3189][])
84
+ * bump datadog-ci dependency to 0.2 ([#3186][])
85
+ * Enable allocation counting feature by default for some Ruby 3 versions ([#3176][])
86
+ * Tracing: Introduce async configuration for test mode to use standard writer when needed ([#3158][])
87
+ * Appsec: Update AppSec rules to 1.8.0 ([#3140][])
88
+ * Appsec: Update AppSec rules to 1.7.2 ([#3139][])
89
+ * Appsec: ASM API security. Schema extraction ([#3131][], [#3166][], [#3177][])
90
+ * Tracing: peer.service adjustment for sql propagation with DBM ([#3127][])
91
+ * Ci-app: CI visibility: validate git tags ([#3100][])
92
+ * Appsec: Enable configuring blocking response via Remote Configuration ([#3099][])
93
+ * Profiling: Record allocation type when sampling objects ([#3096][])
94
+ * Appsec: Uppgrade libddwaf-rb version to 1.11.0 ([#3087][])
95
+ * Profiling: Mergequeue-status: removed: Include 'ruby vm type' in profiler allocation samples ([#3074][])
96
+ * Detect WebMock to disable telemetry and remote configuration ([#3065][])
97
+ * Ensure Rails testing is considered a development environment ([#3062][])
98
+ * Tracing: Implements `_dd.base_service` tag ([#3018][])
99
+ * Appsec: Allow blocking response template configuration via ENV variables ([#2975][])
100
+ * Ci-app: agentless mode ([#3186][])
101
+
102
+ ### Changed
103
+ * Appsec: skip passing waf addresses when the value is empty ([#3188][])
104
+ * Tracing: Disable memcached command tag by default ([#3171][])
105
+ * Profiling: Upgrade to libdatadog 5 ([#3169][])
106
+ * Profiling: Restore support for Ruby 3.3 ([#3167][])
107
+ * Bump debase-ruby_core_source dependency to 3.2.2 ([#3163][])
108
+ * Profiling: Add approximate thread state categorization for timeline ([#3162][])
109
+ * Tracing: remove variable helpers module from our configuration DSL ([#3152][])
110
+ * Profiling: Tracing: ekump/decouple core transport ([#3150][])
111
+ * Test:Remove explicit dependency on `addressable` ([#3148][])
112
+ * Detect Cucumber as a development environment ([#3145][])
113
+ * Tracing: rename core configuration option on_set to after_set ([#3107][])
114
+ * Profiling: Upgrade to libdatadog 4 ([#3104][])
115
+ * Profiling: Wire up allocation sampling into `CpuAndWallTimeWorker` ([#3103][])
116
+ * Tracing: rename experimental_default_proc to default_proc ([#3091][])
117
+ * remove `delegate_to` configuration option from our DSL ([#3086][])
118
+ * Ci-app: Fix Datadog::CI::Environment to support the new CI specs ([#3080][])
119
+ * Tracing: Use first valid extracted style for distributed tracing ([#2879][])
120
+
121
+ ### Fixed
122
+ * Profiling: Add workaround for incorrect invoke location when logging gem is in use ([#3183][])
123
+ * Profiling: Fix missing endpoint profiling when request_queuing is enabled in rack instrumentation ([#3109][])
124
+ * Appsec: Fix a bug with ASM span tags reporting the number of WAF failed loaded rules ([#3106][])
125
+ * Tracing: Fix tagging with empty data ([#3102][])
126
+ * Tracing: fix(grpc): allow custom error_handler for client interceptor ([#3095][])
127
+ * Tracing: Correctly set `rails.cache.backend` span tag for multiple stores ([#3060][])
128
+
129
+ ### Removed
130
+ * Profiling: Remove legacy profiler codepath ([#3172][])
131
+ * Ci-app: remove CI module and add a dependency on datadog-ci gem ([#3128][])
132
+ * Tracing: Remove `depends_on` from Core Configuration option ([#3085][])
133
+
5
134
  ## [1.14.0] - 2023-08-24
6
135
 
7
136
  ### Added
@@ -2534,7 +2663,8 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1
2534
2663
 
2535
2664
  Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
2536
2665
 
2537
- [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v1.14.0...master
2666
+ [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v1.15.0...master
2667
+ [1.15.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.14.0...v1.15.0
2538
2668
  [1.14.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.13.1...1.14.0
2539
2669
  [1.13.1]: https://github.com/DataDog/dd-trace-rb/compare/v1.13.0...1.13.1
2540
2670
  [1.13.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.12.1...v1.13.0
@@ -3624,6 +3754,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3624
3754
  [#2874]: https://github.com/DataDog/dd-trace-rb/issues/2874
3625
3755
  [#2875]: https://github.com/DataDog/dd-trace-rb/issues/2875
3626
3756
  [#2877]: https://github.com/DataDog/dd-trace-rb/issues/2877
3757
+ [#2879]: https://github.com/DataDog/dd-trace-rb/issues/2879
3627
3758
  [#2882]: https://github.com/DataDog/dd-trace-rb/issues/2882
3628
3759
  [#2883]: https://github.com/DataDog/dd-trace-rb/issues/2883
3629
3760
  [#2890]: https://github.com/DataDog/dd-trace-rb/issues/2890
@@ -3659,6 +3790,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3659
3790
  [#2972]: https://github.com/DataDog/dd-trace-rb/issues/2972
3660
3791
  [#2973]: https://github.com/DataDog/dd-trace-rb/issues/2973
3661
3792
  [#2974]: https://github.com/DataDog/dd-trace-rb/issues/2974
3793
+ [#2975]: https://github.com/DataDog/dd-trace-rb/issues/2975
3662
3794
  [#2977]: https://github.com/DataDog/dd-trace-rb/issues/2977
3663
3795
  [#2978]: https://github.com/DataDog/dd-trace-rb/issues/2978
3664
3796
  [#2982]: https://github.com/DataDog/dd-trace-rb/issues/2982
@@ -3671,6 +3803,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3671
3803
  [#3005]: https://github.com/DataDog/dd-trace-rb/issues/3005
3672
3804
  [#3007]: https://github.com/DataDog/dd-trace-rb/issues/3007
3673
3805
  [#3011]: https://github.com/DataDog/dd-trace-rb/issues/3011
3806
+ [#3018]: https://github.com/DataDog/dd-trace-rb/issues/3018
3674
3807
  [#3019]: https://github.com/DataDog/dd-trace-rb/issues/3019
3675
3808
  [#3020]: https://github.com/DataDog/dd-trace-rb/issues/3020
3676
3809
  [#3022]: https://github.com/DataDog/dd-trace-rb/issues/3022
@@ -3685,8 +3818,51 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3685
3818
  [#3054]: https://github.com/DataDog/dd-trace-rb/issues/3054
3686
3819
  [#3056]: https://github.com/DataDog/dd-trace-rb/issues/3056
3687
3820
  [#3057]: https://github.com/DataDog/dd-trace-rb/issues/3057
3821
+ [#3060]: https://github.com/DataDog/dd-trace-rb/issues/3060
3688
3822
  [#3061]: https://github.com/DataDog/dd-trace-rb/issues/3061
3823
+ [#3062]: https://github.com/DataDog/dd-trace-rb/issues/3062
3824
+ [#3065]: https://github.com/DataDog/dd-trace-rb/issues/3065
3689
3825
  [#3070]: https://github.com/DataDog/dd-trace-rb/issues/3070
3826
+ [#3074]: https://github.com/DataDog/dd-trace-rb/issues/3074
3827
+ [#3080]: https://github.com/DataDog/dd-trace-rb/issues/3080
3828
+ [#3085]: https://github.com/DataDog/dd-trace-rb/issues/3085
3829
+ [#3086]: https://github.com/DataDog/dd-trace-rb/issues/3086
3830
+ [#3087]: https://github.com/DataDog/dd-trace-rb/issues/3087
3831
+ [#3091]: https://github.com/DataDog/dd-trace-rb/issues/3091
3832
+ [#3095]: https://github.com/DataDog/dd-trace-rb/issues/3095
3833
+ [#3096]: https://github.com/DataDog/dd-trace-rb/issues/3096
3834
+ [#3099]: https://github.com/DataDog/dd-trace-rb/issues/3099
3835
+ [#3100]: https://github.com/DataDog/dd-trace-rb/issues/3100
3836
+ [#3102]: https://github.com/DataDog/dd-trace-rb/issues/3102
3837
+ [#3103]: https://github.com/DataDog/dd-trace-rb/issues/3103
3838
+ [#3104]: https://github.com/DataDog/dd-trace-rb/issues/3104
3839
+ [#3106]: https://github.com/DataDog/dd-trace-rb/issues/3106
3840
+ [#3107]: https://github.com/DataDog/dd-trace-rb/issues/3107
3841
+ [#3109]: https://github.com/DataDog/dd-trace-rb/issues/3109
3842
+ [#3127]: https://github.com/DataDog/dd-trace-rb/issues/3127
3843
+ [#3128]: https://github.com/DataDog/dd-trace-rb/issues/3128
3844
+ [#3131]: https://github.com/DataDog/dd-trace-rb/issues/3131
3845
+ [#3139]: https://github.com/DataDog/dd-trace-rb/issues/3139
3846
+ [#3140]: https://github.com/DataDog/dd-trace-rb/issues/3140
3847
+ [#3145]: https://github.com/DataDog/dd-trace-rb/issues/3145
3848
+ [#3148]: https://github.com/DataDog/dd-trace-rb/issues/3148
3849
+ [#3150]: https://github.com/DataDog/dd-trace-rb/issues/3150
3850
+ [#3152]: https://github.com/DataDog/dd-trace-rb/issues/3152
3851
+ [#3158]: https://github.com/DataDog/dd-trace-rb/issues/3158
3852
+ [#3162]: https://github.com/DataDog/dd-trace-rb/issues/3162
3853
+ [#3163]: https://github.com/DataDog/dd-trace-rb/issues/3163
3854
+ [#3166]: https://github.com/DataDog/dd-trace-rb/issues/3166
3855
+ [#3167]: https://github.com/DataDog/dd-trace-rb/issues/3167
3856
+ [#3169]: https://github.com/DataDog/dd-trace-rb/issues/3169
3857
+ [#3171]: https://github.com/DataDog/dd-trace-rb/issues/3171
3858
+ [#3172]: https://github.com/DataDog/dd-trace-rb/issues/3172
3859
+ [#3176]: https://github.com/DataDog/dd-trace-rb/issues/3176
3860
+ [#3177]: https://github.com/DataDog/dd-trace-rb/issues/3177
3861
+ [#3183]: https://github.com/DataDog/dd-trace-rb/issues/3183
3862
+ [#3186]: https://github.com/DataDog/dd-trace-rb/issues/3186
3863
+ [#3188]: https://github.com/DataDog/dd-trace-rb/issues/3188
3864
+ [#3189]: https://github.com/DataDog/dd-trace-rb/issues/3189
3865
+ [#3190]: https://github.com/DataDog/dd-trace-rb/issues/3190
3690
3866
  [@AdrianLC]: https://github.com/AdrianLC
3691
3867
  [@Azure7111]: https://github.com/Azure7111
3692
3868
  [@BabyGroot]: https://github.com/BabyGroot
@@ -3838,4 +4014,4 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3838
4014
  [@y-yagi]: https://github.com/y-yagi
3839
4015
  [@yujideveloper]: https://github.com/yujideveloper
3840
4016
  [@yukimurasawa]: https://github.com/yukimurasawa
3841
- [@zachmccormick]: https://github.com/zachmccormick
4017
+ [@zachmccormick]: https://github.com/zachmccormick
@@ -16,8 +16,7 @@ the gem. Setting `DD_PROFILING_NO_EXTENSION` at installation time skips compilat
16
16
 
17
17
  (If you're a customer and needed to use this, please tell us why on <https://github.com/DataDog/dd-trace-rb/issues/new>.)
18
18
 
19
- In past releases, it was possible for the profiler to run without the native extension, but that's no longer the case,
20
- and disabling the extension will disable profiling.
19
+ Disabling the profiler extension will disable profiling.
21
20
 
22
21
  ## Who is this page for?
23
22
 
@@ -83,7 +82,7 @@ contribute upstream changes so that they become official public VM APIs.
83
82
  Ruby versions 2.6 to 3.2 shipped a JIT compiler called MJIT. This compiler does not directly generate machine code;
84
83
  instead it generates C code and uses the system C compiler to turn it into machine code.
85
84
 
86
- The generated C code `#include`s a private header -- which we reference as "the MJIT header" everywhere.
85
+ The generated C code `#include`s a private header -- which we call "the MJIT header".
87
86
  The MJIT header gets shipped with all MJIT-enabled Rubies and includes the layout of many internal VM structures;
88
87
  and of course the intention is that it is only used by the Ruby MJIT compiler.
89
88
 
@@ -104,8 +103,7 @@ Thus, even though a regular Ruby installation does not include these files, we c
104
103
  * **OS support**: Linux
105
104
 
106
105
  To enable CPU-time profiling, we use the `pthread_getcpuclockid(pthread_t thread, clockid_t *clockid)` C function to
107
- obtain a `clockid_t` that can then be used with the `Process.clock_gettime` method (or directly with the
108
- `clock_gettime()` C function).
106
+ obtain a `clockid_t` that can then be used with the `clock_gettime` function.
109
107
 
110
108
  The challenge with using `pthread_getcpuclockid()` is that we need to get the `pthread_t` for a given Ruby `Thread`
111
109
  object. We previously did this with a weird combination of monkey patching and `pthread_self()` (effectively patching
@@ -17,9 +17,6 @@ typedef struct thread_cpu_time {
17
17
 
18
18
  void self_test_clock_id(void);
19
19
 
20
- // TODO: Remove this after the OldStack profiler gets removed
21
- VALUE clock_id_for(VALUE self, VALUE thread);
22
-
23
20
  // Safety: This function is assumed never to raise exceptions by callers
24
21
  thread_cpu_time_id thread_cpu_time_id_for(VALUE thread);
25
22
  thread_cpu_time thread_cpu_time_for(thread_cpu_time_id time_id);
@@ -22,28 +22,6 @@ void self_test_clock_id(void) {
22
22
  if (expected_pthread_id != actual_pthread_id) rb_raise(rb_eRuntimeError, "pthread_id_for() self-test failed");
23
23
  }
24
24
 
25
- // TODO: Remove this after the OldStack profiler gets removed
26
- VALUE clock_id_for(DDTRACE_UNUSED VALUE _self, VALUE thread) {
27
- rb_nativethread_id_t thread_id = pthread_id_for(thread);
28
-
29
- clockid_t clock_id;
30
- int error = pthread_getcpuclockid(thread_id, &clock_id);
31
-
32
- if (error == 0) {
33
- return CLOCKID2NUM(clock_id);
34
- } else {
35
- switch(error) {
36
- // The more specific error messages are based on the pthread_getcpuclockid(3) man page
37
- case ENOENT:
38
- rb_exc_raise(rb_syserr_new(error, "Failed to get clock_id for given thread: Per-thread CPU time clocks are not supported by the system."));
39
- case ESRCH:
40
- rb_exc_raise(rb_syserr_new(error, "Failed to get clock_id for given thread: No thread could be found."));
41
- default:
42
- rb_exc_raise(rb_syserr_new(error, "Failed to get clock_id for given thread"));
43
- }
44
- }
45
- }
46
-
47
25
  // Safety: This function is assumed never to raise exceptions by callers
48
26
  thread_cpu_time_id thread_cpu_time_id_for(VALUE thread) {
49
27
  rb_nativethread_id_t thread_id = pthread_id_for(thread);
@@ -10,7 +10,6 @@
10
10
  #include "helpers.h"
11
11
 
12
12
  void self_test_clock_id(void) { } // Nothing to check
13
- VALUE clock_id_for(DDTRACE_UNUSED VALUE _self, DDTRACE_UNUSED VALUE _thread) { return Qnil; } // Nothing to return
14
13
 
15
14
  thread_cpu_time_id thread_cpu_time_id_for(DDTRACE_UNUSED VALUE _thread) {
16
15
  return (thread_cpu_time_id) {.valid = false};
@@ -83,6 +83,7 @@ struct cpu_and_wall_time_worker_state {
83
83
  bool allocation_counting_enabled;
84
84
  bool no_signals_workaround_enabled;
85
85
  bool dynamic_sampling_rate_enabled;
86
+ int allocation_sample_every; // Temporarily used for development/testing of allocation profiling
86
87
  VALUE self_instance;
87
88
  VALUE thread_context_collector_instance;
88
89
  VALUE idle_sampling_helper_instance;
@@ -150,7 +151,8 @@ static VALUE _native_initialize(
150
151
  VALUE idle_sampling_helper_instance,
151
152
  VALUE allocation_counting_enabled,
152
153
  VALUE no_signals_workaround_enabled,
153
- VALUE dynamic_sampling_rate_enabled
154
+ VALUE dynamic_sampling_rate_enabled,
155
+ VALUE allocation_sample_every
154
156
  );
155
157
  static void cpu_and_wall_time_worker_typed_data_mark(void *state_ptr);
156
158
  static VALUE _native_sampling_loop(VALUE self, VALUE instance);
@@ -183,9 +185,10 @@ static void grab_gvl_and_sample(void);
183
185
  static void reset_stats(struct cpu_and_wall_time_worker_state *state);
184
186
  static void sleep_for(uint64_t time_ns);
185
187
  static VALUE _native_allocation_count(DDTRACE_UNUSED VALUE self);
186
- static void on_newobj_event(DDTRACE_UNUSED VALUE tracepoint_data, DDTRACE_UNUSED void *unused);
188
+ static void on_newobj_event(VALUE tracepoint_data, DDTRACE_UNUSED void *unused);
187
189
  static void disable_tracepoints(struct cpu_and_wall_time_worker_state *state);
188
190
  static VALUE _native_with_blocked_sigprof(DDTRACE_UNUSED VALUE self);
191
+ static VALUE rescued_sample_allocation(VALUE tracepoint_data);
189
192
 
190
193
  // Note on sampler global state safety:
191
194
  //
@@ -223,7 +226,7 @@ void collectors_cpu_and_wall_time_worker_init(VALUE profiling_module) {
223
226
  // https://bugs.ruby-lang.org/issues/18007 for a discussion around this.
224
227
  rb_define_alloc_func(collectors_cpu_and_wall_time_worker_class, _native_new);
225
228
 
226
- rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_initialize", _native_initialize, 7);
229
+ rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_initialize", _native_initialize, 8);
227
230
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_sampling_loop", _native_sampling_loop, 1);
228
231
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_stop", _native_stop, 2);
229
232
  rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_reset_after_fork", _native_reset_after_fork, 1);
@@ -257,10 +260,14 @@ static const rb_data_type_t cpu_and_wall_time_worker_typed_data = {
257
260
  static VALUE _native_new(VALUE klass) {
258
261
  struct cpu_and_wall_time_worker_state *state = ruby_xcalloc(1, sizeof(struct cpu_and_wall_time_worker_state));
259
262
 
263
+ // Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory
264
+ // being leaked.
265
+
260
266
  state->gc_profiling_enabled = false;
261
267
  state->allocation_counting_enabled = false;
262
268
  state->no_signals_workaround_enabled = false;
263
269
  state->dynamic_sampling_rate_enabled = true;
270
+ state->allocation_sample_every = 0;
264
271
  state->thread_context_collector_instance = Qnil;
265
272
  state->idle_sampling_helper_instance = Qnil;
266
273
  state->owner_thread = Qnil;
@@ -287,12 +294,14 @@ static VALUE _native_initialize(
287
294
  VALUE idle_sampling_helper_instance,
288
295
  VALUE allocation_counting_enabled,
289
296
  VALUE no_signals_workaround_enabled,
290
- VALUE dynamic_sampling_rate_enabled
297
+ VALUE dynamic_sampling_rate_enabled,
298
+ VALUE allocation_sample_every
291
299
  ) {
292
300
  ENFORCE_BOOLEAN(gc_profiling_enabled);
293
301
  ENFORCE_BOOLEAN(allocation_counting_enabled);
294
302
  ENFORCE_BOOLEAN(no_signals_workaround_enabled);
295
303
  ENFORCE_BOOLEAN(dynamic_sampling_rate_enabled);
304
+ ENFORCE_TYPE(allocation_sample_every, T_FIXNUM);
296
305
 
297
306
  struct cpu_and_wall_time_worker_state *state;
298
307
  TypedData_Get_Struct(self_instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
@@ -301,6 +310,12 @@ static VALUE _native_initialize(
301
310
  state->allocation_counting_enabled = (allocation_counting_enabled == Qtrue);
302
311
  state->no_signals_workaround_enabled = (no_signals_workaround_enabled == Qtrue);
303
312
  state->dynamic_sampling_rate_enabled = (dynamic_sampling_rate_enabled == Qtrue);
313
+ state->allocation_sample_every = NUM2INT(allocation_sample_every);
314
+
315
+ if (state->allocation_sample_every < 0) {
316
+ rb_raise(rb_eArgError, "Unexpected value for allocation_sample_every: %d. This value must be >= 0.", state->allocation_sample_every);
317
+ }
318
+
304
319
  state->thread_context_collector_instance = enforce_thread_context_collector_instance(thread_context_collector_instance);
305
320
  state->idle_sampling_helper_instance = idle_sampling_helper_instance;
306
321
  state->gc_tracepoint = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_GC_ENTER | RUBY_INTERNAL_EVENT_GC_EXIT, on_gc_event, NULL /* unused */);
@@ -880,7 +895,7 @@ static VALUE _native_allocation_count(DDTRACE_UNUSED VALUE self) {
880
895
 
881
896
  // Implements memory-related profiling events. This function is called by Ruby via the `object_allocation_tracepoint`
882
897
  // when the RUBY_INTERNAL_EVENT_NEWOBJ event is triggered.
883
- static void on_newobj_event(DDTRACE_UNUSED VALUE tracepoint_data, DDTRACE_UNUSED void *unused) {
898
+ static void on_newobj_event(VALUE tracepoint_data, DDTRACE_UNUSED void *unused) {
884
899
  // Update thread-local allocation count
885
900
  if (RB_UNLIKELY(allocation_count == UINT64_MAX)) {
886
901
  allocation_count = 0;
@@ -907,7 +922,12 @@ static void on_newobj_event(DDTRACE_UNUSED VALUE tracepoint_data, DDTRACE_UNUSED
907
922
  // defined as not being able to allocate) sets this.
908
923
  state->during_sample = true;
909
924
 
910
- // TODO: Sampling goes here (calling into `thread_context_collector_sample_allocation`)
925
+ // TODO: This is a placeholder sampling decision strategy. We plan to replace it with a better one soon (e.g. before
926
+ // beta), and having something here allows us to test the rest of feature, sampling decision aside.
927
+ if (state->allocation_sample_every > 0 && ((allocation_count % state->allocation_sample_every) == 0)) {
928
+ // Rescue against any exceptions that happen during sampling
929
+ safely_call(rescued_sample_allocation, tracepoint_data, state->self_instance);
930
+ }
911
931
 
912
932
  state->during_sample = false;
913
933
  }
@@ -929,3 +949,18 @@ static VALUE _native_with_blocked_sigprof(DDTRACE_UNUSED VALUE self) {
929
949
  return result;
930
950
  }
931
951
  }
952
+
953
+ static VALUE rescued_sample_allocation(VALUE tracepoint_data) {
954
+ struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
955
+
956
+ // This should not happen in a normal situation because on_newobj_event already checked for this, but just in case...
957
+ if (state == NULL) return Qnil;
958
+
959
+ rb_trace_arg_t *data = rb_tracearg_from_tracepoint(tracepoint_data);
960
+ VALUE new_object = rb_tracearg_object(data);
961
+
962
+ thread_context_collector_sample_allocation(state->thread_context_collector_instance, state->allocation_sample_every, new_object);
963
+
964
+ // Return a dummy VALUE because we're called from rb_rescue2 which requires it
965
+ return Qnil;
966
+ }
@@ -78,6 +78,9 @@ static const rb_data_type_t idle_sampling_helper_typed_data = {
78
78
  static VALUE _native_new(VALUE klass) {
79
79
  struct idle_sampling_loop_state *state = ruby_xcalloc(1, sizeof(struct idle_sampling_loop_state));
80
80
 
81
+ // Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory
82
+ // being leaked.
83
+
81
84
  reset_state(state);
82
85
 
83
86
  return TypedData_Wrap_Struct(klass, &idle_sampling_helper_typed_data, state);