ddtrace 0.45.0 → 0.47.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (302) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +131 -12
  3. data/.circleci/images/primary/{Dockerfile-jruby-9.2 → Dockerfile-jruby-9.2-latest} +2 -1
  4. data/.circleci/images/primary/Dockerfile-jruby-9.2.0.0 +73 -0
  5. data/.circleci/images/primary/Dockerfile-truffleruby-21.0.0 +73 -0
  6. data/.github/workflows/create-next-milestone.yml +2 -2
  7. data/.rubocop.yml +250 -7
  8. data/.rubocop_todo.yml +397 -0
  9. data/.simplecov +6 -0
  10. data/Appraisals +16 -1
  11. data/CHANGELOG.md +150 -1
  12. data/Gemfile +53 -3
  13. data/LICENSE-3rdparty.csv +2 -0
  14. data/Rakefile +5 -23
  15. data/ddtrace.gemspec +6 -36
  16. data/docker-compose.yml +75 -7
  17. data/docs/DevelopmentGuide.md +28 -0
  18. data/docs/GettingStarted.md +69 -17
  19. data/integration/README.md +68 -0
  20. data/integration/apps/rack/.dockerignore +1 -0
  21. data/integration/apps/rack/.envrc.sample +1 -0
  22. data/integration/apps/rack/.gitignore +4 -0
  23. data/integration/apps/rack/.rspec +1 -0
  24. data/integration/apps/rack/Dockerfile +25 -0
  25. data/integration/apps/rack/Dockerfile-ci +11 -0
  26. data/integration/apps/rack/Gemfile +24 -0
  27. data/integration/apps/rack/README.md +93 -0
  28. data/integration/apps/rack/app/acme.rb +80 -0
  29. data/integration/apps/rack/app/datadog.rb +17 -0
  30. data/integration/apps/rack/bin/run +22 -0
  31. data/integration/apps/rack/bin/setup +17 -0
  32. data/integration/apps/rack/bin/test +24 -0
  33. data/integration/apps/rack/config.ru +6 -0
  34. data/integration/apps/rack/config/puma.rb +14 -0
  35. data/integration/apps/rack/config/unicorn.rb +23 -0
  36. data/integration/apps/rack/docker-compose.ci.yml +62 -0
  37. data/integration/apps/rack/docker-compose.yml +78 -0
  38. data/integration/apps/rack/script/build-images +38 -0
  39. data/integration/apps/rack/script/ci +50 -0
  40. data/integration/apps/rack/spec/integration/basic_spec.rb +10 -0
  41. data/integration/apps/rack/spec/spec_helper.rb +16 -0
  42. data/integration/apps/rack/spec/support/integration_helper.rb +22 -0
  43. data/integration/apps/rails-five/.dockerignore +1 -0
  44. data/integration/apps/rails-five/.env +3 -0
  45. data/integration/apps/rails-five/.envrc.sample +1 -0
  46. data/integration/apps/rails-five/.gitignore +30 -0
  47. data/integration/apps/rails-five/Dockerfile +25 -0
  48. data/integration/apps/rails-five/Dockerfile-ci +11 -0
  49. data/integration/apps/rails-five/Gemfile +104 -0
  50. data/integration/apps/rails-five/README.md +94 -0
  51. data/integration/apps/rails-five/Rakefile +6 -0
  52. data/integration/apps/rails-five/app/channels/application_cable/channel.rb +4 -0
  53. data/integration/apps/rails-five/app/channels/application_cable/connection.rb +4 -0
  54. data/integration/apps/rails-five/app/controllers/application_controller.rb +2 -0
  55. data/integration/apps/rails-five/app/controllers/basic_controller.rb +36 -0
  56. data/integration/apps/rails-five/app/controllers/concerns/.keep +0 -0
  57. data/integration/apps/rails-five/app/controllers/health_controller.rb +9 -0
  58. data/integration/apps/rails-five/app/controllers/jobs_controller.rb +12 -0
  59. data/integration/apps/rails-five/app/jobs/application_job.rb +2 -0
  60. data/integration/apps/rails-five/app/jobs/test_job.rb +12 -0
  61. data/integration/apps/rails-five/app/mailers/application_mailer.rb +4 -0
  62. data/integration/apps/rails-five/app/models/application_record.rb +3 -0
  63. data/integration/apps/rails-five/app/models/concerns/.keep +0 -0
  64. data/integration/apps/rails-five/app/models/test.rb +2 -0
  65. data/integration/apps/rails-five/app/views/layouts/mailer.html.erb +13 -0
  66. data/integration/apps/rails-five/app/views/layouts/mailer.text.erb +1 -0
  67. data/integration/apps/rails-five/bin/bundle +3 -0
  68. data/integration/apps/rails-five/bin/rails +9 -0
  69. data/integration/apps/rails-five/bin/rake +9 -0
  70. data/integration/apps/rails-five/bin/run +24 -0
  71. data/integration/apps/rails-five/bin/setup +27 -0
  72. data/integration/apps/rails-five/bin/spring +17 -0
  73. data/integration/apps/rails-five/bin/test +21 -0
  74. data/integration/apps/rails-five/bin/update +28 -0
  75. data/integration/apps/rails-five/config.ru +5 -0
  76. data/integration/apps/rails-five/config/application.rb +97 -0
  77. data/integration/apps/rails-five/config/boot.rb +4 -0
  78. data/integration/apps/rails-five/config/cable.yml +10 -0
  79. data/integration/apps/rails-five/config/credentials.yml.enc +1 -0
  80. data/integration/apps/rails-five/config/database.yml +28 -0
  81. data/integration/apps/rails-five/config/environment.rb +5 -0
  82. data/integration/apps/rails-five/config/environments/development.rb +51 -0
  83. data/integration/apps/rails-five/config/environments/production.rb +82 -0
  84. data/integration/apps/rails-five/config/environments/test.rb +43 -0
  85. data/integration/apps/rails-five/config/initializers/datadog.rb +18 -0
  86. data/integration/apps/rails-five/config/initializers/filter_parameter_logging.rb +4 -0
  87. data/integration/apps/rails-five/config/initializers/resque.rb +4 -0
  88. data/integration/apps/rails-five/config/initializers/rollbar.rb +5 -0
  89. data/integration/apps/rails-five/config/initializers/wrap_parameters.rb +14 -0
  90. data/integration/apps/rails-five/config/locales/en.yml +33 -0
  91. data/integration/apps/rails-five/config/puma.rb +24 -0
  92. data/integration/apps/rails-five/config/routes.rb +11 -0
  93. data/integration/apps/rails-five/config/spring.rb +6 -0
  94. data/integration/apps/rails-five/config/unicorn.rb +29 -0
  95. data/integration/apps/rails-five/db/migrate/20190927215052_create_tests.rb +11 -0
  96. data/integration/apps/rails-five/db/schema.rb +23 -0
  97. data/integration/apps/rails-five/db/seeds.rb +7 -0
  98. data/integration/apps/rails-five/docker-compose.ci.yml +98 -0
  99. data/integration/apps/rails-five/docker-compose.yml +100 -0
  100. data/integration/apps/rails-five/lib/tasks/.keep +0 -0
  101. data/integration/apps/rails-five/log/.keep +0 -0
  102. data/integration/apps/rails-five/public/robots.txt +1 -0
  103. data/integration/apps/rails-five/script/build-images +35 -0
  104. data/integration/apps/rails-five/script/ci +50 -0
  105. data/integration/apps/rails-five/spec/integration/basic_spec.rb +10 -0
  106. data/integration/apps/rails-five/spec/spec_helper.rb +16 -0
  107. data/integration/apps/rails-five/spec/support/integration_helper.rb +22 -0
  108. data/integration/apps/rails-five/storage/.keep +0 -0
  109. data/integration/apps/rails-five/tmp/.keep +0 -0
  110. data/integration/apps/rails-five/vendor/.keep +0 -0
  111. data/integration/apps/ruby/.dockerignore +1 -0
  112. data/integration/apps/ruby/.envrc.sample +1 -0
  113. data/integration/apps/ruby/.gitignore +2 -0
  114. data/integration/apps/ruby/Dockerfile +25 -0
  115. data/integration/apps/ruby/Dockerfile-ci +11 -0
  116. data/integration/apps/ruby/Gemfile +11 -0
  117. data/integration/apps/ruby/README.md +70 -0
  118. data/integration/apps/ruby/agent.yaml +3 -0
  119. data/integration/apps/ruby/app/datadog.rb +13 -0
  120. data/integration/apps/ruby/app/fibonacci.rb +58 -0
  121. data/integration/apps/ruby/bin/run +20 -0
  122. data/integration/apps/ruby/bin/setup +17 -0
  123. data/integration/apps/ruby/bin/test +21 -0
  124. data/integration/apps/ruby/docker-compose.ci.yml +51 -0
  125. data/integration/apps/ruby/docker-compose.yml +63 -0
  126. data/integration/apps/ruby/script/build-images +38 -0
  127. data/integration/apps/ruby/script/ci +50 -0
  128. data/integration/images/agent/Dockerfile +2 -0
  129. data/integration/images/agent/agent.yaml +3 -0
  130. data/integration/images/include/datadog/analyzer.rb +71 -0
  131. data/integration/images/include/datadog/demo_env.rb +101 -0
  132. data/integration/images/include/http-health-check +33 -0
  133. data/integration/images/ruby/2.0/Dockerfile +54 -0
  134. data/integration/images/ruby/2.1/Dockerfile +54 -0
  135. data/integration/images/ruby/2.2/Dockerfile +54 -0
  136. data/integration/images/ruby/2.3/Dockerfile +70 -0
  137. data/integration/images/ruby/2.4/Dockerfile +54 -0
  138. data/integration/images/ruby/2.5/Dockerfile +54 -0
  139. data/integration/images/ruby/2.6/Dockerfile +54 -0
  140. data/integration/images/ruby/2.7/Dockerfile +54 -0
  141. data/integration/images/ruby/3.0/Dockerfile +54 -0
  142. data/integration/images/wrk/Dockerfile +33 -0
  143. data/integration/images/wrk/scripts/entrypoint.sh +17 -0
  144. data/integration/images/wrk/scripts/scenarios/basic/default.lua +1 -0
  145. data/integration/images/wrk/scripts/scenarios/basic/fibonacci.lua +1 -0
  146. data/integration/script/build-images +43 -0
  147. data/lib/ddtrace.rb +0 -5
  148. data/lib/ddtrace/analytics.rb +2 -0
  149. data/lib/ddtrace/buffer.rb +4 -4
  150. data/lib/ddtrace/configuration.rb +92 -23
  151. data/lib/ddtrace/configuration/base.rb +1 -1
  152. data/lib/ddtrace/configuration/components.rb +2 -2
  153. data/lib/ddtrace/configuration/option_definition.rb +1 -3
  154. data/lib/ddtrace/configuration/options.rb +4 -7
  155. data/lib/ddtrace/configuration/settings.rb +17 -3
  156. data/lib/ddtrace/context.rb +5 -6
  157. data/lib/ddtrace/context_provider.rb +0 -1
  158. data/lib/ddtrace/contrib/action_cable/event.rb +1 -0
  159. data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +1 -3
  160. data/lib/ddtrace/contrib/action_view/event.rb +1 -1
  161. data/lib/ddtrace/contrib/action_view/utils.rb +1 -1
  162. data/lib/ddtrace/contrib/active_record/configuration/resolver.rb +101 -18
  163. data/lib/ddtrace/contrib/active_record/utils.rb +1 -0
  164. data/lib/ddtrace/contrib/active_support/notifications/event.rb +2 -1
  165. data/lib/ddtrace/contrib/active_support/notifications/subscriber.rb +1 -0
  166. data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +9 -5
  167. data/lib/ddtrace/contrib/auto_instrument.rb +1 -0
  168. data/lib/ddtrace/contrib/aws/patcher.rb +1 -0
  169. data/lib/ddtrace/contrib/aws/services.rb +2 -0
  170. data/lib/ddtrace/contrib/configurable.rb +63 -39
  171. data/lib/ddtrace/contrib/configuration/resolver.rb +70 -5
  172. data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +19 -20
  173. data/lib/ddtrace/contrib/configuration/settings.rb +7 -6
  174. data/lib/ddtrace/contrib/cucumber/configuration/settings.rb +0 -10
  175. data/lib/ddtrace/contrib/cucumber/ext.rb +0 -2
  176. data/lib/ddtrace/contrib/cucumber/formatter.rb +5 -11
  177. data/lib/ddtrace/contrib/dalli/patcher.rb +0 -38
  178. data/lib/ddtrace/contrib/delayed_job/plugin.rb +0 -1
  179. data/lib/ddtrace/contrib/elasticsearch/patcher.rb +1 -0
  180. data/lib/ddtrace/contrib/elasticsearch/quantize.rb +3 -2
  181. data/lib/ddtrace/contrib/ethon/easy_patch.rb +5 -5
  182. data/lib/ddtrace/contrib/excon/middleware.rb +2 -6
  183. data/lib/ddtrace/contrib/extensions.rb +27 -3
  184. data/lib/ddtrace/contrib/faraday/middleware.rb +1 -3
  185. data/lib/ddtrace/contrib/faraday/patcher.rb +0 -36
  186. data/lib/ddtrace/contrib/grape/endpoint.rb +8 -15
  187. data/lib/ddtrace/contrib/grape/patcher.rb +0 -42
  188. data/lib/ddtrace/contrib/grpc/datadog_interceptor.rb +8 -8
  189. data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +1 -0
  190. data/lib/ddtrace/contrib/grpc/patcher.rb +0 -36
  191. data/lib/ddtrace/contrib/http/circuit_breaker.rb +1 -3
  192. data/lib/ddtrace/contrib/http/instrumentation.rb +5 -5
  193. data/lib/ddtrace/contrib/httpclient/instrumentation.rb +14 -19
  194. data/lib/ddtrace/contrib/httpclient/patcher.rb +5 -2
  195. data/lib/ddtrace/contrib/httprb/instrumentation.rb +14 -20
  196. data/lib/ddtrace/contrib/httprb/patcher.rb +5 -2
  197. data/lib/ddtrace/contrib/mongodb/instrumentation.rb +2 -0
  198. data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -3
  199. data/lib/ddtrace/contrib/patcher.rb +9 -6
  200. data/lib/ddtrace/contrib/presto/patcher.rb +5 -2
  201. data/lib/ddtrace/contrib/qless/qless_job.rb +1 -0
  202. data/lib/ddtrace/contrib/qless/tracer_cleaner.rb +1 -0
  203. data/lib/ddtrace/contrib/que/ext.rb +19 -19
  204. data/lib/ddtrace/contrib/que/tracer.rb +1 -1
  205. data/lib/ddtrace/contrib/racecar/event.rb +1 -0
  206. data/lib/ddtrace/contrib/rack/configuration/settings.rb +3 -3
  207. data/lib/ddtrace/contrib/rack/middlewares.rb +5 -10
  208. data/lib/ddtrace/contrib/rack/patcher.rb +1 -3
  209. data/lib/ddtrace/contrib/rails/patcher.rb +6 -2
  210. data/lib/ddtrace/contrib/rake/instrumentation.rb +4 -2
  211. data/lib/ddtrace/contrib/redis/configuration/resolver.rb +11 -4
  212. data/lib/ddtrace/contrib/redis/quantize.rb +1 -0
  213. data/lib/ddtrace/contrib/redis/vendor/LICENSE +20 -0
  214. data/lib/ddtrace/contrib/redis/vendor/resolver.rb +6 -7
  215. data/lib/ddtrace/contrib/registry.rb +2 -2
  216. data/lib/ddtrace/contrib/resque/integration.rb +1 -1
  217. data/lib/ddtrace/contrib/resque/resque_job.rb +2 -0
  218. data/lib/ddtrace/contrib/rest_client/request_patch.rb +1 -3
  219. data/lib/ddtrace/contrib/rspec/configuration/settings.rb +0 -10
  220. data/lib/ddtrace/contrib/rspec/example.rb +24 -10
  221. data/lib/ddtrace/contrib/rspec/ext.rb +0 -3
  222. data/lib/ddtrace/contrib/rspec/integration.rb +1 -1
  223. data/lib/ddtrace/contrib/rspec/patcher.rb +0 -2
  224. data/lib/ddtrace/contrib/sequel/utils.rb +5 -6
  225. data/lib/ddtrace/contrib/shoryuken/tracer.rb +0 -1
  226. data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +2 -7
  227. data/lib/ddtrace/contrib/sidekiq/tracing.rb +0 -1
  228. data/lib/ddtrace/contrib/sinatra/env.rb +1 -3
  229. data/lib/ddtrace/contrib/sinatra/headers.rb +1 -3
  230. data/lib/ddtrace/contrib/sinatra/tracer.rb +1 -3
  231. data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +3 -3
  232. data/lib/ddtrace/contrib/sneakers/ext.rb +11 -11
  233. data/lib/ddtrace/contrib/sneakers/tracer.rb +2 -4
  234. data/lib/ddtrace/contrib/status_code_matcher.rb +5 -3
  235. data/lib/ddtrace/correlation.rb +1 -0
  236. data/lib/ddtrace/diagnostics/environment_logger.rb +2 -1
  237. data/lib/ddtrace/distributed_tracing/headers/headers.rb +1 -0
  238. data/lib/ddtrace/distributed_tracing/headers/helpers.rb +1 -3
  239. data/lib/ddtrace/ext/ci.rb +2 -2
  240. data/lib/ddtrace/ext/distributed.rb +1 -1
  241. data/lib/ddtrace/ext/http.rb +1 -1
  242. data/lib/ddtrace/ext/runtime.rb +3 -1
  243. data/lib/ddtrace/forced_tracing.rb +2 -0
  244. data/lib/ddtrace/logger.rb +1 -1
  245. data/lib/ddtrace/metrics.rb +10 -6
  246. data/lib/ddtrace/opentracer/distributed_headers.rb +3 -0
  247. data/lib/ddtrace/opentracer/span.rb +2 -6
  248. data/lib/ddtrace/opentracer/thread_local_scope.rb +1 -0
  249. data/lib/ddtrace/patcher.rb +25 -4
  250. data/lib/ddtrace/pin.rb +8 -61
  251. data/lib/ddtrace/pipeline/span_filter.rb +1 -1
  252. data/lib/ddtrace/propagation/grpc_propagator.rb +1 -0
  253. data/lib/ddtrace/quantization/http.rb +1 -0
  254. data/lib/ddtrace/runtime/cgroup.rb +2 -2
  255. data/lib/ddtrace/runtime/container.rb +27 -29
  256. data/lib/ddtrace/runtime/identity.rb +8 -0
  257. data/lib/ddtrace/sampler.rb +1 -1
  258. data/lib/ddtrace/sampling/rule_sampler.rb +1 -0
  259. data/lib/ddtrace/span.rb +7 -7
  260. data/lib/ddtrace/sync_writer.rb +12 -12
  261. data/lib/ddtrace/tracer.rb +7 -5
  262. data/lib/ddtrace/transport/http.rb +15 -8
  263. data/lib/ddtrace/transport/http/adapters/net.rb +27 -8
  264. data/lib/ddtrace/transport/http/adapters/registry.rb +1 -0
  265. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +2 -4
  266. data/lib/ddtrace/transport/http/builder.rb +7 -1
  267. data/lib/ddtrace/transport/http/env.rb +8 -0
  268. data/lib/ddtrace/transport/http/traces.rb +2 -3
  269. data/lib/ddtrace/transport/io.rb +1 -1
  270. data/lib/ddtrace/transport/io/response.rb +1 -3
  271. data/lib/ddtrace/transport/io/traces.rb +6 -0
  272. data/lib/ddtrace/transport/traces.rb +18 -1
  273. data/lib/ddtrace/utils/compression.rb +27 -0
  274. data/lib/ddtrace/utils/object_set.rb +41 -0
  275. data/lib/ddtrace/utils/only_once.rb +40 -0
  276. data/lib/ddtrace/utils/sequence.rb +17 -0
  277. data/lib/ddtrace/utils/string_table.rb +45 -0
  278. data/lib/ddtrace/utils/time.rb +32 -1
  279. data/lib/ddtrace/vendor/active_record/MIT-LICENSE +20 -0
  280. data/lib/ddtrace/vendor/multipart-post/LICENSE +11 -0
  281. data/lib/ddtrace/vendor/multipart-post/multipart.rb +12 -0
  282. data/lib/ddtrace/vendor/multipart-post/multipart/post.rb +8 -0
  283. data/lib/ddtrace/vendor/multipart-post/multipart/post/composite_read_io.rb +116 -0
  284. data/lib/ddtrace/vendor/multipart-post/multipart/post/multipartable.rb +57 -0
  285. data/lib/ddtrace/vendor/multipart-post/multipart/post/parts.rb +135 -0
  286. data/lib/ddtrace/vendor/multipart-post/multipart/post/version.rb +9 -0
  287. data/lib/ddtrace/vendor/multipart-post/net/http/post/multipart.rb +32 -0
  288. data/lib/ddtrace/version.rb +1 -1
  289. data/lib/ddtrace/workers.rb +5 -0
  290. data/lib/ddtrace/workers/async.rb +11 -3
  291. data/lib/ddtrace/workers/loop.rb +17 -3
  292. data/lib/ddtrace/workers/polling.rb +1 -0
  293. data/lib/ddtrace/workers/queue.rb +1 -0
  294. data/lib/ddtrace/workers/trace_writer.rb +10 -10
  295. data/lib/ddtrace/writer.rb +7 -4
  296. metadata +152 -402
  297. data/lib/ddtrace/augmentation.rb +0 -13
  298. data/lib/ddtrace/augmentation/method_wrapper.rb +0 -20
  299. data/lib/ddtrace/augmentation/method_wrapping.rb +0 -38
  300. data/lib/ddtrace/augmentation/shim.rb +0 -102
  301. data/lib/ddtrace/contrib/rspec/example_group.rb +0 -61
  302. data/lib/ddtrace/monkey.rb +0 -58
