ddtrace 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +79 -0
- data/.rubocop.yml +250 -7
- data/.rubocop_todo.yml +396 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +68 -1
- data/Gemfile +38 -3
- data/Rakefile +5 -23
- data/ddtrace.gemspec +6 -36
- data/docs/DevelopmentGuide.md +28 -0
- data/docs/GettingStarted.md +8 -9
- data/integration/README.md +68 -0
- data/integration/apps/rack/.dockerignore +1 -0
- data/integration/apps/rack/.envrc.sample +1 -0
- data/integration/apps/rack/.gitignore +4 -0
- data/integration/apps/rack/.rspec +1 -0
- data/integration/apps/rack/Dockerfile +25 -0
- data/integration/apps/rack/Dockerfile-ci +11 -0
- data/integration/apps/rack/Gemfile +24 -0
- data/integration/apps/rack/README.md +93 -0
- data/integration/apps/rack/app/acme.rb +80 -0
- data/integration/apps/rack/app/datadog.rb +17 -0
- data/integration/apps/rack/bin/run +22 -0
- data/integration/apps/rack/bin/setup +17 -0
- data/integration/apps/rack/bin/test +24 -0
- data/integration/apps/rack/config.ru +6 -0
- data/integration/apps/rack/config/puma.rb +14 -0
- data/integration/apps/rack/config/unicorn.rb +23 -0
- data/integration/apps/rack/docker-compose.ci.yml +62 -0
- data/integration/apps/rack/docker-compose.yml +78 -0
- data/integration/apps/rack/script/build-images +38 -0
- data/integration/apps/rack/script/ci +50 -0
- data/integration/apps/rack/spec/integration/basic_spec.rb +10 -0
- data/integration/apps/rack/spec/spec_helper.rb +16 -0
- data/integration/apps/rack/spec/support/integration_helper.rb +22 -0
- data/integration/apps/rails-five/.dockerignore +1 -0
- data/integration/apps/rails-five/.env +3 -0
- data/integration/apps/rails-five/.envrc.sample +1 -0
- data/integration/apps/rails-five/.gitignore +30 -0
- data/integration/apps/rails-five/Dockerfile +25 -0
- data/integration/apps/rails-five/Dockerfile-ci +11 -0
- data/integration/apps/rails-five/Gemfile +104 -0
- data/integration/apps/rails-five/README.md +94 -0
- data/integration/apps/rails-five/Rakefile +6 -0
- data/integration/apps/rails-five/app/channels/application_cable/channel.rb +4 -0
- data/integration/apps/rails-five/app/channels/application_cable/connection.rb +4 -0
- data/integration/apps/rails-five/app/controllers/application_controller.rb +2 -0
- data/integration/apps/rails-five/app/controllers/basic_controller.rb +36 -0
- data/integration/apps/rails-five/app/controllers/concerns/.keep +0 -0
- data/integration/apps/rails-five/app/controllers/health_controller.rb +9 -0
- data/integration/apps/rails-five/app/controllers/jobs_controller.rb +12 -0
- data/integration/apps/rails-five/app/jobs/application_job.rb +2 -0
- data/integration/apps/rails-five/app/jobs/test_job.rb +12 -0
- data/integration/apps/rails-five/app/mailers/application_mailer.rb +4 -0
- data/integration/apps/rails-five/app/models/application_record.rb +3 -0
- data/integration/apps/rails-five/app/models/concerns/.keep +0 -0
- data/integration/apps/rails-five/app/models/test.rb +2 -0
- data/integration/apps/rails-five/app/views/layouts/mailer.html.erb +13 -0
- data/integration/apps/rails-five/app/views/layouts/mailer.text.erb +1 -0
- data/integration/apps/rails-five/bin/bundle +3 -0
- data/integration/apps/rails-five/bin/rails +9 -0
- data/integration/apps/rails-five/bin/rake +9 -0
- data/integration/apps/rails-five/bin/run +24 -0
- data/integration/apps/rails-five/bin/setup +27 -0
- data/integration/apps/rails-five/bin/spring +17 -0
- data/integration/apps/rails-five/bin/test +21 -0
- data/integration/apps/rails-five/bin/update +28 -0
- data/integration/apps/rails-five/config.ru +5 -0
- data/integration/apps/rails-five/config/application.rb +97 -0
- data/integration/apps/rails-five/config/boot.rb +4 -0
- data/integration/apps/rails-five/config/cable.yml +10 -0
- data/integration/apps/rails-five/config/credentials.yml.enc +1 -0
- data/integration/apps/rails-five/config/database.yml +28 -0
- data/integration/apps/rails-five/config/environment.rb +5 -0
- data/integration/apps/rails-five/config/environments/development.rb +51 -0
- data/integration/apps/rails-five/config/environments/production.rb +82 -0
- data/integration/apps/rails-five/config/environments/test.rb +43 -0
- data/integration/apps/rails-five/config/initializers/datadog.rb +18 -0
- data/integration/apps/rails-five/config/initializers/filter_parameter_logging.rb +4 -0
- data/integration/apps/rails-five/config/initializers/resque.rb +4 -0
- data/integration/apps/rails-five/config/initializers/rollbar.rb +5 -0
- data/integration/apps/rails-five/config/initializers/wrap_parameters.rb +14 -0
- data/integration/apps/rails-five/config/locales/en.yml +33 -0
- data/integration/apps/rails-five/config/puma.rb +24 -0
- data/integration/apps/rails-five/config/routes.rb +11 -0
- data/integration/apps/rails-five/config/spring.rb +6 -0
- data/integration/apps/rails-five/config/unicorn.rb +29 -0
- data/integration/apps/rails-five/db/migrate/20190927215052_create_tests.rb +11 -0
- data/integration/apps/rails-five/db/schema.rb +23 -0
- data/integration/apps/rails-five/db/seeds.rb +7 -0
- data/integration/apps/rails-five/docker-compose.ci.yml +98 -0
- data/integration/apps/rails-five/docker-compose.yml +100 -0
- data/integration/apps/rails-five/lib/tasks/.keep +0 -0
- data/integration/apps/rails-five/log/.keep +0 -0
- data/integration/apps/rails-five/public/robots.txt +1 -0
- data/integration/apps/rails-five/script/build-images +35 -0
- data/integration/apps/rails-five/script/ci +50 -0
- data/integration/apps/rails-five/spec/integration/basic_spec.rb +10 -0
- data/integration/apps/rails-five/spec/spec_helper.rb +16 -0
- data/integration/apps/rails-five/spec/support/integration_helper.rb +22 -0
- data/integration/apps/rails-five/storage/.keep +0 -0
- data/integration/apps/rails-five/tmp/.keep +0 -0
- data/integration/apps/rails-five/vendor/.keep +0 -0
- data/integration/apps/ruby/.dockerignore +1 -0
- data/integration/apps/ruby/.envrc.sample +1 -0
- data/integration/apps/ruby/.gitignore +2 -0
- data/integration/apps/ruby/Dockerfile +25 -0
- data/integration/apps/ruby/Dockerfile-ci +11 -0
- data/integration/apps/ruby/Gemfile +11 -0
- data/integration/apps/ruby/README.md +70 -0
- data/integration/apps/ruby/agent.yaml +3 -0
- data/integration/apps/ruby/app/datadog.rb +13 -0
- data/integration/apps/ruby/app/fibonacci.rb +58 -0
- data/integration/apps/ruby/bin/run +20 -0
- data/integration/apps/ruby/bin/setup +17 -0
- data/integration/apps/ruby/bin/test +21 -0
- data/integration/apps/ruby/docker-compose.ci.yml +51 -0
- data/integration/apps/ruby/docker-compose.yml +63 -0
- data/integration/apps/ruby/script/build-images +38 -0
- data/integration/apps/ruby/script/ci +50 -0
- data/integration/images/agent/Dockerfile +2 -0
- data/integration/images/agent/agent.yaml +3 -0
- data/integration/images/include/datadog/analyzer.rb +71 -0
- data/integration/images/include/datadog/demo_env.rb +101 -0
- data/integration/images/include/http-health-check +33 -0
- data/integration/images/ruby/2.0/Dockerfile +54 -0
- data/integration/images/ruby/2.1/Dockerfile +54 -0
- data/integration/images/ruby/2.2/Dockerfile +54 -0
- data/integration/images/ruby/2.3/Dockerfile +70 -0
- data/integration/images/ruby/2.4/Dockerfile +54 -0
- data/integration/images/ruby/2.5/Dockerfile +54 -0
- data/integration/images/ruby/2.6/Dockerfile +54 -0
- data/integration/images/ruby/2.7/Dockerfile +54 -0
- data/integration/images/ruby/3.0/Dockerfile +54 -0
- data/integration/images/wrk/Dockerfile +33 -0
- data/integration/images/wrk/scripts/entrypoint.sh +17 -0
- data/integration/images/wrk/scripts/scenarios/basic/default.lua +1 -0
- data/integration/images/wrk/scripts/scenarios/basic/fibonacci.lua +1 -0
- data/integration/script/build-images +43 -0
- data/lib/ddtrace.rb +0 -5
- data/lib/ddtrace/analytics.rb +2 -0
- data/lib/ddtrace/buffer.rb +4 -4
- data/lib/ddtrace/configuration.rb +1 -1
- data/lib/ddtrace/configuration/base.rb +1 -1
- data/lib/ddtrace/configuration/components.rb +2 -2
- data/lib/ddtrace/configuration/option_definition.rb +1 -3
- data/lib/ddtrace/configuration/options.rb +2 -3
- data/lib/ddtrace/configuration/settings.rb +17 -3
- data/lib/ddtrace/context.rb +5 -6
- data/lib/ddtrace/context_provider.rb +1 -0
- data/lib/ddtrace/contrib/action_cable/event.rb +1 -0
- data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +1 -3
- data/lib/ddtrace/contrib/action_view/event.rb +1 -1
- data/lib/ddtrace/contrib/action_view/utils.rb +1 -1
- data/lib/ddtrace/contrib/active_record/configuration/resolver.rb +17 -5
- data/lib/ddtrace/contrib/active_record/utils.rb +1 -0
- data/lib/ddtrace/contrib/active_support/notifications/event.rb +2 -1
- data/lib/ddtrace/contrib/active_support/notifications/subscriber.rb +1 -0
- data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +9 -5
- data/lib/ddtrace/contrib/auto_instrument.rb +1 -0
- data/lib/ddtrace/contrib/aws/patcher.rb +1 -0
- data/lib/ddtrace/contrib/aws/services.rb +1 -0
- data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +1 -4
- data/lib/ddtrace/contrib/cucumber/configuration/settings.rb +0 -10
- data/lib/ddtrace/contrib/cucumber/ext.rb +0 -2
- data/lib/ddtrace/contrib/cucumber/formatter.rb +5 -11
- data/lib/ddtrace/contrib/dalli/patcher.rb +0 -38
- data/lib/ddtrace/contrib/delayed_job/plugin.rb +0 -1
- data/lib/ddtrace/contrib/elasticsearch/quantize.rb +3 -2
- data/lib/ddtrace/contrib/ethon/easy_patch.rb +5 -5
- data/lib/ddtrace/contrib/excon/middleware.rb +2 -6
- data/lib/ddtrace/contrib/extensions.rb +1 -0
- data/lib/ddtrace/contrib/faraday/middleware.rb +1 -3
- data/lib/ddtrace/contrib/faraday/patcher.rb +0 -36
- data/lib/ddtrace/contrib/grape/endpoint.rb +8 -15
- data/lib/ddtrace/contrib/grape/patcher.rb +0 -42
- data/lib/ddtrace/contrib/grpc/datadog_interceptor.rb +8 -8
- data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +1 -0
- data/lib/ddtrace/contrib/grpc/patcher.rb +0 -36
- data/lib/ddtrace/contrib/http/circuit_breaker.rb +1 -3
- data/lib/ddtrace/contrib/http/instrumentation.rb +5 -5
- data/lib/ddtrace/contrib/httpclient/instrumentation.rb +2 -3
- data/lib/ddtrace/contrib/httprb/instrumentation.rb +2 -3
- data/lib/ddtrace/contrib/mongodb/instrumentation.rb +2 -0
- data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -3
- data/lib/ddtrace/contrib/patcher.rb +1 -1
- data/lib/ddtrace/contrib/qless/qless_job.rb +1 -0
- data/lib/ddtrace/contrib/qless/tracer_cleaner.rb +1 -0
- data/lib/ddtrace/contrib/que/ext.rb +19 -19
- data/lib/ddtrace/contrib/que/tracer.rb +1 -1
- data/lib/ddtrace/contrib/racecar/event.rb +1 -0
- data/lib/ddtrace/contrib/rack/configuration/settings.rb +3 -3
- data/lib/ddtrace/contrib/rack/middlewares.rb +5 -10
- data/lib/ddtrace/contrib/rack/patcher.rb +1 -3
- data/lib/ddtrace/contrib/rake/instrumentation.rb +4 -2
- data/lib/ddtrace/contrib/redis/quantize.rb +1 -0
- data/lib/ddtrace/contrib/redis/vendor/LICENSE +20 -0
- data/lib/ddtrace/contrib/redis/vendor/resolver.rb +6 -7
- data/lib/ddtrace/contrib/registry.rb +2 -2
- data/lib/ddtrace/contrib/resque/resque_job.rb +2 -0
- data/lib/ddtrace/contrib/rest_client/request_patch.rb +1 -3
- data/lib/ddtrace/contrib/rspec/configuration/settings.rb +0 -10
- data/lib/ddtrace/contrib/rspec/example.rb +24 -10
- data/lib/ddtrace/contrib/rspec/ext.rb +0 -3
- data/lib/ddtrace/contrib/rspec/integration.rb +1 -1
- data/lib/ddtrace/contrib/rspec/patcher.rb +0 -2
- data/lib/ddtrace/contrib/sequel/utils.rb +5 -6
- data/lib/ddtrace/contrib/shoryuken/tracer.rb +0 -1
- data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +2 -7
- data/lib/ddtrace/contrib/sidekiq/tracing.rb +0 -1
- data/lib/ddtrace/contrib/sinatra/env.rb +1 -3
- data/lib/ddtrace/contrib/sinatra/headers.rb +1 -3
- data/lib/ddtrace/contrib/sinatra/tracer.rb +1 -3
- data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +3 -3
- data/lib/ddtrace/contrib/sneakers/ext.rb +11 -11
- data/lib/ddtrace/contrib/sneakers/tracer.rb +2 -4
- data/lib/ddtrace/contrib/status_code_matcher.rb +5 -3
- data/lib/ddtrace/correlation.rb +1 -0
- data/lib/ddtrace/diagnostics/environment_logger.rb +2 -1
- data/lib/ddtrace/distributed_tracing/headers/headers.rb +1 -0
- data/lib/ddtrace/distributed_tracing/headers/helpers.rb +1 -3
- data/lib/ddtrace/ext/ci.rb +2 -2
- data/lib/ddtrace/ext/distributed.rb +1 -1
- data/lib/ddtrace/ext/http.rb +1 -1
- data/lib/ddtrace/ext/runtime.rb +1 -1
- data/lib/ddtrace/forced_tracing.rb +2 -0
- data/lib/ddtrace/logger.rb +1 -1
- data/lib/ddtrace/metrics.rb +10 -6
- data/lib/ddtrace/opentracer/distributed_headers.rb +3 -0
- data/lib/ddtrace/opentracer/span.rb +2 -6
- data/lib/ddtrace/opentracer/thread_local_scope.rb +1 -0
- data/lib/ddtrace/patcher.rb +2 -3
- data/lib/ddtrace/pin.rb +3 -52
- data/lib/ddtrace/pipeline/span_filter.rb +1 -1
- data/lib/ddtrace/propagation/grpc_propagator.rb +1 -0
- data/lib/ddtrace/quantization/http.rb +1 -0
- data/lib/ddtrace/runtime/cgroup.rb +1 -1
- data/lib/ddtrace/runtime/container.rb +2 -2
- data/lib/ddtrace/sampler.rb +1 -1
- data/lib/ddtrace/sampling/rule_sampler.rb +1 -0
- data/lib/ddtrace/span.rb +7 -7
- data/lib/ddtrace/sync_writer.rb +7 -10
- data/lib/ddtrace/tracer.rb +1 -1
- data/lib/ddtrace/transport/http.rb +1 -3
- data/lib/ddtrace/transport/http/adapters/net.rb +9 -4
- data/lib/ddtrace/transport/http/adapters/registry.rb +1 -0
- data/lib/ddtrace/transport/http/adapters/unix_socket.rb +2 -4
- data/lib/ddtrace/transport/http/builder.rb +2 -0
- data/lib/ddtrace/transport/http/traces.rb +2 -3
- data/lib/ddtrace/transport/io.rb +1 -1
- data/lib/ddtrace/transport/traces.rb +3 -0
- data/lib/ddtrace/utils/time.rb +25 -1
- data/lib/ddtrace/vendor/active_record/MIT-LICENSE +20 -0
- data/lib/ddtrace/version.rb +1 -1
- data/lib/ddtrace/workers.rb +5 -0
- data/lib/ddtrace/workers/async.rb +8 -0
- data/lib/ddtrace/workers/loop.rb +3 -0
- data/lib/ddtrace/workers/polling.rb +1 -0
- data/lib/ddtrace/workers/trace_writer.rb +9 -10
- data/lib/ddtrace/writer.rb +3 -3
- metadata +133 -400
- data/lib/ddtrace/augmentation.rb +0 -13
- data/lib/ddtrace/augmentation/method_wrapper.rb +0 -20
- data/lib/ddtrace/augmentation/method_wrapping.rb +0 -38
- data/lib/ddtrace/augmentation/shim.rb +0 -102
- data/lib/ddtrace/contrib/rspec/example_group.rb +0 -61
- data/lib/ddtrace/monkey.rb +0 -58
|
@@ -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 @@
|
|
|
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,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
|