ddtrace 0.13.0 → 0.47.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (628) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +598 -381
  3. data/.circleci/images/primary/Dockerfile-2.0.0 +6 -2
  4. data/.circleci/images/primary/Dockerfile-2.1.10 +6 -2
  5. data/.circleci/images/primary/Dockerfile-2.2.10 +6 -2
  6. data/.circleci/images/primary/Dockerfile-2.3.8 +75 -0
  7. data/.circleci/images/primary/Dockerfile-2.4.6 +73 -0
  8. data/.circleci/images/primary/{Dockerfile-2.3.7 → Dockerfile-2.5.6} +2 -2
  9. data/.circleci/images/primary/{Dockerfile-2.4.4 → Dockerfile-2.6.4} +2 -2
  10. data/.circleci/images/primary/Dockerfile-2.7.0 +73 -0
  11. data/.circleci/images/primary/Dockerfile-3.0.0 +73 -0
  12. data/.circleci/images/primary/Dockerfile-jruby-9.2-latest +78 -0
  13. data/.circleci/images/primary/Dockerfile-jruby-9.2.0.0 +73 -0
  14. data/.circleci/images/primary/{Dockerfile-1.9.3 → Dockerfile-truffleruby-21.0.0} +6 -2
  15. data/.env +5 -2
  16. data/.github/CODEOWNERS +1 -0
  17. data/.github/workflows/add-milestone-to-pull-requests.yml +42 -0
  18. data/.github/workflows/create-next-milestone.yml +20 -0
  19. data/.gitignore +2 -0
  20. data/.gitlab-ci.yml +27 -0
  21. data/.rubocop.yml +270 -6
  22. data/.rubocop_todo.yml +397 -0
  23. data/.simplecov +47 -0
  24. data/Appraisals +933 -127
  25. data/CHANGELOG.md +2106 -97
  26. data/CONTRIBUTING.md +85 -0
  27. data/Gemfile +55 -2
  28. data/LICENSE +4 -22
  29. data/LICENSE-3rdparty.csv +2 -0
  30. data/LICENSE.Apache +200 -0
  31. data/LICENSE.BSD3 +24 -0
  32. data/NOTICE +4 -0
  33. data/README.md +5 -34
  34. data/Rakefile +825 -351
  35. data/benchmarks/postgres_database.yml +9 -0
  36. data/benchmarks/sidekiq_test.rb +154 -0
  37. data/ddtrace.gemspec +8 -17
  38. data/docker-compose.yml +260 -47
  39. data/docs/DevelopmentGuide.md +249 -0
  40. data/docs/GettingStarted.md +1435 -290
  41. data/integration/README.md +68 -0
  42. data/integration/apps/rack/.dockerignore +1 -0
  43. data/integration/apps/rack/.envrc.sample +1 -0
  44. data/integration/apps/rack/.gitignore +4 -0
  45. data/integration/apps/rack/.rspec +1 -0
  46. data/integration/apps/rack/Dockerfile +25 -0
  47. data/integration/apps/rack/Dockerfile-ci +11 -0
  48. data/integration/apps/rack/Gemfile +24 -0
  49. data/integration/apps/rack/README.md +93 -0
  50. data/integration/apps/rack/app/acme.rb +80 -0
  51. data/integration/apps/rack/app/datadog.rb +17 -0
  52. data/integration/apps/rack/bin/run +22 -0
  53. data/integration/apps/rack/bin/setup +17 -0
  54. data/integration/apps/rack/bin/test +24 -0
  55. data/integration/apps/rack/config.ru +6 -0
  56. data/integration/apps/rack/config/puma.rb +14 -0
  57. data/integration/apps/rack/config/unicorn.rb +23 -0
  58. data/integration/apps/rack/docker-compose.ci.yml +62 -0
  59. data/integration/apps/rack/docker-compose.yml +78 -0
  60. data/integration/apps/rack/script/build-images +38 -0
  61. data/integration/apps/rack/script/ci +50 -0
  62. data/integration/apps/rack/spec/integration/basic_spec.rb +10 -0
  63. data/integration/apps/rack/spec/spec_helper.rb +16 -0
  64. data/integration/apps/rack/spec/support/integration_helper.rb +22 -0
  65. data/integration/apps/rails-five/.dockerignore +1 -0
  66. data/integration/apps/rails-five/.env +3 -0
  67. data/integration/apps/rails-five/.envrc.sample +1 -0
  68. data/integration/apps/rails-five/.gitignore +30 -0
  69. data/integration/apps/rails-five/Dockerfile +25 -0
  70. data/integration/apps/rails-five/Dockerfile-ci +11 -0
  71. data/integration/apps/rails-five/Gemfile +104 -0
  72. data/integration/apps/rails-five/README.md +94 -0
  73. data/integration/apps/rails-five/Rakefile +6 -0
  74. data/integration/apps/rails-five/app/channels/application_cable/channel.rb +4 -0
  75. data/integration/apps/rails-five/app/channels/application_cable/connection.rb +4 -0
  76. data/integration/apps/rails-five/app/controllers/application_controller.rb +2 -0
  77. data/integration/apps/rails-five/app/controllers/basic_controller.rb +36 -0
  78. data/integration/apps/rails-five/app/controllers/concerns/.keep +0 -0
  79. data/integration/apps/rails-five/app/controllers/health_controller.rb +9 -0
  80. data/integration/apps/rails-five/app/controllers/jobs_controller.rb +12 -0
  81. data/integration/apps/rails-five/app/jobs/application_job.rb +2 -0
  82. data/integration/apps/rails-five/app/jobs/test_job.rb +12 -0
  83. data/integration/apps/rails-five/app/mailers/application_mailer.rb +4 -0
  84. data/integration/apps/rails-five/app/models/application_record.rb +3 -0
  85. data/integration/apps/rails-five/app/models/concerns/.keep +0 -0
  86. data/integration/apps/rails-five/app/models/test.rb +2 -0
  87. data/integration/apps/rails-five/app/views/layouts/mailer.html.erb +13 -0
  88. data/integration/apps/rails-five/app/views/layouts/mailer.text.erb +1 -0
  89. data/integration/apps/rails-five/bin/bundle +3 -0
  90. data/integration/apps/rails-five/bin/rails +9 -0
  91. data/integration/apps/rails-five/bin/rake +9 -0
  92. data/integration/apps/rails-five/bin/run +24 -0
  93. data/integration/apps/rails-five/bin/setup +27 -0
  94. data/integration/apps/rails-five/bin/spring +17 -0
  95. data/integration/apps/rails-five/bin/test +21 -0
  96. data/integration/apps/rails-five/bin/update +28 -0
  97. data/integration/apps/rails-five/config.ru +5 -0
  98. data/integration/apps/rails-five/config/application.rb +97 -0
  99. data/integration/apps/rails-five/config/boot.rb +4 -0
  100. data/integration/apps/rails-five/config/cable.yml +10 -0
  101. data/integration/apps/rails-five/config/credentials.yml.enc +1 -0
  102. data/integration/apps/rails-five/config/database.yml +28 -0
  103. data/integration/apps/rails-five/config/environment.rb +5 -0
  104. data/integration/apps/rails-five/config/environments/development.rb +51 -0
  105. data/integration/apps/rails-five/config/environments/production.rb +82 -0
  106. data/integration/apps/rails-five/config/environments/test.rb +43 -0
  107. data/integration/apps/rails-five/config/initializers/datadog.rb +18 -0
  108. data/integration/apps/rails-five/config/initializers/filter_parameter_logging.rb +4 -0
  109. data/integration/apps/rails-five/config/initializers/resque.rb +4 -0
  110. data/integration/apps/rails-five/config/initializers/rollbar.rb +5 -0
  111. data/integration/apps/rails-five/config/initializers/wrap_parameters.rb +14 -0
  112. data/integration/apps/rails-five/config/locales/en.yml +33 -0
  113. data/integration/apps/rails-five/config/puma.rb +24 -0
  114. data/integration/apps/rails-five/config/routes.rb +11 -0
  115. data/integration/apps/rails-five/config/spring.rb +6 -0
  116. data/integration/apps/rails-five/config/unicorn.rb +29 -0
  117. data/integration/apps/rails-five/db/migrate/20190927215052_create_tests.rb +11 -0
  118. data/integration/apps/rails-five/db/schema.rb +23 -0
  119. data/integration/apps/rails-five/db/seeds.rb +7 -0
  120. data/integration/apps/rails-five/docker-compose.ci.yml +98 -0
  121. data/integration/apps/rails-five/docker-compose.yml +100 -0
  122. data/integration/apps/rails-five/lib/tasks/.keep +0 -0
  123. data/integration/apps/rails-five/log/.keep +0 -0
  124. data/integration/apps/rails-five/public/robots.txt +1 -0
  125. data/integration/apps/rails-five/script/build-images +35 -0
  126. data/integration/apps/rails-five/script/ci +50 -0
  127. data/integration/apps/rails-five/spec/integration/basic_spec.rb +10 -0
  128. data/integration/apps/rails-five/spec/spec_helper.rb +16 -0
  129. data/integration/apps/rails-five/spec/support/integration_helper.rb +22 -0
  130. data/integration/apps/rails-five/storage/.keep +0 -0
  131. data/integration/apps/rails-five/tmp/.keep +0 -0
  132. data/integration/apps/rails-five/vendor/.keep +0 -0
  133. data/integration/apps/ruby/.dockerignore +1 -0
  134. data/integration/apps/ruby/.envrc.sample +1 -0
  135. data/integration/apps/ruby/.gitignore +2 -0
  136. data/integration/apps/ruby/Dockerfile +25 -0
  137. data/integration/apps/ruby/Dockerfile-ci +11 -0
  138. data/integration/apps/ruby/Gemfile +11 -0
  139. data/integration/apps/ruby/README.md +70 -0
  140. data/integration/apps/ruby/agent.yaml +3 -0
  141. data/integration/apps/ruby/app/datadog.rb +13 -0
  142. data/integration/apps/ruby/app/fibonacci.rb +58 -0
  143. data/integration/apps/ruby/bin/run +20 -0
  144. data/integration/apps/ruby/bin/setup +17 -0
  145. data/integration/apps/ruby/bin/test +21 -0
  146. data/integration/apps/ruby/docker-compose.ci.yml +51 -0
  147. data/integration/apps/ruby/docker-compose.yml +63 -0
  148. data/integration/apps/ruby/script/build-images +38 -0
  149. data/integration/apps/ruby/script/ci +50 -0
  150. data/integration/images/agent/Dockerfile +2 -0
  151. data/integration/images/agent/agent.yaml +3 -0
  152. data/integration/images/include/datadog/analyzer.rb +71 -0
  153. data/integration/images/include/datadog/demo_env.rb +101 -0
  154. data/integration/images/include/http-health-check +33 -0
  155. data/integration/images/ruby/2.0/Dockerfile +54 -0
  156. data/integration/images/ruby/2.1/Dockerfile +54 -0
  157. data/integration/images/ruby/2.2/Dockerfile +54 -0
  158. data/integration/images/ruby/2.3/Dockerfile +70 -0
  159. data/integration/images/ruby/2.4/Dockerfile +54 -0
  160. data/integration/images/ruby/2.5/Dockerfile +54 -0
  161. data/integration/images/ruby/2.6/Dockerfile +54 -0
  162. data/integration/images/ruby/2.7/Dockerfile +54 -0
  163. data/integration/images/ruby/3.0/Dockerfile +54 -0
  164. data/integration/images/wrk/Dockerfile +33 -0
  165. data/integration/images/wrk/scripts/entrypoint.sh +17 -0
  166. data/integration/images/wrk/scripts/scenarios/basic/default.lua +1 -0
  167. data/integration/images/wrk/scripts/scenarios/basic/fibonacci.lua +1 -0
  168. data/integration/script/build-images +43 -0
  169. data/lib/ddtrace.rb +65 -62
  170. data/lib/ddtrace/analytics.rb +38 -0
  171. data/lib/ddtrace/auto_instrument.rb +3 -0
  172. data/lib/ddtrace/auto_instrument_base.rb +6 -0
  173. data/lib/ddtrace/buffer.rb +298 -32
  174. data/lib/ddtrace/chunker.rb +34 -0
  175. data/lib/ddtrace/configuration.rb +151 -26
  176. data/lib/ddtrace/configuration/base.rb +84 -0
  177. data/lib/ddtrace/configuration/components.rb +151 -0
  178. data/lib/ddtrace/configuration/{resolver.rb → dependency_resolver.rb} +2 -2
  179. data/lib/ddtrace/configuration/option.rb +64 -0
  180. data/lib/ddtrace/configuration/option_definition.rb +121 -0
  181. data/lib/ddtrace/configuration/option_definition_set.rb +18 -0
  182. data/lib/ddtrace/configuration/option_set.rb +6 -0
  183. data/lib/ddtrace/configuration/options.rb +111 -0
  184. data/lib/ddtrace/configuration/pin_setup.rb +4 -3
  185. data/lib/ddtrace/configuration/settings.rb +299 -0
  186. data/lib/ddtrace/context.rb +133 -66
  187. data/lib/ddtrace/context_flush.rb +51 -114
  188. data/lib/ddtrace/context_provider.rb +61 -0
  189. data/lib/ddtrace/contrib/action_cable/configuration/settings.rb +30 -0
  190. data/lib/ddtrace/contrib/action_cable/event.rb +66 -0
  191. data/lib/ddtrace/contrib/action_cable/events.rb +33 -0
  192. data/lib/ddtrace/contrib/action_cable/events/broadcast.rb +49 -0
  193. data/lib/ddtrace/contrib/action_cable/events/perform_action.rb +55 -0
  194. data/lib/ddtrace/contrib/action_cable/events/transmit.rb +50 -0
  195. data/lib/ddtrace/contrib/action_cable/ext.rb +26 -0
  196. data/lib/ddtrace/contrib/action_cable/instrumentation.rb +31 -0
  197. data/lib/ddtrace/contrib/action_cable/integration.rb +45 -0
  198. data/lib/ddtrace/contrib/action_cable/patcher.rb +27 -0
  199. data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +146 -0
  200. data/lib/ddtrace/contrib/action_pack/action_controller/patcher.rb +25 -0
  201. data/lib/ddtrace/contrib/action_pack/configuration/settings.rb +32 -0
  202. data/lib/ddtrace/contrib/action_pack/ext.rb +19 -0
  203. data/lib/ddtrace/contrib/action_pack/integration.rb +45 -0
  204. data/lib/ddtrace/contrib/action_pack/patcher.rb +23 -0
  205. data/lib/ddtrace/contrib/action_pack/utils.rb +36 -0
  206. data/lib/ddtrace/contrib/action_view/configuration/settings.rb +31 -0
  207. data/lib/ddtrace/contrib/action_view/event.rb +35 -0
  208. data/lib/ddtrace/contrib/action_view/events.rb +30 -0
  209. data/lib/ddtrace/contrib/action_view/events/render_partial.rb +46 -0
  210. data/lib/ddtrace/contrib/action_view/events/render_template.rb +49 -0
  211. data/lib/ddtrace/contrib/action_view/ext.rb +20 -0
  212. data/lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb +74 -0
  213. data/lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb +167 -0
  214. data/lib/ddtrace/contrib/action_view/integration.rb +52 -0
  215. data/lib/ddtrace/contrib/action_view/patcher.rb +47 -0
  216. data/lib/ddtrace/contrib/action_view/utils.rb +32 -0
  217. data/lib/ddtrace/contrib/active_model_serializers/configuration/settings.rb +30 -0
  218. data/lib/ddtrace/contrib/active_model_serializers/event.rb +14 -3
  219. data/lib/ddtrace/contrib/active_model_serializers/events/render.rb +2 -2
  220. data/lib/ddtrace/contrib/active_model_serializers/events/serialize.rb +2 -2
  221. data/lib/ddtrace/contrib/active_model_serializers/ext.rb +20 -0
  222. data/lib/ddtrace/contrib/active_model_serializers/integration.rb +40 -0
  223. data/lib/ddtrace/contrib/active_model_serializers/patcher.rb +12 -45
  224. data/lib/ddtrace/contrib/active_record/configuration/resolver.rb +128 -0
  225. data/lib/ddtrace/contrib/active_record/configuration/settings.rb +35 -0
  226. data/lib/ddtrace/contrib/active_record/event.rb +1 -1
  227. data/lib/ddtrace/contrib/active_record/events/instantiation.rb +17 -8
  228. data/lib/ddtrace/contrib/active_record/events/sql.rb +32 -12
  229. data/lib/ddtrace/contrib/active_record/ext.rb +24 -0
  230. data/lib/ddtrace/contrib/active_record/integration.rb +53 -0
  231. data/lib/ddtrace/contrib/active_record/patcher.rb +5 -35
  232. data/lib/ddtrace/contrib/active_record/utils.rb +85 -31
  233. data/lib/ddtrace/contrib/active_support/cache/instrumentation.rb +258 -0
  234. data/lib/ddtrace/contrib/active_support/cache/patcher.rb +69 -0
  235. data/lib/ddtrace/contrib/active_support/cache/redis.rb +47 -0
  236. data/lib/ddtrace/contrib/active_support/configuration/settings.rb +30 -0
  237. data/lib/ddtrace/contrib/active_support/ext.rb +27 -0
  238. data/lib/ddtrace/contrib/active_support/integration.rb +46 -0
  239. data/lib/ddtrace/contrib/active_support/notifications/event.rb +15 -2
  240. data/lib/ddtrace/contrib/active_support/notifications/subscriber.rb +3 -2
  241. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +20 -12
  242. data/lib/ddtrace/contrib/active_support/patcher.rb +23 -0
  243. data/lib/ddtrace/contrib/analytics.rb +24 -0
  244. data/lib/ddtrace/contrib/auto_instrument.rb +49 -0
  245. data/lib/ddtrace/contrib/aws/configuration/settings.rb +30 -0
  246. data/lib/ddtrace/contrib/aws/ext.rb +23 -0
  247. data/lib/ddtrace/contrib/aws/instrumentation.rb +37 -19
  248. data/lib/ddtrace/contrib/aws/integration.rb +42 -0
  249. data/lib/ddtrace/contrib/aws/patcher.rb +30 -40
  250. data/lib/ddtrace/contrib/aws/services.rb +3 -0
  251. data/lib/ddtrace/contrib/concurrent_ruby/configuration/settings.rb +20 -0
  252. data/lib/ddtrace/contrib/concurrent_ruby/context_composite_executor_service.rb +41 -0
  253. data/lib/ddtrace/contrib/concurrent_ruby/ext.rb +12 -0
  254. data/lib/ddtrace/contrib/concurrent_ruby/future_patch.rb +23 -0
  255. data/lib/ddtrace/contrib/concurrent_ruby/integration.rb +38 -0
  256. data/lib/ddtrace/contrib/concurrent_ruby/patcher.rb +28 -0
  257. data/lib/ddtrace/contrib/configurable.rb +102 -0
  258. data/lib/ddtrace/contrib/configuration/resolver.rb +81 -0
  259. data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +39 -0
  260. data/lib/ddtrace/contrib/configuration/settings.rb +55 -0
  261. data/lib/ddtrace/contrib/cucumber/configuration/settings.rb +28 -0
  262. data/lib/ddtrace/contrib/cucumber/ext.rb +17 -0
  263. data/lib/ddtrace/contrib/cucumber/formatter.rb +98 -0
  264. data/lib/ddtrace/contrib/cucumber/instrumentation.rb +24 -0
  265. data/lib/ddtrace/contrib/cucumber/integration.rb +45 -0
  266. data/lib/ddtrace/contrib/cucumber/patcher.rb +23 -0
  267. data/lib/ddtrace/contrib/dalli/configuration/settings.rb +30 -0
  268. data/lib/ddtrace/contrib/dalli/ext.rb +20 -0
  269. data/lib/ddtrace/contrib/dalli/instrumentation.rb +36 -17
  270. data/lib/ddtrace/contrib/dalli/integration.rb +38 -0
  271. data/lib/ddtrace/contrib/dalli/patcher.rb +13 -41
  272. data/lib/ddtrace/contrib/dalli/quantize.rb +4 -4
  273. data/lib/ddtrace/contrib/delayed_job/configuration/settings.rb +32 -0
  274. data/lib/ddtrace/contrib/delayed_job/ext.rb +23 -0
  275. data/lib/ddtrace/contrib/delayed_job/integration.rb +38 -0
  276. data/lib/ddtrace/contrib/delayed_job/patcher.rb +28 -0
  277. data/lib/ddtrace/contrib/delayed_job/plugin.rb +84 -0
  278. data/lib/ddtrace/contrib/elasticsearch/configuration/settings.rb +31 -0
  279. data/lib/ddtrace/contrib/elasticsearch/ext.rb +22 -0
  280. data/lib/ddtrace/contrib/elasticsearch/integration.rb +39 -0
  281. data/lib/ddtrace/contrib/elasticsearch/patcher.rb +49 -50
  282. data/lib/ddtrace/contrib/elasticsearch/quantize.rb +3 -2
  283. data/lib/ddtrace/contrib/ethon/configuration/settings.rb +32 -0
  284. data/lib/ddtrace/contrib/ethon/easy_patch.rb +151 -0
  285. data/lib/ddtrace/contrib/ethon/ext.rb +19 -0
  286. data/lib/ddtrace/contrib/ethon/integration.rb +43 -0
  287. data/lib/ddtrace/contrib/ethon/multi_patch.rb +84 -0
  288. data/lib/ddtrace/contrib/ethon/patcher.rb +25 -0
  289. data/lib/ddtrace/contrib/excon/configuration/settings.rb +33 -0
  290. data/lib/ddtrace/contrib/excon/ext.rb +17 -0
  291. data/lib/ddtrace/contrib/excon/integration.rb +43 -0
  292. data/lib/ddtrace/contrib/excon/middleware.rb +47 -23
  293. data/lib/ddtrace/contrib/excon/patcher.rb +7 -30
  294. data/lib/ddtrace/contrib/extensions.rb +143 -0
  295. data/lib/ddtrace/contrib/faraday/configuration/settings.rb +38 -0
  296. data/lib/ddtrace/contrib/faraday/connection.rb +18 -0
  297. data/lib/ddtrace/contrib/faraday/ext.rb +17 -0
  298. data/lib/ddtrace/contrib/faraday/integration.rb +43 -0
  299. data/lib/ddtrace/contrib/faraday/middleware.rb +46 -29
  300. data/lib/ddtrace/contrib/faraday/patcher.rb +36 -56
  301. data/lib/ddtrace/contrib/faraday/rack_builder.rb +18 -0
  302. data/lib/ddtrace/contrib/grape/configuration/settings.rb +38 -0
  303. data/lib/ddtrace/contrib/grape/endpoint.rb +192 -120
  304. data/lib/ddtrace/contrib/grape/ext.rb +23 -0
  305. data/lib/ddtrace/contrib/grape/instrumentation.rb +33 -0
  306. data/lib/ddtrace/contrib/grape/integration.rb +39 -0
  307. data/lib/ddtrace/contrib/grape/patcher.rb +15 -59
  308. data/lib/ddtrace/contrib/graphql/configuration/settings.rb +32 -0
  309. data/lib/ddtrace/contrib/graphql/ext.rb +16 -0
  310. data/lib/ddtrace/contrib/graphql/integration.rb +39 -0
  311. data/lib/ddtrace/contrib/graphql/patcher.rb +37 -34
  312. data/lib/ddtrace/contrib/grpc/configuration/settings.rb +30 -0
  313. data/lib/ddtrace/contrib/grpc/datadog_interceptor.rb +36 -27
  314. data/lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb +17 -8
  315. data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +20 -5
  316. data/lib/ddtrace/contrib/grpc/ext.rb +18 -0
  317. data/lib/ddtrace/contrib/grpc/integration.rb +38 -0
  318. data/lib/ddtrace/contrib/grpc/patcher.rb +8 -38
  319. data/lib/ddtrace/contrib/http/circuit_breaker.rb +37 -0
  320. data/lib/ddtrace/contrib/http/configuration/settings.rb +32 -0
  321. data/lib/ddtrace/contrib/http/ext.rb +17 -0
  322. data/lib/ddtrace/contrib/http/instrumentation.rb +179 -0
  323. data/lib/ddtrace/contrib/http/integration.rb +45 -0
  324. data/lib/ddtrace/contrib/http/patcher.rb +9 -144
  325. data/lib/ddtrace/contrib/http_annotation_helper.rb +10 -0
  326. data/lib/ddtrace/contrib/httpclient/configuration/settings.rb +32 -0
  327. data/lib/ddtrace/contrib/httpclient/ext.rb +17 -0
  328. data/lib/ddtrace/contrib/httpclient/instrumentation.rb +147 -0
  329. data/lib/ddtrace/contrib/httpclient/integration.rb +43 -0
  330. data/lib/ddtrace/contrib/httpclient/patcher.rb +38 -0
  331. data/lib/ddtrace/contrib/httprb/configuration/settings.rb +32 -0
  332. data/lib/ddtrace/contrib/httprb/ext.rb +17 -0
  333. data/lib/ddtrace/contrib/httprb/instrumentation.rb +157 -0
  334. data/lib/ddtrace/contrib/httprb/integration.rb +43 -0
  335. data/lib/ddtrace/contrib/httprb/patcher.rb +38 -0
  336. data/lib/ddtrace/contrib/integration.rb +16 -0
  337. data/lib/ddtrace/contrib/kafka/configuration/settings.rb +30 -0
  338. data/lib/ddtrace/contrib/kafka/consumer_event.rb +14 -0
  339. data/lib/ddtrace/contrib/kafka/consumer_group_event.rb +14 -0
  340. data/lib/ddtrace/contrib/kafka/event.rb +51 -0
  341. data/lib/ddtrace/contrib/kafka/events.rb +44 -0
  342. data/lib/ddtrace/contrib/kafka/events/connection/request.rb +34 -0
  343. data/lib/ddtrace/contrib/kafka/events/consumer/process_batch.rb +41 -0
  344. data/lib/ddtrace/contrib/kafka/events/consumer/process_message.rb +39 -0
  345. data/lib/ddtrace/contrib/kafka/events/consumer_group/heartbeat.rb +39 -0
  346. data/lib/ddtrace/contrib/kafka/events/consumer_group/join_group.rb +29 -0
  347. data/lib/ddtrace/contrib/kafka/events/consumer_group/leave_group.rb +29 -0
  348. data/lib/ddtrace/contrib/kafka/events/consumer_group/sync_group.rb +29 -0
  349. data/lib/ddtrace/contrib/kafka/events/produce_operation/send_messages.rb +32 -0
  350. data/lib/ddtrace/contrib/kafka/events/producer/deliver_messages.rb +35 -0
  351. data/lib/ddtrace/contrib/kafka/ext.rb +41 -0
  352. data/lib/ddtrace/contrib/kafka/integration.rb +39 -0
  353. data/lib/ddtrace/contrib/kafka/patcher.rb +26 -0
  354. data/lib/ddtrace/contrib/mongodb/configuration/settings.rb +33 -0
  355. data/lib/ddtrace/contrib/mongodb/ext.rb +23 -0
  356. data/lib/ddtrace/contrib/mongodb/instrumentation.rb +69 -0
  357. data/lib/ddtrace/contrib/mongodb/integration.rb +38 -0
  358. data/lib/ddtrace/contrib/mongodb/patcher.rb +11 -74
  359. data/lib/ddtrace/contrib/mongodb/subscribers.rb +57 -18
  360. data/lib/ddtrace/contrib/mysql2/configuration/settings.rb +30 -0
  361. data/lib/ddtrace/contrib/mysql2/ext.rb +18 -0
  362. data/lib/ddtrace/contrib/mysql2/instrumentation.rb +64 -0
  363. data/lib/ddtrace/contrib/mysql2/integration.rb +38 -0
  364. data/lib/ddtrace/contrib/mysql2/patcher.rb +9 -25
  365. data/lib/ddtrace/contrib/patchable.rb +70 -0
  366. data/lib/ddtrace/contrib/patcher.rb +65 -0
  367. data/lib/ddtrace/contrib/presto/configuration/settings.rb +30 -0
  368. data/lib/ddtrace/contrib/presto/ext.rb +28 -0
  369. data/lib/ddtrace/contrib/presto/instrumentation.rb +110 -0
  370. data/lib/ddtrace/contrib/presto/integration.rb +38 -0
  371. data/lib/ddtrace/contrib/presto/patcher.rb +33 -0
  372. data/lib/ddtrace/contrib/qless/configuration/settings.rb +35 -0
  373. data/lib/ddtrace/contrib/qless/ext.rb +20 -0
  374. data/lib/ddtrace/contrib/qless/integration.rb +38 -0
  375. data/lib/ddtrace/contrib/qless/patcher.rb +35 -0
  376. data/lib/ddtrace/contrib/qless/qless_job.rb +73 -0
  377. data/lib/ddtrace/contrib/qless/tracer_cleaner.rb +33 -0
  378. data/lib/ddtrace/contrib/que/configuration/settings.rb +43 -0
  379. data/lib/ddtrace/contrib/que/ext.rb +30 -0
  380. data/lib/ddtrace/contrib/que/integration.rb +42 -0
  381. data/lib/ddtrace/contrib/que/patcher.rb +24 -0
  382. data/lib/ddtrace/contrib/que/tracer.rb +57 -0
  383. data/lib/ddtrace/contrib/racecar/configuration/settings.rb +30 -0
  384. data/lib/ddtrace/contrib/racecar/event.rb +22 -7
  385. data/lib/ddtrace/contrib/racecar/events.rb +2 -0
  386. data/lib/ddtrace/contrib/racecar/events/batch.rb +2 -2
  387. data/lib/ddtrace/contrib/racecar/events/consume.rb +27 -0
  388. data/lib/ddtrace/contrib/racecar/events/message.rb +2 -2
  389. data/lib/ddtrace/contrib/racecar/ext.rb +25 -0
  390. data/lib/ddtrace/contrib/racecar/integration.rb +39 -0
  391. data/lib/ddtrace/contrib/racecar/patcher.rb +11 -42
  392. data/lib/ddtrace/contrib/rack/configuration/settings.rb +46 -0
  393. data/lib/ddtrace/contrib/rack/ext.rb +21 -0
  394. data/lib/ddtrace/contrib/rack/integration.rb +45 -0
  395. data/lib/ddtrace/contrib/rack/middlewares.rb +105 -54
  396. data/lib/ddtrace/contrib/rack/patcher.rb +65 -49
  397. data/lib/ddtrace/contrib/rack/request_queue.rb +17 -7
  398. data/lib/ddtrace/contrib/rails/auto_instrument_railtie.rb +10 -0
  399. data/lib/ddtrace/contrib/rails/configuration/settings.rb +93 -0
  400. data/lib/ddtrace/contrib/rails/ext.rb +17 -0
  401. data/lib/ddtrace/contrib/rails/framework.rb +82 -33
  402. data/lib/ddtrace/contrib/rails/integration.rb +44 -0
  403. data/lib/ddtrace/contrib/rails/log_injection.rb +81 -0
  404. data/lib/ddtrace/contrib/rails/middlewares.rb +8 -2
  405. data/lib/ddtrace/contrib/rails/patcher.rb +88 -34
  406. data/lib/ddtrace/contrib/rails/railtie.rb +5 -9
  407. data/lib/ddtrace/contrib/rails/utils.rb +7 -31
  408. data/lib/ddtrace/contrib/rake/configuration/settings.rb +31 -0
  409. data/lib/ddtrace/contrib/rake/ext.rb +21 -0
  410. data/lib/ddtrace/contrib/rake/instrumentation.rb +33 -13
  411. data/lib/ddtrace/contrib/rake/integration.rb +38 -0
  412. data/lib/ddtrace/contrib/rake/patcher.rb +10 -33
  413. data/lib/ddtrace/contrib/redis/configuration/resolver.rb +45 -0
  414. data/lib/ddtrace/contrib/redis/configuration/settings.rb +35 -0
  415. data/lib/ddtrace/contrib/redis/ext.rb +22 -0
  416. data/lib/ddtrace/contrib/redis/integration.rb +42 -0
  417. data/lib/ddtrace/contrib/redis/patcher.rb +58 -53
  418. data/lib/ddtrace/contrib/redis/quantize.rb +47 -1
  419. data/lib/ddtrace/contrib/redis/tags.rb +33 -7
  420. data/lib/ddtrace/contrib/redis/vendor/LICENSE +20 -0
  421. data/lib/ddtrace/contrib/redis/vendor/resolver.rb +158 -0
  422. data/lib/ddtrace/contrib/registerable.rb +33 -0
  423. data/lib/ddtrace/contrib/registry.rb +42 -0
  424. data/lib/ddtrace/contrib/resque/configuration/settings.rb +32 -0
  425. data/lib/ddtrace/contrib/resque/ext.rb +17 -0
  426. data/lib/ddtrace/contrib/resque/integration.rb +47 -0
  427. data/lib/ddtrace/contrib/resque/patcher.rb +16 -38
  428. data/lib/ddtrace/contrib/resque/resque_job.rb +61 -20
  429. data/lib/ddtrace/contrib/rest_client/configuration/settings.rb +31 -0
  430. data/lib/ddtrace/contrib/rest_client/ext.rb +17 -0
  431. data/lib/ddtrace/contrib/rest_client/integration.rb +38 -0
  432. data/lib/ddtrace/contrib/rest_client/patcher.rb +23 -0
  433. data/lib/ddtrace/contrib/rest_client/request_patch.rb +91 -0
  434. data/lib/ddtrace/contrib/rspec/configuration/settings.rb +28 -0
  435. data/lib/ddtrace/contrib/rspec/example.rb +75 -0
  436. data/lib/ddtrace/contrib/rspec/ext.rb +16 -0
  437. data/lib/ddtrace/contrib/rspec/integration.rb +46 -0
  438. data/lib/ddtrace/contrib/rspec/patcher.rb +23 -0
  439. data/lib/ddtrace/contrib/sequel/configuration/settings.rb +28 -0
  440. data/lib/ddtrace/contrib/sequel/database.rb +9 -4
  441. data/lib/ddtrace/contrib/sequel/dataset.rb +7 -3
  442. data/lib/ddtrace/contrib/sequel/ext.rb +19 -0
  443. data/lib/ddtrace/contrib/sequel/integration.rb +38 -0
  444. data/lib/ddtrace/contrib/sequel/patcher.rb +6 -29
  445. data/lib/ddtrace/contrib/sequel/utils.rb +60 -14
  446. data/lib/ddtrace/contrib/shoryuken/configuration/settings.rb +30 -0
  447. data/lib/ddtrace/contrib/shoryuken/ext.rb +21 -0
  448. data/lib/ddtrace/contrib/shoryuken/integration.rb +39 -0
  449. data/lib/ddtrace/contrib/shoryuken/patcher.rb +24 -0
  450. data/lib/ddtrace/contrib/shoryuken/tracer.rb +51 -0
  451. data/lib/ddtrace/contrib/sidekiq/client_tracer.rb +43 -0
  452. data/lib/ddtrace/contrib/sidekiq/configuration/settings.rb +37 -0
  453. data/lib/ddtrace/contrib/sidekiq/ext.rb +27 -0
  454. data/lib/ddtrace/contrib/sidekiq/integration.rb +38 -0
  455. data/lib/ddtrace/contrib/sidekiq/patcher.rb +22 -14
  456. data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +65 -0
  457. data/lib/ddtrace/contrib/sidekiq/tracing.rb +44 -0
  458. data/lib/ddtrace/contrib/sinatra/configuration/settings.rb +39 -0
  459. data/lib/ddtrace/contrib/sinatra/env.rb +27 -9
  460. data/lib/ddtrace/contrib/sinatra/ext.rb +27 -0
  461. data/lib/ddtrace/contrib/sinatra/headers.rb +1 -3
  462. data/lib/ddtrace/contrib/sinatra/integration.rb +38 -0
  463. data/lib/ddtrace/contrib/sinatra/patcher.rb +28 -0
  464. data/lib/ddtrace/contrib/sinatra/tracer.rb +79 -65
  465. data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +60 -16
  466. data/lib/ddtrace/contrib/sneakers/configuration/settings.rb +33 -0
  467. data/lib/ddtrace/contrib/sneakers/ext.rb +22 -0
  468. data/lib/ddtrace/contrib/sneakers/integration.rb +41 -0
  469. data/lib/ddtrace/contrib/sneakers/patcher.rb +24 -0
  470. data/lib/ddtrace/contrib/sneakers/tracer.rb +53 -0
  471. data/lib/ddtrace/contrib/status_code_matcher.rb +69 -0
  472. data/lib/ddtrace/contrib/sucker_punch/configuration/settings.rb +30 -0
  473. data/lib/ddtrace/contrib/sucker_punch/ext.rb +21 -0
  474. data/lib/ddtrace/contrib/sucker_punch/instrumentation.rb +29 -5
  475. data/lib/ddtrace/contrib/sucker_punch/integration.rb +38 -0
  476. data/lib/ddtrace/contrib/sucker_punch/patcher.rb +21 -33
  477. data/lib/ddtrace/correlation.rb +39 -0
  478. data/lib/ddtrace/diagnostics/environment_logger.rb +279 -0
  479. data/lib/ddtrace/diagnostics/health.rb +33 -0
  480. data/lib/ddtrace/distributed_tracing/headers/b3.rb +44 -0
  481. data/lib/ddtrace/distributed_tracing/headers/b3_single.rb +56 -0
  482. data/lib/ddtrace/distributed_tracing/headers/datadog.rb +42 -0
  483. data/lib/ddtrace/distributed_tracing/headers/headers.rb +71 -0
  484. data/lib/ddtrace/distributed_tracing/headers/helpers.rb +43 -0
  485. data/lib/ddtrace/encoding.rb +36 -32
  486. data/lib/ddtrace/environment.rb +41 -0
  487. data/lib/ddtrace/event.rb +52 -0
  488. data/lib/ddtrace/ext/analytics.rb +12 -0
  489. data/lib/ddtrace/ext/app_types.rb +1 -0
  490. data/lib/ddtrace/ext/ci.rb +297 -0
  491. data/lib/ddtrace/ext/correlation.rb +11 -0
  492. data/lib/ddtrace/ext/diagnostics.rb +36 -0
  493. data/lib/ddtrace/ext/distributed.rb +22 -0
  494. data/lib/ddtrace/ext/environment.rb +16 -0
  495. data/lib/ddtrace/ext/forced_tracing.rb +25 -0
  496. data/lib/ddtrace/ext/git.rb +11 -0
  497. data/lib/ddtrace/ext/http.rb +4 -2
  498. data/lib/ddtrace/ext/integration.rb +8 -0
  499. data/lib/ddtrace/ext/manual_tracing.rb +9 -0
  500. data/lib/ddtrace/ext/metrics.rb +15 -0
  501. data/lib/ddtrace/ext/net.rb +2 -0
  502. data/lib/ddtrace/ext/runtime.rb +30 -0
  503. data/lib/ddtrace/ext/sampling.rb +16 -0
  504. data/lib/ddtrace/ext/test.rb +24 -0
  505. data/lib/ddtrace/ext/transport.rb +18 -0
  506. data/lib/ddtrace/forced_tracing.rb +38 -0
  507. data/lib/ddtrace/logger.rb +5 -4
  508. data/lib/ddtrace/metrics.rb +226 -0
  509. data/lib/ddtrace/opentelemetry/extensions.rb +13 -0
  510. data/lib/ddtrace/opentelemetry/span.rb +33 -0
  511. data/lib/ddtrace/opentracer.rb +40 -0
  512. data/lib/ddtrace/opentracer/binary_propagator.rb +24 -0
  513. data/lib/ddtrace/opentracer/carrier.rb +6 -0
  514. data/lib/ddtrace/opentracer/distributed_headers.rb +55 -0
  515. data/lib/ddtrace/opentracer/global_tracer.rb +15 -0
  516. data/lib/ddtrace/opentracer/propagator.rb +22 -0
  517. data/lib/ddtrace/opentracer/rack_propagator.rb +60 -0
  518. data/lib/ddtrace/opentracer/scope.rb +15 -0
  519. data/lib/ddtrace/opentracer/scope_manager.rb +6 -0
  520. data/lib/ddtrace/opentracer/span.rb +94 -0
  521. data/lib/ddtrace/opentracer/span_context.rb +14 -0
  522. data/lib/ddtrace/opentracer/span_context_factory.rb +23 -0
  523. data/lib/ddtrace/opentracer/text_map_propagator.rb +75 -0
  524. data/lib/ddtrace/opentracer/thread_local_scope.rb +31 -0
  525. data/lib/ddtrace/opentracer/thread_local_scope_manager.rb +40 -0
  526. data/lib/ddtrace/opentracer/tracer.rb +208 -0
  527. data/lib/ddtrace/patcher.rb +33 -5
  528. data/lib/ddtrace/pin.rb +35 -20
  529. data/lib/ddtrace/pipeline.rb +1 -1
  530. data/lib/ddtrace/pipeline/span_filter.rb +15 -15
  531. data/lib/ddtrace/propagation/grpc_propagator.rb +26 -6
  532. data/lib/ddtrace/propagation/http_propagator.rb +72 -10
  533. data/lib/ddtrace/quantization/http.rb +1 -0
  534. data/lib/ddtrace/runtime/cgroup.rb +44 -0
  535. data/lib/ddtrace/runtime/class_count.rb +17 -0
  536. data/lib/ddtrace/runtime/container.rb +71 -0
  537. data/lib/ddtrace/runtime/gc.rb +16 -0
  538. data/lib/ddtrace/runtime/identity.rb +48 -0
  539. data/lib/ddtrace/runtime/metrics.rb +114 -0
  540. data/lib/ddtrace/runtime/object_space.rb +19 -0
  541. data/lib/ddtrace/runtime/socket.rb +14 -0
  542. data/lib/ddtrace/runtime/thread_count.rb +16 -0
  543. data/lib/ddtrace/sampler.rb +218 -37
  544. data/lib/ddtrace/sampling.rb +2 -0
  545. data/lib/ddtrace/sampling/matcher.rb +57 -0
  546. data/lib/ddtrace/sampling/rate_limiter.rb +176 -0
  547. data/lib/ddtrace/sampling/rule.rb +61 -0
  548. data/lib/ddtrace/sampling/rule_sampler.rb +126 -0
  549. data/lib/ddtrace/span.rb +244 -34
  550. data/lib/ddtrace/sync_writer.rb +47 -16
  551. data/lib/ddtrace/tracer.rb +215 -117
  552. data/lib/ddtrace/transport/http.rb +113 -0
  553. data/lib/ddtrace/transport/http/adapters/net.rb +145 -0
  554. data/lib/ddtrace/transport/http/adapters/registry.rb +25 -0
  555. data/lib/ddtrace/transport/http/adapters/test.rb +83 -0
  556. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +66 -0
  557. data/lib/ddtrace/transport/http/api.rb +46 -0
  558. data/lib/ddtrace/transport/http/api/endpoint.rb +27 -0
  559. data/lib/ddtrace/transport/http/api/fallbacks.rb +22 -0
  560. data/lib/ddtrace/transport/http/api/instance.rb +33 -0
  561. data/lib/ddtrace/transport/http/api/map.rb +14 -0
  562. data/lib/ddtrace/transport/http/api/spec.rb +15 -0
  563. data/lib/ddtrace/transport/http/builder.rb +169 -0
  564. data/lib/ddtrace/transport/http/client.rb +50 -0
  565. data/lib/ddtrace/transport/http/env.rb +56 -0
  566. data/lib/ddtrace/transport/http/response.rb +26 -0
  567. data/lib/ddtrace/transport/http/statistics.rb +43 -0
  568. data/lib/ddtrace/transport/http/traces.rb +142 -0
  569. data/lib/ddtrace/transport/io.rb +26 -0
  570. data/lib/ddtrace/transport/io/client.rb +76 -0
  571. data/lib/ddtrace/transport/io/response.rb +23 -0
  572. data/lib/ddtrace/transport/io/traces.rb +97 -0
  573. data/lib/ddtrace/transport/parcel.rb +13 -0
  574. data/lib/ddtrace/transport/request.rb +13 -0
  575. data/lib/ddtrace/transport/response.rb +60 -0
  576. data/lib/ddtrace/transport/statistics.rb +72 -0
  577. data/lib/ddtrace/transport/traces.rb +205 -0
  578. data/lib/ddtrace/utils.rb +17 -14
  579. data/lib/ddtrace/utils/compression.rb +27 -0
  580. data/lib/ddtrace/utils/database.rb +7 -3
  581. data/lib/ddtrace/utils/forking.rb +52 -0
  582. data/lib/ddtrace/utils/object_set.rb +41 -0
  583. data/lib/ddtrace/utils/only_once.rb +40 -0
  584. data/lib/ddtrace/utils/sequence.rb +17 -0
  585. data/lib/ddtrace/utils/string_table.rb +45 -0
  586. data/lib/ddtrace/utils/time.rb +45 -0
  587. data/lib/ddtrace/vendor/active_record/MIT-LICENSE +20 -0
  588. data/lib/ddtrace/vendor/active_record/connection_specification.rb +301 -0
  589. data/lib/ddtrace/vendor/multipart-post/LICENSE +11 -0
  590. data/lib/ddtrace/vendor/multipart-post/multipart.rb +12 -0
  591. data/lib/ddtrace/vendor/multipart-post/multipart/post.rb +8 -0
  592. data/lib/ddtrace/vendor/multipart-post/multipart/post/composite_read_io.rb +116 -0
  593. data/lib/ddtrace/vendor/multipart-post/multipart/post/multipartable.rb +57 -0
  594. data/lib/ddtrace/vendor/multipart-post/multipart/post/parts.rb +135 -0
  595. data/lib/ddtrace/vendor/multipart-post/multipart/post/version.rb +9 -0
  596. data/lib/ddtrace/vendor/multipart-post/net/http/post/multipart.rb +32 -0
  597. data/lib/ddtrace/version.rb +3 -1
  598. data/lib/ddtrace/worker.rb +20 -0
  599. data/lib/ddtrace/workers.rb +39 -40
  600. data/lib/ddtrace/workers/async.rb +173 -0
  601. data/lib/ddtrace/workers/loop.rb +119 -0
  602. data/lib/ddtrace/workers/polling.rb +49 -0
  603. data/lib/ddtrace/workers/queue.rb +40 -0
  604. data/lib/ddtrace/workers/runtime_metrics.rb +51 -0
  605. data/lib/ddtrace/workers/trace_writer.rb +202 -0
  606. data/lib/ddtrace/writer.rb +121 -57
  607. data/tasks/release_gem.rake +28 -0
  608. metadata +501 -211
  609. data/lib/ddtrace/configurable.rb +0 -83
  610. data/lib/ddtrace/configuration/proxy.rb +0 -25
  611. data/lib/ddtrace/contrib/base.rb +0 -15
  612. data/lib/ddtrace/contrib/mysql2/client.rb +0 -60
  613. data/lib/ddtrace/contrib/rails/action_controller.rb +0 -91
  614. data/lib/ddtrace/contrib/rails/action_controller_patch.rb +0 -77
  615. data/lib/ddtrace/contrib/rails/action_view.rb +0 -19
  616. data/lib/ddtrace/contrib/rails/active_support.rb +0 -65
  617. data/lib/ddtrace/contrib/rails/core_extensions.rb +0 -356
  618. data/lib/ddtrace/contrib/sidekiq/tracer.rb +0 -72
  619. data/lib/ddtrace/ext/cache.rb +0 -8
  620. data/lib/ddtrace/ext/grpc.rb +0 -7
  621. data/lib/ddtrace/ext/mongo.rb +0 -12
  622. data/lib/ddtrace/ext/redis.rb +0 -17
  623. data/lib/ddtrace/monkey.rb +0 -65
  624. data/lib/ddtrace/propagation/distributed_headers.rb +0 -48
  625. data/lib/ddtrace/provider.rb +0 -21
  626. data/lib/ddtrace/registry.rb +0 -42
  627. data/lib/ddtrace/registry/registerable.rb +0 -20
  628. data/lib/ddtrace/transport.rb +0 -212