File without changes
File without changes
@@ -0,0 +1 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ APP_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5
+ APP_DIR=${APP_SCRIPT_DIR%/script}
6
+ cd $APP_DIR
7
+
8
+ while getopts ":v:" opt; do
9
+ case $opt in
10
+ v)
11
+ APP_RUBY_VERSION=$OPTARG
12
+ ;;
13
+ \?)
14
+ echo "Invalid option: -$OPTARG" >&2
15
+ exit 1
16
+ ;;
17
+ :)
18
+ echo "Option -$OPTARG requires an argument." >&2
19
+ exit 1
20
+ ;;
21
+ esac
22
+ done
23
+
24
+ echo "== Building Rails 5 images... =="
25
+ if [ -v APP_RUBY_VERSION ]; then
26
+ docker build --build-arg BASE_IMAGE=datadog/dd-apm-demo:rb-$APP_RUBY_VERSION -t datadog/dd-apm-demo:rb-$APP_RUBY_VERSION-rails-five .
27
+ else
28
+ docker build --build-arg BASE_IMAGE=datadog/dd-apm-demo:rb-2.3 -t datadog/dd-apm-demo:rb-2.3-rails-five .
29
+ docker build --build-arg BASE_IMAGE=datadog/dd-apm-demo:rb-2.4 -t datadog/dd-apm-demo:rb-2.4-rails-five .
30
+ docker build --build-arg BASE_IMAGE=datadog/dd-apm-demo:rb-2.5 -t datadog/dd-apm-demo:rb-2.5-rails-five .
31
+ docker build --build-arg BASE_IMAGE=datadog/dd-apm-demo:rb-2.6 -t datadog/dd-apm-demo:rb-2.6-rails-five .
32
+ docker build --build-arg BASE_IMAGE=datadog/dd-apm-demo:rb-2.7 -t datadog/dd-apm-demo:rb-2.7-rails-five .
33
+ docker build --build-arg BASE_IMAGE=datadog/dd-apm-demo:rb-3.0 -t datadog/dd-apm-demo:rb-3.0-rails-five .
34
+ fi
35
+ echo "== Done building Rails 5 images. =="
@@ -0,0 +1,50 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+
4
+ APP_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5
+ APP_DIR=${APP_SCRIPT_DIR%/script}
6
+ cd $APP_DIR
7
+
8
+ # Parse options
9
+ while getopts "v:" opt; do
10
+ case $opt in
11
+ v)
12
+ APP_RUBY_VERSION=$OPTARG
13
+ ;;
14
+ \?)
15
+ echo "Invalid option: -$OPTARG" >&2
16
+ exit 1
17
+ ;;
18
+ :)
19
+ echo "Option -$OPTARG requires an argument." >&2
20
+ exit 1
21
+ ;;
22
+ esac
23
+ done
24
+
25
+ # Validate options
26
+ if [ -z ${APP_RUBY_VERSION+x} ]; then
27
+ echo "You must specify a Ruby version with -v. (e.g. 2.7)" >&2
28
+ exit 1
29
+ fi
30
+
31
+ # Set configuration
32
+ APP_BASE_IMAGE=${APP_BASE_IMAGE:-datadog/dd-apm-demo:rb-$APP_RUBY_VERSION}
33
+ APP_IMAGE=${APP_IMAGE:-$APP_BASE_IMAGE-rails-five}
34
+ APP_COMPOSE_FILES="-f docker-compose.ci.yml"
35
+
36
+ echo "== Running integration tests... =="
37
+ echo " - App: rails-five"
38
+ echo " - Ruby version: $APP_RUBY_VERSION"
39
+ echo " - Base image: $APP_BASE_IMAGE"
40
+ echo " - App image: $APP_IMAGE"
41
+ echo ""
42
+
43
+ # Pull/build any missing images
44
+ APP_IMAGE=$APP_IMAGE docker-compose $APP_COMPOSE_FILES build
45
+
46
+ # Run the test suite
47
+ APP_IMAGE=$APP_IMAGE docker-compose $APP_COMPOSE_FILES run integration-tester
48
+
49
+ # Cleanup
50
+ APP_IMAGE=$APP_IMAGE docker-compose $APP_COMPOSE_FILES down -t 0 --remove-orphans
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'Basic scenarios' do
4
+ include_context 'integration test'
5
+
6
+ context 'default' do
7
+ subject { get('basic/default') }
8
+ it { is_expected.to be_a_kind_of(Net::HTTPOK) }
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'byebug'
2
+ require 'support/integration_helper'
3
+
4
+ RSpec.configure do |config|
5
+ config.include IntegrationHelper
6
+
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.shared_context_metadata_behavior = :apply_to_host_groups
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'net/http'
2
+
3
+ module IntegrationHelper
4
+ shared_context 'integration test' do
5
+ before do
6
+ skip 'Integration tests not enabled.' unless ENV['TEST_INTEGRATION']
7
+ end
8
+
9
+ def hostname
10
+ ENV['TEST_HOSTNAME']
11
+ end
12
+
13
+ def port
14
+ ENV['TEST_PORT']
15
+ end
16
+
17
+ def get(path)
18
+ uri = URI("http://#{hostname}:#{port}/#{path}")
19
+ Net::HTTP.get_response(uri)
20
+ end
21
+ end
22
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1 @@
1
+ export DD_API_KEY=<Your Datadog API key here>
@@ -0,0 +1,2 @@
1
+ .envrc
2
+ .byebug_history
@@ -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,11 @@
1
+ require 'datadog/demo_env'
2
+
3
+ source 'https://rubygems.org' do
4
+ gem 'ffi'
5
+ gem 'google-protobuf'
6
+
7
+ # Choose correct specs for 'ddtrace' demo environment
8
+ gem 'ddtrace', *Datadog::DemoEnv.gem_spec('ddtrace')
9
+
10
+ gem 'byebug'
11
+ end
@@ -0,0 +1,70 @@
1
+ # Ruby: Demo application for Datadog APM
2
+
3
+ A generic Ruby 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 application
24
+
25
+ Run `docker-compose up` to auto-start the application.
26
+
27
+ Alternatively, you can run it manually with:
28
+
29
+ ```sh
30
+ docker-compose run --rm 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
+ - `fibonacci`: Fibonacci number generator
40
+ - `irb`: IRB session
41
+
42
+ Alternatively, set `DD_DEMO_ENV_PROCESS` to run a particular process by default when `bin/run` is run.
43
+
44
+ ##### Features
45
+
46
+ Set `DD_DEMO_ENV_PROCESS` to a comma-delimited list of any of the following values to activate the feature:
47
+
48
+ - `tracing`: Tracing instrumentation
49
+ - `profiling`: Profiling (NOTE: Must also set `DD_PROFILING_ENABLED` to match.)
50
+ - `debug`: Enable diagnostic debug mode
51
+ - `analytics`: Enable trace analytics
52
+ - `runtime_metrics`: Enable runtime metrics
53
+ - `pprof_to_file`: Dump profiling pprof to file instead of agent.
54
+
55
+ e.g. `DD_DEMO_ENV_PROCESS=tracing,profiling`
56
+
57
+ ### Running integration tests
58
+
59
+ You can run integration tests using the following and substituting for the Ruby major and minor version (e.g. `2.7`)
60
+
61
+ ```sh
62
+ ./script/build-images -v <RUBY_VERSION>
63
+ ./script/ci -v <RUBY_VERSION>
64
+ ```
65
+
66
+ Or inside a running container:
67
+
68
+ ```sh
69
+ ./bin/test
70
+ ```
@@ -0,0 +1,3 @@
1
+ use_dogstatsd: true
2
+ dogstatsd_port: 8125
3
+ dogstatsd_non_local_traffic: true
@@ -0,0 +1,13 @@
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?('pprof_to_file')
10
+ # Reconfigure transport to write pprof to file
11
+ c.profiling.exporter.transport = Datadog::DemoEnv.profiler_file_transport
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ require_relative 'datadog'
2
+
3
+ def fib(n)
4
+ n <= 1 ? n : fib(n-1) + fib(n-2)
5
+ end
6
+
7
+ def trace(*options, &block)
8
+ raise ArgumentError('Must provide trace block') unless block_given?
9
+
10
+ if Datadog::DemoEnv.feature?('tracing')
11
+ Datadog.tracer.trace(*options, &block)
12
+ else
13
+ yield
14
+ end
15
+ end
16
+
17
+ def generate_fib
18
+ loop do
19
+ n = rand(25..35)
20
+
21
+ trace('compute.fibonacci') do |span|
22
+ result = fib(n)
23
+ span.set_metric('operation.fibonacci.n', n)
24
+ span.set_metric('operation.fibonacci.result', result)
25
+ yield(span) if block_given?
26
+ end
27
+
28
+ sleep(0.1)
29
+ end
30
+ end
31
+
32
+ if defined?(Ractor)
33
+ # Ractor version
34
+ # DEV: Disabled for now because Ractors cannot access ENV.
35
+ # This results in a shareable-object violation.
36
+ # Enable when we figure out how to make DemoEnv ractor-safe.
37
+
38
+ # require 'securerandom'
39
+ # ractors = []
40
+
41
+ # 3.times do |i|
42
+ # ractors << Ractor.new do
43
+ # ractor_id = SecureRandom.uuid
44
+ # generate_fib { |span| span.set_tag('ractor.id', ractor_id) }
45
+ # end
46
+ # end
47
+
48
+ # # Wait indefinitely for ractors
49
+ # loop do
50
+ # ractors.collect(&:take)
51
+ # end
52
+
53
+ # DEV: Use single-threaded version instead for now...
54
+ generate_fib
55
+ else
56
+ # Single-threaded version
57
+ generate_fib
58
+ end
@@ -0,0 +1,20 @@
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 'fibonacci'
10
+ 'bundle exec ruby app/fibonacci.rb'
11
+ when 'irb'
12
+ "bundle exec #{profiling}irb"
13
+ when nil, ''
14
+ abort("\n== ERROR: Must specify a application process! ==")
15
+ else
16
+ abort("\n== ERROR: Unknown application process '#{process}' ==")
17
+ end
18
+
19
+ puts "Run: #{command}"
20
+ 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,21 @@
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
+ puts "\n== Run test suite =="
18
+ # DEV: There are no RSpec tests right now.
19
+ # Re-enable this when we have something worth testing.
20
+ # system!('rspec')
21
+ end
@@ -0,0 +1,51 @@
1
+ version: '3.4'
2
+ services:
3
+ app:
4
+ # Build at dd-trace-rb level to copy in current code
5
+ # and use it as the `ddtrace` gem.
6
+ build:
7
+ context: ../../..
8
+ dockerfile: integration/apps/ruby/Dockerfile-ci
9
+ args:
10
+ BASE_IMAGE: ${APP_IMAGE}
11
+ depends_on:
12
+ - ddagent
13
+ environment:
14
+ - BUNDLE_GEMFILE=/app/Gemfile
15
+ - DD_AGENT_HOST=ddagent
16
+ - DD_METRIC_AGENT_PORT=8125
17
+ - DD_TRACE_AGENT_PORT=8126
18
+ - DD_HEALTH_METRICS_ENABLED=true
19
+ - DD_SERVICE=acme-ruby
20
+ - DD_PROFILING_ENABLED=true
21
+ # Use these to choose what is run
22
+ - DD_DEMO_ENV_PROCESS=fibonacci
23
+ - DD_DEMO_ENV_FEATURES=tracing
24
+ stdin_open: true
25
+ tty: true
26
+ ddagent:
27
+ image: datadog/dd-apm-demo:agent
28
+ environment:
29
+ - DD_APM_ENABLED=true
30
+ - DD_PROCESS_AGENT_ENABLED=false
31
+ - DD_BIND_HOST=0.0.0.0
32
+ - DD_API_KEY=invalid_api_key
33
+ - LOG_LEVEL=DEBUG
34
+ - DD_LOGS_STDOUT=yes
35
+ - DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true
36
+ expose:
37
+ - "8125/udp"
38
+ - "8126"
39
+ # Build at dd-trace-rb level to copy in current code
40
+ # and use it as the `ddtrace` gem.
41
+ integration-tester:
42
+ build:
43
+ context: ../../..
44
+ dockerfile: integration/apps/ruby/Dockerfile-ci
45
+ args:
46
+ BASE_IMAGE: ${APP_IMAGE}
47
+ command: bin/test
48
+ # volumes:
49
+ # - .:/app
50
+ # - ../../images/include:/vendor/dd-demo
51
+ # - ../../..:/vendor/dd-trace-rb