ddtrace 1.1.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (641) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +423 -1
  3. data/LICENSE-3rdparty.csv +3 -0
  4. data/README.md +9 -4
  5. data/ext/ddtrace_profiling_loader/ddtrace_profiling_loader.c +21 -5
  6. data/ext/ddtrace_profiling_loader/extconf.rb +22 -1
  7. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +52 -8
  8. data/ext/ddtrace_profiling_native_extension/clock_id.h +22 -1
  9. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +34 -3
  10. data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +11 -2
  11. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +899 -0
  12. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +9 -0
  13. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +776 -0
  14. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.c +142 -0
  15. data/ext/ddtrace_profiling_native_extension/collectors_dynamic_sampling_rate.h +14 -0
  16. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +241 -0
  17. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.h +3 -0
  18. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +175 -63
  19. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +18 -0
  20. data/ext/ddtrace_profiling_native_extension/extconf.rb +90 -18
  21. data/ext/ddtrace_profiling_native_extension/helpers.h +17 -0
  22. data/ext/ddtrace_profiling_native_extension/http_transport.c +354 -0
  23. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +18 -0
  24. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +154 -21
  25. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +256 -17
  26. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +17 -5
  27. data/ext/ddtrace_profiling_native_extension/profiling.c +223 -3
  28. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +110 -0
  29. data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +89 -0
  30. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +115 -0
  31. data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +11 -0
  32. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +392 -44
  33. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +25 -14
  34. data/ext/ddtrace_profiling_native_extension/time_helpers.c +17 -0
  35. data/ext/ddtrace_profiling_native_extension/time_helpers.h +10 -0
  36. data/lib/datadog/appsec/assets/blocked.html +98 -3
  37. data/lib/datadog/appsec/assets/blocked.json +1 -0
  38. data/lib/datadog/appsec/assets/blocked.text +5 -0
  39. data/lib/datadog/appsec/assets/waf_rules/recommended.json +1250 -300
  40. data/lib/datadog/appsec/assets/waf_rules/risky.json +78 -78
  41. data/lib/datadog/appsec/assets/waf_rules/strict.json +308 -73
  42. data/lib/datadog/appsec/assets.rb +3 -3
  43. data/lib/datadog/appsec/autoload.rb +4 -2
  44. data/lib/datadog/appsec/configuration/settings.rb +40 -23
  45. data/lib/datadog/appsec/configuration.rb +9 -3
  46. data/lib/datadog/appsec/contrib/auto_instrument.rb +1 -3
  47. data/lib/datadog/appsec/contrib/configuration/settings.rb +2 -2
  48. data/lib/datadog/appsec/contrib/integration.rb +1 -1
  49. data/lib/datadog/appsec/contrib/patcher.rb +1 -1
  50. data/lib/datadog/appsec/contrib/rack/configuration/settings.rb +3 -3
  51. data/lib/datadog/appsec/contrib/rack/ext.rb +1 -1
  52. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +32 -27
  53. data/lib/datadog/appsec/contrib/rack/integration.rb +5 -5
  54. data/lib/datadog/appsec/contrib/rack/patcher.rb +2 -2
  55. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +17 -21
  56. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +13 -13
  57. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +13 -13
  58. data/lib/datadog/appsec/contrib/rack/request.rb +21 -1
  59. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -3
  60. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +50 -23
  61. data/lib/datadog/appsec/contrib/rack/response.rb +1 -1
  62. data/lib/datadog/appsec/contrib/rails/configuration/settings.rb +3 -3
  63. data/lib/datadog/appsec/contrib/rails/ext.rb +1 -1
  64. data/lib/datadog/appsec/contrib/rails/framework.rb +1 -1
  65. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +12 -11
  66. data/lib/datadog/appsec/contrib/rails/integration.rb +5 -5
  67. data/lib/datadog/appsec/contrib/rails/patcher.rb +14 -13
  68. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +13 -13
  69. data/lib/datadog/appsec/contrib/rails/request.rb +4 -1
  70. data/lib/datadog/appsec/contrib/rails/request_middleware.rb +1 -1
  71. data/lib/datadog/appsec/contrib/sinatra/configuration/settings.rb +3 -3
  72. data/lib/datadog/appsec/contrib/sinatra/ext.rb +2 -1
  73. data/lib/datadog/appsec/contrib/sinatra/framework.rb +1 -1
  74. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +21 -19
  75. data/lib/datadog/appsec/contrib/sinatra/integration.rb +4 -4
  76. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +22 -15
  77. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +12 -12
  78. data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +1 -1
  79. data/lib/datadog/appsec/event.rb +10 -14
  80. data/lib/datadog/appsec/extensions.rb +43 -23
  81. data/lib/datadog/appsec/instrumentation/gateway.rb +17 -3
  82. data/lib/datadog/appsec/processor.rb +51 -21
  83. data/lib/datadog/appsec/rate_limiter.rb +1 -1
  84. data/lib/datadog/appsec/reactive/address_hash.rb +1 -1
  85. data/lib/datadog/appsec/reactive/engine.rb +3 -3
  86. data/lib/datadog/appsec/reactive/operation.rb +5 -5
  87. data/lib/datadog/appsec/reactive/subscriber.rb +1 -1
  88. data/lib/datadog/appsec/response.rb +63 -0
  89. data/lib/datadog/appsec/utils/http/media_range.rb +201 -0
  90. data/lib/datadog/appsec/utils/http/media_type.rb +87 -0
  91. data/lib/datadog/appsec/utils/http.rb +9 -0
  92. data/lib/datadog/appsec/utils.rb +7 -0
  93. data/lib/datadog/appsec.rb +6 -6
  94. data/lib/datadog/ci/configuration/components.rb +1 -1
  95. data/lib/datadog/ci/configuration/settings.rb +1 -1
  96. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +2 -2
  97. data/lib/datadog/ci/contrib/cucumber/formatter.rb +5 -5
  98. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +1 -1
  99. data/lib/datadog/ci/contrib/cucumber/integration.rb +4 -4
  100. data/lib/datadog/ci/contrib/cucumber/patcher.rb +2 -2
  101. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +2 -2
  102. data/lib/datadog/ci/contrib/rspec/example.rb +5 -5
  103. data/lib/datadog/ci/contrib/rspec/integration.rb +4 -4
  104. data/lib/datadog/ci/contrib/rspec/patcher.rb +2 -2
  105. data/lib/datadog/ci/ext/environment.rb +78 -20
  106. data/lib/datadog/ci/extensions.rb +4 -4
  107. data/lib/datadog/ci/flush.rb +2 -2
  108. data/lib/datadog/ci/test.rb +3 -3
  109. data/lib/datadog/ci.rb +6 -6
  110. data/lib/datadog/core/buffer/cruby.rb +1 -1
  111. data/lib/datadog/core/buffer/thread_safe.rb +1 -1
  112. data/lib/datadog/core/configuration/agent_settings_resolver.rb +8 -11
  113. data/lib/datadog/core/configuration/base.rb +14 -2
  114. data/lib/datadog/core/configuration/components.rb +103 -52
  115. data/lib/datadog/core/configuration/ext.rb +26 -0
  116. data/lib/datadog/core/configuration/option_definition.rb +12 -3
  117. data/lib/datadog/core/configuration/option_definition_set.rb +1 -1
  118. data/lib/datadog/core/configuration/options.rb +3 -3
  119. data/lib/datadog/core/configuration/settings.rb +78 -250
  120. data/lib/datadog/core/configuration.rb +9 -6
  121. data/lib/datadog/core/diagnostics/environment_logger.rb +10 -5
  122. data/lib/datadog/core/diagnostics/health.rb +5 -23
  123. data/lib/datadog/core/environment/cgroup.rb +1 -1
  124. data/lib/datadog/core/environment/container.rb +1 -1
  125. data/lib/datadog/core/environment/ext.rb +1 -1
  126. data/lib/datadog/core/environment/identity.rb +2 -2
  127. data/lib/datadog/core/environment/platform.rb +40 -0
  128. data/lib/datadog/core/environment/socket.rb +1 -1
  129. data/lib/datadog/core/environment/variable_helpers.rb +58 -10
  130. data/lib/datadog/core/error.rb +1 -1
  131. data/lib/datadog/core/extensions.rb +1 -1
  132. data/lib/datadog/core/header_collection.rb +41 -0
  133. data/lib/datadog/core/metrics/client.rb +10 -9
  134. data/lib/datadog/core/metrics/ext.rb +0 -2
  135. data/lib/datadog/core/metrics/options.rb +3 -3
  136. data/lib/datadog/core/runtime/ext.rb +1 -1
  137. data/lib/datadog/core/runtime/metrics.rb +6 -6
  138. data/lib/datadog/core/telemetry/client.rb +79 -0
  139. data/lib/datadog/core/telemetry/collector.rb +233 -0
  140. data/lib/datadog/core/telemetry/emitter.rb +48 -0
  141. data/lib/datadog/core/telemetry/event.rb +71 -0
  142. data/lib/datadog/core/telemetry/ext.rb +11 -0
  143. data/lib/datadog/core/telemetry/heartbeat.rb +37 -0
  144. data/lib/datadog/core/telemetry/http/adapters/net.rb +113 -0
  145. data/lib/datadog/core/telemetry/http/env.rb +20 -0
  146. data/lib/datadog/core/telemetry/http/ext.rb +20 -0
  147. data/lib/datadog/core/telemetry/http/response.rb +68 -0
  148. data/lib/datadog/core/telemetry/http/transport.rb +53 -0
  149. data/lib/datadog/core/telemetry/v1/app_event.rb +52 -0
  150. data/lib/datadog/core/telemetry/v1/application.rb +86 -0
  151. data/lib/datadog/core/telemetry/v1/configuration.rb +25 -0
  152. data/lib/datadog/core/telemetry/v1/dependency.rb +36 -0
  153. data/lib/datadog/core/telemetry/v1/host.rb +51 -0
  154. data/lib/datadog/core/telemetry/v1/integration.rb +58 -0
  155. data/lib/datadog/core/telemetry/v1/product.rb +28 -0
  156. data/lib/datadog/core/telemetry/v1/telemetry_request.rb +100 -0
  157. data/lib/datadog/core/utils/compression.rb +5 -1
  158. data/lib/datadog/core/utils/object_set.rb +1 -1
  159. data/lib/datadog/core/utils/sequence.rb +5 -0
  160. data/lib/datadog/core/utils/string_table.rb +1 -1
  161. data/lib/datadog/core/utils/time.rb +3 -3
  162. data/lib/datadog/core/utils.rb +1 -22
  163. data/lib/datadog/core/vendor/multipart-post/multipart/post/multipartable.rb +2 -2
  164. data/lib/datadog/core/vendor/multipart-post/net/http/post/multipart.rb +3 -3
  165. data/lib/datadog/core/workers/async.rb +1 -3
  166. data/lib/datadog/core/workers/polling.rb +2 -2
  167. data/lib/datadog/core/workers/runtime_metrics.rb +4 -4
  168. data/lib/datadog/core.rb +22 -56
  169. data/lib/datadog/kit/appsec/events.rb +75 -0
  170. data/lib/datadog/kit/enable_core_dumps.rb +1 -0
  171. data/lib/datadog/kit/identity.rb +8 -7
  172. data/lib/datadog/kit.rb +1 -1
  173. data/lib/datadog/opentelemetry/api/context.rb +187 -0
  174. data/lib/datadog/opentelemetry/api/trace/span.rb +15 -0
  175. data/lib/datadog/opentelemetry/sdk/configurator.rb +38 -0
  176. data/lib/datadog/opentelemetry/sdk/id_generator.rb +27 -0
  177. data/lib/datadog/opentelemetry/sdk/propagator.rb +91 -0
  178. data/lib/datadog/opentelemetry/sdk/span_processor.rb +92 -0
  179. data/lib/datadog/opentelemetry.rb +48 -0
  180. data/lib/datadog/opentracer/distributed_headers.rb +7 -9
  181. data/lib/datadog/opentracer/rack_propagator.rb +10 -9
  182. data/lib/datadog/opentracer/span.rb +1 -1
  183. data/lib/datadog/opentracer/text_map_propagator.rb +13 -12
  184. data/lib/datadog/opentracer/thread_local_scope_manager.rb +26 -3
  185. data/lib/datadog/opentracer/tracer.rb +23 -21
  186. data/lib/datadog/opentracer.rb +16 -16
  187. data/lib/datadog/profiling/buffer.rb +3 -3
  188. data/lib/datadog/profiling/collectors/code_provenance.rb +1 -0
  189. data/lib/datadog/profiling/collectors/cpu_and_wall_time.rb +43 -0
  190. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +91 -0
  191. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
  192. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
  193. data/lib/datadog/profiling/collectors/old_stack.rb +15 -8
  194. data/lib/datadog/profiling/collectors/stack.rb +3 -6
  195. data/lib/datadog/profiling/encoding/profile.rb +8 -12
  196. data/lib/datadog/profiling/events/stack.rb +1 -1
  197. data/lib/datadog/profiling/exporter.rb +69 -9
  198. data/lib/datadog/profiling/ext/forking.rb +41 -42
  199. data/lib/datadog/profiling/ext.rb +3 -15
  200. data/lib/datadog/profiling/flush.rb +25 -56
  201. data/lib/datadog/profiling/http_transport.rb +132 -0
  202. data/lib/datadog/profiling/old_recorder.rb +109 -0
  203. data/lib/datadog/profiling/pprof/builder.rb +4 -4
  204. data/lib/datadog/profiling/pprof/converter.rb +1 -1
  205. data/lib/datadog/profiling/pprof/message_set.rb +1 -1
  206. data/lib/datadog/profiling/pprof/stack_sample.rb +4 -4
  207. data/lib/datadog/profiling/pprof/string_table.rb +1 -1
  208. data/lib/datadog/profiling/pprof/template.rb +5 -5
  209. data/lib/datadog/profiling/preload.rb +1 -1
  210. data/lib/datadog/profiling/profiler.rb +7 -0
  211. data/lib/datadog/profiling/scheduler.rb +28 -49
  212. data/lib/datadog/profiling/stack_recorder.rb +50 -4
  213. data/lib/datadog/profiling/tag_builder.rb +6 -1
  214. data/lib/datadog/profiling/tasks/setup.rb +2 -9
  215. data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +2 -2
  216. data/lib/datadog/profiling/trace_identifiers/helper.rb +1 -1
  217. data/lib/datadog/profiling.rb +24 -21
  218. data/lib/datadog/tracing/analytics.rb +1 -1
  219. data/lib/datadog/tracing/buffer.rb +5 -5
  220. data/lib/datadog/tracing/client_ip.rb +164 -0
  221. data/lib/datadog/tracing/configuration/ext.rb +47 -4
  222. data/lib/datadog/tracing/configuration/settings.rb +433 -0
  223. data/lib/datadog/tracing/context.rb +1 -1
  224. data/lib/datadog/tracing/context_provider.rb +18 -2
  225. data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +2 -2
  226. data/lib/datadog/tracing/contrib/action_cable/event.rb +4 -5
  227. data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +4 -4
  228. data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +3 -3
  229. data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +4 -4
  230. data/lib/datadog/tracing/contrib/action_cable/events.rb +4 -4
  231. data/lib/datadog/tracing/contrib/action_cable/instrumentation.rb +3 -4
  232. data/lib/datadog/tracing/contrib/action_cable/integration.rb +4 -4
  233. data/lib/datadog/tracing/contrib/action_cable/patcher.rb +4 -4
  234. data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +2 -2
  235. data/lib/datadog/tracing/contrib/action_mailer/event.rb +3 -3
  236. data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +3 -3
  237. data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +3 -3
  238. data/lib/datadog/tracing/contrib/action_mailer/events.rb +2 -2
  239. data/lib/datadog/tracing/contrib/action_mailer/integration.rb +4 -4
  240. data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +3 -3
  241. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +10 -6
  242. data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -2
  243. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +2 -2
  244. data/lib/datadog/tracing/contrib/action_pack/integration.rb +4 -4
  245. data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -2
  246. data/lib/datadog/tracing/contrib/action_pack/utils.rb +1 -1
  247. data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +2 -2
  248. data/lib/datadog/tracing/contrib/action_view/event.rb +1 -1
  249. data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +5 -5
  250. data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +5 -5
  251. data/lib/datadog/tracing/contrib/action_view/events.rb +2 -2
  252. data/lib/datadog/tracing/contrib/action_view/instrumentation/partial_renderer.rb +2 -2
  253. data/lib/datadog/tracing/contrib/action_view/instrumentation/template_renderer.rb +2 -2
  254. data/lib/datadog/tracing/contrib/action_view/integration.rb +4 -4
  255. data/lib/datadog/tracing/contrib/action_view/patcher.rb +7 -7
  256. data/lib/datadog/tracing/contrib/action_view/utils.rb +1 -1
  257. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +3 -3
  258. data/lib/datadog/tracing/contrib/active_job/event.rb +3 -3
  259. data/lib/datadog/tracing/contrib/active_job/events/discard.rb +4 -4
  260. data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +4 -4
  261. data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +4 -4
  262. data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +4 -4
  263. data/lib/datadog/tracing/contrib/active_job/events/perform.rb +4 -4
  264. data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +4 -4
  265. data/lib/datadog/tracing/contrib/active_job/events.rb +6 -6
  266. data/lib/datadog/tracing/contrib/active_job/integration.rb +4 -4
  267. data/lib/datadog/tracing/contrib/active_job/log_injection.rb +0 -2
  268. data/lib/datadog/tracing/contrib/active_job/patcher.rb +4 -4
  269. data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +2 -2
  270. data/lib/datadog/tracing/contrib/active_model_serializers/event.rb +4 -5
  271. data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +3 -3
  272. data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +2 -2
  273. data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +2 -2
  274. data/lib/datadog/tracing/contrib/active_model_serializers/integration.rb +3 -3
  275. data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +3 -4
  276. data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +2 -2
  277. data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +3 -3
  278. data/lib/datadog/tracing/contrib/active_record/event.rb +1 -1
  279. data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +4 -4
  280. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +6 -6
  281. data/lib/datadog/tracing/contrib/active_record/events.rb +2 -2
  282. data/lib/datadog/tracing/contrib/active_record/integration.rb +6 -6
  283. data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -2
  284. data/lib/datadog/tracing/contrib/active_record/utils.rb +2 -2
  285. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +19 -9
  286. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +2 -2
  287. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +1 -1
  288. data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +2 -2
  289. data/lib/datadog/tracing/contrib/active_support/integration.rb +5 -5
  290. data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +1 -1
  291. data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +1 -1
  292. data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -2
  293. data/lib/datadog/tracing/contrib/analytics.rb +1 -1
  294. data/lib/datadog/tracing/contrib/auto_instrument.rb +4 -4
  295. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +6 -3
  296. data/lib/datadog/tracing/contrib/aws/ext.rb +1 -0
  297. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +5 -4
  298. data/lib/datadog/tracing/contrib/aws/integration.rb +3 -3
  299. data/lib/datadog/tracing/contrib/aws/patcher.rb +5 -5
  300. data/lib/datadog/tracing/contrib/aws/services.rb +0 -2
  301. data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +2 -2
  302. data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +1 -1
  303. data/lib/datadog/tracing/contrib/concurrent_ruby/integration.rb +3 -3
  304. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +2 -2
  305. data/lib/datadog/tracing/contrib/configurable.rb +2 -2
  306. data/lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb +1 -1
  307. data/lib/datadog/tracing/contrib/configuration/settings.rb +2 -2
  308. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -3
  309. data/lib/datadog/tracing/contrib/dalli/ext.rb +2 -0
  310. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +8 -5
  311. data/lib/datadog/tracing/contrib/dalli/integration.rb +3 -3
  312. data/lib/datadog/tracing/contrib/dalli/patcher.rb +3 -3
  313. data/lib/datadog/tracing/contrib/dalli/quantize.rb +1 -1
  314. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +3 -3
  315. data/lib/datadog/tracing/contrib/delayed_job/ext.rb +2 -0
  316. data/lib/datadog/tracing/contrib/delayed_job/integration.rb +3 -3
  317. data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +8 -2
  318. data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +7 -4
  319. data/lib/datadog/tracing/contrib/delayed_job/server_internal_tracer/worker.rb +32 -0
  320. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +7 -3
  321. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +3 -0
  322. data/lib/datadog/tracing/contrib/elasticsearch/integration.rb +3 -3
  323. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +9 -7
  324. data/lib/datadog/tracing/contrib/elasticsearch/quantize.rb +1 -1
  325. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +8 -3
  326. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +6 -7
  327. data/lib/datadog/tracing/contrib/ethon/ext.rb +1 -0
  328. data/lib/datadog/tracing/contrib/ethon/integration.rb +4 -4
  329. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +5 -4
  330. data/lib/datadog/tracing/contrib/ethon/patcher.rb +3 -3
  331. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +7 -3
  332. data/lib/datadog/tracing/contrib/excon/ext.rb +1 -0
  333. data/lib/datadog/tracing/contrib/excon/integration.rb +4 -4
  334. data/lib/datadog/tracing/contrib/excon/middleware.rb +8 -7
  335. data/lib/datadog/tracing/contrib/excon/patcher.rb +2 -2
  336. data/lib/datadog/tracing/contrib/ext.rb +25 -0
  337. data/lib/datadog/tracing/contrib/extensions.rb +5 -3
  338. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +7 -3
  339. data/lib/datadog/tracing/contrib/faraday/ext.rb +1 -0
  340. data/lib/datadog/tracing/contrib/faraday/integration.rb +4 -4
  341. data/lib/datadog/tracing/contrib/faraday/middleware.rb +8 -8
  342. data/lib/datadog/tracing/contrib/faraday/patcher.rb +5 -5
  343. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +3 -3
  344. data/lib/datadog/tracing/contrib/grape/endpoint.rb +4 -7
  345. data/lib/datadog/tracing/contrib/grape/integration.rb +3 -3
  346. data/lib/datadog/tracing/contrib/grape/patcher.rb +4 -4
  347. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +3 -3
  348. data/lib/datadog/tracing/contrib/graphql/integration.rb +3 -3
  349. data/lib/datadog/tracing/contrib/graphql/patcher.rb +2 -3
  350. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +10 -4
  351. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +20 -5
  352. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +17 -17
  353. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +7 -4
  354. data/lib/datadog/tracing/contrib/grpc/distributed/fetcher.rb +27 -0
  355. data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +43 -0
  356. data/lib/datadog/tracing/contrib/grpc/ext.rb +4 -0
  357. data/lib/datadog/tracing/contrib/grpc/integration.rb +3 -3
  358. data/lib/datadog/tracing/contrib/grpc/patcher.rb +3 -5
  359. data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +47 -0
  360. data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +22 -0
  361. data/lib/datadog/tracing/contrib/hanami/ext.rb +24 -0
  362. data/lib/datadog/tracing/contrib/hanami/integration.rb +44 -0
  363. data/lib/datadog/tracing/contrib/hanami/patcher.rb +33 -0
  364. data/lib/datadog/tracing/contrib/hanami/plugin.rb +23 -0
  365. data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +41 -0
  366. data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +44 -0
  367. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +1 -2
  368. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +13 -3
  369. data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +39 -0
  370. data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +38 -0
  371. data/lib/datadog/tracing/contrib/http/ext.rb +2 -0
  372. data/lib/datadog/tracing/contrib/http/instrumentation.rb +8 -10
  373. data/lib/datadog/tracing/contrib/http/integration.rb +6 -6
  374. data/lib/datadog/tracing/contrib/http/patcher.rb +3 -3
  375. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +13 -3
  376. data/lib/datadog/tracing/contrib/httpclient/ext.rb +2 -0
  377. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +9 -9
  378. data/lib/datadog/tracing/contrib/httpclient/integration.rb +4 -4
  379. data/lib/datadog/tracing/contrib/httpclient/patcher.rb +3 -3
  380. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +13 -3
  381. data/lib/datadog/tracing/contrib/httprb/ext.rb +2 -0
  382. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +9 -9
  383. data/lib/datadog/tracing/contrib/httprb/integration.rb +4 -4
  384. data/lib/datadog/tracing/contrib/httprb/patcher.rb +3 -3
  385. data/lib/datadog/tracing/contrib/integration.rb +3 -3
  386. data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +2 -2
  387. data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +1 -0
  388. data/lib/datadog/tracing/contrib/kafka/event.rb +3 -3
  389. data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +2 -2
  390. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +3 -3
  391. data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +3 -3
  392. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +4 -4
  393. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/join_group.rb +4 -4
  394. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/leave_group.rb +4 -4
  395. data/lib/datadog/tracing/contrib/kafka/events/consumer_group/sync_group.rb +4 -4
  396. data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +3 -2
  397. data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +3 -2
  398. data/lib/datadog/tracing/contrib/kafka/events.rb +9 -9
  399. data/lib/datadog/tracing/contrib/kafka/integration.rb +3 -3
  400. data/lib/datadog/tracing/contrib/kafka/patcher.rb +3 -3
  401. data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +2 -2
  402. data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +1 -2
  403. data/lib/datadog/tracing/contrib/lograge/integration.rb +3 -3
  404. data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -2
  405. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +7 -3
  406. data/lib/datadog/tracing/contrib/mongodb/ext.rb +8 -0
  407. data/lib/datadog/tracing/contrib/mongodb/instrumentation.rb +3 -3
  408. data/lib/datadog/tracing/contrib/mongodb/integration.rb +4 -4
  409. data/lib/datadog/tracing/contrib/mongodb/parsers.rb +1 -1
  410. data/lib/datadog/tracing/contrib/mongodb/patcher.rb +3 -3
  411. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +10 -4
  412. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +18 -3
  413. data/lib/datadog/tracing/contrib/mysql2/ext.rb +2 -0
  414. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +20 -5
  415. data/lib/datadog/tracing/contrib/mysql2/integration.rb +3 -3
  416. data/lib/datadog/tracing/contrib/mysql2/patcher.rb +2 -2
  417. data/lib/datadog/tracing/contrib/patcher.rb +16 -4
  418. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +50 -0
  419. data/lib/datadog/tracing/contrib/pg/ext.rb +33 -0
  420. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +168 -0
  421. data/lib/datadog/tracing/contrib/pg/integration.rb +43 -0
  422. data/lib/datadog/tracing/contrib/pg/patcher.rb +31 -0
  423. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +6 -3
  424. data/lib/datadog/tracing/contrib/presto/ext.rb +1 -0
  425. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +2 -3
  426. data/lib/datadog/tracing/contrib/presto/integration.rb +3 -3
  427. data/lib/datadog/tracing/contrib/presto/patcher.rb +4 -4
  428. data/lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb +43 -0
  429. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +33 -0
  430. data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +28 -0
  431. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +47 -0
  432. data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +2 -2
  433. data/lib/datadog/tracing/contrib/qless/integration.rb +3 -3
  434. data/lib/datadog/tracing/contrib/qless/patcher.rb +1 -2
  435. data/lib/datadog/tracing/contrib/qless/qless_job.rb +2 -3
  436. data/lib/datadog/tracing/contrib/qless/tracer_cleaner.rb +0 -2
  437. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +3 -3
  438. data/lib/datadog/tracing/contrib/que/integration.rb +4 -4
  439. data/lib/datadog/tracing/contrib/que/patcher.rb +1 -1
  440. data/lib/datadog/tracing/contrib/que/tracer.rb +3 -1
  441. data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +2 -2
  442. data/lib/datadog/tracing/contrib/racecar/event.rb +4 -5
  443. data/lib/datadog/tracing/contrib/racecar/events/batch.rb +6 -3
  444. data/lib/datadog/tracing/contrib/racecar/events/consume.rb +2 -2
  445. data/lib/datadog/tracing/contrib/racecar/events/message.rb +6 -3
  446. data/lib/datadog/tracing/contrib/racecar/events.rb +3 -3
  447. data/lib/datadog/tracing/contrib/racecar/integration.rb +3 -3
  448. data/lib/datadog/tracing/contrib/racecar/patcher.rb +3 -3
  449. data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +2 -2
  450. data/lib/datadog/tracing/contrib/rack/header_collection.rb +35 -0
  451. data/lib/datadog/tracing/contrib/rack/integration.rb +4 -4
  452. data/lib/datadog/tracing/contrib/rack/middlewares.rb +129 -61
  453. data/lib/datadog/tracing/contrib/rack/patcher.rb +12 -2
  454. data/lib/datadog/tracing/contrib/rails/auto_instrument_railtie.rb +1 -1
  455. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -1
  456. data/lib/datadog/tracing/contrib/rails/framework.rb +18 -22
  457. data/lib/datadog/tracing/contrib/rails/integration.rb +4 -4
  458. data/lib/datadog/tracing/contrib/rails/log_injection.rb +0 -2
  459. data/lib/datadog/tracing/contrib/rails/middlewares.rb +1 -2
  460. data/lib/datadog/tracing/contrib/rails/patcher.rb +7 -8
  461. data/lib/datadog/tracing/contrib/rails/railtie.rb +3 -3
  462. data/lib/datadog/tracing/contrib/rails/utils.rb +1 -1
  463. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +17 -2
  464. data/lib/datadog/tracing/contrib/rake/instrumentation.rb +12 -7
  465. data/lib/datadog/tracing/contrib/rake/integration.rb +3 -3
  466. data/lib/datadog/tracing/contrib/rake/patcher.rb +3 -4
  467. data/lib/datadog/tracing/contrib/redis/configuration/resolver.rb +1 -1
  468. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +6 -3
  469. data/lib/datadog/tracing/contrib/redis/ext.rb +3 -0
  470. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +36 -26
  471. data/lib/datadog/tracing/contrib/redis/integration.rb +37 -4
  472. data/lib/datadog/tracing/contrib/redis/patcher.rb +57 -13
  473. data/lib/datadog/tracing/contrib/redis/quantize.rb +12 -9
  474. data/lib/datadog/tracing/contrib/redis/tags.rb +12 -10
  475. data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +72 -0
  476. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +3 -3
  477. data/lib/datadog/tracing/contrib/resque/integration.rb +3 -3
  478. data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -2
  479. data/lib/datadog/tracing/contrib/resque/resque_job.rb +5 -4
  480. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +9 -3
  481. data/lib/datadog/tracing/contrib/rest_client/ext.rb +1 -0
  482. data/lib/datadog/tracing/contrib/rest_client/integration.rb +3 -3
  483. data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -2
  484. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +7 -6
  485. data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +2 -2
  486. data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +1 -2
  487. data/lib/datadog/tracing/contrib/semantic_logger/integration.rb +3 -3
  488. data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -2
  489. data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +2 -2
  490. data/lib/datadog/tracing/contrib/sequel/database.rb +4 -5
  491. data/lib/datadog/tracing/contrib/sequel/dataset.rb +4 -5
  492. data/lib/datadog/tracing/contrib/sequel/integration.rb +3 -3
  493. data/lib/datadog/tracing/contrib/sequel/patcher.rb +3 -3
  494. data/lib/datadog/tracing/contrib/sequel/utils.rb +2 -2
  495. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +3 -3
  496. data/lib/datadog/tracing/contrib/shoryuken/integration.rb +4 -4
  497. data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +1 -1
  498. data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +3 -1
  499. data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +9 -5
  500. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +3 -3
  501. data/lib/datadog/tracing/contrib/sidekiq/ext.rb +6 -0
  502. data/lib/datadog/tracing/contrib/sidekiq/integration.rb +3 -3
  503. data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +14 -7
  504. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/heartbeat.rb +19 -1
  505. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/{scheduled_push.rb → redis_info.rb} +5 -6
  506. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/scheduled_poller.rb +53 -0
  507. data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +10 -6
  508. data/lib/datadog/tracing/contrib/sidekiq/tracing.rb +2 -2
  509. data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +2 -2
  510. data/lib/datadog/tracing/contrib/sinatra/env.rb +14 -25
  511. data/lib/datadog/tracing/contrib/sinatra/ext.rb +7 -3
  512. data/lib/datadog/tracing/contrib/sinatra/framework.rb +0 -2
  513. data/lib/datadog/tracing/contrib/sinatra/headers.rb +1 -1
  514. data/lib/datadog/tracing/contrib/sinatra/integration.rb +3 -3
  515. data/lib/datadog/tracing/contrib/sinatra/patcher.rb +7 -7
  516. data/lib/datadog/tracing/contrib/sinatra/tracer.rb +15 -88
  517. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +20 -16
  518. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +2 -2
  519. data/lib/datadog/tracing/contrib/sneakers/integration.rb +4 -4
  520. data/lib/datadog/tracing/contrib/sneakers/patcher.rb +2 -2
  521. data/lib/datadog/tracing/contrib/sneakers/tracer.rb +4 -3
  522. data/lib/datadog/tracing/contrib/status_code_matcher.rb +2 -2
  523. data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +33 -0
  524. data/lib/datadog/tracing/contrib/stripe/ext.rb +26 -0
  525. data/lib/datadog/tracing/contrib/stripe/integration.rb +43 -0
  526. data/lib/datadog/tracing/contrib/stripe/patcher.rb +29 -0
  527. data/lib/datadog/tracing/contrib/stripe/request.rb +67 -0
  528. data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +2 -2
  529. data/lib/datadog/tracing/contrib/sucker_punch/instrumentation.rb +3 -4
  530. data/lib/datadog/tracing/contrib/sucker_punch/integration.rb +3 -3
  531. data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +4 -5
  532. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +92 -10
  533. data/lib/datadog/tracing/contrib.rb +50 -47
  534. data/lib/datadog/tracing/correlation.rb +1 -1
  535. data/lib/datadog/{core → tracing}/diagnostics/ext.rb +1 -6
  536. data/lib/datadog/tracing/diagnostics/health.rb +40 -0
  537. data/lib/datadog/tracing/distributed/b3_multi.rb +66 -0
  538. data/lib/datadog/tracing/distributed/b3_single.rb +66 -0
  539. data/lib/datadog/tracing/distributed/datadog.rb +153 -0
  540. data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +85 -0
  541. data/lib/datadog/tracing/distributed/fetcher.rb +30 -0
  542. data/lib/datadog/tracing/distributed/headers/ext.rb +19 -15
  543. data/lib/datadog/tracing/distributed/helpers.rb +40 -4
  544. data/lib/datadog/tracing/distributed/none.rb +19 -0
  545. data/lib/datadog/tracing/distributed/propagation.rb +127 -0
  546. data/lib/datadog/tracing/distributed/trace_context.rb +378 -0
  547. data/lib/datadog/tracing/event.rb +1 -1
  548. data/lib/datadog/tracing/flush.rb +57 -35
  549. data/lib/datadog/tracing/metadata/analytics.rb +2 -2
  550. data/lib/datadog/tracing/metadata/errors.rb +2 -2
  551. data/lib/datadog/tracing/metadata/ext.rb +28 -1
  552. data/lib/datadog/tracing/metadata/tagging.rb +23 -2
  553. data/lib/datadog/tracing/metadata.rb +3 -3
  554. data/lib/datadog/tracing/pipeline/span_filter.rb +10 -6
  555. data/lib/datadog/tracing/pipeline.rb +3 -3
  556. data/lib/datadog/tracing/propagation/http.rb +3 -98
  557. data/lib/datadog/tracing/runtime/metrics.rb +1 -1
  558. data/lib/datadog/tracing/sampling/all_sampler.rb +1 -1
  559. data/lib/datadog/tracing/sampling/ext.rb +31 -0
  560. data/lib/datadog/tracing/sampling/priority_sampler.rb +62 -9
  561. data/lib/datadog/tracing/sampling/rate_by_key_sampler.rb +10 -11
  562. data/lib/datadog/tracing/sampling/rate_by_service_sampler.rb +32 -8
  563. data/lib/datadog/tracing/sampling/rate_limiter.rb +4 -1
  564. data/lib/datadog/tracing/sampling/rate_sampler.rb +27 -10
  565. data/lib/datadog/tracing/sampling/rule.rb +3 -3
  566. data/lib/datadog/tracing/sampling/rule_sampler.rb +8 -7
  567. data/lib/datadog/tracing/sampling/span/ext.rb +25 -0
  568. data/lib/datadog/tracing/sampling/span/matcher.rb +89 -0
  569. data/lib/datadog/tracing/sampling/span/rule.rb +82 -0
  570. data/lib/datadog/tracing/sampling/span/rule_parser.rb +104 -0
  571. data/lib/datadog/tracing/sampling/span/sampler.rb +75 -0
  572. data/lib/datadog/tracing/span.rb +24 -20
  573. data/lib/datadog/tracing/span_operation.rb +13 -13
  574. data/lib/datadog/tracing/sync_writer.rb +5 -5
  575. data/lib/datadog/tracing/trace_digest.rb +88 -2
  576. data/lib/datadog/tracing/trace_operation.rb +60 -15
  577. data/lib/datadog/tracing/trace_segment.rb +13 -8
  578. data/lib/datadog/tracing/tracer.rb +49 -21
  579. data/lib/datadog/tracing/utils.rb +50 -0
  580. data/lib/datadog/tracing/workers/trace_writer.rb +9 -9
  581. data/lib/datadog/tracing/workers.rb +3 -3
  582. data/lib/datadog/tracing/writer.rb +12 -5
  583. data/lib/datadog/tracing.rb +8 -8
  584. data/lib/ddtrace/auto_instrument.rb +9 -2
  585. data/lib/ddtrace/transport/ext.rb +7 -1
  586. data/lib/ddtrace/transport/http/adapters/net.rb +3 -2
  587. data/lib/ddtrace/transport/http/adapters/test.rb +1 -1
  588. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +2 -2
  589. data/lib/ddtrace/transport/http/api/map.rb +1 -1
  590. data/lib/ddtrace/transport/http/api.rb +4 -4
  591. data/lib/ddtrace/transport/http/builder.rb +5 -5
  592. data/lib/ddtrace/transport/http/client.rb +2 -2
  593. data/lib/ddtrace/transport/http/response.rb +1 -1
  594. data/lib/ddtrace/transport/http/statistics.rb +1 -1
  595. data/lib/ddtrace/transport/http/traces.rb +5 -5
  596. data/lib/ddtrace/transport/http.rb +12 -9
  597. data/lib/ddtrace/transport/io/client.rb +2 -2
  598. data/lib/ddtrace/transport/io/response.rb +1 -1
  599. data/lib/ddtrace/transport/io/traces.rb +3 -3
  600. data/lib/ddtrace/transport/io.rb +3 -3
  601. data/lib/ddtrace/transport/statistics.rb +2 -2
  602. data/lib/ddtrace/transport/trace_formatter.rb +14 -10
  603. data/lib/ddtrace/transport/traces.rb +8 -6
  604. data/lib/ddtrace/version.rb +1 -1
  605. data/lib/ddtrace.rb +6 -6
  606. metadata +127 -48
  607. data/.editorconfig +0 -22
  608. data/.gitignore +0 -58
  609. data/CONTRIBUTING.md +0 -81
  610. data/ddtrace.gemspec +0 -68
  611. data/docs/0.x-trace.png +0 -0
  612. data/docs/1.0-trace.png +0 -0
  613. data/docs/AutoInstrumentation.md +0 -36
  614. data/docs/Deprecation.md +0 -8
  615. data/docs/DevelopmentGuide.md +0 -259
  616. data/docs/GettingStarted.md +0 -2688
  617. data/docs/ProfilingDevelopment.md +0 -110
  618. data/docs/PublicApi.md +0 -14
  619. data/docs/UpgradeGuide.md +0 -736
  620. data/ext/ddtrace_profiling_native_extension/libddprof_helpers.h +0 -13
  621. data/lib/datadog/profiling/recorder.rb +0 -117
  622. data/lib/datadog/profiling/transport/client.rb +0 -16
  623. data/lib/datadog/profiling/transport/http/api/endpoint.rb +0 -107
  624. data/lib/datadog/profiling/transport/http/api/instance.rb +0 -38
  625. data/lib/datadog/profiling/transport/http/api/spec.rb +0 -42
  626. data/lib/datadog/profiling/transport/http/api.rb +0 -45
  627. data/lib/datadog/profiling/transport/http/builder.rb +0 -30
  628. data/lib/datadog/profiling/transport/http/client.rb +0 -35
  629. data/lib/datadog/profiling/transport/http/response.rb +0 -23
  630. data/lib/datadog/profiling/transport/http.rb +0 -112
  631. data/lib/datadog/profiling/transport/io/client.rb +0 -29
  632. data/lib/datadog/profiling/transport/io/response.rb +0 -18
  633. data/lib/datadog/profiling/transport/io.rb +0 -32
  634. data/lib/datadog/profiling/transport/parcel.rb +0 -19
  635. data/lib/datadog/profiling/transport/request.rb +0 -17
  636. data/lib/datadog/profiling/transport/response.rb +0 -10
  637. data/lib/datadog/tracing/distributed/headers/b3.rb +0 -55
  638. data/lib/datadog/tracing/distributed/headers/b3_single.rb +0 -67
  639. data/lib/datadog/tracing/distributed/headers/datadog.rb +0 -52
  640. data/lib/datadog/tracing/distributed/parser.rb +0 -70
  641. data/lib/datadog/tracing/propagation/grpc.rb +0 -88
