ddtrace 1.10.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (364) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +125 -1
  3. data/README.md +8 -10
  4. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +110 -18
  5. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +26 -3
  6. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +3 -0
  7. data/lib/datadog/appsec/component.rb +40 -6
  8. data/lib/datadog/appsec/configuration/settings.rb +20 -4
  9. data/lib/datadog/appsec/configuration.rb +8 -0
  10. data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -0
  11. data/lib/datadog/appsec/contrib/configuration/settings.rb +2 -0
  12. data/lib/datadog/appsec/contrib/integration.rb +2 -0
  13. data/lib/datadog/appsec/contrib/patcher.rb +2 -0
  14. data/lib/datadog/appsec/contrib/rack/configuration/settings.rb +2 -0
  15. data/lib/datadog/appsec/contrib/rack/gateway/request.rb +4 -15
  16. data/lib/datadog/appsec/contrib/rack/gateway/response.rb +1 -1
  17. data/lib/datadog/appsec/contrib/rack/patcher.rb +2 -0
  18. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +6 -0
  19. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +17 -4
  20. data/lib/datadog/appsec/contrib/rails/configuration/settings.rb +2 -0
  21. data/lib/datadog/appsec/contrib/rails/framework.rb +2 -0
  22. data/lib/datadog/appsec/contrib/rails/gateway/request.rb +1 -1
  23. data/lib/datadog/appsec/contrib/rails/request.rb +2 -0
  24. data/lib/datadog/appsec/contrib/rails/request_middleware.rb +2 -0
  25. data/lib/datadog/appsec/contrib/sinatra/configuration/settings.rb +2 -0
  26. data/lib/datadog/appsec/contrib/sinatra/framework.rb +2 -0
  27. data/lib/datadog/appsec/contrib/sinatra/gateway/route_params.rb +1 -1
  28. data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +2 -0
  29. data/lib/datadog/appsec/extensions.rb +2 -0
  30. data/lib/datadog/appsec/instrumentation/gateway/argument.rb +2 -4
  31. data/lib/datadog/appsec/processor/rule_loader.rb +63 -0
  32. data/lib/datadog/appsec/processor/rule_merger.rb +146 -0
  33. data/lib/datadog/appsec/processor.rb +15 -70
  34. data/lib/datadog/appsec/remote.rb +121 -0
  35. data/lib/datadog/appsec/utils/http.rb +2 -0
  36. data/lib/datadog/appsec/utils.rb +2 -0
  37. data/lib/datadog/appsec.rb +18 -4
  38. data/lib/datadog/ci/configuration/components.rb +2 -0
  39. data/lib/datadog/ci/configuration/settings.rb +2 -0
  40. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +2 -0
  41. data/lib/datadog/ci/contrib/cucumber/formatter.rb +2 -0
  42. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +2 -0
  43. data/lib/datadog/ci/contrib/cucumber/patcher.rb +2 -0
  44. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +2 -0
  45. data/lib/datadog/ci/contrib/rspec/patcher.rb +2 -0
  46. data/lib/datadog/ci/extensions.rb +2 -0
  47. data/lib/datadog/ci/flush.rb +2 -0
  48. data/lib/datadog/ci.rb +2 -0
  49. data/lib/datadog/core/buffer/cruby.rb +2 -0
  50. data/lib/datadog/core/buffer/random.rb +2 -0
  51. data/lib/datadog/core/buffer/thread_safe.rb +2 -0
  52. data/lib/datadog/core/chunker.rb +2 -0
  53. data/lib/datadog/core/configuration/agent_settings_resolver.rb +68 -17
  54. data/lib/datadog/core/configuration/components.rb +11 -14
  55. data/lib/datadog/core/configuration/dependency_resolver.rb +2 -0
  56. data/lib/datadog/core/configuration/option.rb +2 -0
  57. data/lib/datadog/core/configuration/option_definition.rb +2 -0
  58. data/lib/datadog/core/configuration/option_definition_set.rb +2 -0
  59. data/lib/datadog/core/configuration/option_set.rb +2 -0
  60. data/lib/datadog/core/configuration/settings.rb +70 -16
  61. data/lib/datadog/core/diagnostics/health.rb +2 -0
  62. data/lib/datadog/core/environment/class_count.rb +2 -0
  63. data/lib/datadog/core/environment/gc.rb +2 -0
  64. data/lib/datadog/core/environment/identity.rb +58 -0
  65. data/lib/datadog/core/environment/socket.rb +2 -0
  66. data/lib/datadog/core/environment/thread_count.rb +2 -0
  67. data/lib/datadog/core/environment/variable_helpers.rb +10 -2
  68. data/lib/datadog/core/environment/vm_cache.rb +2 -0
  69. data/lib/datadog/core/extensions.rb +2 -0
  70. data/lib/datadog/core/header_collection.rb +2 -0
  71. data/lib/datadog/core/metrics/helpers.rb +2 -0
  72. data/lib/datadog/core/metrics/metric.rb +2 -0
  73. data/lib/datadog/core/remote/client/capabilities.rb +57 -0
  74. data/lib/datadog/core/remote/client.rb +225 -0
  75. data/lib/datadog/core/remote/component.rb +158 -0
  76. data/lib/datadog/core/remote/configuration/content.rb +84 -0
  77. data/lib/datadog/core/remote/configuration/digest.rb +62 -0
  78. data/lib/datadog/core/remote/configuration/path.rb +90 -0
  79. data/lib/datadog/core/remote/configuration/repository.rb +292 -0
  80. data/lib/datadog/core/remote/configuration/target.rb +74 -0
  81. data/lib/datadog/core/remote/configuration.rb +18 -0
  82. data/lib/datadog/core/remote/dispatcher.rb +59 -0
  83. data/lib/datadog/core/remote/ext.rb +12 -0
  84. data/lib/datadog/core/remote/negotiation.rb +57 -0
  85. data/lib/datadog/core/remote/worker.rb +96 -0
  86. data/lib/datadog/core/remote.rb +24 -0
  87. data/lib/datadog/core/telemetry/collector.rb +8 -9
  88. data/lib/datadog/core/telemetry/heartbeat.rb +2 -0
  89. data/lib/datadog/core/telemetry/http/env.rb +2 -0
  90. data/lib/datadog/core/telemetry/http/transport.rb +2 -0
  91. data/lib/datadog/core/telemetry/v1/app_event.rb +2 -0
  92. data/lib/datadog/core/telemetry/v1/application.rb +7 -1
  93. data/lib/datadog/core/telemetry/v1/dependency.rb +7 -1
  94. data/lib/datadog/core/telemetry/v1/host.rb +9 -1
  95. data/lib/datadog/core/telemetry/v1/integration.rb +7 -1
  96. data/lib/datadog/core/telemetry/v1/product.rb +9 -1
  97. data/lib/datadog/core/telemetry/v1/telemetry_request.rb +7 -1
  98. data/lib/datadog/core/transport/config.rb +58 -0
  99. data/lib/datadog/core/transport/http/api/instance.rb +37 -0
  100. data/lib/datadog/core/transport/http/api/spec.rb +19 -0
  101. data/lib/datadog/core/transport/http/api.rb +57 -0
  102. data/lib/datadog/core/transport/http/builder.rb +217 -0
  103. data/lib/datadog/core/transport/http/client.rb +45 -0
  104. data/lib/datadog/core/transport/http/config.rb +268 -0
  105. data/lib/datadog/core/transport/http/negotiation.rb +144 -0
  106. data/lib/datadog/core/transport/http.rb +169 -0
  107. data/lib/datadog/core/transport/negotiation.rb +60 -0
  108. data/lib/datadog/core/utils/compression.rb +2 -0
  109. data/lib/datadog/core/utils/hash.rb +32 -0
  110. data/lib/datadog/core/utils/object_set.rb +2 -0
  111. data/lib/datadog/core/utils/safe_dup.rb +20 -2
  112. data/lib/datadog/core/utils/sequence.rb +2 -0
  113. data/lib/datadog/core/utils/time.rb +2 -0
  114. data/lib/datadog/core/worker.rb +2 -0
  115. data/lib/datadog/core/workers/async.rb +6 -2
  116. data/lib/datadog/core/workers/interval_loop.rb +7 -1
  117. data/lib/datadog/core/workers/queue.rb +2 -0
  118. data/lib/datadog/core/workers/runtime_metrics.rb +2 -0
  119. data/lib/datadog/kit.rb +2 -0
  120. data/lib/datadog/opentracer/binary_propagator.rb +2 -0
  121. data/lib/datadog/opentracer/carrier.rb +2 -0
  122. data/lib/datadog/opentracer/global_tracer.rb +2 -0
  123. data/lib/datadog/opentracer/propagator.rb +2 -0
  124. data/lib/datadog/opentracer/scope.rb +2 -0
  125. data/lib/datadog/opentracer/scope_manager.rb +2 -0
  126. data/lib/datadog/opentracer/span_context.rb +2 -0
  127. data/lib/datadog/opentracer/span_context_factory.rb +2 -0
  128. data/lib/datadog/opentracer/thread_local_scope.rb +2 -0
  129. data/lib/datadog/opentracer.rb +2 -0
  130. data/lib/datadog/profiling/backtrace_location.rb +2 -0
  131. data/lib/datadog/profiling/buffer.rb +2 -0
  132. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +19 -3
  133. data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +2 -0
  134. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  135. data/lib/datadog/profiling/collectors/stack.rb +2 -0
  136. data/lib/datadog/profiling/collectors/thread_context.rb +2 -2
  137. data/lib/datadog/profiling/component.rb +103 -29
  138. data/lib/datadog/profiling/event.rb +2 -0
  139. data/lib/datadog/profiling/events/stack.rb +2 -0
  140. data/lib/datadog/profiling/ext.rb +28 -26
  141. data/lib/datadog/profiling/flush.rb +2 -0
  142. data/lib/datadog/profiling/native_extension.rb +2 -0
  143. data/lib/datadog/profiling/pprof/message_set.rb +2 -0
  144. data/lib/datadog/profiling/pprof/payload.rb +2 -0
  145. data/lib/datadog/profiling/pprof/string_table.rb +2 -0
  146. data/lib/datadog/profiling/preload.rb +2 -0
  147. data/lib/datadog/profiling/scheduler.rb +3 -1
  148. data/lib/datadog/profiling/stack_recorder.rb +0 -18
  149. data/lib/datadog/profiling/tag_builder.rb +2 -0
  150. data/lib/datadog/profiling/tasks/setup.rb +0 -26
  151. data/lib/datadog/profiling.rb +2 -1
  152. data/lib/datadog/tracing/analytics.rb +2 -0
  153. data/lib/datadog/tracing/configuration/ext.rb +7 -0
  154. data/lib/datadog/tracing/configuration/settings.rb +14 -0
  155. data/lib/datadog/tracing/context.rb +2 -0
  156. data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +2 -0
  157. data/lib/datadog/tracing/contrib/action_cable/event.rb +2 -0
  158. data/lib/datadog/tracing/contrib/action_cable/events.rb +2 -0
  159. data/lib/datadog/tracing/contrib/action_cable/patcher.rb +2 -0
  160. data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +2 -0
  161. data/lib/datadog/tracing/contrib/action_mailer/event.rb +2 -0
  162. data/lib/datadog/tracing/contrib/action_mailer/events.rb +2 -0
  163. data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +2 -0
  164. data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +2 -24
  165. data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -0
  166. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +14 -1
  167. data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -0
  168. data/lib/datadog/tracing/contrib/action_view/event.rb +2 -0
  169. data/lib/datadog/tracing/contrib/action_view/events.rb +2 -0
  170. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +2 -0
  171. data/lib/datadog/tracing/contrib/active_job/event.rb +2 -0
  172. data/lib/datadog/tracing/contrib/active_job/events.rb +2 -0
  173. data/lib/datadog/tracing/contrib/active_job/log_injection.rb +2 -0
  174. data/lib/datadog/tracing/contrib/active_job/patcher.rb +2 -0
  175. data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +2 -0
  176. data/lib/datadog/tracing/contrib/active_model_serializers/event.rb +2 -0
  177. data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +2 -0
  178. data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +2 -0
  179. data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +8 -1
  180. data/lib/datadog/tracing/contrib/active_record/event.rb +2 -0
  181. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -1
  182. data/lib/datadog/tracing/contrib/active_record/events.rb +2 -0
  183. data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -0
  184. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +6 -2
  185. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +2 -0
  186. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -0
  187. data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +2 -0
  188. data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +2 -0
  189. data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +2 -0
  190. data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -0
  191. data/lib/datadog/tracing/contrib/analytics.rb +2 -0
  192. data/lib/datadog/tracing/contrib/auto_instrument.rb +2 -0
  193. data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +9 -1
  194. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +8 -1
  195. data/lib/datadog/tracing/contrib/aws/patcher.rb +2 -0
  196. data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +2 -0
  197. data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +2 -0
  198. data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +2 -0
  199. data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +2 -0
  200. data/lib/datadog/tracing/contrib/configurable.rb +2 -0
  201. data/lib/datadog/tracing/contrib/configuration/resolver.rb +2 -0
  202. data/lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb +2 -0
  203. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +8 -1
  204. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +4 -1
  205. data/lib/datadog/tracing/contrib/dalli/patcher.rb +2 -0
  206. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +2 -0
  207. data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +2 -0
  208. data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +2 -0
  209. data/lib/datadog/tracing/contrib/delayed_job/server_internal_tracer/worker.rb +2 -0
  210. data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +8 -1
  211. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +4 -1
  212. data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +8 -1
  213. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -3
  214. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +6 -2
  215. data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -0
  216. data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +8 -1
  217. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -2
  218. data/lib/datadog/tracing/contrib/excon/patcher.rb +2 -0
  219. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +8 -1
  220. data/lib/datadog/tracing/contrib/faraday/connection.rb +2 -0
  221. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -2
  222. data/lib/datadog/tracing/contrib/faraday/rack_builder.rb +2 -0
  223. data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +2 -0
  224. data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -0
  225. data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +2 -0
  226. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +8 -1
  227. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +5 -2
  228. data/lib/datadog/tracing/contrib/grpc/intercept_with_datadog.rb +2 -0
  229. data/lib/datadog/tracing/contrib/grpc/patcher.rb +2 -0
  230. data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +2 -0
  231. data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +2 -0
  232. data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -0
  233. data/lib/datadog/tracing/contrib/hanami/plugin.rb +2 -0
  234. data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +2 -0
  235. data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +2 -0
  236. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +2 -0
  237. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +8 -1
  238. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -2
  239. data/lib/datadog/tracing/contrib/http/integration.rb +2 -0
  240. data/lib/datadog/tracing/contrib/http/patcher.rb +2 -0
  241. data/lib/datadog/tracing/contrib/http_annotation_helper.rb +2 -0
  242. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +2 -0
  243. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +2 -0
  244. data/lib/datadog/tracing/contrib/integration.rb +2 -0
  245. data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +2 -0
  246. data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +2 -0
  247. data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +2 -0
  248. data/lib/datadog/tracing/contrib/kafka/event.rb +2 -0
  249. data/lib/datadog/tracing/contrib/kafka/events.rb +2 -0
  250. data/lib/datadog/tracing/contrib/kafka/patcher.rb +2 -0
  251. data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +2 -0
  252. data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +2 -0
  253. data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -0
  254. data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +2 -0
  255. data/lib/datadog/tracing/contrib/mongodb/instrumentation.rb +2 -0
  256. data/lib/datadog/tracing/contrib/mongodb/patcher.rb +2 -0
  257. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +2 -0
  258. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -0
  259. data/lib/datadog/tracing/contrib/mysql2/patcher.rb +2 -0
  260. data/lib/datadog/tracing/contrib/patchable.rb +2 -0
  261. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +2 -0
  262. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +2 -0
  263. data/lib/datadog/tracing/contrib/pg/patcher.rb +2 -0
  264. data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +2 -0
  265. data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +2 -0
  266. data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +2 -0
  267. data/lib/datadog/tracing/contrib/qless/patcher.rb +2 -0
  268. data/lib/datadog/tracing/contrib/qless/tracer_cleaner.rb +2 -0
  269. data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +2 -0
  270. data/lib/datadog/tracing/contrib/racecar/event.rb +2 -0
  271. data/lib/datadog/tracing/contrib/racecar/events.rb +2 -0
  272. data/lib/datadog/tracing/contrib/racecar/patcher.rb +2 -0
  273. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +9 -2
  274. data/lib/datadog/tracing/contrib/rails/framework.rb +2 -0
  275. data/lib/datadog/tracing/contrib/rails/middlewares.rb +2 -0
  276. data/lib/datadog/tracing/contrib/rails/utils.rb +3 -1
  277. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +2 -0
  278. data/lib/datadog/tracing/contrib/rake/patcher.rb +2 -0
  279. data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +2 -0
  280. data/lib/datadog/tracing/contrib/redis/tags.rb +2 -0
  281. data/lib/datadog/tracing/contrib/registerable.rb +2 -0
  282. data/lib/datadog/tracing/contrib/registry.rb +2 -0
  283. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +2 -0
  284. data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -0
  285. data/lib/datadog/tracing/contrib/resque/resque_job.rb +2 -0
  286. data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +2 -0
  287. data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -0
  288. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +2 -0
  289. data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +34 -0
  290. data/lib/datadog/tracing/contrib/roda/ext.rb +18 -0
  291. data/lib/datadog/tracing/contrib/roda/instrumentation.rb +76 -0
  292. data/lib/datadog/tracing/contrib/roda/integration.rb +45 -0
  293. data/lib/datadog/tracing/contrib/roda/patcher.rb +30 -0
  294. data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +2 -0
  295. data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +3 -0
  296. data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -0
  297. data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +2 -0
  298. data/lib/datadog/tracing/contrib/sequel/dataset.rb +2 -0
  299. data/lib/datadog/tracing/contrib/sequel/patcher.rb +2 -0
  300. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +2 -0
  301. data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -0
  302. data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +2 -0
  303. data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +12 -3
  304. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +3 -0
  305. data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +38 -0
  306. data/lib/datadog/tracing/contrib/sidekiq/integration.rb +8 -0
  307. data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +16 -2
  308. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/heartbeat.rb +11 -4
  309. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/job_fetch.rb +2 -0
  310. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/redis_info.rb +2 -0
  311. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/scheduled_poller.rb +2 -0
  312. data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/stop.rb +34 -0
  313. data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +18 -2
  314. data/lib/datadog/tracing/contrib/sidekiq/{tracing.rb → utils.rb} +3 -1
  315. data/lib/datadog/tracing/contrib/sinatra/headers.rb +2 -0
  316. data/lib/datadog/tracing/contrib/sinatra/patcher.rb +2 -0
  317. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +2 -0
  318. data/lib/datadog/tracing/contrib/span_attribute_schema.rb +28 -0
  319. data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +2 -0
  320. data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +2 -0
  321. data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +2 -0
  322. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  323. data/lib/datadog/tracing/contrib.rb +3 -0
  324. data/lib/datadog/tracing/correlation.rb +10 -10
  325. data/lib/datadog/tracing/diagnostics/health.rb +2 -0
  326. data/lib/datadog/tracing/distributed/trace_context.rb +22 -15
  327. data/lib/datadog/tracing/flush.rb +2 -0
  328. data/lib/datadog/tracing/metadata/analytics.rb +2 -0
  329. data/lib/datadog/tracing/metadata/errors.rb +2 -0
  330. data/lib/datadog/tracing/metadata/ext.rb +6 -0
  331. data/lib/datadog/tracing/metadata.rb +2 -0
  332. data/lib/datadog/tracing/pipeline/span_filter.rb +2 -0
  333. data/lib/datadog/tracing/pipeline/span_processor.rb +2 -0
  334. data/lib/datadog/tracing/propagation/http.rb +2 -0
  335. data/lib/datadog/tracing/runtime/metrics.rb +2 -0
  336. data/lib/datadog/tracing/sampling/all_sampler.rb +2 -0
  337. data/lib/datadog/tracing/sampling/matcher.rb +2 -0
  338. data/lib/datadog/tracing/sampling/priority_sampler.rb +2 -0
  339. data/lib/datadog/tracing/sampling/span/sampler.rb +2 -0
  340. data/lib/datadog/tracing/sync_writer.rb +2 -0
  341. data/lib/datadog/tracing/trace_digest.rb +2 -0
  342. data/lib/datadog/tracing/utils.rb +2 -0
  343. data/lib/datadog/tracing.rb +2 -0
  344. data/lib/ddtrace/auto_instrument.rb +2 -0
  345. data/lib/ddtrace/auto_instrument_base.rb +2 -0
  346. data/lib/ddtrace/transport/http/adapters/net.rb +12 -0
  347. data/lib/ddtrace/transport/http/adapters/registry.rb +2 -0
  348. data/lib/ddtrace/transport/http/api/endpoint.rb +2 -0
  349. data/lib/ddtrace/transport/http/api/fallbacks.rb +2 -0
  350. data/lib/ddtrace/transport/http/api/instance.rb +2 -0
  351. data/lib/ddtrace/transport/http/api/map.rb +2 -0
  352. data/lib/ddtrace/transport/http/api/spec.rb +2 -0
  353. data/lib/ddtrace/transport/http/env.rb +2 -0
  354. data/lib/ddtrace/transport/http/response.rb +2 -0
  355. data/lib/ddtrace/transport/io/response.rb +2 -0
  356. data/lib/ddtrace/transport/io/traces.rb +2 -0
  357. data/lib/ddtrace/transport/io.rb +2 -0
  358. data/lib/ddtrace/transport/parcel.rb +2 -0
  359. data/lib/ddtrace/transport/request.rb +3 -1
  360. data/lib/ddtrace/transport/statistics.rb +2 -0
  361. data/lib/ddtrace/transport/trace_formatter.rb +2 -0
  362. data/lib/ddtrace/version.rb +9 -5
  363. data/lib/ddtrace.rb +2 -0
  364. metadata +43 -6
