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,68 @@
1
+ # Datadog APM Ruby integration test suite
2
+
3
+ Integration tests for `ddtrace` that use a variety of real applications.
4
+
5
+ ## Quickstart
6
+
7
+ 1. Build Docker base images:
8
+
9
+ ```sh
10
+ #!/bin/bash
11
+ ./script/build-images
12
+ ```
13
+
14
+ 2. Choose an application and follow instructions (in corresponding `README.md`.)
15
+
16
+ ## Demo applications
17
+
18
+ Ruby demo applications are configured with Datadog APM, which can be used to generate sample traces/profiles. These are used to drive tests in the integration suite.
19
+
20
+ ### Applications
21
+
22
+ See `README.md` in each directory for more information:
23
+
24
+ - `apps/rack`: Rack application
25
+ - `apps/rails-five`: Rails 5 application
26
+
27
+ ### Base images
28
+
29
+ The `images/` folders hosts some images for Ruby applications.
30
+
31
+ - `datadog/dd-apm-demo:wrk` / `images/wrk/Dockerfile`: `wrk` load testing application (for generating load)
32
+ - `datadog/dd-apm-demo:agent` / `images/agent/Dockerfile`: Datadog agent (with default configuration)
33
+ - `datadog/dd-apm-demo:rb-<RUBY_VERSION>` / `images/<RUBY_VERSION>/Dockerfile`: MRI Ruby & `Datadog::DemoEnv` (where `<RUBY_VERSION>` is minor version e.g. `2.7`)
34
+
35
+ Ruby base images include `Datadog::DemoEnv` and other helpers.
36
+
37
+ ### Debugging
38
+
39
+ #### Profiling memory
40
+
41
+ Create a memory heap dump via:
42
+
43
+ ```sh
44
+ # Profile for 5 minutes, dump heap to /data/app/ruby-heap.dump
45
+ # Where PID = process ID
46
+ bundle exec rbtrace -p PID -e 'Thread.new{GC.start; require "objspace"; ObjectSpace.trace_object_allocations_start; sleep(300); io=File.open("/data/app/ruby-heap.dump", "w"); ObjectSpace.dump_all(output: io); io.close}'
47
+ ```
48
+
49
+ Then analyze it using `analyzer.rb` (built into the Ruby base images) with:
50
+
51
+ ```sh
52
+ # Group objects by generation
53
+ ruby /vendor/dd-demo/datadog/analyzer.rb /data/app/ruby-heap.dump
54
+
55
+ # List objects in GEN_NUM, group by source location
56
+ ruby /vendor/dd-demo/datadog/analyzer.rb /data/app/ruby-heap.dump GEN_NUM
57
+
58
+ # List objects in all generations, group by source location, descending.
59
+ ruby /vendor/dd-demo/datadog/analyzer.rb /data/app/ruby-heap.dump objects
60
+
61
+ # List objects in all generations, group by source location, descending.
62
+ # Up to generation END_GEN.
63
+ ruby /vendor/dd-demo/datadog/analyzer.rb /data/app/ruby-heap.dump objects END_GEN
64
+
65
+ # List objects in all generations, group by source location, descending.
66
+ # Between generations START_GEN to END_GEN inclusive.
67
+ ruby /vendor/dd-demo/datadog/analyzer.rb /data/app/ruby-heap.dump objects END_GEN START_GEN
68
+ ```
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ export DD_API_KEY=<Your Datadog API key here>
@@ -0,0 +1,4 @@
1
+ # Ignore local variables
2
+ .envrc
3
+ .byebug_history
4
+ data
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,25 @@
1
+ # Select base image
2
+ ARG BASE_IMAGE
3
+ FROM ${BASE_IMAGE}
4
+
5
+ # Setup directory
6
+ RUN mkdir /app
7
+ WORKDIR /app
8
+
9
+ # Setup specific version of ddtrace, if specified.
10
+ ARG ddtrace_git
11
+ ENV DD_DEMO_ENV_GEM_GIT_DDTRACE ${ddtrace_git}
12
+
13
+ ARG ddtrace_ref
14
+ ENV DD_DEMO_ENV_GEM_REF_DDTRACE ${ddtrace_ref}
15
+
16
+ # Install dependencies
17
+ COPY Gemfile /app/Gemfile
18
+ RUN bundle install
19
+
20
+ # Add files
21
+ COPY . /app
22
+
23
+ # Set entrypoint
24
+ ENTRYPOINT ["/bin/bash", "-c"]
25
+ CMD ["bin/setup && bin/run"]
@@ -0,0 +1,11 @@
1
+ # Select base image
2
+ ARG BASE_IMAGE
3
+ FROM ${BASE_IMAGE}
4
+
5
+ # Add gem
6
+ COPY . /vendor/dd-trace-rb
7
+
8
+ # Install dependencies
9
+ # Setup specific version of ddtrace, if specified.
10
+ ENV DD_DEMO_ENV_GEM_LOCAL_DDTRACE /vendor/dd-trace-rb
11
+ RUN bundle install
@@ -0,0 +1,24 @@
1
+ require 'datadog/demo_env'
2
+
3
+ source 'https://rubygems.org' do
4
+ gem 'puma'
5
+ gem 'unicorn'
6
+
7
+ gem 'dogstatsd-ruby'
8
+ gem 'rack'
9
+
10
+ gem 'ffi'
11
+ gem 'google-protobuf'
12
+
13
+ # Choose correct specs for 'ddtrace' demo environment
14
+ gem 'ddtrace', *Datadog::DemoEnv.gem_spec('ddtrace')
15
+
16
+ # Development
17
+ gem 'byebug'
18
+ # gem 'pry-stack_explorer', platform: :ruby
19
+ # gem 'rbtrace'
20
+ # gem 'ruby-prof'
21
+
22
+ # Testing/CI
23
+ gem 'rspec'
24
+ end
@@ -0,0 +1,93 @@
1
+ # Rack: Demo application for Datadog APM
2
+
3
+ A generic Rack web application with some common use scenarios.
4
+
5
+ For generating Datadog APM traces and profiles.
6
+
7
+ ## Installation
8
+
9
+ Install [direnv](https://github.com/direnv/direnv) for applying local settings.
10
+
11
+ 1. `cp .envrc.sample .envrc` and add your Datadog API key.
12
+ 2. `direnv allow` to load the env var.
13
+ 4. `docker-compose run --rm app bin/setup`
14
+
15
+ ## Running the application
16
+
17
+ ### To monitor performance of Docker containers with Datadog
18
+
19
+ ```sh
20
+ docker run --rm --name dd-agent -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e API_KEY=$DD_API_KEY datadog/docker-dd-agent:latest
21
+ ```
22
+
23
+ ### Starting the web server
24
+
25
+ Run `docker-compose up` to auto-start the webserver. It should bind to `localhost:80`.
26
+
27
+ Alternatively, you can run it manually with:
28
+
29
+ ```sh
30
+ docker-compose run --rm -p 80:80 app bin/run <process>
31
+ ```
32
+
33
+ The `<process>` argument is optional, and will default to `DD_DEMO_ENV_PROCESS` if not provided. See [Processes](#processes) for more details.
34
+
35
+ ##### Processes
36
+
37
+ Within the container, run `bin/run <process>` where `<process>` is one of the following values:
38
+
39
+ - `puma`: Puma web server
40
+ - `unicorn`: Unicorn web server
41
+ - `irb`: IRB session
42
+
43
+ Alternatively, set `DD_DEMO_ENV_PROCESS` to run a particular process by default when `bin/run` is run.
44
+
45
+ ##### Features
46
+
47
+ Set `DD_DEMO_ENV_PROCESS` to a comma-delimited list of any of the following values to activate the feature:
48
+
49
+ - `tracing`: Tracing instrumentation
50
+ - `profiling`: Profiling (NOTE: Must also set `DD_PROFILING_ENABLED` to match.)
51
+ - `debug`: Enable diagnostic debug mode
52
+ - `analytics`: Enable trace analytics
53
+ - `runtime_metrics`: Enable runtime metrics
54
+ - `pprof_to_file`: Dump profiling pprof to file instead of agent.
55
+
56
+ e.g. `DD_DEMO_ENV_PROCESS=tracing,profiling`
57
+
58
+ ##### Routes
59
+
60
+ ```sh
61
+ # Health check
62
+ curl -v localhost/health
63
+
64
+ # Basic demo scenarios
65
+ curl -v localhost/basic/fibonacci
66
+ curl -v -XPOST localhost/basic/default
67
+
68
+ # Job demo scenarios
69
+ curl -v -XPOST localhost/jobs
70
+ ```
71
+
72
+ ### Load tester
73
+
74
+ Docker configuration automatically creates and runs [Wrk](https://github.com/wg/wrk) load testing containers. By default it runs the `basic/default` scenario described in the `wrk` image to give a baseload.
75
+
76
+ You can modify the `load-tester` container in `docker-compose.yml` to change the load type or scenario run. Set the container's `command` to any set of arguments `wrk` accepts.
77
+
78
+ You can also define your own custom scenario by creating a LUA file, mounting it into the container, and passing it as an argument via `command`.
79
+
80
+ ### Running integration tests
81
+
82
+ You can run integration tests using the following and substituting for the Ruby major and minor version (e.g. `2.7`)
83
+
84
+ ```sh
85
+ ./script/build-images -v <RUBY_VERSION>
86
+ ./script/ci -v <RUBY_VERSION>
87
+ ```
88
+
89
+ Or inside a running container:
90
+
91
+ ```sh
92
+ ./bin/test
93
+ ```
@@ -0,0 +1,80 @@
1
+ require 'rack'
2
+
3
+ module Acme
4
+ class Application
5
+ def call(env)
6
+ request = Rack::Request.new(env)
7
+ router.route!(request)
8
+ end
9
+
10
+ def router
11
+ Router.new(
12
+ '/' => { controller: controllers[:health], action: :check },
13
+ '/health' => { controller: controllers[:health], action: :check },
14
+ '/basic/fibonacci' => { controller: controllers[:basic], action: :fibonacci },
15
+ '/basic/default' => { controller: controllers[:basic], action: :default }
16
+ )
17
+ end
18
+
19
+ def controllers
20
+ {
21
+ basic: Controllers::Basic.new,
22
+ health: Controllers::Health.new
23
+ }
24
+ end
25
+ end
26
+
27
+ class Router
28
+ attr_reader :routes
29
+
30
+ def initialize(routes)
31
+ @routes = routes
32
+ end
33
+
34
+ def route!(request)
35
+ begin
36
+ if route = routes[request.path]
37
+ route[:controller].send(route[:action], request)
38
+ else
39
+ not_found(request)
40
+ end
41
+ rescue StandardError => e
42
+ application_error(request, e)
43
+ end
44
+ end
45
+
46
+ def not_found(request)
47
+ [404, { 'Content-Type' => 'text/plain' }, ["404 Not Found: #{request.path}"]]
48
+ end
49
+
50
+ def application_error(request, error)
51
+ [500, { 'Content-Type' => 'text/plain' }, ["500 Application Error: #{error.message} Location: #{error.backtrace.first(3)}"]]
52
+ end
53
+ end
54
+
55
+ module Controllers
56
+ class Basic
57
+ def fibonacci(request)
58
+ n = rand(25..35)
59
+ result = fib(n)
60
+ ['200', { 'Content-Type' => 'text/plain' }, ["Basic: Fibonacci(#{n}): #{result}"]]
61
+ end
62
+
63
+ def default(request)
64
+ ['200', { 'Content-Type' => 'text/plain' }, ['Basic: Default']]
65
+ end
66
+
67
+ private
68
+
69
+ def fib(n)
70
+ n <= 1 ? n : fib(n-1) + fib(n-2)
71
+ end
72
+ end
73
+
74
+ class Health
75
+ def check(request)
76
+ ['204', {}, []]
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,17 @@
1
+ require 'datadog/demo_env'
2
+ require 'ddtrace'
3
+
4
+ Datadog.configure do |c|
5
+ c.diagnostics.debug = true if Datadog::DemoEnv.feature?('debug')
6
+ c.analytics_enabled = true if Datadog::DemoEnv.feature?('analytics')
7
+ c.runtime_metrics.enabled = true if Datadog::DemoEnv.feature?('runtime_metrics')
8
+
9
+ if Datadog::DemoEnv.feature?('tracing')
10
+ c.use :rack, service_name: 'acme-rack'
11
+ end
12
+
13
+ if Datadog::DemoEnv.feature?('pprof_to_file')
14
+ # Reconfigure transport to write pprof to file
15
+ c.profiling.exporter.transport = Datadog::DemoEnv.profiler_file_transport
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Start application process
4
+ puts "\n== Starting application process =="
5
+
6
+ profiling = Datadog::DemoEnv.feature?('profiling') ? 'DD_PROFILING_ENABLED=true ddtracerb exec ' : ''
7
+ process = (ARGV[0] || Datadog::DemoEnv.process)
8
+ command = case process
9
+ when 'puma'
10
+ "bundle exec #{profiling}puma -C /app/config/puma.rb /app/config.ru"
11
+ when 'unicorn'
12
+ "bundle exec #{profiling}unicorn -c /app/config/unicorn.rb /app/config.ru"
13
+ when 'irb'
14
+ "bundle exec #{profiling}irb"
15
+ when nil, ''
16
+ abort("\n== ERROR: Must specify a application process! ==")
17
+ else
18
+ abort("\n== ERROR: Unknown application process '#{process}' ==")
19
+ end
20
+
21
+ puts "Run: #{command}"
22
+ Kernel.exec(command)
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ puts "Run: #{args.join(' ')}"
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ puts "\n== Installing dependencies =="
15
+ system! 'gem install bundler --conservative'
16
+ system('bundle check') || system!('bundle install')
17
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ puts "Run: #{args.join(' ')}"
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ puts "\n== Performing setup =="
15
+ system!('./bin/setup')
16
+
17
+ if ENV['TEST_INTEGRATION']
18
+ puts "\n== Wait for healthy HTTP server... =="
19
+ system!('bash /vendor/dd-demo/http-health-check')
20
+ end
21
+
22
+ puts "\n== Run test suite =="
23
+ system!('rspec')
24
+ end
@@ -0,0 +1,6 @@
1
+ require 'datadog/demo_env'
2
+ require_relative 'app/datadog'
3
+ require_relative 'app/acme'
4
+
5
+ use Datadog::Contrib::Rack::TraceMiddleware if Datadog::DemoEnv.feature?('tracing')
6
+ run Acme::Application.new
@@ -0,0 +1,14 @@
1
+ require 'datadog/demo_env'
2
+
3
+ Datadog::DemoEnv.print_env('Puma master environment')
4
+
5
+ workers Integer(ENV["WEB_CONCURRENCY"] || 1)
6
+ threads 2, Integer(ENV['WEB_MAX_THREADS'] || 24)
7
+
8
+ preload_app!
9
+
10
+ bind 'tcp://0.0.0.0:80'
11
+
12
+ on_worker_boot do
13
+ Datadog::DemoEnv.print_env('Puma worker environment')
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'datadog/demo_env'
2
+
3
+ # config/unicorn.rb
4
+ worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
5
+ timeout 15
6
+ preload_app true
7
+
8
+ Datadog::DemoEnv.print_env('Unicorn master environment')
9
+
10
+ before_fork do |server, worker|
11
+ Signal.trap 'TERM' do
12
+ puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
13
+ Process.kill 'QUIT', Process.pid
14
+ end
15
+ end
16
+
17
+ after_fork do |server, worker|
18
+ Signal.trap 'TERM' do
19
+ puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
20
+ end
21
+
22
+ Datadog::DemoEnv.print_env('Unicorn worker environment')
23
+ end