ddtrace 1.14.0 → 1.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +146 -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 +67 -2
  31. data/lib/datadog/appsec/contrib/rack/gateway/request.rb +6 -2
  32. data/lib/datadog/appsec/contrib/rack/gateway/response.rb +46 -0
  33. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
  34. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +2 -7
  35. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +2 -5
  36. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +7 -5
  37. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
  38. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +34 -10
  39. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
  40. data/lib/datadog/appsec/contrib/rails/patcher.rb +9 -3
  41. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +2 -5
  42. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
  43. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
  44. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +2 -5
  45. data/lib/datadog/appsec/event.rb +106 -50
  46. data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
  47. data/lib/datadog/appsec/monitor/reactive/set_user.rb +2 -5
  48. data/lib/datadog/appsec/processor/actions.rb +49 -0
  49. data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
  50. data/lib/datadog/appsec/processor.rb +34 -6
  51. data/lib/datadog/appsec/remote.rb +4 -1
  52. data/lib/datadog/appsec/response.rb +82 -4
  53. data/lib/datadog/appsec/sample_rate.rb +21 -0
  54. data/lib/datadog/appsec.rb +2 -2
  55. data/lib/datadog/core/configuration/agent_settings_resolver.rb +29 -24
  56. data/lib/datadog/core/configuration/base.rb +1 -11
  57. data/lib/datadog/core/configuration/components.rb +7 -2
  58. data/lib/datadog/core/configuration/ext.rb +21 -0
  59. data/lib/datadog/core/configuration/option.rb +2 -4
  60. data/lib/datadog/core/configuration/option_definition.rb +17 -41
  61. data/lib/datadog/core/configuration/options.rb +5 -5
  62. data/lib/datadog/core/configuration/settings.rb +47 -45
  63. data/lib/datadog/core/environment/execution.rb +47 -9
  64. data/lib/datadog/core/environment/variable_helpers.rb +0 -69
  65. data/lib/datadog/core/error.rb +1 -0
  66. data/lib/datadog/core/git/ext.rb +2 -0
  67. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  68. data/lib/datadog/core/remote/component.rb +2 -2
  69. data/lib/datadog/core/remote/negotiation.rb +2 -2
  70. data/lib/datadog/core/remote/transport/config.rb +60 -0
  71. data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
  72. data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
  73. data/lib/datadog/core/remote/transport/http/api.rb +58 -0
  74. data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
  75. data/lib/datadog/core/remote/transport/http/client.rb +48 -0
  76. data/lib/datadog/core/remote/transport/http/config.rb +280 -0
  77. data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
  78. data/lib/datadog/core/remote/transport/http.rb +179 -0
  79. data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
  80. data/lib/datadog/core/remote/worker.rb +3 -1
  81. data/lib/datadog/core/telemetry/collector.rb +3 -2
  82. data/lib/datadog/core/telemetry/http/transport.rb +2 -1
  83. data/lib/datadog/core/transport/ext.rb +47 -0
  84. data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
  85. data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
  86. data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
  87. data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
  88. data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
  89. data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
  90. data/lib/datadog/core/transport/http/api/map.rb +18 -0
  91. data/lib/datadog/core/transport/http/env.rb +62 -0
  92. data/lib/datadog/core/transport/http/response.rb +60 -0
  93. data/lib/datadog/core/transport/parcel.rb +22 -0
  94. data/lib/datadog/core/transport/request.rb +17 -0
  95. data/lib/datadog/core/transport/response.rb +64 -0
  96. data/lib/datadog/core/workers/polling.rb +2 -2
  97. data/lib/datadog/opentelemetry/api/context.rb +10 -3
  98. data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
  99. data/lib/datadog/opentelemetry/sdk/span_processor.rb +14 -2
  100. data/lib/datadog/opentelemetry/sdk/trace/span.rb +68 -0
  101. data/lib/datadog/opentelemetry/trace.rb +58 -0
  102. data/lib/datadog/opentelemetry.rb +1 -0
  103. data/lib/datadog/opentracer.rb +9 -0
  104. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +14 -19
  105. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  106. data/lib/datadog/profiling/collectors/thread_context.rb +9 -1
  107. data/lib/datadog/profiling/component.rb +24 -99
  108. data/lib/datadog/profiling/ext.rb +0 -12
  109. data/lib/datadog/profiling/flush.rb +0 -3
  110. data/lib/datadog/profiling/http_transport.rb +6 -3
  111. data/lib/datadog/profiling/native_extension.rb +0 -21
  112. data/lib/datadog/profiling/profiler.rb +36 -13
  113. data/lib/datadog/profiling/scheduler.rb +16 -9
  114. data/lib/datadog/profiling.rb +8 -81
  115. data/lib/datadog/tracing/component.rb +10 -4
  116. data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
  117. data/lib/datadog/tracing/configuration/ext.rb +4 -2
  118. data/lib/datadog/tracing/configuration/settings.rb +14 -7
  119. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -1
  120. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -1
  121. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
  122. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +106 -197
  123. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
  124. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +7 -0
  125. data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +14 -14
  126. data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +3 -10
  127. data/lib/datadog/tracing/contrib/concurrent_ruby/integration.rb +2 -1
  128. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +8 -1
  129. data/lib/datadog/tracing/contrib/concurrent_ruby/promises_future_patch.rb +22 -0
  130. data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
  131. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -0
  132. data/lib/datadog/tracing/contrib/dalli/ext.rb +7 -0
  133. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +9 -2
  134. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -1
  135. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +5 -0
  136. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -0
  137. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +8 -0
  138. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -0
  139. data/lib/datadog/tracing/contrib/ext.rb +3 -0
  140. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
  141. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -0
  142. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +21 -1
  143. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +11 -1
  144. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +18 -0
  145. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
  146. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +3 -3
  147. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -0
  148. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -0
  149. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -0
  150. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +7 -0
  151. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +13 -3
  152. data/lib/datadog/tracing/contrib/opensearch/integration.rb +2 -2
  153. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +7 -0
  154. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +5 -0
  155. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +5 -0
  156. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
  157. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -1
  158. data/lib/datadog/tracing/contrib/racecar/event.rb +5 -0
  159. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +14 -4
  160. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -4
  161. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -1
  162. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +1 -1
  163. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +3 -38
  164. data/lib/datadog/tracing/contrib/redis/tags.rb +7 -2
  165. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +46 -33
  166. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -1
  167. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -0
  168. data/lib/datadog/tracing/contrib/sequel/utils.rb +5 -0
  169. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -1
  170. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -1
  171. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -1
  172. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  173. data/lib/datadog/tracing/diagnostics/environment_logger.rb +6 -0
  174. data/lib/datadog/tracing/distributed/propagation.rb +13 -33
  175. data/lib/datadog/tracing/metadata/tagging.rb +3 -3
  176. data/lib/datadog/tracing/sync_writer.rb +3 -3
  177. data/lib/datadog/tracing/tracer.rb +2 -0
  178. data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
  179. data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
  180. data/lib/datadog/tracing/transport/http/api.rb +43 -0
  181. data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
  182. data/lib/datadog/tracing/transport/http/client.rb +57 -0
  183. data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
  184. data/lib/datadog/tracing/transport/http/traces.rb +152 -0
  185. data/lib/datadog/tracing/transport/http.rb +124 -0
  186. data/lib/datadog/tracing/transport/io/client.rb +89 -0
  187. data/lib/datadog/tracing/transport/io/response.rb +27 -0
  188. data/lib/datadog/tracing/transport/io/traces.rb +101 -0
  189. data/lib/datadog/tracing/transport/io.rb +30 -0
  190. data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
  191. data/lib/datadog/tracing/transport/statistics.rb +77 -0
  192. data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
  193. data/lib/datadog/tracing/transport/traces.rb +224 -0
  194. data/lib/datadog/tracing/workers/trace_writer.rb +5 -3
  195. data/lib/datadog/tracing/workers.rb +3 -2
  196. data/lib/datadog/tracing/writer.rb +5 -2
  197. data/lib/ddtrace/transport/ext.rb +17 -15
  198. data/lib/ddtrace/version.rb +1 -1
  199. data/lib/ddtrace.rb +1 -1
  200. metadata +73 -96
  201. data/lib/datadog/ci/configuration/components.rb +0 -32
  202. data/lib/datadog/ci/configuration/settings.rb +0 -51
  203. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -35
  204. data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -22
  205. data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
  206. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
  207. data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
  208. data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
  209. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +0 -35
  210. data/lib/datadog/ci/contrib/minitest/ext.rb +0 -21
  211. data/lib/datadog/ci/contrib/minitest/integration.rb +0 -49
  212. data/lib/datadog/ci/contrib/minitest/patcher.rb +0 -27
  213. data/lib/datadog/ci/contrib/minitest/test_helper.rb +0 -68
  214. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -35
  215. data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
  216. data/lib/datadog/ci/contrib/rspec/ext.rb +0 -21
  217. data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
  218. data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
  219. data/lib/datadog/ci/ext/app_types.rb +0 -9
  220. data/lib/datadog/ci/ext/environment.rb +0 -575
  221. data/lib/datadog/ci/ext/settings.rb +0 -10
  222. data/lib/datadog/ci/ext/test.rb +0 -35
  223. data/lib/datadog/ci/extensions.rb +0 -19
  224. data/lib/datadog/ci/flush.rb +0 -38
  225. data/lib/datadog/ci/test.rb +0 -81
  226. data/lib/datadog/ci.rb +0 -21
  227. data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
  228. data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
  229. data/lib/datadog/core/configuration/option_set.rb +0 -10
  230. data/lib/datadog/core/transport/config.rb +0 -58
  231. data/lib/datadog/core/transport/http/api.rb +0 -57
  232. data/lib/datadog/core/transport/http/client.rb +0 -45
  233. data/lib/datadog/core/transport/http/config.rb +0 -278
  234. data/lib/datadog/core/transport/http/negotiation.rb +0 -144
  235. data/lib/datadog/core/transport/http.rb +0 -169
  236. data/lib/datadog/core/utils/object_set.rb +0 -43
  237. data/lib/datadog/core/utils/string_table.rb +0 -47
  238. data/lib/datadog/profiling/backtrace_location.rb +0 -34
  239. data/lib/datadog/profiling/buffer.rb +0 -43
  240. data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
  241. data/lib/datadog/profiling/encoding/profile.rb +0 -41
  242. data/lib/datadog/profiling/event.rb +0 -15
  243. data/lib/datadog/profiling/events/stack.rb +0 -82
  244. data/lib/datadog/profiling/old_recorder.rb +0 -107
  245. data/lib/datadog/profiling/pprof/builder.rb +0 -125
  246. data/lib/datadog/profiling/pprof/converter.rb +0 -102
  247. data/lib/datadog/profiling/pprof/message_set.rb +0 -16
  248. data/lib/datadog/profiling/pprof/payload.rb +0 -20
  249. data/lib/datadog/profiling/pprof/pprof.proto +0 -212
  250. data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
  251. data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
  252. data/lib/datadog/profiling/pprof/string_table.rb +0 -12
  253. data/lib/datadog/profiling/pprof/template.rb +0 -118
  254. data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
  255. data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
  256. data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
  257. data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
  258. data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
  259. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
  260. data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
  261. data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
  262. data/lib/ddtrace/transport/http/api/instance.rb +0 -35
  263. data/lib/ddtrace/transport/http/api/map.rb +0 -16
  264. data/lib/ddtrace/transport/http/api/spec.rb +0 -17
  265. data/lib/ddtrace/transport/http/api.rb +0 -39
  266. data/lib/ddtrace/transport/http/builder.rb +0 -176
  267. data/lib/ddtrace/transport/http/client.rb +0 -52
  268. data/lib/ddtrace/transport/http/env.rb +0 -58
  269. data/lib/ddtrace/transport/http/response.rb +0 -58
  270. data/lib/ddtrace/transport/http/statistics.rb +0 -43
  271. data/lib/ddtrace/transport/http/traces.rb +0 -144
  272. data/lib/ddtrace/transport/http.rb +0 -117
  273. data/lib/ddtrace/transport/io/client.rb +0 -85
  274. data/lib/ddtrace/transport/io/response.rb +0 -25
  275. data/lib/ddtrace/transport/io/traces.rb +0 -99
  276. data/lib/ddtrace/transport/io.rb +0 -28
  277. data/lib/ddtrace/transport/parcel.rb +0 -20
  278. data/lib/ddtrace/transport/request.rb +0 -15
  279. data/lib/ddtrace/transport/response.rb +0 -60
  280. data/lib/ddtrace/transport/serializable_trace.rb +0 -122
  281. data/lib/ddtrace/transport/statistics.rb +0 -75
  282. data/lib/ddtrace/transport/trace_formatter.rb +0 -207
  283. 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: 59aaa9c3c11af9219405c9eee4e318df4cafdaae57eb42c7b5105d46764d3293