@@ -1,2688 +0,0 @@
1
- ***Version 1.0.0 has been released. Check out our [upgrade guide](https://github.com/DataDog/dd-trace-rb/blob/master/docs/UpgradeGuide.md#from-0x-to-10) for more details.***
2
-
3
- # Datadog Ruby Trace Client
4
-
5
- `ddtrace` is Datadog’s tracing client for Ruby. It is used to trace requests as they flow across web servers,
6
- databases and microservices so that developers have high visibility into bottlenecks and troublesome requests.
7
-
8
- ## Getting started
9
-
10
- For the general APM documentation, see our [setup documentation][setup docs].
11
-
12
- For more information about what APM looks like once your application is sending information to Datadog, take a look at [Visualizing your APM data][visualization docs].
13
-
14
- For the library API documentation, see our [YARD documentation][yard docs].
15
-
16
- To contribute, check out the [contribution guidelines][contribution docs] and [development guide][development docs].
17
-
18
- [setup docs]: https://docs.datadoghq.com/tracing/
19
- [development docs]: https://github.com/DataDog/dd-trace-rb/blob/master/README.md#development
20
- [visualization docs]: https://docs.datadoghq.com/tracing/visualization/
21
- [contribution docs]: https://github.com/DataDog/dd-trace-rb/blob/master/CONTRIBUTING.md
22
- [development docs]: https://github.com/DataDog/dd-trace-rb/blob/master/docs/DevelopmentGuide.md
23
- [yard docs]: https://www.rubydoc.info/gems/ddtrace/
24
-
25
- ## Table of Contents
26
-
27
- - [Compatibility](#compatibility)
28
- - [Installation](#installation)
29
- - [Setup the Datadog Agent for tracing](#setup-the-datadog-agent-for-tracing)
30
- - [Instrument your application](#instrument-your-application)
31
- - [Rails applications](#rails-applications)
32
- - [Ruby applications](#ruby-applications)
33
- - [Configuring OpenTracing](#configuring-opentracing)
34
- - [Configuring OpenTelemetry](#configuring-opentelemetry)
35
- - [Connect your application to the Datadog Agent](#connect-your-application-to-the-datadog-agent)
36
- - [Manual instrumentation](#manual-instrumentation)
37
- - [Integration instrumentation](#integration-instrumentation)
38
- - [Action Cable](#action-cable)
39
- - [Action Mailer](#action-mailer)
40
- - [Action Pack](#action-pack)
41
- - [Action View](#action-view)
42
- - [Active Job](#active-job)
43
- - [Active Model Serializers](#active-model-serializers)
44
- - [Active Record](#active-record)
45
- - [Active Support](#active-support)
46
- - [AWS](#aws)
47
- - [Concurrent Ruby](#concurrent-ruby)
48
- - [Cucumber](#cucumber)
49
- - [Dalli](#dalli)
50
- - [DelayedJob](#delayedjob)
51
- - [Elasticsearch](#elasticsearch)
52
- - [Ethon & Typhoeus](#ethon)
53
- - [Excon](#excon)
54
- - [Faraday](#faraday)
55
- - [Grape](#grape)
56
- - [GraphQL](#graphql)
57
- - [gRPC](#grpc)
58
- - [http.rb](#httprb)
59
- - [httpclient](#httpclient)
60
- - [httpx](#httpx)
61
- - [Kafka](#kafka)
62
- - [MongoDB](#mongodb)
63
- - [MySQL2](#mysql2)
64
- - [Net/HTTP](#nethttp)
65
- - [Presto](#presto)
66
- - [Qless](#qless)
67
- - [Que](#que)
68
- - [Racecar](#racecar)
69
- - [Rack](#rack)
70
- - [Rails](#rails)
71
- - [Rake](#rake)
72
- - [Redis](#redis)
73
- - [Resque](#resque)
74
- - [Rest Client](#rest-client)
75
- - [RSpec](#rspec)
76
- - [Sequel](#sequel)
77
- - [Shoryuken](#shoryuken)
78
- - [Sidekiq](#sidekiq)
79
- - [Sinatra](#sinatra)
80
- - [Sneakers](#sneakers)
81
- - [Sucker Punch](#sucker-punch)
82
- - [Additional configuration](#additional-configuration)
83
- - [Custom logging](#custom-logging)
84
- - [Environment and tags](#environment-and-tags)
85
- - [Debugging and diagnostics](#debugging-and-diagnostics)
86
- - [Sampling](#sampling)
87
- - [Application-side sampling](#application-side-sampling)
88
- - [Priority sampling](#priority-sampling)
89
- - [Distributed tracing](#distributed-tracing)
90
- - [HTTP request queuing](#http-request-queuing)
91
- - [Processing pipeline](#processing-pipeline)
92
- - [Filtering](#filtering)
93
- - [Processing](#processing)
94
- - [Trace correlation](#trace-correlation)
95
- - [Configuring the transport layer](#configuring-the-transport-layer)
96
- - [Metrics](#metrics)
97
- - [For application runtime](#for-application-runtime)
98
- - [OpenTracing](#opentracing)
99
- - [Profiling](#profiling)
100
- - [Troubleshooting](#troubleshooting)
101
- - [Profiling Resque jobs](#profiling-resque-jobs)
102
- - [Known issues and suggested configurations](#known-issues-and-suggested-configurations)
103
- - [Payload too large](#payload-too-large)
104
- - [Stack level too deep](#stack-level-too-deep)
105
-
106
- ## Compatibility
107
-
108
- <!--
109
- Note: Please replicate any changes to this section also to
110
- https://github.com/datadog/documentation/blob/master/content/en/tracing/setup_overview/compatibility_requirements/ruby.md
111
- so that they remain in sync.
112
- -->
113
-
114
- **Supported Ruby interpreters**:
115
-
116
- | Type | Documentation | Version | Support type | Gem version support |
117
- | ----- | -------------------------- | ----- | ------------------------------------ | ------------------- |
118
- | MRI | https://www.ruby-lang.org/ | 3.1 | Full | Latest |
119
- | | | 3.0 | Full | Latest |
120
- | | | 2.7 | Full | Latest |
121
- | | | 2.6 | Full | Latest |
122
- | | | 2.5 | Full | Latest |
123
- | | | 2.4 | Full | Latest |
124
- | | | 2.3 | Full | Latest |
125
- | | | 2.2 | Full | Latest |
126
- | | | 2.1 | Full | Latest |
127
- | | | 2.0 | EOL since June 7th, 2021 | < 0.50.0 |
128
- | | | 1.9.3 | EOL since August 6th, 2020 | < 0.27.0 |
129
- | | | 1.9.1 | EOL since August 6th, 2020 | < 0.27.0 |
130
- | JRuby | https://www.jruby.org | 9.3 | Full | Latest |
131
- | | | 9.2 | Full | Latest |
132
-
133
- **Supported web servers**:
134
-
135
- | Type | Documentation | Version | Support type |
136
- | --------- | --------------------------------- | ------------ | ------------ |
137
- | Puma | http://puma.io/ | 2.16+ / 3.6+ | Full |
138
- | Unicorn | https://bogomips.org/unicorn/ | 4.8+ / 5.1+ | Full |
139
- | Passenger | https://www.phusionpassenger.com/ | 5.0+ | Full |
140
-
141
- **Supported tracing frameworks**:
142
-
143
- | Type | Documentation | Version | Gem version support |
144
- | ----------- | ----------------------------------------------- | --------------------- | ------------------- |
145
- | OpenTracing | https://github.com/opentracing/opentracing-ruby | 0.4.1+ (w/ Ruby 2.1+) | >= 0.16.0 |
146
-
147
- *Full* support indicates all tracer features are available.
148
-
149
- *Deprecated* indicates support will transition to *Maintenance* in a future release.
150
-
151
- *Maintenance* indicates only critical bugfixes are backported until EOL.
152
-
153
- *EOL* indicates support is no longer provided.
154
-
155
- ### Apple macOS support
156
-
157
- Use of `ddtrace` on macOS is supported for development, but not for production deployments.
158
-
159
- ### Microsoft Windows support
160
-
161
- Using `ddtrace` on Microsoft Windows is currently unsupported. We'll still accept community contributions and issues,
162
- but will consider them as having low priority.
163
-
164
- ## Installation
165
-
166
- Adding tracing to your Ruby application only takes a few quick steps:
167
-
168
- 1. Setup the Datadog Agent for tracing
169
- 2. Instrument your application
170
- 3. Connect your application to the Datadog Agent
171
-
172
- ### Setup the Datadog Agent for tracing
173
-
174
- Before installing `ddtrace`, [install the Datadog Agent](https://docs.datadoghq.com/agent/), to which `ddtrace` will send trace data.
175
-
176
- Then configure the Datadog Agent to accept traces. To do this, either:
177
-
178
- - Set `DD_APM_ENABLED=true` in the agent's environment
179
-
180
- OR
181
-
182
- - Add `apm_enabled: true` to the [agent's configuration file](https://docs.datadoghq.com/agent/guide/agent-configuration-files/?tab=agentv6v7#agent-main-configuration-file)
183
-
184
- *Additionally, in containerized environments...*
185
-
186
- - Set `DD_APM_NON_LOCAL_TRAFFIC=true` in the agent's environment
187
-
188
- OR
189
-
190
- - Add `apm_non_local_traffic: true` to the [agent's configuration file](https://docs.datadoghq.com/agent/guide/agent-configuration-files/?tab=agentv6v7#agent-main-configuration-file).
191
-
192
- See the specific setup instructions for [Docker](https://docs.datadoghq.com/agent/docker/apm/?tab=ruby), [Kubernetes](https://docs.datadoghq.com/agent/kubernetes/apm/?tab=helm), [Amazon ECS](https://docs.datadoghq.com/agent/amazon_ecs/apm/?tab=ruby) or [Fargate](https://docs.datadoghq.com/integrations/ecs_fargate/#trace-collection) to ensure that the Agent is configured to receive traces in a containerized environment.
193
-
194
- #### Configuring trace data ingestion
195
-
196
- The Datadog agent will listen for traces via HTTP on port `8126` by default.
197
-
198
- You may change the protocol or port the agent listens for trace data using the following:
199
-
200
- **For HTTP over TCP**:
201
-
202
- - Set `DD_APM_RECEIVER_PORT=<port>` in the agent's environment
203
-
204
- OR
205
-
206
- - Add `apm_config: receiver_port: <port>` to the [agent's configuration file](https://docs.datadoghq.com/agent/guide/agent-configuration-files/?tab=agentv6v7#agent-main-configuration-file)
207
-
208
- **For Unix Domain Socket (UDS)**:
209
-
210
- - Set `DD_APM_RECEIVER_SOCKET=<path-to-socket-file>`
211
-
212
- OR
213
-
214
- - Add `apm_config: receiver_socket: <path-to-socket-file>` to the [agent's configuration file](https://docs.datadoghq.com/agent/guide/agent-configuration-files/?tab=agentv6v7#agent-main-configuration-file)
215
-
216
- ### Instrument your application
217
-
218
- #### Rails applications
219
-
220
- 1. Add the `ddtrace` gem to your Gemfile:
221
-
222
- ```ruby
223
- source 'https://rubygems.org'
224
- gem 'ddtrace', require: 'ddtrace/auto_instrument'
225
- ```
226
-
227
- 2. Install the gem with `bundle install`
228
-
229
- 3. Create a `config/initializers/datadog.rb` file containing:
230
-
231
- ```ruby
232
- Datadog.configure do |c|
233
- # Add additional configuration here.
234
- # Activate integrations, change tracer settings, etc...
235
- end
236
- ```
237
-
238
- Using this block you can:
239
-
240
- - [Add additional configuration settings](#additional-configuration)
241
- - [Activate or reconfigure instrumentation](#integration-instrumentation)
242
-
243
- #### Ruby applications
244
-
245
- 1. Add the `ddtrace` gem to your Gemfile:
246
-
247
- ```ruby
248
- source 'https://rubygems.org'
249
- gem 'ddtrace'
250
- ```
251
-
252
- 2. Install the gem with `bundle install`
253
- 3. `require` any [supported libraries or frameworks](#integration-instrumentation) that should be instrumented.
254
- 4. Add `require 'ddtrace/auto_instrument'` to your application. _Note:_ This must be done _after_ requiring any supported libraries or frameworks.
255
-
256
- ```ruby
257
- # Example frameworks and libraries
258
- require 'sinatra'
259
- require 'faraday'
260
- require 'redis'
261
-
262
- require 'ddtrace/auto_instrument'
263
- ```
264
-
265
- 5. Add a configuration block to your application:
266
-
267
- ```ruby
268
- Datadog.configure do |c|
269
- # Add additional configuration here.
270
- # Activate integrations, change tracer settings, etc...
271
- end
272
- ```
273
-
274
- Using this block you can:
275
-
276
- - [Add additional configuration settings](#additional-configuration)
277
- - [Activate or reconfigure instrumentation](#integration-instrumentation)
278
-
279
- #### Configuring OpenTracing
280
-
281
- 1. Add the `ddtrace` gem to your Gemfile:
282
-
283
- ```ruby
284
- source 'https://rubygems.org'
285
- gem 'ddtrace'
286
- ```
287
-
288
- 2. Install the gem with `bundle install`
289
- 3. To your OpenTracing configuration file, add the following:
290
-
291
- ```ruby
292
- require 'opentracing'
293
- require 'datadog/tracing'
294
- require 'datadog/opentracer'
295
-
296
- # Activate the Datadog tracer for OpenTracing
297
- OpenTracing.global_tracer = Datadog::OpenTracer::Tracer.new
298
- ```
299
-
300
- 4. Add a configuration block to your application:
301
-
302
- ```ruby
303
- Datadog.configure do |c|
304
- # Configure the Datadog tracer here.
305
- # Activate integrations, change tracer settings, etc...
306
- # By default without additional configuration,
307
- # no additional integrations will be traced, only
308
- # what you have instrumented with OpenTracing.
309
- end
310
- ```
311
-
312
- Using this block you can:
313
-
314
- - [Add additional Datadog configuration settings](#additional-configuration)
315
- - [Activate or reconfigure Datadog instrumentation](#integration-instrumentation)
316
-
317
- #### Configuring OpenTelemetry
318
-
319
- You can send OpenTelemetry traces directly to the Datadog agent (without `ddtrace`) by using OTLP. Check out our documentation on [OTLP ingest in the Datadog Agent](https://docs.datadoghq.com/tracing/setup_overview/open_standards/#otlp-ingest-in-datadog-agent) for details.
320
-
321
- ### Connect your application to the Datadog Agent
322
-
323
- By default, `ddtrace` will connect to the agent using the first available settings in the listed priority:
324
-
325
- 1. Via any explicitly provided configuration settings (hostname/port/transport)
326
- 2. Via Unix Domain Socket (UDS) located at `/var/run/datadog/apm.socket`
327
- 3. Via HTTP over TCP to `127.0.0.1:8126`
328
-
329
- If your Datadog Agent is listening at any of these locations, no further configuration should be required.
330
-
331
- If your agent runs on a different host or container than your application, or you would like to send traces via a different protocol, you will need to configure your application accordingly.
332
-
333
- - [How to send trace data via HTTP over TCP to agent](#changing-default-agent-hostname-and-port)
334
- - [How to send trace data via Unix Domain Socket (UDS) to agent](#using-the-unix-domain-socket-uds-adapter)
335
-
336
- ### Final steps for installation
337
-
338
- After setting up, your services will appear on the [APM services page](https://app.datadoghq.com/apm/services) within a few minutes. Learn more about [using the APM UI][visualization docs].
339
-
340
- ## Manual Instrumentation
341
-
342
- If you aren't using a supported framework instrumentation, you may want to manually instrument your code.
343
-
344
- To trace any Ruby code, you can use the `Datadog::Tracing.trace` method:
345
-
346
- ```ruby
347
- Datadog::Tracing.trace(name, options) do |span, trace|
348
- # Wrap this block around the code you want to instrument
349
- # Additionally, you can modify the span here.
350
- # e.g. Change the resource name, set tags, etc...
351
- end
352
- ```
353
-
354
- Where `name` should be a `String` that describes the generic kind of operation being done (e.g. `'web.request'`, or `'request.parse'`)
355
-
356
- And `options` is an optional `Hash` that accepts the following parameters:
357
-
358
- | Key | Type | Description | Default |
359
- | --------------- | ----------------------- | --- | --- |
360
- | `autostart` | `Bool` | Whether the time measurement should be started automatically. If `false`, user must call `span.start`. | `true` |
361
- | `continue_from` | `Datadog::TraceDigest` | Continues a trace that originated from another execution context. TraceDigest describes the continuation point. | `nil` |
362
- | `on_error` | `Proc` | Overrides error handling behavior, when a span raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
363
- | `resource` | `String` | Name of the resource or action being operated on. Traces with the same resource value will be grouped together for the purpose of metrics (but still independently viewable.) Usually domain specific, such as a URL, query, request, etc. (e.g. `'Article#submit'`, `http://example.com/articles/list`.) | `name` of Span. |
364
- | `service` | `String` | The service name which this span belongs (e.g. `'my-web-service'`) | Tracer `default-service`, `$PROGRAM_NAME` or `'ruby'` |
365
- | `start_time` | `Time` | When the span actually starts. Useful when tracing events that have already happened. | `Time.now` |
366
- | `tags` | `Hash` | Extra tags which should be added to the span. | `{}` |
367
- | `type` | `String` | The type of the span (such as `'http'`, `'db'`, etc.) | `nil` |
368
-
369
- It's highly recommended you set both `service` and `resource` at a minimum. Spans without a `service` or `resource` as `nil` will be discarded by the Datadog agent.
370
-
371
- Example of manual instrumentation in action:
372
-
373
- ```ruby
374
- get '/posts' do
375
- Datadog::Tracing.trace('web.request', service: 'my-blog', resource: 'GET /posts') do |span|
376
- # Trace the activerecord call
377
- Datadog::Tracing.trace('posts.fetch') do
378
- @posts = Posts.order(created_at: :desc).limit(10)
379
- end
380
-
381
- # Add some APM tags
382
- span.set_tag('http.method', request.request_method)
383
- span.set_tag('posts.count', @posts.length)
384
-
385
- # Trace the template rendering
386
- Datadog::Tracing.trace('template.render') do
387
- erb :index
388
- end
389
- end
390
- end
391
- ```
392
-
393
- ### Asynchronous tracing
394
-
395
- It might not always be possible to wrap `Datadog::Tracing.trace` around a block of code. Some event or notification based instrumentation might only notify you when an event begins or ends.
396
-
397
- To trace these operations, you can trace code asynchronously by calling `Datadog::Tracing.trace` without a block:
398
-
399
- ```ruby
400
- # Some instrumentation framework calls this after an event finishes...
401
- def db_query(start, finish, query)
402
- span = Datadog::Tracing.trace('database.query', start_time: start)
403
- span.resource = query
404
- span.finish(finish)
405
- end
406
- ```
407
-
408
- Calling `Datadog::Tracing.trace` without a block will cause the function to return a `Datadog::SpanOperation` that is started, but not finished. You can then modify this span however you wish, then close it `finish`.
409
-
410
- *You must not leave any unfinished spans.* If any spans are left open when the trace completes, the trace will be discarded. You can [activate debug mode](#tracer-settings) to check for warnings if you suspect this might be happening.
411
-
412
- To avoid this scenario when handling start/finish events, you can use `Datadog::Tracing.active_span` to get the current active span.
413
-
414
- ```ruby
415
- # e.g. ActiveSupport::Notifications calls this when an event starts
416
- def start(name, id, payload)
417
- # Start a span
418
- Datadog::Tracing.trace(name)
419
- end
420
-
421
- # e.g. ActiveSupport::Notifications calls this when an event finishes
422
- def finish(name, id, payload)
423
- # Retrieve current active span (thread-safe)
424
- current_span = Datadog::Tracing.active_span
425
- unless current_span.nil?
426
- current_span.resource = payload[:query]
427
- current_span.finish
428
- end
429
- end
430
- ```
431
- ### Enriching traces from nested methods
432
-
433
- You can tag additional information to the current active span from any method. Note however that if the method is called and there is no span currently active `active_span` will be nil.
434
-
435
- ```ruby
436
- # e.g. adding tag to active span
437
-
438
- current_span = Datadog::Tracing.active_span
439
- current_span.set_tag('my_tag', 'my_value') unless current_span.nil?
440
- ```
441
-
442
- You can also get the current active trace using the `active_trace` method. This method will return `nil` if there is no active trace.
443
-
444
- ```ruby
445
- # e.g. accessing active trace
446
-
447
- current_trace = Datadog::Tracing.active_trace
448
- ```
449
-
450
- ## Integration instrumentation
451
-
452
- Many popular libraries and frameworks are supported out-of-the-box, which can be auto-instrumented. Although they are not activated automatically, they can be easily activated and configured by using the `Datadog.configure` API:
453
-
454
- ```ruby
455
- Datadog.configure do |c|
456
- # Activates and configures an integration
457
- c.tracing.instrument :integration_name, options
458
- end
459
- ```
460
-
461
- `options` is a `Hash` of integration-specific configuration settings.
462
-
463
- For a list of available integrations, and their configuration options, please refer to the following:
464
-
465
- <!--
466
- Note: Please replicate any changes to this section also to
467
- https://github.com/datadog/documentation/blob/master/content/en/tracing/setup_overview/compatibility_requirements/ruby.md
468
- so that they remain in sync.
469
- -->
470
-
471
- | Name | Key | Versions Supported: MRI | Versions Supported: JRuby | How to configure | Gem source |
472
- | -------------------------- | -------------------------- | ------------------------ | --------------------------| ----------------------------------- | ------------------------------------------------------------------------------ |
473
- | Action Cable | `action_cable` | `>= 5.0` | `>= 5.0` | *[Link](#action-cable)* | *[Link](https://github.com/rails/rails/tree/master/actioncable)* |
474
- | Action Mailer | `action_mailer` | `>= 5.0` | `>= 5.0` | *[Link](#action-mailer)* | *[Link](https://github.com/rails/rails/tree/master/actionmailer)* |
475
- | Action Pack | `action_pack` | `>= 3.2` | `>= 3.2` | *[Link](#action-pack)* | *[Link](https://github.com/rails/rails/tree/master/actionpack)* |
476
- | Action View | `action_view` | `>= 3.2` | `>= 3.2` | *[Link](#action-view)* | *[Link](https://github.com/rails/rails/tree/master/actionview)* |
477
- | Active Job | `active_job` | `>= 4.2` | `>= 4.2` | *[Link](#active-job)* | *[Link](https://github.com/rails/rails/tree/master/activejob)* |
478
- | Active Model Serializers | `active_model_serializers` | `>= 0.9` | `>= 0.9` | *[Link](#active-model-serializers)* | *[Link](https://github.com/rails-api/active_model_serializers)* |
479
- | Active Record | `active_record` | `>= 3.2` | `>= 3.2` | *[Link](#active-record)* | *[Link](https://github.com/rails/rails/tree/master/activerecord)* |
480
- | Active Support | `active_support` | `>= 3.2` | `>= 3.2` | *[Link](#active-support)* | *[Link](https://github.com/rails/rails/tree/master/activesupport)* |
481
- | AWS | `aws` | `>= 2.0` | `>= 2.0` | *[Link](#aws)* | *[Link](https://github.com/aws/aws-sdk-ruby)* |
482
- | Concurrent Ruby | `concurrent_ruby` | `>= 0.9` | `>= 0.9` | *[Link](#concurrent-ruby)* | *[Link](https://github.com/ruby-concurrency/concurrent-ruby)* |
483
- | Dalli | `dalli` | `>= 2.0` | `>= 2.0` | *[Link](#dalli)* | *[Link](https://github.com/petergoldstein/dalli)* |
484
- | DelayedJob | `delayed_job` | `>= 4.1` | `>= 4.1` | *[Link](#delayedjob)* | *[Link](https://github.com/collectiveidea/delayed_job)* |
485
- | Elasticsearch | `elasticsearch` | `>= 1.0` | `>= 1.0` | *[Link](#elasticsearch)* | *[Link](https://github.com/elastic/elasticsearch-ruby)* |
486
- | Ethon | `ethon` | `>= 0.11` | `>= 0.11` | *[Link](#ethon)* | *[Link](https://github.com/typhoeus/ethon)* |
487
- | Excon | `excon` | `>= 0.50` | `>= 0.50` | *[Link](#excon)* | *[Link](https://github.com/excon/excon)* |
488
- | Faraday | `faraday` | `>= 0.14` | `>= 0.14` | *[Link](#faraday)* | *[Link](https://github.com/lostisland/faraday)* |
489
- | Grape | `grape` | `>= 1.0` | `>= 1.0` | *[Link](#grape)* | *[Link](https://github.com/ruby-grape/grape)* |
490
- | GraphQL | `graphql` | `>= 1.7.9` | `>= 1.7.9` | *[Link](#graphql)* | *[Link](https://github.com/rmosolgo/graphql-ruby)* |
491
- | gRPC | `grpc` | `>= 1.7` | *gem not available* | *[Link](#grpc)* | *[Link](https://github.com/grpc/grpc/tree/master/src/rubyc)* |
492
- | http.rb | `httprb` | `>= 2.0` | `>= 2.0` | *[Link](#httprb)* | *[Link](https://github.com/httprb/http)* |
493
- | httpclient | `httpclient` | `>= 2.2` | `>= 2.2` | *[Link](#httpclient)* | *[Link](https://github.com/nahi/httpclient)* |
494
- | httpx | `httpx` | `>= 0.11` | `>= 0.11` | *[Link](#httpx)* | *[Link](https://gitlab.com/honeyryderchuck/httpx)* |
495
- | Kafka | `ruby-kafka` | `>= 0.7.10` | `>= 0.7.10` | *[Link](#kafka)* | *[Link](https://github.com/zendesk/ruby-kafka)* |
496
- | Makara (via Active Record) | `makara` | `>= 0.3.5` | `>= 0.3.5` | *[Link](#active-record)* | *[Link](https://github.com/instacart/makara)* |
497
- | MongoDB | `mongo` | `>= 2.1` | `>= 2.1` | *[Link](#mongodb)* | *[Link](https://github.com/mongodb/mongo-ruby-driver)* |
498
- | MySQL2 | `mysql2` | `>= 0.3.21` | *gem not available* | *[Link](#mysql2)* | *[Link](https://github.com/brianmario/mysql2)* |
499
- | Net/HTTP | `http` | *(Any supported Ruby)* | *(Any supported Ruby)* | *[Link](#nethttp)* | *[Link](https://ruby-doc.org/stdlib-2.4.0/libdoc/net/http/rdoc/Net/HTTP.html)* |
500
- | Presto | `presto` | `>= 0.5.14` | `>= 0.5.14` | *[Link](#presto)* | *[Link](https://github.com/treasure-data/presto-client-ruby)* |
501
- | Qless | `qless` | `>= 0.10.0` | `>= 0.10.0` | *[Link](#qless)* | *[Link](https://github.com/seomoz/qless)* |
502
- | Que | `que` | `>= 1.0.0.beta2` | `>= 1.0.0.beta2` | *[Link](#que)* | *[Link](https://github.com/que-rb/que)* |
503
- | Racecar | `racecar` | `>= 0.3.5` | `>= 0.3.5` | *[Link](#racecar)* | *[Link](https://github.com/zendesk/racecar)* |
504
- | Rack | `rack` | `>= 1.1` | `>= 1.1` | *[Link](#rack)* | *[Link](https://github.com/rack/rack)* |
505
- | Rails | `rails` | `>= 3.2` | `>= 3.2` | *[Link](#rails)* | *[Link](https://github.com/rails/rails)* |
506
- | Rake | `rake` | `>= 12.0` | `>= 12.0` | *[Link](#rake)* | *[Link](https://github.com/ruby/rake)* |
507
- | Redis | `redis` | `>= 3.2` | `>= 3.2` | *[Link](#redis)* | *[Link](https://github.com/redis/redis-rb)* |
508
- | Resque | `resque` | `>= 1.0` | `>= 1.0` | *[Link](#resque)* | *[Link](https://github.com/resque/resque)* |
509
- | Rest Client | `rest-client` | `>= 1.8` | `>= 1.8` | *[Link](#rest-client)* | *[Link](https://github.com/rest-client/rest-client)* |
510
- | Sequel | `sequel` | `>= 3.41` | `>= 3.41` | *[Link](#sequel)* | *[Link](https://github.com/jeremyevans/sequel)* |
511
- | Shoryuken | `shoryuken` | `>= 3.2` | `>= 3.2` | *[Link](#shoryuken)* | *[Link](https://github.com/phstc/shoryuken)* |
512
- | Sidekiq | `sidekiq` | `>= 3.5.4` | `>= 3.5.4` | *[Link](#sidekiq)* | *[Link](https://github.com/mperham/sidekiq)* |
513
- | Sinatra | `sinatra` | `>= 1.4` | `>= 1.4` | *[Link](#sinatra)* | *[Link](https://github.com/sinatra/sinatra)* |
514
- | Sneakers | `sneakers` | `>= 2.12.0` | `>= 2.12.0` | *[Link](#sneakers)* | *[Link](https://github.com/jondot/sneakers)* |
515
- | Sucker Punch | `sucker_punch` | `>= 2.0` | `>= 2.0` | *[Link](#sucker-punch)* | *[Link](https://github.com/brandonhilkert/sucker_punch)* |
516
-
517
- #### CI Visibility
518
-
519
- For Datadog CI Visibility, library instrumentation can be activated and configured by using the following `Datadog.configure` API:
520
-
521
- ```ruby
522
- Datadog.configure do |c|
523
- # Activates and configures an integration
524
- c.ci.instrument :integration_name, options
525
- end
526
- ```
527
-
528
- `options` is a `Hash` of integration-specific configuration settings.
529
-
530
- These are the available CI Visibility integrations:
531
-
532
- | Name | Key | Versions Supported: MRI | Versions Supported: JRuby | How to configure | Gem source |
533
- |-----------|------------|-------------------------|---------------------------|---------------------|-----------------------------------------------------|
534
- | Cucumber | `cucumber` | `>= 3.0` | `>= 1.7.16` | *[Link](#cucumber)* | *[Link](https://github.com/cucumber/cucumber-ruby)* |
535
- | RSpec | `rspec` | `>= 3.0.0` | `>= 3.0.0` | *[Link](#rspec)* | *[Link](https://github.com/rspec/rspec)* |
536
-
537
- ### Action Cable
538
-
539
- The Action Cable integration traces broadcast messages and channel actions.
540
-
541
- You can enable it through `Datadog.configure`:
542
-
543
- ```ruby
544
- require 'ddtrace'
545
-
546
- Datadog.configure do |c|
547
- c.tracing.instrument :action_cable
548
- end
549
- ```
550
-
551
- ### Action Mailer
552
-
553
- The Action Mailer integration provides tracing for Rails 5 ActionMailer actions.
554
-
555
- You can enable it through `Datadog.configure`:
556
-
557
- ```ruby
558
- require 'ddtrace'
559
- Datadog.configure do |c|
560
- c.tracing.instrument :action_mailer, options
561
- end
562
- ```
563
-
564
- Where `options` is an optional `Hash` that accepts the following parameters:
565
-
566
- | Key | Description | Default |
567
- | --- | ----------- | ------- |
568
- | `analytics_enabled` | Enable analytics for spans produced by this integration. `true` for on, `nil` to defer to global setting, `false` for off. | `false` |
569
- | `email_data` | Whether or not to append additional email payload metadata to `action_mailer.deliver` spans. Fields include `['subject', 'to', 'from', 'bcc', 'cc', 'date', 'perform_deliveries']`. | `false` |
570
-
571
- ### Action Pack
572
-
573
- Most of the time, Action Pack is set up as part of Rails, but it can be activated separately:
574
-
575
- ```ruby
576
- require 'actionpack'
577
- require 'ddtrace'
578
-
579
- Datadog.configure do |c|
580
- c.tracing.instrument :action_pack
581
- end
582
- ```
583
-
584
- ### Action View
585
-
586
- Most of the time, Action View is set up as part of Rails, but it can be activated separately:
587
-
588
- ```ruby
589
- require 'actionview'
590
- require 'ddtrace'
591
-
592
- Datadog.configure do |c|
593
- c.tracing.instrument :action_view, options
594
- end
595
- ```
596
-
597
- Where `options` is an optional `Hash` that accepts the following parameters:
598
-
599
- | Key | Description | Default |
600
- | ---| --- | --- |
601
- | `template_base_path` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` |
602
-
603
- ### Active Job
604
-
605
- Most of the time, Active Job is set up as part of Rails, but it can be activated separately:
606
-
607
- ```ruby
608
- require 'active_job'
609
- require 'ddtrace'
610
-
611
- Datadog.configure do |c|
612
- c.tracing.instrument :active_job
613
- end
614
-
615
- ExampleJob.perform_later
616
- ```
617
-
618
- ### Active Model Serializers
619
-
620
- The Active Model Serializers integration traces the `serialize` event for version 0.9+ and the `render` event for version 0.10+.
621
-
622
- ```ruby
623
- require 'active_model_serializers'
624
- require 'ddtrace'
625
-
626
- Datadog.configure do |c|
627
- c.tracing.instrument :active_model_serializers
628
- end
629
-
630
- my_object = MyModel.new(name: 'my object')
631
- ActiveModelSerializers::SerializableResource.new(test_obj).serializable_hash
632
- ```
633
-
634
- ### Active Record
635
-
636
- Most of the time, Active Record is set up as part of a web framework (Rails, Sinatra...) however, it can be set up alone:
637
-
638
- ```ruby
639
- require 'tmpdir'
640
- require 'sqlite3'
641
- require 'active_record'
642
- require 'ddtrace'
643
-
644
- Datadog.configure do |c|
645
- c.tracing.instrument :active_record, options
646
- end
647
-
648
- Dir::Tmpname.create(['test', '.sqlite']) do |db|
649
- conn = ActiveRecord::Base.establish_connection(adapter: 'sqlite3',
650
- database: db)
651
- conn.connection.execute('SELECT 42') # traced!
652
- end
653
- ```
654
-
655
- Where `options` is an optional `Hash` that accepts the following parameters:
656
-
657
- | Key | Description | Default |
658
- | ---| --- | --- |
659
- | `service_name` | Service name used for database portion of `active_record` instrumentation. | Name of database adapter (e.g. `'mysql2'`) |
660
-
661
- **Configuring trace settings per database**
662
-
663
- You can configure trace settings per database connection by using the `describes` option:
664
-
665
- ```ruby
666
- # Provide a `:describes` option with a connection key.
667
- # Any of the following keys are acceptable and equivalent to one another.
668
- # If a block is provided, it yields a Settings object that
669
- # accepts any of the configuration options listed above.
670
-
671
- Datadog.configure do |c|
672
- # Symbol matching your database connection in config/database.yml
673
- # Only available if you are using Rails with ActiveRecord.
674
- c.tracing.instrument :active_record, describes: :secondary_database, service_name: 'secondary-db'
675
-
676
- # Block configuration pattern.
677
- c.tracing.instrument :active_record, describes: :secondary_database do |second_db|
678
- second_db.service_name = 'secondary-db'
679
- end
680
-
681
- # Connection string with the following connection settings:
682
- # adapter, username, host, port, database
683
- # Other fields are ignored.
684
- c.tracing.instrument :active_record, describes: 'mysql2://root@127.0.0.1:3306/mysql', service_name: 'secondary-db'
685
-
686
- # Hash with following connection settings:
687
- # adapter, username, host, port, database
688
- # Other fields are ignored.
689
- c.tracing.instrument :active_record, describes: {
690
- adapter: 'mysql2',
691
- host: '127.0.0.1',
692
- port: '3306',
693
- database: 'mysql',
694
- username: 'root'
695
- },
696
- service_name: 'secondary-db'
697
-
698
- # If using the `makara` gem, it's possible to match on connection `role`:
699
- c.tracing.instrument :active_record, describes: { makara_role: 'primary' }, service_name: 'primary-db'
700
- c.tracing.instrument :active_record, describes: { makara_role: 'replica' }, service_name: 'secondary-db'
701
- end
702
- ```
703
-
704
- You can also create configurations based on partial matching of database connection fields:
705
-
706
- ```ruby
707
- Datadog.configure do |c|
708
- # Matches any connection on host `127.0.0.1`.
709
- c.tracing.instrument :active_record, describes: { host: '127.0.0.1' }, service_name: 'local-db'
710
-
711
- # Matches any `mysql2` connection.
712
- c.tracing.instrument :active_record, describes: { adapter: 'mysql2'}, service_name: 'mysql-db'
713
-
714
- # Matches any `mysql2` connection to the `reports` database.
715
- #
716
- # In case of multiple matching `describe` configurations, the latest one applies.
717
- # In this case a connection with both adapter `mysql` and database `reports`
718
- # will be configured `service_name: 'reports-db'`, not `service_name: 'mysql-db'`.
719
- c.tracing.instrument :active_record, describes: { adapter: 'mysql2', database: 'reports'}, service_name: 'reports-db'
720
- end
721
- ```
722
-
723
- When multiple `describes` configurations match a connection, the latest configured rule that matches will be applied.
724
-
725
- If ActiveRecord traces an event that uses a connection that matches a key defined by `describes`, it will use the trace settings assigned to that connection. If the connection does not match any of the described connections, it will use default settings defined by `c.tracing.instrument :active_record` instead.
726
-
727
- ### Active Support
728
-
729
- Most of the time, Active Support is set up as part of Rails, but it can be activated separately:
730
-
731
- ```ruby
732
- require 'activesupport'
733
- require 'ddtrace'
734
-
735
- Datadog.configure do |c|
736
- c.tracing.instrument :active_support, options
737
- end
738
-
739
- cache = ActiveSupport::Cache::MemoryStore.new
740
- cache.read('city')
741
- ```
742
-
743
- Where `options` is an optional `Hash` that accepts the following parameters:
744
-
745
- | Key | Description | Default |
746
- | ---| --- | --- |
747
- | `cache_service` | Service name used for caching with `active_support` instrumentation. | `active_support-cache` |
748
-
749
- ### AWS
750
-
751
- The AWS integration will trace every interaction (e.g. API calls) with AWS services (S3, ElastiCache etc.).
752
-
753
- ```ruby
754
- require 'aws-sdk'
755
- require 'ddtrace'
756
-
757
- Datadog.configure do |c|
758
- c.tracing.instrument :aws, options
759
- end
760
-
761
- # Perform traced call
762
- Aws::S3::Client.new.list_buckets
763
- ```
764
-
765
- Where `options` is an optional `Hash` that accepts the following parameters:
766
-
767
- | Key | Description | Default |
768
- | --- | ----------- | ------- |
769
- | `service_name` | Service name used for `aws` instrumentation | `'aws'` |
770
-
771
- ### Concurrent Ruby
772
-
773
- The Concurrent Ruby integration adds support for context propagation when using `::Concurrent::Future`.
774
- Making sure that code traced within the `Future#execute` will have correct parent set.
775
-
776
- To activate your integration, use the `Datadog.configure` method:
777
-
778
- ```ruby
779
- # Inside Rails initializer or equivalent
780
- Datadog.configure do |c|
781
- # Patches ::Concurrent::Future to use ExecutorService that propagates context
782
- c.tracing.instrument :concurrent_ruby
783
- end
784
-
785
- # Pass context into code executed within Concurrent::Future
786
- Datadog::Tracing.trace('outer') do
787
- Concurrent::Future.execute { Datadog::Tracing.trace('inner') { } }.wait
788
- end
789
- ```
790
-
791
- ### Cucumber
792
-
793
- Cucumber integration will trace all executions of scenarios and steps when using `cucumber` framework.
794
-
795
- To activate your integration, use the `Datadog.configure` method:
796
-
797
- ```ruby
798
- require 'cucumber'
799
- require 'ddtrace'
800
-
801
- # Configure default Cucumber integration
802
- Datadog.configure do |c|
803
- c.ci.instrument :cucumber, options
804
- end
805
-
806
- # Example of how to attach tags from scenario to active span
807
- Around do |scenario, block|
808
- active_span = Datadog.configuration[:cucumber][:tracer].active_span
809
- unless active_span.nil?
810
- scenario.tags.filter { |tag| tag.include? ':' }.each do |tag|
811
- active_span.set_tag(*tag.name.split(':', 2))
812
- end
813
- end
814
- block.call
815
- end
816
- ```
817
-
818
- Where `options` is an optional `Hash` that accepts the following parameters:
819
-
820
- | Key | Description | Default |
821
- | --- | ----------- | ------- |
822
- | `enabled` | Defines whether Cucumber tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
823
- | `service_name` | Service name used for `cucumber` instrumentation. | `'cucumber'` |
824
- | `operation_name` | Operation name used for `cucumber` instrumentation. Useful if you want rename automatic trace metrics e.g. `trace.#{operation_name}.errors`. | `'cucumber.test'` |
825
-
826
- ### Dalli
827
-
828
- Dalli integration will trace all calls to your `memcached` server:
829
-
830
- ```ruby
831
- require 'dalli'
832
- require 'ddtrace'
833
-
834
- # Configure default Dalli tracing behavior
835
- Datadog.configure do |c|
836
- c.tracing.instrument :dalli, options
837
- end
838
-
839
- # Configure Dalli tracing behavior for single client
840
- client = Dalli::Client.new('localhost:11211', options)
841
- client.set('abc', 123)
842
- ```
843
-
844
- Where `options` is an optional `Hash` that accepts the following parameters:
845
-
846
- | Key | Description | Default |
847
- | --- | ----------- | ------- |
848
- | `service_name` | Service name used for `dalli` instrumentation | `'memcached'` |
849
-
850
- ### DelayedJob
851
-
852
- The DelayedJob integration uses lifecycle hooks to trace the job executions and enqueues.
853
-
854
- You can enable it through `Datadog.configure`:
855
-
856
- ```ruby
857
- require 'ddtrace'
858
-
859
- Datadog.configure do |c|
860
- c.tracing.instrument :delayed_job, options
861
- end
862
- ```
863
-
864
- Where `options` is an optional `Hash` that accepts the following parameters:
865
-
866
- | Key | Description | Default |
867
- | --- | ----------- | ------- |
868
- | `error_handler` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
869
-
870
- ### Elasticsearch
871
-
872
- The Elasticsearch integration will trace any call to `perform_request` in the `Client` object:
873
-
874
- ```ruby
875
- require 'elasticsearch/transport'
876
- require 'ddtrace'
877
-
878
- Datadog.configure do |c|
879
- c.tracing.instrument :elasticsearch, options
880
- end
881
-
882
- # Perform a query to Elasticsearch
883
- client = Elasticsearch::Client.new url: 'http://127.0.0.1:9200'
884
- response = client.perform_request 'GET', '_cluster/health'
885
-
886
- # In case you want to override the global configuration for a certain client instance
887
- Datadog.configure_onto(client.transport, **options)
888
- ```
889
-
890
- Where `options` is an optional `Hash` that accepts the following parameters:
891
-
892
- | Key | Description | Default |
893
- | --- | ----------- | ------- |
894
- | `quantize` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{}` |
895
- | `service_name` | Service name used for `elasticsearch` instrumentation | `'elasticsearch'` |
896
-
897
- ### Ethon
898
-
899
- The `ethon` integration will trace any HTTP request through `Easy` or `Multi` objects. Note that this integration also supports `Typhoeus` library which is based on `Ethon`.
900
-
901
- ```ruby
902
- require 'ddtrace'
903
-
904
- Datadog.configure do |c|
905
- c.tracing.instrument :ethon, options
906
-
907
- # optionally, specify a different service name for hostnames matching a regex
908
- c.tracing.instrument :ethon, describes: /user-[^.]+\.example\.com/ do |ethon|
909
- ethon.service_name = 'user.example.com'
910
- ethon.split_by_domain = false # Only necessary if split_by_domain is true by default
911
- end
912
- end
913
- ```
914
-
915
- Where `options` is an optional `Hash` that accepts the following parameters:
916
-
917
- | Key | Description | Default |
918
- | --- | ----------- | ------- |
919
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) | `true` |
920
- | `service_name` | Service name for `ethon` instrumentation. | `'ethon'` |
921
- | `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
922
-
923
- ### Excon
924
-
925
- The `excon` integration is available through the `ddtrace` middleware:
926
-
927
- ```ruby
928
- require 'excon'
929
- require 'ddtrace'
930
-
931
- # Configure default Excon tracing behavior
932
- Datadog.configure do |c|
933
- c.tracing.instrument :excon, options
934
-
935
- # optionally, specify a different service name for hostnames matching a regex
936
- c.tracing.instrument :excon, describes: /user-[^.]+\.example\.com/ do |excon|
937
- excon.service_name = 'user.example.com'
938
- excon.split_by_domain = false # Only necessary if split_by_domain is true by default
939
- end
940
- end
941
-
942
- connection = Excon.new('https://example.com')
943
- connection.get
944
- ```
945
-
946
- Where `options` is an optional `Hash` that accepts the following parameters:
947
-
948
- | Key | Description | Default |
949
- | --- | ----------- | ------- |
950
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) | `true` |
951
- | `error_handler` | A `Proc` that accepts a `response` parameter. If it evaluates to a *truthy* value, the trace span is marked as an error. By default only sets 5XX responses as errors. | `nil` |
952
- | `service_name` | Service name for Excon instrumentation. When provided to middleware for a specific connection, it applies only to that connection object. | `'excon'` |
953
- | `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
954
-
955
- **Configuring connections to use different settings**
956
-
957
- If you use multiple connections with Excon, you can give each of them different settings by configuring their constructors with middleware:
958
-
959
- ```ruby
960
- # Wrap the Datadog tracing middleware around the default middleware stack
961
- Excon.new(
962
- 'http://example.com',
963
- middlewares: Datadog::Tracing::Contrib::Excon::Middleware.with(options).around_default_stack
964
- )
965
-
966
- # Insert the middleware into a custom middleware stack.
967
- # NOTE: Trace middleware must be inserted after ResponseParser!
968
- Excon.new(
969
- 'http://example.com',
970
- middlewares: [
971
- Excon::Middleware::ResponseParser,
972
- Datadog::Tracing::Contrib::Excon::Middleware.with(options),
973
- Excon::Middleware::Idempotent
974
- ]
975
- )
976
- ```
977
-
978
- Where `options` is a Hash that contains any of the parameters listed in the table above.
979
-
980
- ### Faraday
981
-
982
- The `faraday` integration is available through the `ddtrace` middleware:
983
-
984
- ```ruby
985
- require 'faraday'
986
- require 'ddtrace'
987
-
988
- # Configure default Faraday tracing behavior
989
- Datadog.configure do |c|
990
- c.tracing.instrument :faraday, options
991
-
992
- # optionally, specify a different service name for hostnames matching a regex
993
- c.tracing.instrument :faraday, describes: /user-[^.]+\.example\.com/ do |faraday|
994
- faraday.service_name = 'user.example.com'
995
- faraday.split_by_domain = false # Only necessary if split_by_domain is true by default
996
- end
997
- end
998
-
999
- # In case you want to override the global configuration for a certain client instance
1000
- connection = Faraday.new('https://example.com') do |builder|
1001
- builder.use(:ddtrace, options)
1002
- builder.adapter Faraday.default_adapter
1003
- end
1004
-
1005
- connection.get('/foo')
1006
- ```
1007
-
1008
- Where `options` is an optional `Hash` that accepts the following parameters:
1009
-
1010
- | Key | Description | Default |
1011
- | --- | ----------- | ------- |
1012
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) | `true` |
1013
- | `error_handler` | A `Proc` that accepts a `response` parameter. If it evaluates to a *truthy* value, the trace span is marked as an error. By default only sets 5XX responses as errors. | `nil` |
1014
- | `service_name` | Service name for Faraday instrumentation. When provided to middleware for a specific connection, it applies only to that connection object. | `'faraday'` |
1015
- | `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
1016
-
1017
- ### Grape
1018
-
1019
- The Grape integration adds the instrumentation to Grape endpoints and filters. This integration can work side by side with other integrations like Rack and Rails.
1020
-
1021
- To activate your integration, use the `Datadog.configure` method before defining your Grape application:
1022
-
1023
- ```ruby
1024
- # api.rb
1025
- require 'grape'
1026
- require 'ddtrace'
1027
-
1028
- Datadog.configure do |c|
1029
- c.tracing.instrument :grape, options
1030
- end
1031
-
1032
- # Then define your application
1033
- class RackTestingAPI < Grape::API
1034
- desc 'main endpoint'
1035
- get :success do
1036
- 'Hello world!'
1037
- end
1038
- end
1039
- ```
1040
-
1041
- Where `options` is an optional `Hash` that accepts the following parameters:
1042
-
1043
- | Key | Description | Default |
1044
- | --- | ----------- | ------- |
1045
- | `enabled` | Defines whether Grape should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
1046
- | `error_statuses`| Defines a status code or range of status codes which should be marked as errors. `'404,405,500-599'` or `[404,405,'500-599']` | `nil` |
1047
-
1048
- ### GraphQL
1049
-
1050
- The GraphQL integration activates instrumentation for GraphQL queries.
1051
-
1052
- To activate your integration, use the `Datadog.configure` method:
1053
-
1054
- ```ruby
1055
- # Inside Rails initializer or equivalent
1056
- Datadog.configure do |c|
1057
- c.tracing.instrument :graphql, schemas: [YourSchema], options
1058
- end
1059
-
1060
- # Then run a GraphQL query
1061
- YourSchema.execute(query, variables: {}, context: {}, operation_name: nil)
1062
- ```
1063
-
1064
- The `use :graphql` method accepts the following parameters. Additional options can be substituted in for `options`:
1065
-
1066
- | Key | Description | Default |
1067
- | --- | ----------- | ------- |
1068
- | `schemas` | Required. Array of `GraphQL::Schema` objects which to trace. Tracing will be added to all the schemas listed, using the options provided to this configuration. If you do not provide any, then tracing will not be activated. | `[]` |
1069
-
1070
- **Manually configuring GraphQL schemas**
1071
-
1072
- If you prefer to individually configure the tracer settings for a schema (e.g. you have multiple schemas with different service names), in the schema definition, you can add the following [using the GraphQL API](http://graphql-ruby.org/queries/tracing.html):
1073
-
1074
- ```ruby
1075
- # Class-based schema
1076
- class YourSchema < GraphQL::Schema
1077
- use(
1078
- GraphQL::Tracing::DataDogTracing,
1079
- service: 'graphql'
1080
- )
1081
- end
1082
- ```
1083
-
1084
- ```ruby
1085
- # .define-style schema
1086
- YourSchema = GraphQL::Schema.define do
1087
- use(
1088
- GraphQL::Tracing::DataDogTracing,
1089
- service: 'graphql'
1090
- )
1091
- end
1092
- ```
1093
-
1094
- Or you can modify an already defined schema:
1095
-
1096
- ```ruby
1097
- # Class-based schema
1098
- YourSchema.use(
1099
- GraphQL::Tracing::DataDogTracing,
1100
- service: 'graphql'
1101
- )
1102
- ```
1103
-
1104
- ```ruby
1105
- # .define-style schema
1106
- YourSchema.define do
1107
- use(
1108
- GraphQL::Tracing::DataDogTracing,
1109
- service: 'graphql'
1110
- )
1111
- end
1112
- ```
1113
-
1114
- Do *NOT* `use :graphql` in `Datadog.configure` if you choose to configure manually, as to avoid double tracing. These two means of configuring GraphQL tracing are considered mutually exclusive.
1115
-
1116
- ### gRPC
1117
-
1118
- The `grpc` integration adds both client and server interceptors, which run as middleware before executing the service's remote procedure call. As gRPC applications are often distributed, the integration shares trace information between client and server.
1119
-
1120
- To setup your integration, use the `Datadog.configure` method like so:
1121
-
1122
- ```ruby
1123
- require 'grpc'
1124
- require 'ddtrace'
1125
-
1126
- Datadog.configure do |c|
1127
- c.tracing.instrument :grpc, options
1128
- end
1129
-
1130
- # Server side
1131
- server = GRPC::RpcServer.new
1132
- server.add_http2_port('localhost:50051', :this_port_is_insecure)
1133
- server.handle(Demo)
1134
- server.run_till_terminated
1135
-
1136
- # Client side
1137
- client = Demo.rpc_stub_class.new('localhost:50051', :this_channel_is_insecure)
1138
- client.my_endpoint(DemoMessage.new(contents: 'hello!'))
1139
- ```
1140
-
1141
- Where `options` is an optional `Hash` that accepts the following parameters:
1142
-
1143
- | Key | Description | Default |
1144
- | --- | ----------- | ------- |
1145
- | `service_name` | Service name used for `grpc` instrumentation | `'grpc'` |
1146
- | `error_handler` | Custom error handler invoked when a request is an error. A `Proc` that accepts `span` and `error` parameters. Sets error on the span by default. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
1147
-
1148
- **Configuring clients to use different settings**
1149
-
1150
- In situations where you have multiple clients calling multiple distinct services, you may pass the Datadog interceptor directly, like so
1151
-
1152
- ```ruby
1153
- configured_interceptor = Datadog::Tracing::Contrib::GRPC::DatadogInterceptor::Client.new do |c|
1154
- c.service_name = "Alternate"
1155
- end
1156
-
1157
- alternate_client = Demo::Echo::Service.rpc_stub_class.new(
1158
- 'localhost:50052',
1159
- :this_channel_is_insecure,
1160
- :interceptors => [configured_interceptor]
1161
- )
1162
- ```
1163
-
1164
- The integration will ensure that the `configured_interceptor` establishes a unique tracing setup for that client instance.
1165
-
1166
- ### http.rb
1167
-
1168
- The http.rb integration will trace any HTTP call using the Http.rb gem.
1169
-
1170
- ```ruby
1171
- require 'http'
1172
- require 'ddtrace'
1173
- Datadog.configure do |c|
1174
- c.tracing.instrument :httprb, options
1175
- # optionally, specify a different service name for hostnames matching a regex
1176
- c.tracing.instrument :httprb, describes: /user-[^.]+\.example\.com/ do |httprb|
1177
- httprb.service_name = 'user.example.com'
1178
- httprb.split_by_domain = false # Only necessary if split_by_domain is true by default
1179
- end
1180
- end
1181
- ```
1182
-
1183
- Where `options` is an optional `Hash` that accepts the following parameters:
1184
-
1185
- | Key | Description | Default |
1186
- | --- | ----------- | ------- |
1187
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) | `true` |
1188
- | `service_name` | Service name for `httprb` instrumentation. | `'httprb'` |
1189
- | `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
1190
-
1191
- ### httpclient
1192
-
1193
- The httpclient integration will trace any HTTP call using the httpclient gem.
1194
-
1195
- ```ruby
1196
- require 'httpclient'
1197
- require 'ddtrace'
1198
- Datadog.configure do |c|
1199
- c.tracing.instrument :httpclient, options
1200
- # optionally, specify a different service name for hostnames matching a regex
1201
- c.tracing.instrument :httpclient, describes: /user-[^.]+\.example\.com/ do |httpclient|
1202
- httpclient.service_name = 'user.example.com'
1203
- httpclient.split_by_domain = false # Only necessary if split_by_domain is true by default
1204
- end
1205
- end
1206
- ```
1207
-
1208
- Where `options` is an optional `Hash` that accepts the following parameters:
1209
-
1210
- | Key | Description | Default |
1211
- | --- | ----------- | ------- |
1212
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) | `true` |
1213
- | `service_name` | Service name for `httpclient` instrumentation. | `'httpclient'` |
1214
- | `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
1215
-
1216
- ### httpx
1217
-
1218
- `httpx` maintains its [own integration with `ddtrace`](https://honeyryderchuck.gitlab.io/httpx/wiki/Datadog-Adapter):
1219
-
1220
- ```ruby
1221
- require "ddtrace"
1222
- require "httpx/adapters/datadog"
1223
-
1224
- Datadog.configure do |c|
1225
- c.tracing.instrument :httpx
1226
-
1227
- # optionally, specify a different service name for hostnames matching a regex
1228
- c.tracing.instrument :httpx, describes: /user-[^.]+\.example\.com/ do |http|
1229
- http.service_name = 'user.example.com'
1230
- http.split_by_domain = false # Only necessary if split_by_domain is true by default
1231
- end
1232
- end
1233
- ```
1234
-
1235
- ### Kafka
1236
-
1237
- The Kafka integration provides tracing of the `ruby-kafka` gem:
1238
-
1239
- You can enable it through `Datadog.configure`:
1240
-
1241
- ```ruby
1242
- require 'active_support/notifications' # required to enable 'ruby-kafka' instrumentation
1243
- require 'kafka'
1244
- require 'ddtrace'
1245
-
1246
- Datadog.configure do |c|
1247
- c.tracing.instrument :kafka
1248
- end
1249
- ```
1250
-
1251
- ### MongoDB
1252
-
1253
- The integration traces any `Command` that is sent from the [MongoDB Ruby Driver](https://github.com/mongodb/mongo-ruby-driver) to a MongoDB cluster. By extension, Object Document Mappers (ODM) such as Mongoid are automatically instrumented if they use the official Ruby driver. To activate the integration, simply:
1254
-
1255
- ```ruby
1256
- require 'mongo'
1257
- require 'ddtrace'
1258
-
1259
- Datadog.configure do |c|
1260
- c.tracing.instrument :mongo, options
1261
- end
1262
-
1263
- # Create a MongoDB client and use it as usual
1264
- client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'artists')
1265
- collection = client[:people]
1266
- collection.insert_one({ name: 'Steve' })
1267
-
1268
- # In case you want to override the global configuration for a certain client instance
1269
- Datadog.configure_onto(client, **options)
1270
- ```
1271
-
1272
- Where `options` is an optional `Hash` that accepts the following parameters:
1273
-
1274
- | Key | Description | Default |
1275
- | --- | ----------- | ------- |
1276
- | `quantize` | Hash containing options for quantization. May include `:show` with an Array of keys to not quantize (or `:all` to skip quantization), or `:exclude` with Array of keys to exclude entirely. | `{ show: [:collection, :database, :operation] }` |
1277
- | `service_name` | Service name used for `mongo` instrumentation | `'mongodb'` |
1278
-
1279
- **Configuring trace settings per connection**
1280
-
1281
- You can configure trace settings per connection by using the `describes` option:
1282
-
1283
- ```ruby
1284
- # Provide a `:describes` option with a connection key.
1285
- # Any of the following keys are acceptable and equivalent to one another.
1286
- # If a block is provided, it yields a Settings object that
1287
- # accepts any of the configuration options listed above.
1288
-
1289
- Datadog.configure do |c|
1290
- # Network connection string
1291
- c.tracing.instrument :mongo, describes: '127.0.0.1:27017', service_name: 'mongo-primary'
1292
-
1293
- # Network connection regular expression
1294
- c.tracing.instrument :mongo, describes: /localhost.*/, service_name: 'mongo-secondary'
1295
- end
1296
-
1297
- client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'artists')
1298
- collection = client[:people]
1299
- collection.insert_one({ name: 'Steve' })
1300
- # Traced call will belong to `mongo-primary` service
1301
-
1302
- client = Mongo::Client.new([ 'localhost:27017' ], :database => 'artists')
1303
- collection = client[:people]
1304
- collection.insert_one({ name: 'Steve' })
1305
- # Traced call will belong to `mongo-secondary` service
1306
- ```
1307
-
1308
- When multiple `describes` configurations match a connection, the latest configured rule that matches will be applied.
1309
-
1310
- ### MySQL2
1311
-
1312
- The MySQL2 integration traces any SQL command sent through `mysql2` gem.
1313
-
1314
- ```ruby
1315
- require 'mysql2'
1316
- require 'ddtrace'
1317
-
1318
- Datadog.configure do |c|
1319
- c.tracing.instrument :mysql2, options
1320
- end
1321
-
1322
- client = Mysql2::Client.new(:host => "localhost", :username => "root")
1323
- client.query("SELECT * FROM users WHERE group='x'")
1324
- ```
1325
-
1326
- Where `options` is an optional `Hash` that accepts the following parameters:
1327
-
1328
- | Key | Description | Default |
1329
- | --- | ----------- | ------- |
1330
- | `service_name` | Service name used for `mysql2` instrumentation | `'mysql2'` |
1331
-
1332
- ### Net/HTTP
1333
-
1334
- The Net/HTTP integration will trace any HTTP call using the standard lib Net::HTTP module.
1335
-
1336
- ```ruby
1337
- require 'net/http'
1338
- require 'ddtrace'
1339
-
1340
- Datadog.configure do |c|
1341
- c.tracing.instrument :http, options
1342
-
1343
- # optionally, specify a different service name for hostnames matching a regex
1344
- c.tracing.instrument :http, describes: /user-[^.]+\.example\.com/ do |http|
1345
- http.service_name = 'user.example.com'
1346
- http.split_by_domain = false # Only necessary if split_by_domain is true by default
1347
- end
1348
- end
1349
-
1350
- Net::HTTP.start('127.0.0.1', 8080) do |http|
1351
- request = Net::HTTP::Get.new '/index'
1352
- response = http.request(request)
1353
- end
1354
-
1355
- content = Net::HTTP.get(URI('http://127.0.0.1/index.html'))
1356
- ```
1357
-
1358
- Where `options` is an optional `Hash` that accepts the following parameters:
1359
-
1360
- | Key | Description | Default |
1361
- | --- | ----------- | ------- |
1362
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) | `true` |
1363
- | `service_name` | Service name used for `http` instrumentation | `'net/http'` |
1364
- | `split_by_domain` | Uses the request domain as the service name when set to `true`. | `false` |
1365
-
1366
- If you wish to configure each connection object individually, you may use the `Datadog.configure_onto` as it follows:
1367
-
1368
- ```ruby
1369
- client = Net::HTTP.new(host, port)
1370
- Datadog.configure_onto(client, **options)
1371
- ```
1372
-
1373
- ### Presto
1374
-
1375
- The Presto integration traces any SQL command sent through `presto-client` gem.
1376
-
1377
- ```ruby
1378
- require 'presto-client'
1379
- require 'ddtrace'
1380
-
1381
- Datadog.configure do |c|
1382
- c.tracing.instrument :presto, options
1383
- end
1384
-
1385
- client = Presto::Client.new(
1386
- server: "localhost:8880",
1387
- ssl: {verify: false},
1388
- catalog: "native",
1389
- schema: "default",
1390
- time_zone: "US/Pacific",
1391
- language: "English",
1392
- http_debug: true,
1393
- )
1394
-
1395
- client.run("select * from system.nodes")
1396
- ```
1397
-
1398
- Where `options` is an optional `Hash` that accepts the following parameters:
1399
-
1400
- | Key | Description | Default |
1401
- | --- | ----------- | ------- |
1402
- | `service_name` | Service name used for `presto` instrumentation | `'presto'` |
1403
-
1404
- ### Qless
1405
-
1406
- The Qless integration uses lifecycle hooks to trace job executions.
1407
-
1408
- To add tracing to a Qless job:
1409
-
1410
- ```ruby
1411
- require 'ddtrace'
1412
-
1413
- Datadog.configure do |c|
1414
- c.tracing.instrument :qless, options
1415
- end
1416
- ```
1417
-
1418
- Where `options` is an optional `Hash` that accepts the following parameters:
1419
-
1420
- | Key | Description | Default |
1421
- | --- | ----------- | ------- |
1422
- | `tag_job_data` | Enable tagging with job arguments. true for on, false for off. | `false` |
1423
- | `tag_job_tags` | Enable tagging with job tags. true for on, false for off. | `false` |
1424
-
1425
- ### Que
1426
-
1427
- The Que integration is a middleware which will trace job executions.
1428
-
1429
- You can enable it through `Datadog.configure`:
1430
-
1431
- ```ruby
1432
- require 'ddtrace'
1433
-
1434
- Datadog.configure do |c|
1435
- c.tracing.instrument :que, options
1436
- end
1437
- ```
1438
-
1439
- Where `options` is an optional `Hash` that accepts the following parameters:
1440
-
1441
- | Key | Description | Default |
1442
- | --- | ----------- | ------- |
1443
- | `enabled` | Defines whether Que should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
1444
- | `tag_args` | Enable tagging of a job's args field. `true` for on, `false` for off. | `false` |
1445
- | `tag_data` | Enable tagging of a job's data field. `true` for on, `false` for off. | `false` |
1446
- | `error_handler` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
1447
-
1448
- ### Racecar
1449
-
1450
- The Racecar integration provides tracing for Racecar jobs.
1451
-
1452
- You can enable it through `Datadog.configure`:
1453
-
1454
- ```ruby
1455
- require 'ddtrace'
1456
-
1457
- Datadog.configure do |c|
1458
- c.tracing.instrument :racecar, options
1459
- end
1460
- ```
1461
-
1462
- Where `options` is an optional `Hash` that accepts the following parameters:
1463
-
1464
- | Key | Description | Default |
1465
- | --- | ----------- | ------- |
1466
- | `service_name` | Service name used for `racecar` instrumentation | `'racecar'` |
1467
-
1468
- ### Rack
1469
-
1470
- The Rack integration provides a middleware that traces all requests before they reach the underlying framework or application. It responds to the Rack minimal interface, providing reasonable values that can be retrieved at the Rack level.
1471
-
1472
- This integration is automatically activated with web frameworks like Rails. If you're using a plain Rack application, enable the integration it to your `config.ru`:
1473
-
1474
- ```ruby
1475
- # config.ru example
1476
- require 'ddtrace'
1477
-
1478
- Datadog.configure do |c|
1479
- c.tracing.instrument :rack, options
1480
- end
1481
-
1482
- use Datadog::Tracing::Contrib::Rack::TraceMiddleware
1483
-
1484
- app = proc do |env|
1485
- [ 200, {'Content-Type' => 'text/plain'}, ['OK'] ]
1486
- end
1487
-
1488
- run app
1489
- ```
1490
-
1491
- Where `options` is an optional `Hash` that accepts the following parameters:
1492
-
1493
- | Key | Description | Default |
1494
- | --- | ----------- | ------- |
1495
- | `application` | Your Rack application. Required for `middleware_names`. | `nil` |
1496
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` |
1497
- | `headers` | Hash of HTTP request or response headers to add as tags to the `rack.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. | `{ response: ['Content-Type', 'X-Request-ID'] }` |
1498
- | `middleware_names` | Enable this if you want to use the last executed middleware class as the resource name for the `rack` span. If enabled alongside the `rails` instrumention, `rails` takes precedence by setting the `rack` resource name to the active `rails` controller when applicable. Requires `application` option to use. | `false` |
1499
- | `quantize` | Hash containing options for quantization. May include `:query` or `:fragment`. | `{}` |
1500
- | `quantize.query` | Hash containing options for query portion of URL quantization. May include `:show` or `:exclude`. See options below. Option must be nested inside the `quantize` option. | `{}` |
1501
- | `quantize.query.show` | Defines which values should always be shown. Shows no values by default. May be an Array of strings, or `:all` to show all values. Option must be nested inside the `query` option. | `nil` |
1502
- | `quantize.query.exclude` | Defines which values should be removed entirely. Excludes nothing by default. May be an Array of strings, or `:all` to remove the query string entirely. Option must be nested inside the `query` option. | `nil` |
1503
- | `quantize.fragment` | Defines behavior for URL fragments. Removes fragments by default. May be `:show` to show URL fragments. Option must be nested inside the `quantize` option. | `nil` |
1504
- | `request_queuing` | Track HTTP request time spent in the queue of the frontend server. See [HTTP request queuing](#http-request-queuing) for setup details. Set to `true` to enable. | `false` |
1505
- | `web_service_name` | Service name for frontend server request queuing spans. (e.g. `'nginx'`) | `'web-server'` |
1506
-
1507
- **Configuring URL quantization behavior**
1508
-
1509
- ```ruby
1510
- Datadog.configure do |c|
1511
- # Default behavior: all values are quantized, fragment is removed.
1512
- # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id&sort_by
1513
- # http://example.com/path?categories[]=1&categories[]=2 --> http://example.com/path?categories[]
1514
-
1515
- # Show values for any query string parameter matching 'category_id' exactly
1516
- # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id=1&sort_by
1517
- c.tracing.instrument :rack, quantize: { query: { show: ['category_id'] } }
1518
-
1519
- # Show all values for all query string parameters
1520
- # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id=1&sort_by=asc
1521
- c.tracing.instrument :rack, quantize: { query: { show: :all } }
1522
-
1523
- # Totally exclude any query string parameter matching 'sort_by' exactly
1524
- # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id
1525
- c.tracing.instrument :rack, quantize: { query: { exclude: ['sort_by'] } }
1526
-
1527
- # Remove the query string entirely
1528
- # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path
1529
- c.tracing.instrument :rack, quantize: { query: { exclude: :all } }
1530
-
1531
- # Show URL fragments
1532
- # http://example.com/path?category_id=1&sort_by=asc#featured --> http://example.com/path?category_id&sort_by#featured
1533
- c.tracing.instrument :rack, quantize: { fragment: :show }
1534
- end
1535
- ```
1536
-
1537
- ### Rails
1538
-
1539
- The Rails integration will trace requests, database calls, templates rendering, and cache read/write/delete operations. The integration makes use of the Active Support Instrumentation, listening to the Notification API so that any operation instrumented by the API is traced.
1540
-
1541
- To enable the Rails instrumentation, create an initializer file in your `config/initializers` folder:
1542
-
1543
- ```ruby
1544
- # config/initializers/datadog.rb
1545
- require 'ddtrace'
1546
-
1547
- Datadog.configure do |c|
1548
- c.tracing.instrument :rails, options
1549
- end
1550
- ```
1551
-
1552
- Where `options` is an optional `Hash` that accepts the following parameters:
1553
-
1554
- | Key | Description | Default |
1555
- | --- | ----------- | ------- |
1556
- | `cache_service` | Cache service name used when tracing cache activity | `'<app_name>-cache'` |
1557
- | `database_service` | Database service name used when tracing database activity | `'<app_name>-<adapter_name>'` |
1558
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` |
1559
- | `exception_controller` | Class or Module which identifies a custom exception controller class. Tracer provides improved error behavior when it can identify custom exception controllers. By default, without this option, it 'guesses' what a custom exception controller looks like. Providing this option aids this identification. | `nil` |
1560
- | `middleware` | Add the trace middleware to the Rails application. Set to `false` if you don't want the middleware to load. | `true` |
1561
- | `middleware_names` | Enables any short-circuited middleware requests to display the middleware name as a resource for the trace. | `false` |
1562
- | `service_name` | Service name used when tracing application requests (on the `rack` level) | `'<app_name>'` (inferred from your Rails application namespace) |
1563
- | `template_base_path` | Used when the template name is parsed. If you don't store your templates in the `views/` folder, you may need to change this value | `'views/'` |
1564
-
1565
- **Supported versions**
1566
-
1567
- | MRI Versions | JRuby Versions | Rails Versions |
1568
- | ------------- | -------------- | -------------- |
1569
- | 2.1 | | 3.2 - 4.2 |
1570
- | 2.2 - 2.3 | | 3.2 - 5.2 |
1571
- | 2.4 | | 4.2.8 - 5.2 |
1572
- | 2.5 | | 4.2.8 - 6.1 |
1573
- | 2.6 - 2.7 | 9.2 | 5.0 - 6.1 |
1574
- | 3.0 | | 6.1 |
1575
-
1576
- ### Rake
1577
-
1578
- You can add instrumentation around your Rake tasks by activating the `rake` integration. Each task and its subsequent subtasks will be traced.
1579
-
1580
- To activate Rake task tracing, add the following to your `Rakefile`:
1581
-
1582
- ```ruby
1583
- # At the top of your Rakefile:
1584
- require 'rake'
1585
- require 'ddtrace'
1586
-
1587
- Datadog.configure do |c|
1588
- c.tracing.instrument :rake, options
1589
- end
1590
-
1591
- task :my_task do
1592
- # Do something task work here...
1593
- end
1594
-
1595
- Rake::Task['my_task'].invoke
1596
- ```
1597
-
1598
- Where `options` is an optional `Hash` that accepts the following parameters:
1599
-
1600
- | Key | Description | Default |
1601
- | --- | ----------- | ------- |
1602
- | `enabled` | Defines whether Rake tasks should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
1603
- | `quantize` | Hash containing options for quantization of task arguments. See below for more details and examples. | `{}` |
1604
- | `service_name` | Service name used for `rake` instrumentation | `'rake'` |
1605
-
1606
- **Configuring task quantization behavior**
1607
-
1608
- ```ruby
1609
- Datadog.configure do |c|
1610
- # Given a task that accepts :one, :two, :three...
1611
- # Invoked with 'foo', 'bar', 'baz'.
1612
-
1613
- # Default behavior: all arguments are quantized.
1614
- # `rake.invoke.args` tag --> ['?']
1615
- # `rake.execute.args` tag --> { one: '?', two: '?', three: '?' }
1616
- c.tracing.instrument :rake
1617
-
1618
- # Show values for any argument matching :two exactly
1619
- # `rake.invoke.args` tag --> ['?']
1620
- # `rake.execute.args` tag --> { one: '?', two: 'bar', three: '?' }
1621
- c.tracing.instrument :rake, quantize: { args: { show: [:two] } }
1622
-
1623
- # Show all values for all arguments.
1624
- # `rake.invoke.args` tag --> ['foo', 'bar', 'baz']
1625
- # `rake.execute.args` tag --> { one: 'foo', two: 'bar', three: 'baz' }
1626
- c.tracing.instrument :rake, quantize: { args: { show: :all } }
1627
-
1628
- # Totally exclude any argument matching :three exactly
1629
- # `rake.invoke.args` tag --> ['?']
1630
- # `rake.execute.args` tag --> { one: '?', two: '?' }
1631
- c.tracing.instrument :rake, quantize: { args: { exclude: [:three] } }
1632
-
1633
- # Remove the arguments entirely
1634
- # `rake.invoke.args` tag --> ['?']
1635
- # `rake.execute.args` tag --> {}
1636
- c.tracing.instrument :rake, quantize: { args: { exclude: :all } }
1637
- end
1638
- ```
1639
-
1640
- ### Redis
1641
-
1642
- The Redis integration will trace simple calls as well as pipelines.
1643
-
1644
- ```ruby
1645
- require 'redis'
1646
- require 'ddtrace'
1647
-
1648
- Datadog.configure do |c|
1649
- c.tracing.instrument :redis, options
1650
- end
1651
-
1652
- # Perform Redis commands
1653
- redis = Redis.new
1654
- redis.set 'foo', 'bar'
1655
- ```
1656
-
1657
- Where `options` is an optional `Hash` that accepts the following parameters:
1658
-
1659
- | Key | Description | Default |
1660
- | --- | ----------- | ------- |
1661
- | `service_name` | Service name used for `redis` instrumentation | `'redis'` |
1662
- | `command_args` | Show the command arguments (e.g. `key` in `GET key`) as resource name and tag | true |
1663
-
1664
- You can also set *per-instance* configuration as it follows:
1665
-
1666
- ```ruby
1667
- require 'redis'
1668
- require 'ddtrace'
1669
-
1670
- Datadog.configure do |c|
1671
- c.tracing.instrument :redis # Enabling integration instrumentation is still required
1672
- end
1673
-
1674
- customer_cache = Redis.new
1675
- invoice_cache = Redis.new
1676
-
1677
- Datadog.configure_onto(customer_cache, service_name: 'customer-cache')
1678
- Datadog.configure_onto(invoice_cache, service_name: 'invoice-cache')
1679
-
1680
- # Traced call will belong to `customer-cache` service
1681
- customer_cache.get(...)
1682
- # Traced call will belong to `invoice-cache` service
1683
- invoice_cache.get(...)
1684
- ```
1685
-
1686
- **Configuring trace settings per connection**
1687
-
1688
- You can configure trace settings per connection by using the `describes` option:
1689
-
1690
- ```ruby
1691
- # Provide a `:describes` option with a connection key.
1692
- # Any of the following keys are acceptable and equivalent to one another.
1693
- # If a block is provided, it yields a Settings object that
1694
- # accepts any of the configuration options listed above.
1695
-
1696
- Datadog.configure do |c|
1697
- # The default configuration for any redis client
1698
- c.tracing.instrument :redis, service_name: 'redis-default'
1699
-
1700
- # The configuration matching a given unix socket.
1701
- c.tracing.instrument :redis, describes: { url: 'unix://path/to/file' }, service_name: 'redis-unix'
1702
-
1703
- # For network connections, only these fields are considered during matching:
1704
- # scheme, host, port, db
1705
- # Other fields are ignored.
1706
-
1707
- # Network connection string
1708
- c.tracing.instrument :redis, describes: 'redis://127.0.0.1:6379/0', service_name: 'redis-connection-string'
1709
- c.tracing.instrument :redis, describes: { url: 'redis://127.0.0.1:6379/1' }, service_name: 'redis-connection-url'
1710
- # Network client hash
1711
- c.tracing.instrument :redis, describes: { host: 'my-host.com', port: 6379, db: 1, scheme: 'redis' }, service_name: 'redis-connection-hash'
1712
- # Only a subset of the connection hash
1713
- c.tracing.instrument :redis, describes: { host: ENV['APP_CACHE_HOST'], port: ENV['APP_CACHE_PORT'] }, service_name: 'redis-cache'
1714
- c.tracing.instrument :redis, describes: { host: ENV['SIDEKIQ_CACHE_HOST'] }, service_name: 'redis-sidekiq'
1715
- end
1716
- ```
1717
-
1718
- When multiple `describes` configurations match a connection, the latest configured rule that matches will be applied.
1719
-
1720
- ### Resque
1721
-
1722
- The Resque integration uses Resque hooks that wraps the `perform` method.
1723
-
1724
- To add tracing to a Resque job:
1725
-
1726
- ```ruby
1727
- require 'resque'
1728
- require 'ddtrace'
1729
-
1730
- Datadog.configure do |c|
1731
- c.tracing.instrument :resque, **options
1732
- end
1733
- ```
1734
-
1735
- Where `options` is an optional `Hash` that accepts the following parameters:
1736
-
1737
- | Key | Description | Default |
1738
- | --- | ----------- | ------- |
1739
- | `error_handler` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
1740
-
1741
- ### Rest Client
1742
-
1743
- The `rest-client` integration is available through the `ddtrace` middleware:
1744
-
1745
- ```ruby
1746
- require 'rest_client'
1747
- require 'ddtrace'
1748
-
1749
- Datadog.configure do |c|
1750
- c.tracing.instrument :rest_client, options
1751
- end
1752
- ```
1753
-
1754
- Where `options` is an optional `Hash` that accepts the following parameters:
1755
-
1756
- | Key | Description | Default |
1757
- | --- | ----------- | ------- |
1758
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) | `true` |
1759
- | `service_name` | Service name for `rest_client` instrumentation. | `'rest_client'` |
1760
-
1761
- ### RSpec
1762
-
1763
- RSpec integration will trace all executions of example groups and examples when using `rspec` test framework.
1764
-
1765
- To activate your integration, use the `Datadog.configure` method:
1766
-
1767
- ```ruby
1768
- require 'rspec'
1769
- require 'ddtrace'
1770
-
1771
- # Configure default RSpec integration
1772
- Datadog.configure do |c|
1773
- c.ci.instrument :rspec, options
1774
- end
1775
- ```
1776
-
1777
- Where `options` is an optional `Hash` that accepts the following parameters:
1778
-
1779
- | Key | Description | Default |
1780
- | --- | ----------- | ------- |
1781
- | `enabled` | Defines whether RSpec tests should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
1782
- | `service_name` | Service name used for `rspec` instrumentation. | `'rspec'` |
1783
- | `operation_name` | Operation name used for `rspec` instrumentation. Useful if you want rename automatic trace metrics e.g. `trace.#{operation_name}.errors`. | `'rspec.example'` |
1784
-
1785
- ### Sequel
1786
-
1787
- The Sequel integration traces queries made to your database.
1788
-
1789
- ```ruby
1790
- require 'sequel'
1791
- require 'ddtrace'
1792
-
1793
- # Connect to database
1794
- database = Sequel.sqlite
1795
-
1796
- # Create a table
1797
- database.create_table :articles do
1798
- primary_key :id
1799
- String :name
1800
- end
1801
-
1802
- Datadog.configure do |c|
1803
- c.tracing.instrument :sequel, options
1804
- end
1805
-
1806
- # Perform a query
1807
- articles = database[:articles]
1808
- articles.all
1809
- ```
1810
-
1811
- Where `options` is an optional `Hash` that accepts the following parameters:
1812
-
1813
- | Key | Description | Default |
1814
- | --- | ----------- | ------- |
1815
- | `service_name` | Service name for `sequel` instrumentation | Name of database adapter (e.g. `'mysql2'`) |
1816
-
1817
- **Configuring databases to use different settings**
1818
-
1819
- If you use multiple databases with Sequel, you can give each of them different settings by configuring their respective `Sequel::Database` objects:
1820
-
1821
- ```ruby
1822
- sqlite_database = Sequel.sqlite
1823
- postgres_database = Sequel.connect('postgres://user:password@host:port/database_name')
1824
-
1825
- # Configure each database with different service names
1826
- Datadog.configure_onto(sqlite_database, service_name: 'my-sqlite-db')
1827
- Datadog.configure_onto(postgres_database, service_name: 'my-postgres-db')
1828
- ```
1829
-
1830
- ### Shoryuken
1831
-
1832
- The Shoryuken integration is a server-side middleware which will trace job executions.
1833
-
1834
- You can enable it through `Datadog.configure`:
1835
-
1836
- ```ruby
1837
- require 'ddtrace'
1838
-
1839
- Datadog.configure do |c|
1840
- c.tracing.instrument :shoryuken, options
1841
- end
1842
- ```
1843
-
1844
- Where `options` is an optional `Hash` that accepts the following parameters:
1845
-
1846
- | Key | Description | Default |
1847
- | --- | ----------- | ------- |
1848
- | `tag_body` | Tag spans with the SQS message body `true` or `false` | `false` |
1849
- | `error_handler` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
1850
-
1851
- ### Sidekiq
1852
-
1853
- The Sidekiq integration is a client-side & server-side middleware which will trace job queuing and executions respectively.
1854
-
1855
- You can enable it through `Datadog.configure`:
1856
-
1857
- ```ruby
1858
- require 'ddtrace'
1859
-
1860
- Datadog.configure do |c|
1861
- c.tracing.instrument :sidekiq, options
1862
- end
1863
- ```
1864
-
1865
- Where `options` is an optional `Hash` that accepts the following parameters:
1866
-
1867
- | Key | Description | Default |
1868
- | --- | ----------- | ------- |
1869
- | `tag_args` | Enable tagging of job arguments. `true` for on, `false` for off. | `false` |
1870
- | `error_handler` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
1871
- | `quantize` | Hash containing options for quantization of job arguments. | `{}` |
1872
-
1873
- ### Sinatra
1874
-
1875
- The Sinatra integration traces requests and template rendering.
1876
-
1877
- To start using the tracing client, make sure you import `ddtrace` and `use :sinatra` after either `sinatra` or `sinatra/base`, and before you define your application/routes:
1878
-
1879
- #### Classic application
1880
-
1881
- ```ruby
1882
- require 'sinatra'
1883
- require 'ddtrace'
1884
-
1885
- Datadog.configure do |c|
1886
- c.tracing.instrument :sinatra, options
1887
- end
1888
-
1889
- get '/' do
1890
- 'Hello world!'
1891
- end
1892
- ```
1893
-
1894
- #### Modular application
1895
-
1896
- ```ruby
1897
- require 'sinatra/base'
1898
- require 'ddtrace'
1899
-
1900
- Datadog.configure do |c|
1901
- c.tracing.instrument :sinatra, options
1902
- end
1903
-
1904
- class NestedApp < Sinatra::Base
1905
- register Datadog::Tracing::Contrib::Sinatra::Tracer
1906
-
1907
- get '/nested' do
1908
- 'Hello from nested app!'
1909
- end
1910
- end
1911
-
1912
- class App < Sinatra::Base
1913
- register Datadog::Tracing::Contrib::Sinatra::Tracer
1914
-
1915
- use NestedApp
1916
-
1917
- get '/' do
1918
- 'Hello world!'
1919
- end
1920
- end
1921
- ```
1922
-
1923
- Ensure you register `Datadog::Tracing::Contrib::Sinatra::Tracer` as a middleware before you mount your nested applications.
1924
-
1925
- #### Instrumentation options
1926
-
1927
- `options` is an optional `Hash` that accepts the following parameters:
1928
-
1929
- | Key | Description | Default |
1930
- | --- | ----------- | ------- |
1931
- | `distributed_tracing` | Enables [distributed tracing](#distributed-tracing) so that this service trace is connected with a trace of another service if tracing headers are received | `true` |
1932
- | `headers` | Hash of HTTP request or response headers to add as tags to the `sinatra.request`. Accepts `request` and `response` keys with Array values e.g. `['Last-Modified']`. Adds `http.request.headers.*` and `http.response.headers.*` tags respectively. | `{ response: ['Content-Type', 'X-Request-ID'] }` |
1933
- | `resource_script_names` | Prepend resource names with script name | `false` |
1934
-
1935
- ### Sneakers
1936
-
1937
- The Sneakers integration is a server-side middleware which will trace job executions.
1938
-
1939
- You can enable it through `Datadog.configure`:
1940
-
1941
- ```ruby
1942
- require 'ddtrace'
1943
-
1944
- Datadog.configure do |c|
1945
- c.tracing.instrument :sneakers, options
1946
- end
1947
- ```
1948
-
1949
- Where `options` is an optional `Hash` that accepts the following parameters:
1950
-
1951
- | Key | Description | Default |
1952
- | --- | ----------- | ------- |
1953
- | `enabled` | Defines whether Sneakers should be traced. Useful for temporarily disabling tracing. `true` or `false` | `true` |
1954
- | `tag_body` | Enable tagging of job message. `true` for on, `false` for off. | `false` |
1955
- | `error_handler` | Custom error handler invoked when a job raises an error. Provided `span` and `error` as arguments. Sets error on the span by default. Useful for ignoring transient errors. | `proc { |span, error| span.set_error(error) unless span.nil? }` |
1956
-
1957
- ### Sucker Punch
1958
-
1959
- The `sucker_punch` integration traces all scheduled jobs:
1960
-
1961
- ```ruby
1962
- require 'ddtrace'
1963
-
1964
- Datadog.configure do |c|
1965
- c.tracing.instrument :sucker_punch
1966
- end
1967
-
1968
- # Execution of this job is traced
1969
- LogJob.perform_async('login')
1970
- ```
1971
-
1972
- ## Additional configuration
1973
-
1974
- To change the default behavior of Datadog tracing, you can set environment variables, or provide custom options inside a `Datadog.configure` block, e.g.:
1975
-
1976
- ```ruby
1977
- Datadog.configure do |c|
1978
- c.service = 'billing-api'
1979
- c.env = ENV['RACK_ENV']
1980
-
1981
- c.tracing.report_hostname = true
1982
- c.tracing.test_mode.enabled = (ENV['RACK_ENV'] == 'test')
1983
- end
1984
- ```
1985
-
1986
- **Available configuration options:**
1987
-
1988
- | Setting | Env Var | Default | Description |
1989
- |---------------------------------------------------------|--------------------------------|-------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1990
- | **Global** | | | |
1991
- | `agent.host` | `DD_AGENT_HOST` | `127.0.0.1` | Hostname of agent to where trace data will be sent. |
1992
- | `agent.port` | `DD_TRACE_AGENT_PORT` | `8126` | Port of agent host to where trace data will be sent. |
1993
- | | `DD_TRACE_AGENT_URL` | `nil` | Sets the URL endpoint where traces are sent. Has priority over `agent.host` and `agent.port`. |
1994
- | `diagnostics.debug` | `DD_TRACE_DEBUG` | `false` | Enables or disables debug mode. Prints verbose logs. **NOT recommended for production or other sensitive environments.** See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. |
1995
- | `diagnostics.startup_logs.enabled` | `DD_TRACE_STARTUP_LOGS` | `nil` | Prints startup configuration and diagnostics to log. For assessing state of tracing at application startup. See [Debugging and diagnostics](#debugging-and-diagnostics) for more details. |
1996
- | `env` | `DD_ENV` | `nil` | Your application environment. (e.g. `production`, `staging`, etc.) This value is set as a tag on all traces. |
1997
- | `service` | `DD_SERVICE` | *Ruby filename* | Your application's default service name. (e.g. `billing-api`) This value is set as a tag on all traces. |
1998
- | `tags` | `DD_TAGS` | `nil` | Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`) These tags are set on all traces. See [Environment and tags](#environment-and-tags) for more details. |
1999
- | `time_now_provider` | | `->{ Time.now }` | Changes how time is retrieved. See [Setting the time provider](#Setting the time provider) for more details. |
2000
- | `version` | `DD_VERSION` | `nil` | Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.) This value is set as a tag on all traces. |
2001
- | **Tracing** | | | |
2002
- | `tracing.analytics.enabled` | `DD_TRACE_ANALYTICS_ENABLED` | `nil` | Enables or disables trace analytics. See [Sampling](#sampling) for more details. |
2003
- | `tracing.distributed_tracing.propagation_extract_style` | `DD_PROPAGATION_STYLE_EXTRACT` | `['Datadog','B3','B3 single header']` | Distributed tracing header formats to extract. See [Distributed Tracing](#distributed-tracing) for more details. |
2004
- | `tracing.distributed_tracing.propagation_inject_style` | `DD_PROPAGATION_STYLE_INJECT` | `['Datadog']` | Distributed tracing header formats to inject. See [Distributed Tracing](#distributed-tracing) for more details. |
2005
- | `tracing.enabled` | `DD_TRACE_ENABLED` | `true` | Enables or disables tracing. If set to `false` instrumentation will still run, but no traces are sent to the trace agent. |
2006
- | `tracing.instrument(<integration-name>, <options...>)` | | | Activates instrumentation for a specific library. See [Integration instrumentation](#integration-instrumentation) for more details. |
2007
- | `tracing.log_injection` | `DD_LOGS_INJECTION` | `true` | Injects [Trace Correlation](#trace-correlation) information into Rails logs if present. Supports the default logger (`ActiveSupport::TaggedLogging`), `lograge`, and `semantic_logger`. |
2008
- | `tracing.partial_flush.enabled` | | `false` | Enables or disables partial flushing. Partial flushing submits completed portions of a trace to the agent. Used when tracing instruments long running tasks (e.g. jobs) with many spans. |
2009
- | `tracing.partial_flush.min_spans_threshold` | | `500` | The number of spans that must be completed in a trace before partial flushing submits those completed spans. |
2010
- | `tracing.sampler` | | `nil` | Advanced usage only. Sets a custom `Datadog::Tracing::Sampling::Sampler` instance. If provided, the tracer will use this sampler to determine sampling behavior. See [Application-side sampling](#application-side-sampling) for details. |
2011
- | `tracing.sampling.default_rate` | `DD_TRACE_SAMPLE_RATE` | `nil` | Sets the trace sampling rate between `0.0` (0%) and `1.0` (100%). See [Application-side sampling](#application-side-sampling) for details. |
2012
- | `tracing.sampling.rate_limit` | `DD_TRACE_RATE_LIMIT` | `100` (per second) | Sets a maximum number of traces per second to sample. Set a rate limit to avoid the ingestion volume overages in the case of traffic spikes. |
2013
- | `tracing.report_hostname` | `DD_TRACE_REPORT_HOSTNAME` | `false` | Adds hostname tag to traces. |
2014
- | `tracing.test_mode.enabled` | `DD_TRACE_TEST_MODE_ENABLED` | `false` | Enables or disables test mode, for use of tracing in test suites. |
2015
- | `tracing.test_mode.trace_flush` | | `nil` | Object that determines trace flushing behavior. |
2016
-
2017
- #### Custom logging
2018
-
2019
- By default, all logs are processed by the default Ruby logger. When using Rails, you should see the messages in your application log file.
2020
-
2021
- Datadog client log messages are marked with `[ddtrace]` so you should be able to isolate them from other messages.
2022
-
2023
- Additionally, it is possible to override the default logger and replace it by a custom one. This is done using the `log` setting.
2024
-
2025
- ```ruby
2026
- f = File.new("my-custom.log", "w+") # Log messages should go there
2027
- Datadog.configure do |c|
2028
- c.logger.instance = Logger.new(f) # Overriding the default logger
2029
- c.logger.level = ::Logger::INFO
2030
- end
2031
-
2032
- Datadog.logger.info { "this is typically called by tracing code" }
2033
- ```
2034
-
2035
- #### Environment and tags
2036
-
2037
- By default, the trace agent (not this library, but the program running in the background collecting data from various clients) uses the tags set in the agent config file. You can configure the application to automatically tag your traces and metrics, using the following environment variables:
2038
-
2039
- - `DD_ENV`: Your application environment (e.g. `production`, `staging`, etc.)
2040
- - `DD_SERVICE`: Your application's default service name (e.g. `billing-api`)
2041
- - `DD_VERSION`: Your application version (e.g. `2.5`, `202003181415`, `1.3-alpha`, etc.)
2042
- - `DD_TAGS`: Custom tags in value pairs separated by `,` (e.g. `layer:api,team:intake`)
2043
- - If `DD_ENV`, `DD_SERVICE` or `DD_VERSION` are set, it will override any respective `env`/`service`/`version` tag defined in `DD_TAGS`.
2044
- - If `DD_ENV`, `DD_SERVICE` or `DD_VERSION` are NOT set, tags defined in `DD_TAGS` will be used to populate `env`/`service`/`version` respectively.
2045
-
2046
- These values can also be overridden at the tracer level:
2047
-
2048
- ```ruby
2049
- Datadog.configure do |c|
2050
- c.service = 'billing-api'
2051
- c.env = 'test'
2052
- c.tags = { 'team' => 'qa' }
2053
- c.version = '1.3-alpha'
2054
- end
2055
- ```
2056
-
2057
- This enables you to set this value on a per application basis, so you can have for example several applications reporting for different environments on the same host.
2058
-
2059
- Tags can also be set directly on individual spans, which will supersede any conflicting tags defined at the application level.
2060
-
2061
- #### Debugging and diagnostics
2062
-
2063
- There are two different suggested means of producing diagnostics for tracing:
2064
-
2065
- ##### Enabling debug mode
2066
-
2067
- Switching the library into debug mode will produce verbose, detailed logs about tracing activity, including any suppressed errors. This output can be helpful in identifying errors, or confirming trace output to the agent.
2068
-
2069
- You can enable this via `diagnostics.debug = true` or `DD_TRACE_DEBUG`.
2070
-
2071
- ```ruby
2072
- Datadog.configure { |c| c.diagnostics.debug = true }
2073
- ```
2074
-
2075
- **We do NOT recommend use of this feature in production or other sensitive environments**, as it can be very verbose under load. It's best to use this in a controlled environment where you can control application load.
2076
-
2077
- ##### Enabling startup logs
2078
-
2079
- Startup logs produce a report of tracing state when the application is initially configured. This can be helpful for confirming that configuration and instrumentation is activated correctly.
2080
-
2081
- You can enable this via `diagnostics.startup_logs.enabled = true` or `DD_TRACE_STARTUP_LOGS`.
2082
-
2083
- ```ruby
2084
- Datadog.configure { |c| c.diagnostics.startup_logs.enabled = true }
2085
- ```
2086
-
2087
- By default, this will be activated whenever `ddtrace` detects the application is running in a non-development environment.
2088
-
2089
- ### Sampling
2090
-
2091
- #### Application-side sampling
2092
-
2093
- While the trace agent can sample traces to reduce bandwidth usage, application-side sampling reduces the performance overhead.
2094
-
2095
- The default sampling rate can be set between `0.0` (0%) and `1.0` (100%). Configure the rate in order to control the volume of traces sent to Datadog. When this configuration is not set, the Datadog agent will distribute a default sampling rate of 10 traces per second.
2096
-
2097
- Set this value via `DD_TRACE_SAMPLE_RATE` or `Datadog.configure { |c| c.tracing.sampling.default_rate = <value> }`.
2098
-
2099
- Alternatively, you may provide your own sampler. The `Datadog::Tracing::Sampling::RateSampler` samples a ratio of the traces. For example:
2100
-
2101
- ```ruby
2102
- # Sample rate is between 0 (nothing sampled) to 1 (everything sampled).
2103
- sampler = Datadog::Tracing::Sampling::RateSampler.new(0.5) # sample 50% of the traces
2104
-
2105
- Datadog.configure do |c|
2106
- c.tracing.sampler = sampler
2107
- end
2108
- ```
2109
-
2110
- See [Additional Configuration](#additional-configuration) for more details about these settings.
2111
-
2112
- #### Priority sampling
2113
-
2114
- Priority sampling decides whether to keep a trace by using a priority attribute propagated for distributed traces. Its value indicates to the Agent and the backend about how important the trace is.
2115
-
2116
- The sampler can set the priority to the following values:
2117
-
2118
- - `Datadog::Tracing::Sampling::Ext::Priority::AUTO_REJECT`: the sampler automatically decided to reject the trace.
2119
- - `Datadog::Tracing::Sampling::Ext::Priority::AUTO_KEEP`: the sampler automatically decided to keep the trace.
2120
-
2121
- Priority sampling is enabled by default. Enabling it ensures that your sampled distributed traces will be complete. Once enabled, the sampler will automatically assign a priority of 0 or 1 to traces, depending on their service and volume.
2122
-
2123
- You can also set this priority manually to either drop a non-interesting trace or to keep an important one. For that, set the `TraceOperation#sampling_priority` to:
2124
-
2125
- - `Datadog::Tracing::Sampling::Ext::Priority::USER_REJECT`: the user asked to reject the trace.
2126
- - `Datadog::Tracing::Sampling::Ext::Priority::USER_KEEP`: the user asked to keep the trace.
2127
-
2128
- When not using [distributed tracing](#distributed-tracing), you may change the priority at any time, as long as the trace incomplete. But it has to be done before any context propagation (fork, RPC calls) to be useful in a distributed context. Changing the priority after the context has been propagated causes different parts of a distributed trace to use different priorities. Some parts might be kept, some parts might be rejected, and this can cause the trace to be partially stored and remain incomplete.
2129
-
2130
- For this reason, if you change the priority, we recommend you do it as early as possible.
2131
-
2132
- To change the sampling priority, you can use the following methods:
2133
-
2134
- ```ruby
2135
- # Rejects the active trace
2136
- Datadog::Tracing.reject!
2137
-
2138
- # Keeps the active trace
2139
- Datadog::Tracing.keep!
2140
- ```
2141
-
2142
- It's safe to use `Datadog::Tracing.reject!` and `Datadog::Tracing.keep!` when no trace is active.
2143
-
2144
- You can also reject a specific trace instance:
2145
-
2146
- ```ruby
2147
- # First, grab the active span
2148
- trace = Datadog::Tracing.active_trace
2149
-
2150
- # Rejects the trace
2151
- trace.reject!
2152
-
2153
- # Keeps the trace
2154
- trace.keep!
2155
- ```
2156
-
2157
- ### Distributed Tracing
2158
-
2159
- Distributed tracing allows traces to be propagated across multiple instrumented applications so that a request can be presented as a single trace, rather than a separate trace per service.
2160
-
2161
- To trace requests across application boundaries, the following must be propagated between each application:
2162
-
2163
- | Property | Type | Description |
2164
- | --------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------- |
2165
- | **Trace ID** | Integer | ID of the trace. This value should be the same across all requests that belong to the same trace. |
2166
- | **Parent Span ID** | Integer | ID of the span in the service originating the request. This value will always be different for each request within a trace. |
2167
- | **Sampling Priority** | Integer | Sampling priority level for the trace. This value should be the same across all requests that belong to the same trace. |
2168
-
2169
- Such propagation can be visualized as:
2170
-
2171
- ```
2172
- Service A:
2173
- Trace ID: 100000000000000001
2174
- Parent ID: 0
2175
- Span ID: 100000000000000123
2176
- Priority: 1
2177
-
2178
- |
2179
- | Service B Request:
2180
- | Metadata:
2181
- | Trace ID: 100000000000000001
2182
- | Parent ID: 100000000000000123
2183
- | Priority: 1
2184
- |
2185
- V
2186
-
2187
- Service B:
2188
- Trace ID: 100000000000000001
2189
- Parent ID: 100000000000000123
2190
- Span ID: 100000000000000456
2191
- Priority: 1
2192
-
2193
- |
2194
- | Service C Request:
2195
- | Metadata:
2196
- | Trace ID: 100000000000000001
2197
- | Parent ID: 100000000000000456
2198
- | Priority: 1
2199
- |
2200
- V
2201
-
2202
- Service C:
2203
- Trace ID: 100000000000000001
2204
- Parent ID: 100000000000000456
2205
- Span ID: 100000000000000789
2206
- Priority: 1
2207
- ```
2208
-
2209
- **Via HTTP**
2210
-
2211
- For HTTP requests between instrumented applications, this trace metadata is propagated by use of HTTP Request headers:
2212
-
2213
- | Property | Type | HTTP Header name |
2214
- | --------------------- | ------- | ----------------------------- |
2215
- | **Trace ID** | Integer | `x-datadog-trace-id` |
2216
- | **Parent Span ID** | Integer | `x-datadog-parent-id` |
2217
- | **Sampling Priority** | Integer | `x-datadog-sampling-priority` |
2218
-
2219
- Such that:
2220
-
2221
- ```
2222
- Service A:
2223
- Trace ID: 100000000000000001
2224
- Parent ID: 0
2225
- Span ID: 100000000000000123
2226
- Priority: 1
2227
-
2228
- |
2229
- | Service B HTTP Request:
2230
- | Headers:
2231
- | x-datadog-trace-id: 100000000000000001
2232
- | x-datadog-parent-id: 100000000000000123
2233
- | x-datadog-sampling-priority: 1
2234
- |
2235
- V
2236
-
2237
- Service B:
2238
- Trace ID: 100000000000000001
2239
- Parent ID: 100000000000000123
2240
- Span ID: 100000000000000456
2241
- Priority: 1
2242
-
2243
- |
2244
- | Service C HTTP Request:
2245
- | Headers:
2246
- | x-datadog-trace-id: 100000000000000001
2247
- | x-datadog-parent-id: 100000000000000456
2248
- | x-datadog-sampling-priority: 1
2249
- |
2250
- V
2251
-
2252
- Service C:
2253
- Trace ID: 100000000000000001
2254
- Parent ID: 100000000000000456
2255
- Span ID: 100000000000000789
2256
- Priority: 1
2257
- ```
2258
-
2259
- **Distributed header formats**
2260
-
2261
- Tracing supports the following distributed trace formats:
2262
-
2263
- - `Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG` (Default)
2264
- - `Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3`
2265
- - `Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER`
2266
-
2267
- You can enable/disable the use of these formats via `Datadog.configure`:
2268
-
2269
- ```ruby
2270
- Datadog.configure do |c|
2271
- # List of header formats that should be extracted
2272
- c.tracing.distributed_tracing.propagation_extract_style = [
2273
- Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG,
2274
- Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3,
2275
- Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_B3_SINGLE_HEADER
2276
-
2277
- ]
2278
-
2279
- # List of header formats that should be injected
2280
- c.tracing.distributed_tracing.propagation_inject_style = [
2281
- Datadog::Tracing::Configuration::Ext::Distributed::PROPAGATION_STYLE_DATADOG
2282
- ]
2283
- end
2284
- ```
2285
-
2286
- **Activating distributed tracing for integrations**
2287
-
2288
- Many integrations included in `ddtrace` support distributed tracing. Distributed tracing is enabled by default in Agent v7 and most versions of Agent v6. If needed, you can activate distributed tracing with configuration settings.
2289
-
2290
- - If your application receives requests from services with distributed tracing activated, you must activate distributed tracing on the integrations that handle these requests (e.g. Rails)
2291
- - If your application send requests to services with distributed tracing activated, you must activate distributed tracing on the integrations that send these requests (e.g. Faraday)
2292
- - If your application both sends and receives requests implementing distributed tracing, it must activate all integrations that handle these requests.
2293
-
2294
- For more details on how to activate distributed tracing for integrations, see their documentation:
2295
-
2296
- - [Excon](#excon)
2297
- - [Faraday](#faraday)
2298
- - [Rest Client](#rest-client)
2299
- - [Net/HTTP](#nethttp)
2300
- - [Rack](#rack)
2301
- - [Rails](#rails)
2302
- - [Sinatra](#sinatra)
2303
- - [http.rb](#httprb)
2304
- - [httpclient](#httpclient)
2305
- - [httpx](#httpx)
2306
-
2307
- **Using the HTTP propagator**
2308
-
2309
- To make the process of propagating this metadata easier, you can use the `Datadog::Tracing::Propagation::HTTP` module.
2310
-
2311
- On the client:
2312
-
2313
- ```ruby
2314
- Datadog::Tracing.trace('web.call') do |span, trace|
2315
- # Inject trace headers into request headers (`env` must be a Hash)
2316
- Datadog::Tracing::Propagation::HTTP.inject!(trace.to_digest, env)
2317
- end
2318
- ```
2319
-
2320
- On the server:
2321
-
2322
- ```ruby
2323
- trace_digest = Datadog::Tracing::Propagation::HTTP.extract(request.env)
2324
-
2325
- Datadog::Tracing.trace('web.work', continue_from: trace_digest) do |span|
2326
- # Do web work...
2327
- end
2328
- ```
2329
-
2330
- ### HTTP request queuing
2331
-
2332
- Traces that originate from HTTP requests can be configured to include the time spent in a frontend web server or load balancer queue before the request reaches the Ruby application.
2333
-
2334
- This feature is disabled by default. To activate it, you must add an `X-Request-Start` or `X-Queue-Start` header from your web server (i.e., Nginx). The following is an Nginx configuration example:
2335
-
2336
- ```
2337
- # /etc/nginx/conf.d/ruby_service.conf
2338
- server {
2339
- listen 8080;
2340
-
2341
- location / {
2342
- proxy_set_header X-Request-Start "t=${msec}";
2343
- proxy_pass http://web:3000;
2344
- }
2345
- }
2346
- ```
2347
-
2348
- Then you must enable the request queuing feature, by setting `request_queuing: true`, in the integration handling the request. For Rack-based applications, see the [documentation](#rack) for details.
2349
-
2350
- ### Processing Pipeline
2351
-
2352
- Some applications might require that traces be altered or filtered out before they are sent to Datadog. The processing pipeline allows you to create *processors* to define such behavior.
2353
-
2354
- #### Filtering
2355
-
2356
- You can use the `Datadog::Tracing::Pipeline::SpanFilter` processor to remove spans, when the block evaluates as truthy:
2357
-
2358
- ```ruby
2359
- Datadog::Tracing.before_flush(
2360
- # Remove spans that match a particular resource
2361
- Datadog::Tracing::Pipeline::SpanFilter.new { |span| span.resource =~ /PingController/ },
2362
- # Remove spans that are trafficked to localhost
2363
- Datadog::Tracing::Pipeline::SpanFilter.new { |span| span.get_tag('host') == 'localhost' }
2364
- )
2365
- ```
2366
-
2367
- #### Processing
2368
-
2369
- You can use the `Datadog::Tracing::Pipeline::SpanProcessor` processor to modify spans:
2370
-
2371
- ```ruby
2372
- Datadog::Tracing.before_flush(
2373
- # Strip matching text from the resource field
2374
- Datadog::Tracing::Pipeline::SpanProcessor.new { |span| span.resource.gsub!(/password=.*/, '') }
2375
- )
2376
- ```
2377
-
2378
- #### Custom processor
2379
-
2380
- Processors can be any object that responds to `#call` accepting `trace` as an argument (which is an `Array` of `Datadog::Span`s.)
2381
-
2382
- For example, using the short-hand block syntax:
2383
-
2384
- ```ruby
2385
- Datadog::Tracing.before_flush do |trace|
2386
- # Processing logic...
2387
- trace
2388
- end
2389
- ```
2390
-
2391
- For a custom processor class:
2392
-
2393
- ```ruby
2394
- class MyCustomProcessor
2395
- def call(trace)
2396
- # Processing logic...
2397
- trace
2398
- end
2399
- end
2400
-
2401
- Datadog::Tracing.before_flush(MyCustomProcessor.new)
2402
- ```
2403
-
2404
- In both cases, the processor method *must* return the `trace` object; this return value will be passed to the next processor in the pipeline.
2405
-
2406
- ### Trace correlation
2407
-
2408
- In many cases, such as logging, it may be useful to correlate trace IDs to other events or data streams, for easier cross-referencing.
2409
-
2410
- #### For logging in Rails applications
2411
-
2412
- ##### Automatic
2413
-
2414
- For Rails applications using the default logger (`ActiveSupport::TaggedLogging`), `lograge` or `semantic_logger`, trace correlation injection is enabled by default.
2415
-
2416
- It can be disabled by setting the environment variable `DD_LOGS_INJECTION=false`.
2417
-
2418
- #### For logging in Ruby applications
2419
-
2420
- To add correlation IDs to your logger, add a log formatter which retrieves the correlation IDs with `Datadog::Tracing.correlation`, then add them to the message.
2421
-
2422
- To properly correlate with Datadog logging, be sure the following is present in the log message, in order as they appear:
2423
-
2424
- - `dd.env=<ENV>`: Where `<ENV>` is equal to `Datadog::Tracing.correlation.env`. Omit if no environment is configured.
2425
- - `dd.service=<SERVICE>`: Where `<SERVICE>` is equal to `Datadog::Tracing.correlation.service`. Omit if no default service name is configured.
2426
- - `dd.version=<VERSION>`: Where `<VERSION>` is equal to `Datadog::Tracing.correlation.version`. Omit if no application version is configured.
2427
- - `dd.trace_id=<TRACE_ID>`: Where `<TRACE_ID>` is equal to `Datadog::Tracing.correlation.trace_id` or `0` if no trace is active during logging.
2428
- - `dd.span_id=<SPAN_ID>`: Where `<SPAN_ID>` is equal to `Datadog::Tracing.correlation.span_id` or `0` if no trace is active during logging.
2429
-
2430
- `Datadog::Tracing.log_correlation` will return `dd.env=<ENV> dd.service=<SERVICE> dd.version=<VERSION> dd.trace_id=<TRACE_ID> dd.span_id=<SPAN_ID>`.
2431
-
2432
- If a trace is not active and the application environment & version is not configured, it will return `dd.env= dd.service= dd.version= dd.trace_id=0 dd.span_id=0`.
2433
-
2434
- An example of this in practice:
2435
-
2436
- ```ruby
2437
- require 'ddtrace'
2438
- require 'logger'
2439
-
2440
- ENV['DD_ENV'] = 'production'
2441
- ENV['DD_SERVICE'] = 'billing-api'
2442
- ENV['DD_VERSION'] = '2.5.17'
2443
-
2444
- logger = Logger.new(STDOUT)
2445
- logger.progname = 'my_app'
2446
- logger.formatter = proc do |severity, datetime, progname, msg|
2447
- "[#{datetime}][#{progname}][#{severity}][#{Datadog::Tracing.log_correlation}] #{msg}\n"
2448
- end
2449
-
2450
- # When no trace is active
2451
- logger.warn('This is an untraced operation.')
2452
- # [2019-01-16 18:38:41 +0000][my_app][WARN][dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=0 dd.span_id=0] This is an untraced operation.
2453
-
2454
- # When a trace is active
2455
- Datadog::Tracing.trace('my.operation') { logger.warn('This is a traced operation.') }
2456
- # [2019-01-16 18:38:41 +0000][my_app][WARN][dd.env=production dd.service=billing-api dd.version=2.5.17 dd.trace_id=8545847825299552251 dd.span_id=3711755234730770098] This is a traced operation.
2457
- ```
2458
-
2459
- ### Configuring the transport layer
2460
-
2461
- By default, `ddtrace` will connect to the agent using the first available settings in the listed priority:
2462
-
2463
- 1. Via any explicitly provided configuration settings (hostname/port/transport)
2464
- 2. Via Unix Domain Socket (UDS) located at `/var/run/datadog/apm.socket`
2465
- 3. Via HTTP over TCP to `127.0.0.1:8126`
2466
-
2467
- However, the tracer can be configured to send its trace data to alternative destinations, or by alternative protocols.
2468
-
2469
- #### Changing default agent hostname and port
2470
-
2471
- To change the agent host or port, provide `DD_AGENT_HOST` and `DD_TRACE_AGENT_PORT`.
2472
-
2473
- OR within a `Datadog.configure` block, provide the following settings:
2474
-
2475
- ```ruby
2476
- Datadog.configure do |c|
2477
- c.agent.host = '127.0.0.1'
2478
- c.agent.port = 8126
2479
- end
2480
- ```
2481
-
2482
- See [Additional Configuration](#additional-configuration) for more details.
2483
-
2484
- #### Using the Net::HTTP adapter
2485
-
2486
- The `Net` adapter submits traces using `Net::HTTP` over TCP. It is the default transport adapter.
2487
-
2488
- ```ruby
2489
- Datadog.configure do |c|
2490
- c.tracing.transport_options = proc { |t|
2491
- # Hostname, port, and additional options. :timeout is in seconds.
2492
- t.adapter :net_http, '127.0.0.1', 8126, { timeout: 1 }
2493
- }
2494
- end
2495
- ```
2496
-
2497
- #### Using the Unix Domain Socket (UDS) adapter
2498
-
2499
- The `UnixSocket` adapter submits traces using `Net::HTTP` over Unix socket.
2500
-
2501
- To use, first configure your trace agent to listen by Unix socket, then configure the tracer with:
2502
-
2503
- ```ruby
2504
- Datadog.configure do |c|
2505
- c.tracing.transport_options = proc { |t|
2506
- # Provide local path to trace agent Unix socket
2507
- t.adapter :unix, '/tmp/ddagent/trace.sock'
2508
- }
2509
- end
2510
- ```
2511
-
2512
- #### Using the transport test adapter
2513
-
2514
- The `Test` adapter is a no-op transport that can optionally buffer requests. For use in test suites or other non-production environments.
2515
-
2516
- ```ruby
2517
- Datadog.configure do |c|
2518
- c.tracing.transport_options = proc { |t|
2519
- # Set transport to no-op mode. Does not retain traces.
2520
- t.adapter :test
2521
-
2522
- # Alternatively, you can provide a buffer to examine trace output.
2523
- # The buffer must respond to '<<'.
2524
- t.adapter :test, []
2525
- }
2526
- end
2527
- ```
2528
-
2529
- #### Using a custom transport adapter
2530
-
2531
- Custom adapters can be configured with:
2532
-
2533
- ```ruby
2534
- Datadog.configure do |c|
2535
- c.tracing.transport_options = proc { |t|
2536
- # Initialize and pass an instance of the adapter
2537
- custom_adapter = CustomAdapter.new
2538
- t.adapter custom_adapter
2539
- }
2540
- end
2541
- ```
2542
-
2543
- ### Setting the time provider
2544
-
2545
- By default, tracing uses a monotonic clock to measure the duration of spans, and timestamps (`->{ Time.now }`) for the start and end time.
2546
-
2547
- When testing, it might be helpful to use a different time provider.
2548
-
2549
- To change the function that provides timestamps, configure the following:
2550
-
2551
- ```ruby
2552
- Datadog.configure do |c|
2553
- # For Timecop, for example, `->{ Time.now_without_mock_time }` allows the tracer to use the real wall time.
2554
- c.time_now_provider = -> { Time.now_without_mock_time }
2555
- end
2556
- ```
2557
-
2558
- Span duration calculation will still use the system monotonic clock when available, thus not being affected by this setting.
2559
-
2560
- ### Metrics
2561
-
2562
- The tracer and its integrations can produce some additional metrics that can provide useful insight into the performance of your application. These metrics are collected with `dogstatsd-ruby`, and can be sent to the same Datadog agent to which you send your traces.
2563
-
2564
- To configure your application for metrics collection:
2565
-
2566
- 1. [Configure your Datadog agent for StatsD](https://docs.datadoghq.com/developers/dogstatsd/#setup)
2567
- 2. Add `gem 'dogstatsd-ruby', '~> 5.3'` to your Gemfile
2568
-
2569
- #### For application runtime
2570
-
2571
- If runtime metrics are configured, the trace library will automatically collect and send metrics about the health of your application.
2572
-
2573
- To configure runtime metrics, add the following configuration:
2574
-
2575
- ```ruby
2576
- # config/initializers/datadog.rb
2577
- require 'datadog/statsd'
2578
- require 'ddtrace'
2579
-
2580
- Datadog.configure do |c|
2581
- # To enable runtime metrics collection, set `true`. Defaults to `false`
2582
- # You can also set DD_RUNTIME_METRICS_ENABLED=true to configure this.
2583
- c.runtime_metrics.enabled = true
2584
-
2585
- # Optionally, you can configure the Statsd instance used for sending runtime metrics.
2586
- # Statsd is automatically configured with default settings if `dogstatsd-ruby` is available.
2587
- # You can configure with host and port of Datadog agent; defaults to 'localhost:8125'.
2588
- c.runtime_metrics.statsd = Datadog::Statsd.new
2589
- end
2590
- ```
2591
-
2592
- See the [Dogstatsd documentation](https://www.rubydoc.info/github/DataDog/dogstatsd-ruby/master/frames) for more details about configuring `Datadog::Statsd`.
2593
-
2594
- The stats are VM specific and will include:
2595
-
2596
- | Name | Type | Description | Available on |
2597
- | -------------------------- | ------- | -------------------------------------------------------- | ------------ |
2598
- | `runtime.ruby.class_count` | `gauge` | Number of classes in memory space. | CRuby |
2599
- | `runtime.ruby.gc.*` | `gauge` | Garbage collection statistics: collected from `GC.stat`. | All runtimes |
2600
- | `runtime.ruby.thread_count` | `gauge` | Number of threads. | All runtimes |
2601
- | `runtime.ruby.global_constant_state` | `gauge` | Global constant cache generation. | CRuby |
2602
- | `runtime.ruby.global_method_state` | `gauge` | [Global method cache generation.](https://tenderlovemaking.com/2015/12/23/inline-caching-in-mri.html) | [CRuby < 3.0.0](https://docs.ruby-lang.org/en/3.0.0/NEWS_md.html#label-Implementation+improvements) |
2603
-
2604
- In addition, all metrics include the following tags:
2605
-
2606
- | Name | Description |
2607
- | ------------ | ------------------------------------------------------- |
2608
- | `language` | Programming language traced. (e.g. `ruby`) |
2609
- | `service` | List of services this associated with this metric. |
2610
-
2611
- ### OpenTracing
2612
-
2613
- For setting up Datadog with OpenTracing, see our [Configuring OpenTracing](#configuring-opentracing) section for details.
2614
-
2615
- **Configuring Datadog tracer settings**
2616
-
2617
- The underlying Datadog tracer can be configured by passing options (which match `Datadog::Tracer`) when configuring the global tracer:
2618
-
2619
- ```ruby
2620
- # Where `options` is a Hash of options provided to Datadog::Tracer
2621
- OpenTracing.global_tracer = Datadog::OpenTracer::Tracer.new(**options)
2622
- ```
2623
-
2624
- It can also be configured by using `Datadog.configure` described in the [Additional Configuration](#additional-configuration) section.
2625
-
2626
- **Activating and configuring integrations**
2627
-
2628
- By default, configuring OpenTracing with Datadog will not automatically activate any additional instrumentation provided by Datadog. You will only receive spans and traces from OpenTracing instrumentation you have in your application.
2629
-
2630
- However, additional instrumentation provided by Datadog can be activated alongside OpenTracing using `Datadog.configure`, which can be used to enhance your tracing further. To activate this, see [Integration instrumentation](#integration-instrumentation) for more details.
2631
-
2632
- **Supported serialization formats**
2633
-
2634
- | Type | Supported? | Additional information |
2635
- | ------------------------------ | ---------- | ---------------------- |
2636
- | `OpenTracing::FORMAT_TEXT_MAP` | Yes | |
2637
- | `OpenTracing::FORMAT_RACK` | Yes | Because of the loss of resolution in the Rack format, please note that baggage items with names containing either upper case characters or `-` will be converted to lower case and `_` in a round-trip respectively. We recommend avoiding these characters or accommodating accordingly on the receiving end. |
2638
- | `OpenTracing::FORMAT_BINARY` | No | |
2639
-
2640
- ### Profiling
2641
-
2642
- *Currently available as BETA feature.*
2643
-
2644
- `ddtrace` can produce profiles that measure method-level application resource usage within production environments. These profiles can give insight into resources spent in Ruby code outside of existing trace instrumentation.
2645
-
2646
- **Setup**
2647
-
2648
- To get started with profiling, follow the [Enabling the Ruby Profiler](https://docs.datadoghq.com/tracing/profiler/enabling/ruby/) guide.
2649
-
2650
- #### Troubleshooting
2651
-
2652
- If you run into issues with profiling, please check the [Profiler Troubleshooting Guide](https://docs.datadoghq.com/tracing/profiler/profiler_troubleshooting/?code-lang=ruby).
2653
-
2654
- #### Profiling Resque jobs
2655
-
2656
- When profiling [Resque](https://github.com/resque/resque) jobs, you should set the `RUN_AT_EXIT_HOOKS=1` option described in the [Resque](https://github.com/resque/resque/blob/v2.0.0/docs/HOOKS.md#worker-hooks) documentation.
2657
-
2658
- Without this flag, profiles for short-lived Resque jobs will not be available as Resque kills worker processes before they have a chance to submit this information.
2659
-
2660
- ## Known issues and suggested configurations
2661
-
2662
- ### Payload too large
2663
-
2664
- By default, Datadog limits the size of trace payloads to prevent memory overhead within instrumented applications. As a result, traces containing thousands of operations may not be sent to Datadog.
2665
-
2666
- If traces are missing, enable [debug mode](#debugging-and-diagnostics) to check if messages containing `"Dropping trace. Payload too large"` are logged.
2667
-
2668
- Since debug mode is verbose, **Datadog does not recommend leaving this enabled or enabling this in production.** Disable it after confirming. You can inspect the [Datadog Agent logs](https://docs.datadoghq.com/agent/guide/agent-log-files/) for similar messages.
2669
-
2670
- If you have confirmed that traces are dropped due to large payloads, then enable the [partial_flush](#additional-configuration) setting to break down large traces into smaller chunks.
2671
-
2672
- ### Stack level too deep
2673
-
2674
- Datadog tracing collects trace data by adding instrumentation into other common libraries (e.g. Rails, Rack, etc.) Some libraries provide APIs to add this instrumentation, but some do not. In order to add instrumentation into libraries lacking an instrumentation API, Datadog uses a technique called "monkey-patching" to modify the code of that library.
2675
-
2676
- In Ruby version 1.9.3 and earlier, "monkey-patching" often involved the use of [`alias_method`](https://ruby-doc.org/core-3.0.0/Module.html#method-i-alias_method), also known as *method rewriting*, to destructively replace existing Ruby methods. However, this practice would often create conflicts & errors if two libraries attempted to "rewrite" the same method. (e.g. two different APM packages trying to instrument the same method.)
2677
-
2678
- In Ruby 2.0, the [`Module#prepend`](https://ruby-doc.org/core-3.0.0/Module.html#method-i-prepend) feature was introduced. This feature avoids destructive method rewriting and allows multiple "monkey patches" on the same method. Consequently, it has become the safest, preferred means to "monkey patch" code.
2679
-
2680
- Datadog instrumentation almost exclusively uses the `Module#prepend` feature to add instrumentation non-destructively. However, some other libraries (typically those supporting Ruby < 2.0) still use `alias_method` which can create conflicts with Datadog instrumentation, often resulting in `SystemStackError` or `stack level too deep` errors.
2681
-
2682
- As the implementation of `alias_method` exists within those libraries, Datadog generally cannot fix them. However, some libraries have known workarounds:
2683
-
2684
- * `rack-mini-profiler`: [Net::HTTP stack level too deep errors](https://github.com/MiniProfiler/rack-mini-profiler#nethttp-stack-level-too-deep-errors).
2685
-
2686
- For libraries without a known workaround, consider removing the library using `alias` or `Module#alias_method` or separating libraries into different environments for testing.
2687
-
2688
- For any further questions or to report an occurence of this issue, please [reach out to Datadog support](https://docs.datadoghq.com/help)