@@ -0,0 +1,41 @@
1
+ require 'ddtrace/utils/sequence'
2
+
3
+ module Datadog
4
+ module Utils
5
+ # Acts as a unique dictionary of objects
6
+ class ObjectSet
7
+ # You can provide a block that defines how the key
8
+ # for this message type is resolved.
9
+ def initialize(seed = 0, &block)
10
+ @sequence = Utils::Sequence.new(seed)
11
+ @items = {}
12
+ @key_block = block
13
+ end
14
+
15
+ # Submit an array of arguments that define the message.
16
+ # If they match an existing message, it will return the
17
+ # matching object. If it doesn't match, it will yield to
18
+ # the block with the next ID & args given.
19
+ def fetch(*args, &block)
20
+ key = @key_block ? @key_block.call(*args) : args.hash
21
+ # TODO: Ruby 2.0 doesn't like yielding here... switch when 2.0 is dropped.
22
+ # rubocop:disable Performance/RedundantBlockCall
23
+ @items[key] ||= block.call(@sequence.next, *args)
24
+ # rubocop:enable Performance/RedundantBlockCall
25
+ end
26
+
27
+ def length
28
+ @items.length
29
+ end
30
+
31
+ def objects
32
+ @items.values
33
+ end
34
+
35
+ def freeze
36
+ super
37
+ @items.freeze
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Utils
5
+ # Helper class to execute something only once such as not repeating warning logs, and instrumenting classes
6
+ # only once.
7
+ #
8
+ # Thread-safe when used correctly (e.g. be careful of races when lazily initializing instances of this class).
9
+ #
10
+ # Note: In its current state, this class is not Ractor-safe.
11
+ # In https://github.com/DataDog/dd-trace-rb/pull/1398#issuecomment-797378810 we have a discussion of alternatives,
12
+ # including an alternative implementation that is Ractor-safe once spent.
13
+ class OnlyOnce
14
+ def initialize
15
+ @mutex = Mutex.new
16
+ @ran_once = false
17
+ end
18
+
19
+ def run
20
+ @mutex.synchronize do
21
+ return if @ran_once
22
+
23
+ @ran_once = true
24
+
25
+ yield
26
+ end
27
+ end
28
+
29
+ def ran?
30
+ @mutex.synchronize { @ran_once }
31
+ end
32
+
33
+ private
34
+
35
+ def reset_ran_once_state_for_tests
36
+ @mutex.synchronize { @ran_once = false }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ module Datadog
2
+ module Utils
3
+ # Generates values from a consistent sequence
4
+ class Sequence
5
+ def initialize(seed = 0, &block)
6
+ @current = seed
7
+ @next_item = block
8
+ end
9
+
10
+ def next
11
+ next_item = @next_item ? @next_item.call(@current) : @current
12
+ @current += 1
13
+ next_item
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ require 'ddtrace/utils/sequence'
2
+
3
+ module Datadog
4
+ module Utils
5
+ # Tracks strings and returns IDs
6
+ class StringTable
7
+ def initialize
8
+ @sequence = Sequence.new
9
+ @ids = { ''.freeze => @sequence.next }
10
+ end
11
+
12
+ # Returns an ID for the string
13
+ def fetch(string)
14
+ @ids[string.to_s] ||= @sequence.next
15
+ end
16
+
17
+ # Returns the canonical copy of this string
18
+ # Typically used for psuedo interning; reduce
19
+ # identical copies of a string to one object.
20
+ def fetch_string(string)
21
+ return nil if string.nil?
22
+
23
+ # Co-erce to string
24
+ string = string.to_s
25
+
26
+ # Add to string table if no match
27
+ @ids[string] = @sequence.next unless @ids.key?(string)
28
+
29
+ # Get and return matching string in table
30
+ # NOTE: Have to resolve the key and retrieve from table again
31
+ # because "string" argument is not same object as string key.
32
+ id = @ids[string]
33
+ @ids.key(id)
34
+ end
35
+
36
+ def [](id)
37
+ @ids.key(id)
38
+ end
39
+
40
+ def strings
41
+ @ids.keys
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module Datadog
2
+ module Utils
3
+ # Common database-related utility functions.
4
+ module Time
5
+ PROCESS_TIME_SUPPORTED = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.1.0')
6
+
7
+ module_function
8
+
9
+ # Current monotonic time.
10
+ # Falls back to `now` if monotonic clock
11
+ # is not available.
12
+ #
13
+ # @return [Float] in seconds, since some unspecified starting point
14
+ def get_time
15
+ PROCESS_TIME_SUPPORTED ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : now.to_f
16
+ end
17
+
18
+ # Current wall time.
19
+ #
20
+ # @return [Time] current time object
21
+ def now
22
+ ::Time.now
23
+ end
24
+
25
+ # Overrides the implementation of `#now
26
+ # with the provided callable.
27
+ #
28
+ # Overriding the method `#now` instead of
29
+ # indirectly calling `block` removes
30
+ # one level of method call overhead.
31
+ #
32
+ # @param block [Proc] block that returns a `Time` object representing the current wall time
33
+ def now_provider=(block)
34
+ define_singleton_method(:now, &block)
35
+ end
36
+
37
+ def measure
38
+ before = get_time
39
+ yield
40
+ after = get_time
41
+ after - before
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005-2018 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,301 @@
1
+ require 'uri'
2
+
3
+ # NOTE: This code is copied directly from ActiveRecord.
4
+ # Its purpose is to resolve connection information.
5
+ # It exists here only because it doesn't exist in Rails 3.2.
6
+ # When support for Rails 3.2 is dropped, this can be removed.
7
+ module Datadog
8
+ module Vendor
9
+ module ActiveRecord
10
+ # Copy/paste from:
11
+ # https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/connection_handling.rb
12
+ module ConnectionHandling
13
+ RAILS_ENV = -> { (Rails.env if defined?(Rails) && defined?(Rails.env)) || ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence }
14
+ end
15
+
16
+ # Copy/paste from:
17
+ # https://github.com/rails/rails/blob/5-2-stable/activerecord/lib/active_record/connection_adapters/connection_specification.rb
18
+ module ConnectionAdapters
19
+ class ConnectionSpecification
20
+ attr_reader :name, :config, :adapter_method
21
+
22
+ def initialize(name, config, adapter_method)
23
+ @name, @config, @adapter_method = name, config, adapter_method
24
+ end
25
+
26
+ def initialize_dup(original)
27
+ @config = original.config.dup
28
+ end
29
+
30
+ def to_hash
31
+ @config.merge(name: @name)
32
+ end
33
+
34
+ # Expands a connection string into a hash.
35
+ class ConnectionUrlResolver # :nodoc:
36
+ # == Example
37
+ #
38
+ # url = "postgresql://foo:bar@localhost:9000/foo_test?pool=5&timeout=3000"
39
+ # ConnectionUrlResolver.new(url).to_hash
40
+ # # => {
41
+ # "adapter" => "postgresql",
42
+ # "host" => "localhost",
43
+ # "port" => 9000,
44
+ # "database" => "foo_test",
45
+ # "username" => "foo",
46
+ # "password" => "bar",
47
+ # "pool" => "5",
48
+ # "timeout" => "3000"
49
+ # }
50
+ def initialize(url)
51
+ raise "Database URL cannot be empty" if url.blank?
52
+ @uri = uri_parser.parse(url)
53
+ @adapter = @uri.scheme && @uri.scheme.tr("-", "_")
54
+ @adapter = "postgresql" if @adapter == "postgres"
55
+
56
+ if @uri.opaque
57
+ @uri.opaque, @query = @uri.opaque.split("?", 2)
58
+ else
59
+ @query = @uri.query
60
+ end
61
+ end
62
+
63
+ # Converts the given URL to a full connection hash.
64
+ def to_hash
65
+ config = raw_config.reject { |_, value| value.blank? }
66
+ config.map { |key, value| config[key] = uri_parser.unescape(value) if value.is_a? String }
67
+ config
68
+ end
69
+
70
+ private
71
+
72
+ def uri
73
+ @uri
74
+ end
75
+
76
+ def uri_parser
77
+ @uri_parser ||= URI::Parser.new
78
+ end
79
+
80
+ # Converts the query parameters of the URI into a hash.
81
+ #
82
+ # "localhost?pool=5&reaping_frequency=2"
83
+ # # => { "pool" => "5", "reaping_frequency" => "2" }
84
+ #
85
+ # returns empty hash if no query present.
86
+ #
87
+ # "localhost"
88
+ # # => {}
89
+ def query_hash
90
+ Hash[(@query || "").split("&").map { |pair| pair.split("=") }]
91
+ end
92
+
93
+ def raw_config
94
+ if uri.opaque
95
+ query_hash.merge(
96
+ "adapter" => @adapter,
97
+ "database" => uri.opaque)
98
+ else
99
+ query_hash.merge(
100
+ "adapter" => @adapter,
101
+ "username" => uri.user,
102
+ "password" => uri.password,
103
+ "port" => uri.port,
104
+ "database" => database_from_path,
105
+ "host" => uri.hostname)
106
+ end
107
+ end
108
+
109
+ # Returns name of the database.
110
+ def database_from_path
111
+ if @adapter == "sqlite3"
112
+ # 'sqlite3:/foo' is absolute, because that makes sense. The
113
+ # corresponding relative version, 'sqlite3:foo', is handled
114
+ # elsewhere, as an "opaque".
115
+
116
+ uri.path
117
+ else
118
+ # Only SQLite uses a filename as the "database" name; for
119
+ # anything else, a leading slash would be silly.
120
+
121
+ uri.path.sub(%r{^/}, "")
122
+ end
123
+ end
124
+ end
125
+
126
+ ##
127
+ # Builds a ConnectionSpecification from user input.
128
+ class Resolver # :nodoc:
129
+ attr_reader :configurations
130
+
131
+ # Accepts a hash two layers deep, keys on the first layer represent
132
+ # environments such as "production". Keys must be strings.
133
+ def initialize(configurations)
134
+ @configurations = configurations
135
+ end
136
+
137
+ # Returns a hash with database connection information.
138
+ #
139
+ # == Examples
140
+ #
141
+ # Full hash Configuration.
142
+ #
143
+ # configurations = { "production" => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" } }
144
+ # Resolver.new(configurations).resolve(:production)
145
+ # # => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3"}
146
+ #
147
+ # Initialized with URL configuration strings.
148
+ #
149
+ # configurations = { "production" => "postgresql://localhost/foo" }
150
+ # Resolver.new(configurations).resolve(:production)
151
+ # # => { "host" => "localhost", "database" => "foo", "adapter" => "postgresql" }
152
+ #
153
+ def resolve(config)
154
+ if config
155
+ resolve_connection config
156
+ elsif env = ConnectionHandling::RAILS_ENV.call
157
+ resolve_symbol_connection env.to_sym
158
+ else
159
+ raise AdapterNotSpecified
160
+ end
161
+ end
162
+
163
+ # Expands each key in @configurations hash into fully resolved hash
164
+ def resolve_all
165
+ config = configurations.dup
166
+
167
+ if env = ConnectionHandling::DEFAULT_ENV.call
168
+ env_config = config[env] if config[env].is_a?(Hash) && !(config[env].key?("adapter") || config[env].key?("url"))
169
+ end
170
+
171
+ config.reject! { |k, v| v.is_a?(Hash) && !(v.key?("adapter") || v.key?("url")) }
172
+ config.merge! env_config if env_config
173
+
174
+ config.each do |key, value|
175
+ config[key] = resolve(value) if value
176
+ end
177
+
178
+ config
179
+ end
180
+
181
+ # Returns an instance of ConnectionSpecification for a given adapter.
182
+ # Accepts a hash one layer deep that contains all connection information.
183
+ #
184
+ # == Example
185
+ #
186
+ # config = { "production" => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" } }
187
+ # spec = Resolver.new(config).spec(:production)
188
+ # spec.adapter_method
189
+ # # => "sqlite3_connection"
190
+ # spec.config
191
+ # # => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" }
192
+ #
193
+ def spec(config)
194
+ spec = resolve(config).symbolize_keys
195
+
196
+ raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
197
+
198
+ # Require the adapter itself and give useful feedback about
199
+ # 1. Missing adapter gems and
200
+ # 2. Adapter gems' missing dependencies.
201
+ path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter"
202
+ begin
203
+ require path_to_adapter
204
+ rescue LoadError => e
205
+ # We couldn't require the adapter itself. Raise an exception that
206
+ # points out config typos and missing gems.
207
+ if e.path == path_to_adapter
208
+ # We can assume that a non-builtin adapter was specified, so it's
209
+ # either misspelled or missing from Gemfile.
210
+ raise e.class, "Could not load the '#{spec[:adapter]}' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile.", e.backtrace
211
+
212
+ # Bubbled up from the adapter require. Prefix the exception message
213
+ # with some guidance about how to address it and reraise.
214
+ else
215
+ raise e.class, "Error loading the '#{spec[:adapter]}' Active Record adapter. Missing a gem it depends on? #{e.message}", e.backtrace
216
+ end
217
+ end
218
+
219
+ adapter_method = "#{spec[:adapter]}_connection"
220
+
221
+ unless ::ActiveRecord::Base.respond_to?(adapter_method)
222
+ raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
223
+ end
224
+
225
+ ConnectionSpecification.new(spec.delete(:name) || "primary", spec, adapter_method)
226
+ end
227
+
228
+ private
229
+
230
+ # Returns fully resolved connection, accepts hash, string or symbol.
231
+ # Always returns a hash.
232
+ #
233
+ # == Examples
234
+ #
235
+ # Symbol representing current environment.
236
+ #
237
+ # Resolver.new("production" => {}).resolve_connection(:production)
238
+ # # => {}
239
+ #
240
+ # One layer deep hash of connection values.
241
+ #
242
+ # Resolver.new({}).resolve_connection("adapter" => "sqlite3")
243
+ # # => { "adapter" => "sqlite3" }
244
+ #
245
+ # Connection URL.
246
+ #
247
+ # Resolver.new({}).resolve_connection("postgresql://localhost/foo")
248
+ # # => { "host" => "localhost", "database" => "foo", "adapter" => "postgresql" }
249
+ #
250
+ def resolve_connection(spec)
251
+ case spec
252
+ when Symbol
253
+ resolve_symbol_connection spec
254
+ when String
255
+ resolve_url_connection spec
256
+ when Hash
257
+ resolve_hash_connection spec
258
+ end
259
+ end
260
+
261
+ # Takes the environment such as +:production+ or +:development+.
262
+ # This requires that the @configurations was initialized with a key that
263
+ # matches.
264
+ #
265
+ # Resolver.new("production" => {}).resolve_symbol_connection(:production)
266
+ # # => {}
267
+ #
268
+ def resolve_symbol_connection(spec)
269
+ if config = configurations[spec.to_s]
270
+ resolve_connection(config).merge("name" => spec.to_s)
271
+ else
272
+ raise(AdapterNotSpecified, "'#{spec}' database is not configured. Available: #{configurations.keys.inspect}")
273
+ end
274
+ end
275
+
276
+ # Accepts a hash. Expands the "url" key that contains a
277
+ # URL database connection to a full connection
278
+ # hash and merges with the rest of the hash.
279
+ # Connection details inside of the "url" key win any merge conflicts
280
+ def resolve_hash_connection(spec)
281
+ if spec["url"] && spec["url"] !~ /^jdbc:/
282
+ connection_hash = resolve_url_connection(spec.delete("url"))
283
+ spec.merge!(connection_hash)
284
+ end
285
+ spec
286
+ end
287
+
288
+ # Takes a connection URL.
289
+ #
290
+ # Resolver.new({}).resolve_url_connection("postgresql://localhost/foo")
291
+ # # => { "host" => "localhost", "database" => "foo", "adapter" => "postgresql" }
292
+ #
293
+ def resolve_url_connection(url)
294
+ ConnectionUrlResolver.new(url).to_hash
295
+ end
296
+ end
297
+ end
298
+ end
299
+ end
300
+ end
301
+ end