4
+ data.tar.gz: ef0d6766221287a4e9d42bf42f43fd5ddd81990ea381e536b5083be8a3f0b94d
5
5
  SHA512:
6
- metadata.gz: 4b4cdffa9d4ee39e6763be4a87dbdf3e351fd29915d4eaea45dc9c800543c65c8eb21375138422280cfed5715d8f23e95e58190752af6631c14453d39b29b263
7
- data.tar.gz: fbc970e48e5e5038775368618e672ab7b2405cd6ea9b899136b34e9ae776f26a92436087fb0810ef7d66574c2f694cdea03197cf980b08dc35a9defcf4c3dc74
6
+ metadata.gz: 0201e1fd1e96ea0a076cf88af3824cb02f15862312eb26688db474caec2698bdfee9381b947e4ab278bbaa752aeb8a92df2f2188aa7e4ba988e5cdc31331f138
7
+ data.tar.gz: 2a034e4187f41b85a29d7003fbe1098552cdddf0be663e490ab2ca71c4da40a8ad122f3357b11286af10df988f0891cc8d2d71ca59d9949db790dda6011033d0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,91 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [1.16.0] - 2023-11-03
6
+
7
+ **This release includes a security change for the Tracing Redis integration:**
8
+
9
+ Currently, the Datadog Agent removes command arguments from the resource name. However there are cases, like Redis compressed keys, where this obfuscation cannot correctly remove command arguments. To safeguard that situation, the resource name set by the tracer will only be the command (e.g. `SET`) with no arguments. To retain the previous behavior and keep arguments in the span resource, with the potential risk of some command arguments not being fully obfuscated, set ``DD_REDIS_COMMAND_ARGS=true`` or set the option `c.instrument :redis, command_args: true`.
10
+
11
+ ### Added
12
+
13
+ * Tracing: Propagate trace through `Concurrent::Promises.future` ([#1522][])
14
+ * Core: Name `Datadog::Core::Remote::Worker` thread ([#3207][])
15
+
16
+ ### Changed
17
+
18
+ * Tracing: Redis - Omit command arguments from span.resource by default ([#3235][])
19
+ * Ci-app: Bump `datadog-ci` dependency from 0.2.0 to 0.3.0 ([#3223][])
20
+
21
+ ### Fixed
22
+
23
+ * Appsec: ASM parse response body ([#3153][])
24
+ * Appsec: ASM make sure to append content type and length information ([#3204][])
25
+ * Appsec: Make sure function that checks content-type header value accepts nil content-type header value ([#3234][])
26
+ * Profiling: Shut down profiler if any components failed ([#3197][])
27
+ * Tracing: Fix `ActiveSupport` instrumentation of custom cache stores ([#3206][])
28
+
29
+ ## [1.15.0] - 2023-10-09
30
+
31
+ ### Highlights
32
+
33
+ * Timeline view for Profiler beta
34
+ * Configure AppSec blocking responses via configuration or Remote Configuration
35
+ * CI visibility to configure with agentless mode
36
+
37
+ For more details, check the [release notes](https://github.com/DataDog/dd-trace-rb/releases/tag/v1.15.0)
38
+
39
+ ### Added
40
+
41
+ * Enable allocation counting feature by default for some Ruby 3 versions ([#3176][])
42
+ * Detect `WebMock` `Cucumber` and `Rails.env` to disable telemetry and remote configuration for development environment ([#3065][], [#3062][], [#3145][])
43
+ * Profiling: Import java-profiler PID controller and port it to C ([#3190][])
44
+ * Profiling: Record allocation type when sampling objects ([#3096][])
45
+ * Profiling: Include `ruby vm type` in profiler allocation samples ([#3074][])
46
+ * Tracing: Support `Rack` 3 ([#3132][])
47
+ * Tracing: Support `Opensearch` 3 ([#3189][])
48
+ * Tracing: `grpc` adds `client_error_handler` option ([#3095][])
49
+ * Tracing: Add `async` option for `test_mode` configuration ([#3158][])
50
+ * Tracing: Implements `_dd.base_service` tag ([#3018][])
51
+ * Appsec: Allow blocking response template configuration via ENV variables ([#2975][])
52
+ * Appsec: ASM API security. Schema extraction ([#3131][], [#3166][], [#3177][])
53
+ * Appsec: Enable configuring blocking response via Remote Configuration ([#3099][])
54
+ * Ci-app: Validate git tags ([#3100][])
55
+ * Ci-app: Add agentless mode ([#3186][])
56
+
57
+ ### Changed
58
+
59
+ * Appsec: Skip passing waf addresses when the value is empty ([#3188][])
60
+ * Profiling: Restore support for Ruby 3.3 ([#3167][])
61
+ * Profiling: Add approximate thread state categorization for timeline ([#3162][])
62
+ * Profiling: Wire up allocation sampling into `CpuAndWallTimeWorker` ([#3103][])
63
+ * Tracing: `dalli` disable memcached command tag by default ([#3171][])
64
+ * Tracing: Use first valid extracted style for distributed tracing ([#2879][])
65
+ * Tracing: Rename configuration option `on_set` to `after_set` ([#3107][])
66
+ * Tracing: Rename `experimental_default_proc` to `default_proc` ([#3091][])
67
+ * Tracing: Use `peer.service` for sql comment propagation ([#3127][])
68
+ * Ci-app: Fix `Datadog::CI::Environment` to support the new CI specs ([#3080][])
69
+ * Bump `datadog-ci` dependency to 0.2 ([#3186][])
70
+ * Bump `debase-ruby_core_source` dependency to 3.2.2 ([#3163][])
71
+ * Upgrade `libdatadog` 5 ([#3169][], [#3104][])
72
+ * Upgrade `libddwaf-rb` 1.11.0 ([#3087][])
73
+ * Update AppSec rules to 1.8.0 ([#3140][], [#3139][])
74
+
75
+ ### Fixed
76
+
77
+ * Profiling: Add workaround for incorrect invoke location when logging gem is in use ([#3183][])
78
+ * Profiling: Fix missing endpoint profiling when `request_queuing` is enabled in `rack` instrumentation ([#3109][])
79
+ * Appsec: Span tags reporting the number of WAF failed loaded rules ([#3106][])
80
+ * Tracing: Fix tagging with empty data ([#3102][])
81
+ * Tracing: Fix `rails.cache.backend` span tag with multiple stores ([#3060][])
82
+
83
+ ### Removed
84
+
85
+ * Profiling: Remove legacy profiler codepath ([#3172][])
86
+ * Ci-app: Remove CI module and add a dependency on [`datadog-ci` gem](https://github.com/DataDog/datadog-ci-rb) ([#3128][])
87
+ * Tracing: Remove `depends_on` option from configuration DSL ([#3085][])
88
+ * Tracing: Remove `delegate_to` option from configuration DSL ([#3086][])
89
+
5
90
  ## [1.14.0] - 2023-08-24
6
91
 
7
92
  ### Added
@@ -2534,7 +2619,10 @@ Release notes: https://github.com/DataDog/dd-trace-rb/releases/tag/v0.3.1
2534
2619
 
2535
2620
  Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
2536
2621
 
2537
- [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v1.14.0...master
2622
+
2623
+ [Unreleased]: https://github.com/DataDog/dd-trace-rb/compare/v1.16.0...master
2624
+ [1.16.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.15.0...v1.16.0
2625
+ [1.15.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.14.0...v1.15.0
2538
2626
  [1.14.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.13.1...1.14.0
2539
2627
  [1.13.1]: https://github.com/DataDog/dd-trace-rb/compare/v1.13.0...1.13.1
2540
2628
  [1.13.0]: https://github.com/DataDog/dd-trace-rb/compare/v1.12.1...v1.13.0
@@ -3271,6 +3359,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3271
3359
  [#1509]: https://github.com/DataDog/dd-trace-rb/issues/1509
3272
3360
  [#1510]: https://github.com/DataDog/dd-trace-rb/issues/1510
3273
3361
  [#1511]: https://github.com/DataDog/dd-trace-rb/issues/1511
3362
+ [#1522]: https://github.com/DataDog/dd-trace-rb/issues/1522
3274
3363
  [#1523]: https://github.com/DataDog/dd-trace-rb/issues/1523
3275
3364
  [#1524]: https://github.com/DataDog/dd-trace-rb/issues/1524
3276
3365
  [#1529]: https://github.com/DataDog/dd-trace-rb/issues/1529
@@ -3624,6 +3713,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3624
3713
  [#2874]: https://github.com/DataDog/dd-trace-rb/issues/2874
3625
3714
  [#2875]: https://github.com/DataDog/dd-trace-rb/issues/2875
3626
3715
  [#2877]: https://github.com/DataDog/dd-trace-rb/issues/2877
3716
+ [#2879]: https://github.com/DataDog/dd-trace-rb/issues/2879
3627
3717
  [#2882]: https://github.com/DataDog/dd-trace-rb/issues/2882
3628
3718
  [#2883]: https://github.com/DataDog/dd-trace-rb/issues/2883
3629
3719
  [#2890]: https://github.com/DataDog/dd-trace-rb/issues/2890
@@ -3659,6 +3749,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3659
3749
  [#2972]: https://github.com/DataDog/dd-trace-rb/issues/2972
3660
3750
  [#2973]: https://github.com/DataDog/dd-trace-rb/issues/2973
3661
3751
  [#2974]: https://github.com/DataDog/dd-trace-rb/issues/2974
3752
+ [#2975]: https://github.com/DataDog/dd-trace-rb/issues/2975
3662
3753
  [#2977]: https://github.com/DataDog/dd-trace-rb/issues/2977
3663
3754
  [#2978]: https://github.com/DataDog/dd-trace-rb/issues/2978
3664
3755
  [#2982]: https://github.com/DataDog/dd-trace-rb/issues/2982
@@ -3671,6 +3762,7 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3671
3762
  [#3005]: https://github.com/DataDog/dd-trace-rb/issues/3005
3672
3763
  [#3007]: https://github.com/DataDog/dd-trace-rb/issues/3007
3673
3764
  [#3011]: https://github.com/DataDog/dd-trace-rb/issues/3011
3765
+ [#3018]: https://github.com/DataDog/dd-trace-rb/issues/3018
3674
3766
  [#3019]: https://github.com/DataDog/dd-trace-rb/issues/3019
3675
3767
  [#3020]: https://github.com/DataDog/dd-trace-rb/issues/3020
3676
3768
  [#3022]: https://github.com/DataDog/dd-trace-rb/issues/3022
@@ -3685,8 +3777,60 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3685
3777
  [#3054]: https://github.com/DataDog/dd-trace-rb/issues/3054
3686
3778
  [#3056]: https://github.com/DataDog/dd-trace-rb/issues/3056
3687
3779
  [#3057]: https://github.com/DataDog/dd-trace-rb/issues/3057
3780
+ [#3060]: https://github.com/DataDog/dd-trace-rb/issues/3060
3688
3781
  [#3061]: https://github.com/DataDog/dd-trace-rb/issues/3061
3782
+ [#3062]: https://github.com/DataDog/dd-trace-rb/issues/3062
3783
+ [#3065]: https://github.com/DataDog/dd-trace-rb/issues/3065
3689
3784
  [#3070]: https://github.com/DataDog/dd-trace-rb/issues/3070
3785
+ [#3074]: https://github.com/DataDog/dd-trace-rb/issues/3074
3786
+ [#3080]: https://github.com/DataDog/dd-trace-rb/issues/3080
3787
+ [#3085]: https://github.com/DataDog/dd-trace-rb/issues/3085
3788
+ [#3086]: https://github.com/DataDog/dd-trace-rb/issues/3086
3789
+ [#3087]: https://github.com/DataDog/dd-trace-rb/issues/3087
3790
+ [#3091]: https://github.com/DataDog/dd-trace-rb/issues/3091
3791
+ [#3095]: https://github.com/DataDog/dd-trace-rb/issues/3095
3792
+ [#3096]: https://github.com/DataDog/dd-trace-rb/issues/3096
3793
+ [#3099]: https://github.com/DataDog/dd-trace-rb/issues/3099
3794
+ [#3100]: https://github.com/DataDog/dd-trace-rb/issues/3100
3795
+ [#3102]: https://github.com/DataDog/dd-trace-rb/issues/3102
3796
+ [#3103]: https://github.com/DataDog/dd-trace-rb/issues/3103
3797
+ [#3104]: https://github.com/DataDog/dd-trace-rb/issues/3104
3798
+ [#3106]: https://github.com/DataDog/dd-trace-rb/issues/3106
3799
+ [#3107]: https://github.com/DataDog/dd-trace-rb/issues/3107
3800
+ [#3109]: https://github.com/DataDog/dd-trace-rb/issues/3109
3801
+ [#3127]: https://github.com/DataDog/dd-trace-rb/issues/3127
3802
+ [#3128]: https://github.com/DataDog/dd-trace-rb/issues/3128
3803
+ [#3131]: https://github.com/DataDog/dd-trace-rb/issues/3131
3804
+ [#3132]: https://github.com/DataDog/dd-trace-rb/issues/3132
3805
+ [#3139]: https://github.com/DataDog/dd-trace-rb/issues/3139
3806
+ [#3140]: https://github.com/DataDog/dd-trace-rb/issues/3140
3807
+ [#3145]: https://github.com/DataDog/dd-trace-rb/issues/3145
3808
+ [#3148]: https://github.com/DataDog/dd-trace-rb/issues/3148
3809
+ [#3150]: https://github.com/DataDog/dd-trace-rb/issues/3150
3810
+ [#3152]: https://github.com/DataDog/dd-trace-rb/issues/3152
3811
+ [#3153]: https://github.com/DataDog/dd-trace-rb/issues/3153
3812
+ [#3158]: https://github.com/DataDog/dd-trace-rb/issues/3158
3813
+ [#3162]: https://github.com/DataDog/dd-trace-rb/issues/3162
3814
+ [#3163]: https://github.com/DataDog/dd-trace-rb/issues/3163
3815
+ [#3166]: https://github.com/DataDog/dd-trace-rb/issues/3166
3816
+ [#3167]: https://github.com/DataDog/dd-trace-rb/issues/3167
3817
+ [#3169]: https://github.com/DataDog/dd-trace-rb/issues/3169
3818
+ [#3171]: https://github.com/DataDog/dd-trace-rb/issues/3171
3819
+ [#3172]: https://github.com/DataDog/dd-trace-rb/issues/3172
3820
+ [#3176]: https://github.com/DataDog/dd-trace-rb/issues/3176
3821
+ [#3177]: https://github.com/DataDog/dd-trace-rb/issues/3177
3822
+ [#3183]: https://github.com/DataDog/dd-trace-rb/issues/3183
3823
+ [#3186]: https://github.com/DataDog/dd-trace-rb/issues/3186
3824
+ [#3188]: https://github.com/DataDog/dd-trace-rb/issues/3188
3825
+ [#3189]: https://github.com/DataDog/dd-trace-rb/issues/3189
3826
+ [#3190]: https://github.com/DataDog/dd-trace-rb/issues/3190
3827
+ [#3197]: https://github.com/DataDog/dd-trace-rb/issues/3197
3828
+ [#3204]: https://github.com/DataDog/dd-trace-rb/issues/3204
3829
+ [#3206]: https://github.com/DataDog/dd-trace-rb/issues/3206
3830
+ [#3207]: https://github.com/DataDog/dd-trace-rb/issues/3207
3831
+ [#3223]: https://github.com/DataDog/dd-trace-rb/issues/3223
3832
+ [#3234]: https://github.com/DataDog/dd-trace-rb/issues/3234
3833
+ [#3235]: https://github.com/DataDog/dd-trace-rb/issues/3235
3690
3834
  [@AdrianLC]: https://github.com/AdrianLC
3691
3835
  [@Azure7111]: https://github.com/Azure7111
3692
3836
  [@BabyGroot]: https://github.com/BabyGroot
@@ -3838,4 +3982,4 @@ Git diff: https://github.com/DataDog/dd-trace-rb/compare/v0.3.0...v0.3.1
3838
3982
  [@y-yagi]: https://github.com/y-yagi
3839
3983
  [@yujideveloper]: https://github.com/yujideveloper
3840
3984
  [@yukimurasawa]: https://github.com/yukimurasawa
3841
- [@zachmccormick]: https://github.com/zachmccormick
3985
+ [@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);
@@ -23,7 +23,6 @@ struct sampling_buffer {
23
23
  int *lines_buffer;
24
24
  bool *is_ruby_frame;
25
25
  ddog_prof_Location *locations;
26
- ddog_prof_Line *lines;
27
26
  }; // Note: typedef'd in the header to sampling_buffer
28
27
 
29
28
  static VALUE _native_sample(
@@ -41,7 +40,7 @@ static void record_placeholder_stack_in_native_code(
41
40
  sampling_buffer* buffer,
42
41
  VALUE recorder_instance,
43
42
  sample_values values,
44
- ddog_prof_Slice_Label labels,
43
+ sample_labels labels,
45
44
  sampling_buffer *record_buffer,
46
45
  int extra_frames_in_record_buffer
47
46
  );
@@ -50,7 +49,7 @@ static void sample_thread_internal(
50
49
  sampling_buffer* buffer,
51
50
  VALUE recorder_instance,
52
51
  sample_values values,
53
- ddog_prof_Slice_Label labels,
52
+ sample_labels labels,
54
53
  sampling_buffer *record_buffer,
55
54
  int extra_frames_in_record_buffer
56
55
  );
@@ -86,13 +85,14 @@ static VALUE _native_sample(
86
85
  VALUE zero = INT2NUM(0);
87
86
  sample_values values = {
88
87
  .cpu_time_ns = NUM2UINT(rb_hash_lookup2(metric_values_hash, rb_str_new_cstr("cpu-time"), zero)),
89
- .cpu_samples = NUM2UINT(rb_hash_lookup2(metric_values_hash, rb_str_new_cstr("cpu-samples"), zero)),
88
+ .cpu_or_wall_samples = NUM2UINT(rb_hash_lookup2(metric_values_hash, rb_str_new_cstr("cpu-samples"), zero)),
90
89
  .wall_time_ns = NUM2UINT(rb_hash_lookup2(metric_values_hash, rb_str_new_cstr("wall-time"), zero)),
91
90
  .alloc_samples = NUM2UINT(rb_hash_lookup2(metric_values_hash, rb_str_new_cstr("alloc-samples"), zero)),
92
91
  };
93
92
 
94
93
  long labels_count = RARRAY_LEN(labels_array) + RARRAY_LEN(numeric_labels_array);
95
94
  ddog_prof_Label labels[labels_count];
95
+ ddog_prof_Label *state_label = NULL;
96
96
 
97
97
  for (int i = 0; i < RARRAY_LEN(labels_array); i++) {
98
98
  VALUE key_str_pair = rb_ary_entry(labels_array, i);
@@ -101,6 +101,10 @@ static VALUE _native_sample(
101
101
  .key = char_slice_from_ruby_string(rb_ary_entry(key_str_pair, 0)),
102
102
  .str = char_slice_from_ruby_string(rb_ary_entry(key_str_pair, 1))
103
103
  };
104
+
105
+ if (rb_str_equal(rb_ary_entry(key_str_pair, 0), rb_str_new_cstr("state"))) {
106
+ state_label = &labels[i];
107
+ }
104
108
  }
105
109
  for (int i = 0; i < RARRAY_LEN(numeric_labels_array); i++) {
106
110
  VALUE key_str_pair = rb_ary_entry(numeric_labels_array, i);
@@ -116,12 +120,14 @@ static VALUE _native_sample(
116
120
 
117
121
  sampling_buffer *buffer = sampling_buffer_new(max_frames_requested);
118
122
 
123
+ ddog_prof_Slice_Label slice_labels = {.ptr = labels, .len = labels_count};
124
+
119
125
  sample_thread(
120
126
  thread,
121
127
  buffer,
122
128
  recorder_instance,
123
129
  values,
124
- (ddog_prof_Slice_Label) {.ptr = labels, .len = labels_count},
130
+ (sample_labels) {.labels = slice_labels, .state_label = state_label},
125
131
  RTEST(in_gc) ? SAMPLE_IN_GC : SAMPLE_REGULAR
126
132
  );
127
133
 
@@ -135,7 +141,7 @@ void sample_thread(
135
141
  sampling_buffer* buffer,
136
142
  VALUE recorder_instance,
137
143
  sample_values values,
138
- ddog_prof_Slice_Label labels,
144
+ sample_labels labels,
139
145
  sample_type type
140
146
  ) {
141
147
  // Samples thread into recorder
@@ -150,7 +156,7 @@ void sample_thread(
150
156
  if (type == SAMPLE_IN_GC) {
151
157
  ddog_CharSlice function_name = DDOG_CHARSLICE_C("");
152
158
  ddog_CharSlice function_filename = DDOG_CHARSLICE_C("Garbage Collection");
153
- buffer->lines[0] = (ddog_prof_Line) {
159
+ buffer->locations[0] = (ddog_prof_Location) {
154
160
  .function = (ddog_prof_Function) {.name = function_name, .filename = function_filename},
155
161
  .line = 0
156
162
  };
@@ -162,7 +168,6 @@ void sample_thread(
162
168
  .lines_buffer = buffer->lines_buffer + 1,
163
169
  .is_ruby_frame = buffer->is_ruby_frame + 1,
164
170
  .locations = buffer->locations + 1,
165
- .lines = buffer->lines + 1
166
171
  };
167
172
  sampling_buffer *record_buffer = buffer; // We pass in the original buffer as the record_buffer, but not as the regular buffer
168
173
  int extra_frames_in_record_buffer = 1;
@@ -173,6 +178,8 @@ void sample_thread(
173
178
  rb_raise(rb_eArgError, "Unexpected value for sample_type: %d", type);
174
179
  }
175
180
 
181
+ #define CHARSLICE_EQUALS(must_be_a_literal, charslice) (strlen("" must_be_a_literal) == charslice.len && strncmp(must_be_a_literal, charslice.ptr, charslice.len) == 0)
182
+
176
183
  // Idea: Should we release the global vm lock (GVL) after we get the data from `rb_profile_frames`? That way other Ruby threads
177
184
  // could continue making progress while the sample was ingested into the profile.
178
185
  //
@@ -197,7 +204,7 @@ static void sample_thread_internal(
197
204
  sampling_buffer* buffer,
198
205
  VALUE recorder_instance,
199
206
  sample_values values,
200
- ddog_prof_Slice_Label labels,
207
+ sample_labels labels,
201
208
  sampling_buffer *record_buffer,
202
209
  int extra_frames_in_record_buffer
203
210
  ) {
@@ -230,6 +237,15 @@ static void sample_thread_internal(
230
237
  VALUE last_ruby_frame = Qnil;
231
238
  int last_ruby_line = 0;
232
239
 
240
+ ddog_prof_Label *state_label = labels.state_label;
241
+ bool cpu_or_wall_sample = values.cpu_or_wall_samples > 0;
242
+ bool has_cpu_time = cpu_or_wall_sample && values.cpu_time_ns > 0;
243
+ bool only_wall_time = cpu_or_wall_sample && values.cpu_time_ns == 0 && values.wall_time_ns > 0;
244
+
245
+ if (cpu_or_wall_sample && state_label == NULL) rb_raise(rb_eRuntimeError, "BUG: Unexpected missing state_label");
246
+
247
+ if (has_cpu_time) state_label->str = DDOG_CHARSLICE_C("had cpu");
248
+
233
249
  for (int i = captured_frames - 1; i >= 0; i--) {
234
250
  VALUE name, filename;
235
251
  int line;
@@ -250,10 +266,55 @@ static void sample_thread_internal(
250
266
  name = NIL_P(name) ? missing_string : name;
251
267
  filename = NIL_P(filename) ? missing_string : filename;
252
268
 
253
- buffer->lines[i] = (ddog_prof_Line) {
269
+ ddog_CharSlice name_slice = char_slice_from_ruby_string(name);
270
+ ddog_CharSlice filename_slice = char_slice_from_ruby_string(filename);
271
+
272
+ bool top_of_the_stack = i == 0;
273
+
274
+ // When there's only wall-time in a sample, this means that the thread was not active in the sampled period.
275
+ //
276
+ // We try to categorize what it was doing based on what we observe at the top of the stack. This is a very rough
277
+ // approximation, and in the future we hope to replace this with a more accurate approach (such as using the
278
+ // GVL instrumentation API.)
279
+ if (top_of_the_stack && only_wall_time) {
280
+ if (!buffer->is_ruby_frame[i]) {
281
+ // We know that known versions of Ruby implement these using native code; thus if we find a method with the
282
+ // same name that is not native code, we ignore it, as it's probably a user method that coincidentally
283
+ // has the same name. Thus, even though "matching just by method name" is kinda weak,
284
+ // "matching by method name" + is native code seems actually to be good enough for a lot of cases.
285
+
286
+ if (CHARSLICE_EQUALS("sleep", name_slice)) { // Expected to be Kernel.sleep
287
+ state_label->str = DDOG_CHARSLICE_C("sleeping");
288
+ } else if (CHARSLICE_EQUALS("select", name_slice)) { // Expected to be Kernel.select
289
+ state_label->str = DDOG_CHARSLICE_C("waiting");
290
+ } else if (
291
+ CHARSLICE_EQUALS("synchronize", name_slice) || // Expected to be Monitor/Mutex#synchronize
292
+ CHARSLICE_EQUALS("lock", name_slice) || // Expected to be Mutex#lock
293
+ CHARSLICE_EQUALS("join", name_slice) // Expected to be Thread#join
294
+ ) {
295
+ state_label->str = DDOG_CHARSLICE_C("blocked");
296
+ } else if (CHARSLICE_EQUALS("wait_readable", name_slice)) { // Expected to be IO#wait_readable
297
+ state_label->str = DDOG_CHARSLICE_C("network");
298
+ }
299
+ #ifdef NO_PRIMITIVE_POP // Ruby < 3.2
300
+ else if (CHARSLICE_EQUALS("pop", name_slice)) { // Expected to be Queue/SizedQueue#pop
301
+ state_label->str = DDOG_CHARSLICE_C("waiting");
302
+ }
303
+ #endif
304
+ } else {
305
+ #ifndef NO_PRIMITIVE_POP // Ruby >= 3.2
306
+ // Unlike the above, Ruby actually treats this one specially and gives it a nice file name we can match on!
307
+ if (CHARSLICE_EQUALS("pop", name_slice) && CHARSLICE_EQUALS("<internal:thread_sync>", filename_slice)) { // Expected to be Queue/SizedQueue#pop
308
+ state_label->str = DDOG_CHARSLICE_C("waiting");
309
+ }
310
+ #endif
311
+ }
312
+ }
313
+
314
+ buffer->locations[i] = (ddog_prof_Location) {
254
315
  .function = (ddog_prof_Function) {
255
- .name = char_slice_from_ruby_string(name),
256
- .filename = char_slice_from_ruby_string(filename)
316
+ .name = name_slice,
317
+ .filename = filename_slice,
257
318
  },
258
319
  .line = line,
259
320
  };
@@ -292,7 +353,7 @@ static void maybe_add_placeholder_frames_omitted(VALUE thread, sampling_buffer*
292
353
  // `record_sample`. So be careful where it gets allocated. (We do have tests for this, at least!)
293
354
  ddog_CharSlice function_name = DDOG_CHARSLICE_C("");
294
355
  ddog_CharSlice function_filename = {.ptr = frames_omitted_message, .len = strlen(frames_omitted_message)};
295
- buffer->lines[buffer->max_frames - 1] = (ddog_prof_Line) {
356
+ buffer->locations[buffer->max_frames - 1] = (ddog_prof_Location) {
296
357
  .function = (ddog_prof_Function) {.name = function_name, .filename = function_filename},
297
358
  .line = 0,
298
359
  };
@@ -322,13 +383,13 @@ static void record_placeholder_stack_in_native_code(
322
383
  sampling_buffer* buffer,
323
384
  VALUE recorder_instance,
324
385
  sample_values values,
325
- ddog_prof_Slice_Label labels,
386
+ sample_labels labels,
326
387
  sampling_buffer *record_buffer,
327
388
  int extra_frames_in_record_buffer
328
389
  ) {
329
390
  ddog_CharSlice function_name = DDOG_CHARSLICE_C("");
330
391
  ddog_CharSlice function_filename = DDOG_CHARSLICE_C("In native code");
331
- buffer->lines[0] = (ddog_prof_Line) {
392
+ buffer->locations[0] = (ddog_prof_Location) {
332
393
  .function = (ddog_prof_Function) {.name = function_name, .filename = function_filename},
333
394
  .line = 0
334
395
  };
@@ -354,14 +415,6 @@ sampling_buffer *sampling_buffer_new(unsigned int max_frames) {
354
415
  buffer->lines_buffer = ruby_xcalloc(max_frames, sizeof(int));
355
416
  buffer->is_ruby_frame = ruby_xcalloc(max_frames, sizeof(bool));
356
417
  buffer->locations = ruby_xcalloc(max_frames, sizeof(ddog_prof_Location));
357
- buffer->lines = ruby_xcalloc(max_frames, sizeof(ddog_prof_Line));
358
-
359
- // Currently we have a 1-to-1 correspondence between lines and locations, so we just initialize the locations once
360
- // here and then only mutate the contents of the lines.
361
- for (unsigned int i = 0; i < max_frames; i++) {
362
- ddog_prof_Slice_Line lines = (ddog_prof_Slice_Line) {.ptr = &buffer->lines[i], .len = 1};
363
- buffer->locations[i] = (ddog_prof_Location) {.lines = lines};
364
- }
365
418
 
366
419
  return buffer;
367
420
  }
@@ -373,7 +426,6 @@ void sampling_buffer_free(sampling_buffer *buffer) {
373
426
  ruby_xfree(buffer->lines_buffer);
374
427
  ruby_xfree(buffer->is_ruby_frame);
375
428
  ruby_xfree(buffer->locations);
376
- ruby_xfree(buffer->lines);
377
429
 
378
430
  ruby_xfree(buffer);
379
431
  }