@@ -0,0 +1,158 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'worker'
4
+ require_relative 'client/capabilities'
5
+ require_relative 'client'
6
+ require_relative '../transport/http'
7
+ require_relative '../remote'
8
+ require_relative 'negotiation'
9
+
10
+ module Datadog
11
+ module Core
12
+ module Remote
13
+ # Configures the HTTP transport to communicate with the agent
14
+ # to fetch and sync the remote configuration
15
+ class Component
16
+ BARRIER_TIMEOUT = 1.0 # second
17
+
18
+ attr_reader :client
19
+
20
+ def initialize(settings, capabilities, agent_settings)
21
+ transport_options = {}
22
+ transport_options[:agent_settings] = agent_settings if agent_settings
23
+
24
+ negotiation = Negotiation.new(settings, agent_settings)
25
+ transport_v7 = Datadog::Core::Transport::HTTP.v7(**transport_options.dup)
26
+
27
+ @barrier = Barrier.new(BARRIER_TIMEOUT)
28
+
29
+ @client = Client.new(transport_v7, capabilities)
30
+ healthy = false
31
+ Datadog.logger.debug { "new remote configuration client: #{@client.id}" }
32
+
33
+ @worker = Worker.new(interval: settings.remote.poll_interval_seconds) do
34
+ unless healthy || negotiation.endpoint?('/v0.7/config')
35
+ @barrier.lift
36
+
37
+ next
38
+ end
39
+
40
+ begin
41
+ @client.sync
42
+ healthy ||= true
43
+ rescue Client::SyncError => e
44
+ Datadog.logger.error do
45
+ "remote worker client sync error: #{e.message} location: #{Array(e.backtrace).first}. skipping sync"
46
+ end
47
+ rescue StandardError => e
48
+ Datadog.logger.error do
49
+ "remote worker error: #{e.class.name} #{e.message} location: #{Array(e.backtrace).first}. "\
50
+ 'reseting client state'
51
+ end
52
+
53
+ # client state is unknown, state might be corrupted
54
+ @client = Client.new(transport_v7, capabilities)
55
+ healthy = false
56
+ Datadog.logger.debug { "new remote configuration client: #{@client.id}" }
57
+
58
+ # TODO: bail out if too many errors?
59
+ end
60
+
61
+ @barrier.lift
62
+ end
63
+ end
64
+
65
+ def barrier(kind)
66
+ @worker.start
67
+
68
+ case kind
69
+ when :once
70
+ @barrier.wait_once
71
+ end
72
+ end
73
+
74
+ def shutdown!
75
+ @worker.stop
76
+ end
77
+
78
+ # Barrier provides a mechanism to fence execution until a condition happens
79
+ class Barrier
80
+ def initialize(timeout = nil)
81
+ @once = false
82
+ @timeout = timeout
83
+
84
+ @mutex = Mutex.new
85
+ @condition = ConditionVariable.new
86
+ end
87
+
88
+ # Wait for first lift to happen, otherwise don't wait
89
+ def wait_once(timeout = nil)
90
+ # TTAS (Test and Test-And-Set) optimisation
91
+ # Since @once only ever goes from false to true, this is semantically valid
92
+ return if @once
93
+
94
+ begin
95
+ @mutex.lock
96
+
97
+ return if @once
98
+
99
+ timeout ||= @timeout
100
+
101
+ # rbs/core has a bug, timeout type is incorrectly ?Integer
102
+ @condition.wait(@mutex, _ = timeout)
103
+ ensure
104
+ @mutex.unlock
105
+ end
106
+ end
107
+
108
+ # Wait for next lift to happen
109
+ def wait_next(timeout = nil)
110
+ @mutex.lock
111
+
112
+ timeout ||= @timeout
113
+
114
+ # rbs/core has a bug, timeout type is incorrectly ?Integer
115
+ @condition.wait(@mutex, _ = timeout)
116
+ ensure
117
+ @mutex.unlock
118
+ end
119
+
120
+ # Release all current waiters
121
+ def lift
122
+ @mutex.lock
123
+
124
+ @once ||= true
125
+
126
+ @condition.broadcast
127
+ ensure
128
+ @mutex.unlock
129
+ end
130
+ end
131
+
132
+ class << self
133
+ def build(settings, agent_settings)
134
+ return unless settings.remote.enabled
135
+
136
+ capabilities = Client::Capabilities.new(settings)
137
+
138
+ return if capabilities.products.empty?
139
+
140
+ negotiation = Negotiation.new(settings, agent_settings)
141
+
142
+ unless negotiation.endpoint?('/v0.7/config')
143
+ Datadog.logger.error do
144
+ 'endpoint unavailable: disabling remote configuration for this process.'
145
+ end
146
+
147
+ return
148
+ end
149
+
150
+ Datadog.logger.debug { 'agent reachable and reports remote configuration endpoint' }
151
+
152
+ new(settings, capabilities, agent_settings)
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'path'
4
+ require_relative 'digest'
5
+
6
+ module Datadog
7
+ module Core
8
+ module Remote
9
+ class Configuration
10
+ # Content stores the information associated with a specific Configuration::Path
11
+ class Content
12
+ class << self
13
+ def parse(hash)
14
+ path = Path.parse(hash[:path])
15
+ data = hash[:content]
16
+
17
+ new(path: path, data: data)
18
+ end
19
+ end
20
+
21
+ attr_reader :path, :data, :hashes
22
+ attr_accessor :version
23
+
24
+ def initialize(path:, data:)
25
+ @path = path
26
+ @data = data
27
+ @hashes = {}
28
+ @version = 0
29
+ end
30
+
31
+ def hexdigest(type)
32
+ @hashes[type] || compute_and_store_hash(type)
33
+ end
34
+
35
+ def length
36
+ @length ||= @data.size
37
+ end
38
+
39
+ private
40
+
41
+ def compute_and_store_hash(type)
42
+ @hashes[type] = Digest.hexdigest(type, @data)
43
+ end
44
+
45
+ private_class_method :new
46
+ end
47
+
48
+ # ContentList stores a list of Conetnt instances
49
+ # It provides convinient methods for finding content base on Configuration::Path and Configuration::Target
50
+ class ContentList < Array
51
+ class << self
52
+ def parse(array)
53
+ new.concat(array.map { |c| Content.parse(c) })
54
+ end
55
+ end
56
+
57
+ def find_content(path, target)
58
+ find { |c| c.path.eql?(path) && target.check(c) }
59
+ end
60
+
61
+ def [](path)
62
+ find { |c| c.path.eql?(path) }
63
+ end
64
+
65
+ def []=(path, content)
66
+ map! { |c| c.path.eql?(path) ? content : c }
67
+ end
68
+
69
+ def delete(path)
70
+ idx = index { |e| e.path.eql?(path) }
71
+
72
+ return if idx.nil?
73
+
74
+ delete_at(idx)
75
+ end
76
+
77
+ def paths
78
+ map(&:path).uniq
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Remote
8
+ class Configuration
9
+ # Represent a list of Configuration::Digest
10
+ class DigestList < Array
11
+ class << self
12
+ def parse(hash)
13
+ new.concat(hash.map { |type, hexdigest| Digest.new(type, hexdigest) })
14
+ end
15
+ end
16
+
17
+ def check(content)
18
+ map { |digest| digest.check(content) }.reduce(:&)
19
+ end
20
+ end
21
+
22
+ # Stores and validates different cryptographic hash functions
23
+ class Digest
24
+ class InvalidHashTypeError < StandardError; end
25
+ attr_reader :type, :hexdigest
26
+
27
+ DIGEST_CHUNK = 1024
28
+
29
+ class << self
30
+ def hexdigest(type, data)
31
+ d = case type
32
+ when :sha256
33
+ ::Digest::SHA256.new
34
+ when :sha512
35
+ ::Digest::SHA512.new
36
+ else
37
+ raise InvalidHashTypeError, type
38
+ end
39
+
40
+ while (buf = data.read(DIGEST_CHUNK))
41
+ d.update(buf)
42
+ end
43
+
44
+ d.hexdigest
45
+ ensure
46
+ data.rewind
47
+ end
48
+ end
49
+
50
+ def initialize(type, hexdigest)
51
+ @type = type.to_sym
52
+ @hexdigest = hexdigest
53
+ end
54
+
55
+ def check(content)
56
+ content.hexdigest(@type) == hexdigest
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Core
5
+ module Remote
6
+ class Configuration
7
+ # Path stores path information
8
+ class Path
9
+ class ParseError < StandardError; end
10
+
11
+ class << self
12
+ RE = %r{
13
+ ^
14
+ (?<source>
15
+ datadog/(?<org_id>\d+)
16
+ |
17
+ employee
18
+ )
19
+ /
20
+ (?<product>[^/]+)
21
+ /
22
+ (?<config_id>[^/]+)
23
+ /
24
+ (?<name>[^/]+)
25
+ $
26
+ }mx.freeze
27
+
28
+ def parse(path)
29
+ m = RE.match(path)
30
+
31
+ raise ParseError, "could not parse: #{path.inspect}" if m.nil?
32
+
33
+ org_id = m['org_id'] ? m['org_id'].to_i : nil
34
+
35
+ source = m['source']
36
+ raise ParseError, 'missing source value' unless source
37
+
38
+ source = source.delete("/#{org_id}") if org_id
39
+
40
+ product = m['product']
41
+ raise ParseError, 'missing product value' unless product
42
+
43
+ config_id = m['config_id']
44
+ raise ParseError, 'missing config_id value' unless config_id
45
+
46
+ name = m['name']
47
+ raise ParseError, 'missing name value' unless name
48
+
49
+ new(source: source, org_id: org_id, product: product, config_id: config_id, name: name)
50
+ end
51
+ end
52
+
53
+ attr_reader :source, :org_id, :product, :config_id, :name
54
+
55
+ def initialize(source:, product:, config_id:, name:, org_id: nil)
56
+ @source = source
57
+ @org_id = org_id
58
+ @product = product
59
+ @config_id = config_id
60
+ @name = name
61
+ end
62
+
63
+ private_class_method :new
64
+
65
+ def to_s
66
+ if org_id
67
+ "#{source}/#{org_id}/#{product}/#{config_id}/#{name}"
68
+ else
69
+ "#{source}/#{product}/#{config_id}/#{name}"
70
+ end
71
+ end
72
+
73
+ def ==(other)
74
+ return false unless other.is_a?(Path)
75
+
76
+ to_s == other.to_s
77
+ end
78
+
79
+ def hash
80
+ to_s.hash
81
+ end
82
+
83
+ def eql?(other)
84
+ hash == other.hash
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,292 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'content'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Remote
8
+ class Configuration
9
+ # Repository
10
+ class Repository
11
+ attr_reader \
12
+ :contents,
13
+ :opaque_backend_state,
14
+ :root_version,
15
+ :targets_version
16
+
17
+ UNVERIFIED_ROOT_VERSION = 1
18
+
19
+ INITIAL_TARGETS_VERSION = 0
20
+
21
+ def initialize
22
+ @contents = ContentList.new
23
+ @opaque_backend_state = nil
24
+ @root_version = UNVERIFIED_ROOT_VERSION
25
+ @targets_version = INITIAL_TARGETS_VERSION
26
+ end
27
+
28
+ def paths
29
+ @contents.paths
30
+ end
31
+
32
+ def [](path)
33
+ @contents[path]
34
+ end
35
+
36
+ def transaction
37
+ transaction = Transaction.new
38
+
39
+ yield(self, transaction)
40
+
41
+ commit(transaction)
42
+ end
43
+
44
+ def commit(transaction)
45
+ previous = contents.dup
46
+
47
+ touched = transaction.operations.each_with_object([]) do |op, acc|
48
+ acc << op.apply(self)
49
+ end
50
+
51
+ changes = ChangeSet.new
52
+
53
+ touched.uniq.each do |path|
54
+ next if path.nil?
55
+
56
+ changes.add(path, previous[path], @contents[path])
57
+ end
58
+
59
+ changes.freeze
60
+ end
61
+
62
+ def state
63
+ State.new(self)
64
+ end
65
+
66
+ # State store the repository state
67
+ class State
68
+ attr_reader \
69
+ :root_version,
70
+ :targets_version,
71
+ :config_states,
72
+ :has_error,
73
+ :error,
74
+ :opaque_backend_state,
75
+ :cached_target_files
76
+
77
+ def initialize(repository)
78
+ @repository = repository
79
+ @root_version = repository.root_version
80
+ @targets_version = repository.targets_version
81
+ @config_states = contents_to_config_states(repository.contents)
82
+ @has_error = false
83
+ @error = ''
84
+ @opaque_backend_state = repository.opaque_backend_state
85
+ @cached_target_files = contents_to_cached_target_files(repository.contents)
86
+ end
87
+
88
+ private
89
+
90
+ def contents_to_config_states(contents)
91
+ return [] if contents.empty?
92
+
93
+ contents.map do |content|
94
+ {
95
+ id: content.path.config_id,
96
+ version: content.version,
97
+ product: content.path.product
98
+ }
99
+ end
100
+ end
101
+
102
+ def contents_to_cached_target_files(contents)
103
+ return [] if contents.empty?
104
+
105
+ contents.map do |content|
106
+ {
107
+ path: content.path.to_s,
108
+ length: content.length,
109
+ hashes: content.hashes.map do |algorithm, hexdigest|
110
+ {
111
+ algorithm: algorithm,
112
+ hash: hexdigest
113
+ }
114
+ end
115
+ }
116
+ end
117
+ end
118
+ end
119
+
120
+ # Encapsulates transaction operations
121
+ class Transaction
122
+ attr_reader :operations
123
+
124
+ def initialize
125
+ @operations = []
126
+ end
127
+
128
+ def delete(path)
129
+ @operations << Operation::Delete.new(path)
130
+ end
131
+
132
+ def insert(path, target, content)
133
+ @operations << Operation::Insert.new(path, target, content)
134
+ end
135
+
136
+ def update(path, target, content)
137
+ @operations << Operation::Update.new(path, target, content)
138
+ end
139
+
140
+ def set(**options)
141
+ @operations << Operation::Set.new(**options)
142
+ end
143
+ end
144
+
145
+ # Operation
146
+ module Operation
147
+ # Delete contents base on path
148
+ class Delete
149
+ attr_reader :path
150
+
151
+ def initialize(path)
152
+ super()
153
+ @path = path
154
+ end
155
+
156
+ def apply(repository)
157
+ return if repository[@path].nil?
158
+
159
+ repository.contents.delete(@path)
160
+
161
+ @path
162
+ end
163
+ end
164
+
165
+ # Insert content into the reporistory contents
166
+ class Insert
167
+ attr_reader :path, :target, :content
168
+
169
+ def initialize(path, target, content)
170
+ super()
171
+ @path = path
172
+ @target = target
173
+ @content = content
174
+ end
175
+
176
+ def apply(repository)
177
+ return unless repository[@path].nil?
178
+
179
+ @content.version = @target.version
180
+ repository.contents << @content
181
+
182
+ @path
183
+ end
184
+ end
185
+
186
+ # Update existimng repository's contents
187
+ class Update
188
+ attr_reader :path, :target, :content
189
+
190
+ def initialize(path, target, content)
191
+ super()
192
+ @path = path
193
+ @target = target
194
+ @content = content
195
+ end
196
+
197
+ def apply(repository)
198
+ return if repository[@path].nil?
199
+
200
+ @content.version = @target.version
201
+ repository.contents[@path] = @content
202
+
203
+ @path
204
+ end
205
+ end
206
+
207
+ # Set repository metadata
208
+ class Set
209
+ attr_reader :opaque_backend_state, :targets_version
210
+
211
+ def initialize(**options)
212
+ super()
213
+ @opaque_backend_state = options[:opaque_backend_state]
214
+ @targets_version = options[:targets_version]
215
+ end
216
+
217
+ def apply(repository)
218
+ repository.instance_variable_set(:@opaque_backend_state, @opaque_backend_state) if @opaque_backend_state
219
+
220
+ repository.instance_variable_set(:@targets_version, @targets_version) if @targets_version
221
+
222
+ nil
223
+ end
224
+ end
225
+ end
226
+
227
+ private_constant :Operation
228
+
229
+ module Change
230
+ # Delete change
231
+ class Deleted
232
+ attr_reader :path, :previous
233
+
234
+ def initialize(path, previous)
235
+ @path = path
236
+ @previous = previous
237
+ end
238
+ end
239
+
240
+ # Insert change
241
+ class Inserted
242
+ attr_reader :path, :content
243
+
244
+ def initialize(path, content)
245
+ @path = path
246
+ @content = content
247
+ end
248
+ end
249
+
250
+ # Update change
251
+ class Updated
252
+ attr_reader :path, :content, :previous
253
+
254
+ def initialize(path, content, previous)
255
+ @path = path
256
+ @content = content
257
+ @previous = previous
258
+ end
259
+ end
260
+ end
261
+
262
+ # Store list of Changes
263
+ class ChangeSet < Array
264
+ def paths
265
+ map(&:path)
266
+ end
267
+
268
+ def add(path, previous, content)
269
+ return if previous.nil? && content.nil?
270
+
271
+ return deleted(path, previous) if previous && content.nil?
272
+ return inserted(path, content) if content && previous.nil?
273
+ return updated(path, content, previous) if content && previous
274
+ end
275
+
276
+ def deleted(path, previous)
277
+ self << Change::Deleted.new(path, previous).freeze
278
+ end
279
+
280
+ def inserted(path, content)
281
+ self << Change::Inserted.new(path, content).freeze
282
+ end
283
+
284
+ def updated(path, content, previous)
285
+ self << Change::Updated.new(path, content, previous).freeze
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end