ddtrace 0.44.0 → 0.48.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 +183 -15
- data/.circleci/images/primary/Dockerfile-2.0.0 +11 -1
- data/.circleci/images/primary/Dockerfile-2.1.10 +11 -1
- data/.circleci/images/primary/Dockerfile-2.2.10 +11 -1
- data/.circleci/images/primary/Dockerfile-2.3.8 +10 -0
- data/.circleci/images/primary/Dockerfile-2.4.6 +10 -0
- data/.circleci/images/primary/Dockerfile-2.5.6 +10 -0
- data/.circleci/images/primary/Dockerfile-2.6.4 +10 -0
- data/.circleci/images/primary/Dockerfile-2.7.0 +10 -0
- data/.circleci/images/primary/Dockerfile-jruby-9.2-latest +88 -0
- data/.circleci/images/primary/{Dockerfile-jruby-9.2 → Dockerfile-jruby-9.2.0.0} +1 -5
- data/.circleci/images/primary/Dockerfile-truffleruby-21.0.0 +73 -0
- data/.github/workflows/create-next-milestone.yml +2 -2
- data/.gitlab-ci.yml +18 -18
- data/.rubocop.yml +269 -7
- data/.rubocop_todo.yml +438 -0
- data/.simplecov +6 -0
- data/Appraisals +87 -9
- data/CHANGELOG.md +238 -1
- data/Gemfile +63 -3
- data/LICENSE-3rdparty.csv +2 -0
- data/README.md +1 -0
- data/Rakefile +65 -25
- data/bin/ddtracerb +15 -0
- data/ddtrace.gemspec +9 -36
- data/docker-compose.yml +75 -7
- data/docs/DevelopmentGuide.md +28 -0
- data/docs/GettingStarted.md +162 -68
- data/docs/ProfilingDevelopment.md +88 -0
- data/integration/README.md +67 -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 +28 -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 +8 -5
- data/lib/ddtrace/analytics.rb +2 -0
- data/lib/ddtrace/auto_instrument.rb +3 -0
- data/lib/ddtrace/auto_instrument_base.rb +6 -0
- data/lib/ddtrace/buffer.rb +4 -4
- data/lib/ddtrace/configuration.rb +121 -26
- data/lib/ddtrace/configuration/base.rb +1 -1
- data/lib/ddtrace/configuration/components.rb +87 -5
- data/lib/ddtrace/configuration/option_definition.rb +1 -3
- data/lib/ddtrace/configuration/options.rb +4 -7
- data/lib/ddtrace/configuration/settings.rb +48 -3
- data/lib/ddtrace/context.rb +5 -6
- data/lib/ddtrace/context_provider.rb +0 -1
- data/lib/ddtrace/contrib/action_cable/event.rb +1 -0
- data/lib/ddtrace/contrib/action_cable/integration.rb +7 -0
- data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +1 -3
- data/lib/ddtrace/contrib/action_pack/integration.rb +7 -0
- data/lib/ddtrace/contrib/action_view/event.rb +1 -1
- data/lib/ddtrace/contrib/action_view/integration.rb +7 -0
- data/lib/ddtrace/contrib/action_view/utils.rb +1 -1
- data/lib/ddtrace/contrib/active_record/configuration/makara_resolver.rb +30 -0
- data/lib/ddtrace/contrib/active_record/configuration/resolver.rb +107 -18
- data/lib/ddtrace/contrib/active_record/integration.rb +7 -0
- data/lib/ddtrace/contrib/active_record/utils.rb +57 -20
- data/lib/ddtrace/contrib/active_support/integration.rb +7 -1
- 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 +49 -0
- data/lib/ddtrace/contrib/aws/patcher.rb +1 -0
- data/lib/ddtrace/contrib/aws/services.rb +2 -0
- data/lib/ddtrace/contrib/configurable.rb +63 -39
- data/lib/ddtrace/contrib/configuration/resolver.rb +70 -5
- data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +19 -20
- data/lib/ddtrace/contrib/configuration/settings.rb +7 -6
- 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/cucumber/integration.rb +5 -0
- data/lib/ddtrace/contrib/dalli/patcher.rb +0 -38
- data/lib/ddtrace/contrib/delayed_job/plugin.rb +0 -1
- data/lib/ddtrace/contrib/elasticsearch/patcher.rb +1 -0
- data/lib/ddtrace/contrib/elasticsearch/quantize.rb +3 -2
- data/lib/ddtrace/contrib/ethon/easy_patch.rb +10 -9
- data/lib/ddtrace/contrib/excon/middleware.rb +2 -6
- data/lib/ddtrace/contrib/extensions.rb +53 -3
- 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/configuration/settings.rb +32 -0
- data/lib/ddtrace/contrib/httpclient/ext.rb +17 -0
- data/lib/ddtrace/contrib/httpclient/instrumentation.rb +147 -0
- data/lib/ddtrace/contrib/httpclient/integration.rb +43 -0
- data/lib/ddtrace/contrib/httpclient/patcher.rb +38 -0
- data/lib/ddtrace/contrib/httprb/instrumentation.rb +14 -20
- data/lib/ddtrace/contrib/httprb/patcher.rb +5 -2
- data/lib/ddtrace/contrib/mongodb/instrumentation.rb +2 -0
- data/lib/ddtrace/contrib/mongodb/subscribers.rb +2 -3
- data/lib/ddtrace/contrib/patchable.rb +18 -7
- data/lib/ddtrace/contrib/patcher.rb +9 -6
- data/lib/ddtrace/contrib/presto/patcher.rb +5 -2
- 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/integration.rb +7 -0
- data/lib/ddtrace/contrib/rack/middlewares.rb +6 -11
- data/lib/ddtrace/contrib/rack/patcher.rb +1 -3
- data/lib/ddtrace/contrib/rack/request_queue.rb +6 -1
- data/lib/ddtrace/contrib/rails/auto_instrument_railtie.rb +10 -0
- data/lib/ddtrace/contrib/rails/patcher.rb +6 -2
- data/lib/ddtrace/contrib/rails/utils.rb +4 -0
- data/lib/ddtrace/contrib/rake/instrumentation.rb +4 -2
- data/lib/ddtrace/contrib/rake/integration.rb +1 -1
- data/lib/ddtrace/contrib/redis/configuration/resolver.rb +11 -4
- 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/configuration/settings.rb +17 -1
- data/lib/ddtrace/contrib/resque/integration.rb +1 -1
- data/lib/ddtrace/contrib/resque/patcher.rb +4 -4
- data/lib/ddtrace/contrib/resque/resque_job.rb +24 -1
- 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 +6 -1
- data/lib/ddtrace/contrib/rspec/patcher.rb +0 -2
- data/lib/ddtrace/contrib/sequel/utils.rb +5 -6
- data/lib/ddtrace/contrib/shoryuken/configuration/settings.rb +1 -0
- data/lib/ddtrace/contrib/shoryuken/tracer.rb +7 -4
- 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 +3 -2
- data/lib/ddtrace/distributed_tracing/headers/headers.rb +1 -0
- data/lib/ddtrace/distributed_tracing/headers/helpers.rb +1 -3
- data/lib/ddtrace/error.rb +2 -0
- data/lib/ddtrace/ext/ci.rb +43 -10
- data/lib/ddtrace/ext/distributed.rb +1 -1
- data/lib/ddtrace/ext/git.rb +0 -1
- data/lib/ddtrace/ext/http.rb +1 -1
- data/lib/ddtrace/ext/profiling.rb +52 -0
- data/lib/ddtrace/ext/runtime.rb +3 -1
- data/lib/ddtrace/ext/transport.rb +1 -0
- data/lib/ddtrace/forced_tracing.rb +2 -0
- data/lib/ddtrace/logger.rb +1 -1
- data/lib/ddtrace/metrics.rb +14 -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 +25 -4
- data/lib/ddtrace/pin.rb +8 -61
- data/lib/ddtrace/pipeline/span_filter.rb +1 -1
- data/lib/ddtrace/profiling.rb +54 -0
- data/lib/ddtrace/profiling/backtrace_location.rb +32 -0
- data/lib/ddtrace/profiling/buffer.rb +41 -0
- data/lib/ddtrace/profiling/collectors/stack.rb +253 -0
- data/lib/ddtrace/profiling/encoding/profile.rb +31 -0
- data/lib/ddtrace/profiling/event.rb +13 -0
- data/lib/ddtrace/profiling/events/stack.rb +102 -0
- data/lib/ddtrace/profiling/exporter.rb +23 -0
- data/lib/ddtrace/profiling/ext/cpu.rb +54 -0
- data/lib/ddtrace/profiling/ext/cthread.rb +134 -0
- data/lib/ddtrace/profiling/ext/forking.rb +97 -0
- data/lib/ddtrace/profiling/flush.rb +41 -0
- data/lib/ddtrace/profiling/pprof/builder.rb +121 -0
- data/lib/ddtrace/profiling/pprof/converter.rb +85 -0
- data/lib/ddtrace/profiling/pprof/message_set.rb +12 -0
- data/lib/ddtrace/profiling/pprof/payload.rb +18 -0
- data/lib/ddtrace/profiling/pprof/pprof.proto +212 -0
- data/lib/ddtrace/profiling/pprof/pprof_pb.rb +81 -0
- data/lib/ddtrace/profiling/pprof/stack_sample.rb +90 -0
- data/lib/ddtrace/profiling/pprof/string_table.rb +10 -0
- data/lib/ddtrace/profiling/pprof/template.rb +114 -0
- data/lib/ddtrace/profiling/preload.rb +3 -0
- data/lib/ddtrace/profiling/profiler.rb +28 -0
- data/lib/ddtrace/profiling/recorder.rb +87 -0
- data/lib/ddtrace/profiling/scheduler.rb +84 -0
- data/lib/ddtrace/profiling/tasks/setup.rb +77 -0
- data/lib/ddtrace/profiling/transport/client.rb +12 -0
- data/lib/ddtrace/profiling/transport/http.rb +122 -0
- data/lib/ddtrace/profiling/transport/http/api.rb +43 -0
- data/lib/ddtrace/profiling/transport/http/api/endpoint.rb +90 -0
- data/lib/ddtrace/profiling/transport/http/api/instance.rb +36 -0
- data/lib/ddtrace/profiling/transport/http/api/spec.rb +40 -0
- data/lib/ddtrace/profiling/transport/http/builder.rb +28 -0
- data/lib/ddtrace/profiling/transport/http/client.rb +33 -0
- data/lib/ddtrace/profiling/transport/http/response.rb +21 -0
- data/lib/ddtrace/profiling/transport/io.rb +30 -0
- data/lib/ddtrace/profiling/transport/io/client.rb +27 -0
- data/lib/ddtrace/profiling/transport/io/response.rb +16 -0
- data/lib/ddtrace/profiling/transport/parcel.rb +17 -0
- data/lib/ddtrace/profiling/transport/request.rb +15 -0
- data/lib/ddtrace/profiling/transport/response.rb +8 -0
- data/lib/ddtrace/propagation/grpc_propagator.rb +1 -0
- data/lib/ddtrace/propagation/http_propagator.rb +17 -2
- data/lib/ddtrace/quantization/http.rb +1 -0
- data/lib/ddtrace/runtime/cgroup.rb +2 -2
- data/lib/ddtrace/runtime/container.rb +32 -26
- data/lib/ddtrace/runtime/identity.rb +8 -0
- data/lib/ddtrace/sampler.rb +1 -1
- data/lib/ddtrace/sampling/rule_sampler.rb +4 -9
- data/lib/ddtrace/span.rb +7 -7
- data/lib/ddtrace/sync_writer.rb +12 -12
- data/lib/ddtrace/tasks/exec.rb +48 -0
- data/lib/ddtrace/tasks/help.rb +14 -0
- data/lib/ddtrace/tracer.rb +28 -5
- data/lib/ddtrace/transport/http.rb +15 -8
- data/lib/ddtrace/transport/http/adapters/net.rb +27 -8
- 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 +7 -1
- data/lib/ddtrace/transport/http/env.rb +8 -0
- data/lib/ddtrace/transport/http/traces.rb +2 -3
- data/lib/ddtrace/transport/io.rb +1 -1
- data/lib/ddtrace/transport/io/client.rb +15 -8
- data/lib/ddtrace/transport/io/response.rb +1 -3
- data/lib/ddtrace/transport/io/traces.rb +6 -0
- data/lib/ddtrace/transport/parcel.rb +4 -0
- data/lib/ddtrace/transport/traces.rb +18 -1
- data/lib/ddtrace/utils/compression.rb +27 -0
- data/lib/ddtrace/utils/object_set.rb +41 -0
- data/lib/ddtrace/utils/only_once.rb +40 -0
- data/lib/ddtrace/utils/sequence.rb +17 -0
- data/lib/ddtrace/utils/string_table.rb +45 -0
- data/lib/ddtrace/utils/time.rb +32 -1
- data/lib/ddtrace/vendor/active_record/MIT-LICENSE +20 -0
- data/lib/ddtrace/vendor/multipart-post/LICENSE +11 -0
- data/lib/ddtrace/vendor/multipart-post/multipart.rb +12 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post.rb +8 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/composite_read_io.rb +116 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/multipartable.rb +57 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/parts.rb +135 -0
- data/lib/ddtrace/vendor/multipart-post/multipart/post/version.rb +9 -0
- data/lib/ddtrace/vendor/multipart-post/net/http/post/multipart.rb +32 -0
- data/lib/ddtrace/version.rb +3 -1
- data/lib/ddtrace/workers.rb +5 -0
- data/lib/ddtrace/workers/async.rb +11 -3
- data/lib/ddtrace/workers/loop.rb +17 -3
- data/lib/ddtrace/workers/polling.rb +1 -0
- data/lib/ddtrace/workers/queue.rb +1 -0
- data/lib/ddtrace/workers/runtime_metrics.rb +14 -1
- data/lib/ddtrace/workers/trace_writer.rb +10 -10
- data/lib/ddtrace/writer.rb +7 -4
- metadata +213 -379
- 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,114 @@
|
|
|
1
|
+
require 'ddtrace/profiling/pprof/payload'
|
|
2
|
+
require 'ddtrace/profiling/pprof/message_set'
|
|
3
|
+
require 'ddtrace/profiling/pprof/builder'
|
|
4
|
+
|
|
5
|
+
require 'ddtrace/profiling/events/stack'
|
|
6
|
+
require 'ddtrace/profiling/pprof/stack_sample'
|
|
7
|
+
|
|
8
|
+
module Datadog
|
|
9
|
+
module Profiling
|
|
10
|
+
module Pprof
|
|
11
|
+
# Converts a collection of profiling events into a Perftools::Profiles::Profile
|
|
12
|
+
class Template
|
|
13
|
+
DEFAULT_MAPPINGS = {
|
|
14
|
+
Events::StackSample => Pprof::StackSample
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
attr_reader \
|
|
18
|
+
:builder,
|
|
19
|
+
:converters,
|
|
20
|
+
:sample_type_mappings
|
|
21
|
+
|
|
22
|
+
def self.for_event_classes(event_classes)
|
|
23
|
+
# Build a map of event class --> converter class
|
|
24
|
+
mappings = event_classes.each_with_object({}) do |event_class, m|
|
|
25
|
+
converter_class = DEFAULT_MAPPINGS[event_class]
|
|
26
|
+
raise NoProfilingEventConversionError, event_class unless converter_class
|
|
27
|
+
|
|
28
|
+
m[event_class] = converter_class
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
new(mappings)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def initialize(mappings)
|
|
35
|
+
@builder = Builder.new
|
|
36
|
+
@converters = Hash.new { |_h, event_class| raise NoProfilingEventConversionError, event_class }
|
|
37
|
+
@sample_type_mappings = Hash.new { |_h, type| raise UnknownSampleTypeMappingError, type }
|
|
38
|
+
|
|
39
|
+
# Add default mapping
|
|
40
|
+
builder.mappings.fetch($PROGRAM_NAME, &builder.method(:build_mapping))
|
|
41
|
+
|
|
42
|
+
# Combine all sample types from each converter class
|
|
43
|
+
types = mappings.values.each_with_object({}) do |converter_class, t|
|
|
44
|
+
t.merge!(converter_class.sample_value_types)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Build the sample types into sample type objects
|
|
48
|
+
types.each do |type_name, type_args|
|
|
49
|
+
index = nil
|
|
50
|
+
|
|
51
|
+
sample_type = builder.sample_types.fetch(*type_args) do |id, type, unit|
|
|
52
|
+
index = id
|
|
53
|
+
builder.build_value_type(type, unit)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Create mapping between the type and index to which its assigned.
|
|
57
|
+
# Do this for faster lookup while building profile sample values.
|
|
58
|
+
sample_type_mappings[type_name] = index || builder.sample_types.messages.index(sample_type)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Freeze them so they can't be modified.
|
|
62
|
+
# We don't want the number of sample types to vary between samples within the same profile.
|
|
63
|
+
builder.sample_types.freeze
|
|
64
|
+
sample_type_mappings.freeze
|
|
65
|
+
|
|
66
|
+
# Add converters
|
|
67
|
+
mappings.each do |event_class, converter_class|
|
|
68
|
+
converters[event_class] = converter_class.new(builder, sample_type_mappings)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
converters.freeze
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def add_events!(event_class, events)
|
|
75
|
+
converters[event_class].add_events!(events)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def to_pprof
|
|
79
|
+
profile = builder.build_profile
|
|
80
|
+
data = builder.encode_profile(profile)
|
|
81
|
+
types = sample_type_mappings.keys
|
|
82
|
+
|
|
83
|
+
Payload.new(data, types)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Error when an unknown event type is given to be converted
|
|
87
|
+
class NoProfilingEventConversionError < ArgumentError
|
|
88
|
+
attr_reader :type
|
|
89
|
+
|
|
90
|
+
def initialize(type)
|
|
91
|
+
@type = type
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def message
|
|
95
|
+
"Profiling event type '#{type}' cannot be converted to pprof."
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Error when the mapping of a sample type to value index is unknown
|
|
100
|
+
class UnknownSampleTypeMappingError < ArgumentError
|
|
101
|
+
attr_reader :type
|
|
102
|
+
|
|
103
|
+
def initialize(type)
|
|
104
|
+
@type = type
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def message
|
|
108
|
+
"Mapping for sample value type '#{type}' is unknown."
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Datadog
|
|
2
|
+
# Profiling entry point, which coordinates collectors and a scheduler
|
|
3
|
+
class Profiler
|
|
4
|
+
attr_reader \
|
|
5
|
+
:collectors,
|
|
6
|
+
:scheduler
|
|
7
|
+
|
|
8
|
+
def initialize(collectors, scheduler)
|
|
9
|
+
@collectors = collectors
|
|
10
|
+
@scheduler = scheduler
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def start
|
|
14
|
+
collectors.each(&:start)
|
|
15
|
+
scheduler.start
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def shutdown!
|
|
19
|
+
collectors.each do |collector|
|
|
20
|
+
collector.enabled = false
|
|
21
|
+
collector.stop(true)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
scheduler.enabled = false
|
|
25
|
+
scheduler.stop(true)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'ddtrace/profiling/buffer'
|
|
2
|
+
require 'ddtrace/profiling/flush'
|
|
3
|
+
|
|
4
|
+
module Datadog
|
|
5
|
+
module Profiling
|
|
6
|
+
# Stores profiling events gathered by `Collector`s
|
|
7
|
+
class Recorder
|
|
8
|
+
attr_reader :max_size
|
|
9
|
+
|
|
10
|
+
def initialize(event_classes, max_size)
|
|
11
|
+
@buffers = {}
|
|
12
|
+
@last_flush_time = Time.now.utc
|
|
13
|
+
@max_size = max_size
|
|
14
|
+
|
|
15
|
+
# Add a buffer for each class
|
|
16
|
+
event_classes.each do |event_class|
|
|
17
|
+
@buffers[event_class] = Profiling::Buffer.new(max_size)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def [](event_class)
|
|
22
|
+
@buffers[event_class]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def push(events)
|
|
26
|
+
if events.is_a?(Array)
|
|
27
|
+
# Push multiple events
|
|
28
|
+
event_class = events.first.class
|
|
29
|
+
raise UnknownEventError, event_class unless @buffers.key?(event_class)
|
|
30
|
+
|
|
31
|
+
@buffers[event_class].concat(events)
|
|
32
|
+
else
|
|
33
|
+
# Push single event
|
|
34
|
+
event_class = events.class
|
|
35
|
+
raise UnknownEventError, event_class unless @buffers.key?(event_class)
|
|
36
|
+
|
|
37
|
+
@buffers[event_class].push(events)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def flush
|
|
42
|
+
event_count = 0
|
|
43
|
+
|
|
44
|
+
event_groups, start, finish = update_time do
|
|
45
|
+
@buffers.collect do |event_class, buffer|
|
|
46
|
+
events = buffer.pop
|
|
47
|
+
next if events.empty?
|
|
48
|
+
|
|
49
|
+
event_count += events.length
|
|
50
|
+
EventGroup.new(event_class, events)
|
|
51
|
+
end.compact
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
Flush.new(
|
|
55
|
+
start,
|
|
56
|
+
finish,
|
|
57
|
+
event_groups,
|
|
58
|
+
event_count
|
|
59
|
+
)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Error when event of an unknown type is used with the Recorder
|
|
63
|
+
class UnknownEventError < StandardError
|
|
64
|
+
attr_reader :event_class
|
|
65
|
+
|
|
66
|
+
def initialize(event_class)
|
|
67
|
+
@event_class = event_class
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def message
|
|
71
|
+
@message ||= "Unknown event class '#{event_class}' for profiling recorder."
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def update_time
|
|
78
|
+
start = @last_flush_time
|
|
79
|
+
result = yield
|
|
80
|
+
@last_flush_time = Time.now.utc
|
|
81
|
+
|
|
82
|
+
# Return event groups, start time, finish time
|
|
83
|
+
[result, start, @last_flush_time]
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'ddtrace/utils/time'
|
|
2
|
+
|
|
3
|
+
require 'ddtrace/worker'
|
|
4
|
+
require 'ddtrace/workers/polling'
|
|
5
|
+
|
|
6
|
+
module Datadog
|
|
7
|
+
module Profiling
|
|
8
|
+
# Periodically (every DEFAULT_INTERVAL seconds) takes data from the `Recorder` and pushes them to all configured
|
|
9
|
+
# `Exporter`s. Runs on its own background thread.
|
|
10
|
+
class Scheduler < Worker
|
|
11
|
+
include Workers::Polling
|
|
12
|
+
|
|
13
|
+
DEFAULT_INTERVAL = 60
|
|
14
|
+
MIN_INTERVAL = 0
|
|
15
|
+
|
|
16
|
+
attr_reader \
|
|
17
|
+
:exporters,
|
|
18
|
+
:recorder
|
|
19
|
+
|
|
20
|
+
def initialize(recorder, exporters, options = {})
|
|
21
|
+
@recorder = recorder
|
|
22
|
+
@exporters = [exporters].flatten
|
|
23
|
+
|
|
24
|
+
# Workers::Async::Thread settings
|
|
25
|
+
# Restart in forks by default
|
|
26
|
+
self.fork_policy = options[:fork_policy] || Workers::Async::Thread::FORK_POLICY_RESTART
|
|
27
|
+
|
|
28
|
+
# Workers::IntervalLoop settings
|
|
29
|
+
self.loop_base_interval = options[:interval] || DEFAULT_INTERVAL
|
|
30
|
+
|
|
31
|
+
# Workers::Polling settings
|
|
32
|
+
self.enabled = options.key?(:enabled) ? options[:enabled] == true : true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def start
|
|
36
|
+
perform
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def perform
|
|
40
|
+
flush_and_wait
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def loop_back_off?
|
|
44
|
+
false
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def after_fork
|
|
48
|
+
# Clear recorder's buffers by flushing events.
|
|
49
|
+
# Objects from parent process will copy-on-write,
|
|
50
|
+
# and we don't want to send events for the wrong process.
|
|
51
|
+
recorder.flush
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def flush_and_wait
|
|
55
|
+
run_time = Datadog::Utils::Time.measure do
|
|
56
|
+
flush_events
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Update wait time to try to wake consistently on time.
|
|
60
|
+
# Don't drop below the minimum interval.
|
|
61
|
+
self.loop_wait_time = [loop_base_interval - run_time, MIN_INTERVAL].max
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def flush_events
|
|
65
|
+
# Get events from recorder
|
|
66
|
+
flush = recorder.flush
|
|
67
|
+
|
|
68
|
+
# Send events to each exporter
|
|
69
|
+
if flush.event_count > 0
|
|
70
|
+
exporters.each do |exporter|
|
|
71
|
+
begin
|
|
72
|
+
exporter.export(flush)
|
|
73
|
+
rescue StandardError => e
|
|
74
|
+
error_details = "Cause: #{e} Location: #{e.backtrace.first}"
|
|
75
|
+
Datadog.logger.error("Unable to export #{flush.event_count} profiling events. #{error_details}")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
flush
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'ddtrace'
|
|
2
|
+
require 'ddtrace/utils/only_once'
|
|
3
|
+
require 'ddtrace/profiling'
|
|
4
|
+
require 'ddtrace/profiling/ext/cpu'
|
|
5
|
+
require 'ddtrace/profiling/ext/forking'
|
|
6
|
+
|
|
7
|
+
module Datadog
|
|
8
|
+
module Profiling
|
|
9
|
+
module Tasks
|
|
10
|
+
# Takes care of loading our extensions/monkey patches to handle fork() and CPU profiling.
|
|
11
|
+
class Setup
|
|
12
|
+
ACTIVATE_EXTENSIONS_ONLY_ONCE = Datadog::Utils::OnlyOnce.new
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
ACTIVATE_EXTENSIONS_ONLY_ONCE.run do
|
|
16
|
+
begin
|
|
17
|
+
activate_forking_extensions
|
|
18
|
+
activate_cpu_extensions
|
|
19
|
+
setup_at_fork_hooks
|
|
20
|
+
rescue StandardError, ScriptError => e
|
|
21
|
+
log "[DDTRACE] Main extensions unavailable. Cause: #{e.message} Location: #{e.backtrace.first}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def activate_forking_extensions
|
|
29
|
+
if Ext::Forking.supported?
|
|
30
|
+
Ext::Forking.apply!
|
|
31
|
+
elsif Datadog.configuration.profiling.enabled
|
|
32
|
+
# Log warning if profiling was supposed to be activated.
|
|
33
|
+
log '[DDTRACE] Forking extensions skipped; forking not supported.'
|
|
34
|
+
end
|
|
35
|
+
rescue StandardError, ScriptError => e
|
|
36
|
+
log "[DDTRACE] Forking extensions unavailable. Cause: #{e.message} Location: #{e.backtrace.first}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def activate_cpu_extensions
|
|
40
|
+
if Ext::CPU.supported?
|
|
41
|
+
Ext::CPU.apply!
|
|
42
|
+
elsif Datadog.configuration.profiling.enabled
|
|
43
|
+
# Log warning if profiling was supposed to be activated.
|
|
44
|
+
log "[DDTRACE] CPU profiling skipped because native CPU time is not supported: #{Ext::CPU.unsupported_reason}."
|
|
45
|
+
end
|
|
46
|
+
rescue StandardError, ScriptError => e
|
|
47
|
+
log "[DDTRACE] CPU profiling unavailable. Cause: #{e.message} Location: #{e.backtrace.first}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def setup_at_fork_hooks
|
|
51
|
+
if Process.respond_to?(:at_fork)
|
|
52
|
+
Process.at_fork(:child) do
|
|
53
|
+
begin
|
|
54
|
+
# When Ruby forks, clock IDs for each of the threads
|
|
55
|
+
# will change. We can only update these IDs from the
|
|
56
|
+
# execution context of the thread that owns it.
|
|
57
|
+
# This hook will update the IDs for the main thread
|
|
58
|
+
# after a fork occurs.
|
|
59
|
+
Thread.current.send(:update_native_ids) if Thread.current.respond_to?(:update_native_ids, true)
|
|
60
|
+
|
|
61
|
+
# Restart profiler, if enabled
|
|
62
|
+
Datadog.profiler.start if Datadog.profiler
|
|
63
|
+
rescue StandardError => e
|
|
64
|
+
log "[DDTRACE] Error during post-fork hooks. Cause: #{e.message} Location: #{e.backtrace.first}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def log(message)
|
|
71
|
+
# Print to STDOUT for now because logging may not be setup yet...
|
|
72
|
+
puts message
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
require 'ddtrace/ext/runtime'
|
|
2
|
+
require 'ddtrace/ext/transport'
|
|
3
|
+
|
|
4
|
+
require 'ddtrace/runtime/container'
|
|
5
|
+
|
|
6
|
+
require 'ddtrace/profiling/transport/http/builder'
|
|
7
|
+
require 'ddtrace/profiling/transport/http/api'
|
|
8
|
+
|
|
9
|
+
require 'ddtrace/transport/http/adapters/net'
|
|
10
|
+
require 'ddtrace/transport/http/adapters/test'
|
|
11
|
+
require 'ddtrace/transport/http/adapters/unix_socket'
|
|
12
|
+
|
|
13
|
+
module Datadog
|
|
14
|
+
module Profiling
|
|
15
|
+
module Transport
|
|
16
|
+
# TODO: Consolidate with Dataog::Transport::HTTP
|
|
17
|
+
# Namespace for HTTP transport components
|
|
18
|
+
module HTTP
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
# Builds a new Transport::HTTP::Client
|
|
22
|
+
def new(&block)
|
|
23
|
+
Builder.new(&block).to_transport
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Builds a new Transport::HTTP::Client with default settings
|
|
27
|
+
# Pass a block to override any settings.
|
|
28
|
+
def default(options = {})
|
|
29
|
+
new do |transport|
|
|
30
|
+
transport.headers default_headers
|
|
31
|
+
|
|
32
|
+
# Configure adapter & API
|
|
33
|
+
if options[:site] && options[:api_key]
|
|
34
|
+
configure_for_agentless(transport, options)
|
|
35
|
+
else
|
|
36
|
+
configure_for_agent(transport, options)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Additional options
|
|
40
|
+
unless options.empty?
|
|
41
|
+
# Change default API
|
|
42
|
+
transport.default_api = options[:api_version] if options.key?(:api_version)
|
|
43
|
+
|
|
44
|
+
# Add headers
|
|
45
|
+
transport.headers options[:headers] if options.key?(:headers)
|
|
46
|
+
|
|
47
|
+
# Execute on_build callback
|
|
48
|
+
options[:on_build].call(transport) if options[:on_build].is_a?(Proc)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Call block to apply any customization, if provided.
|
|
52
|
+
yield(transport) if block_given?
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def default_headers
|
|
57
|
+
{
|
|
58
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_LANG => Datadog::Ext::Runtime::LANG,
|
|
59
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_LANG_VERSION => Datadog::Ext::Runtime::LANG_VERSION,
|
|
60
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_LANG_INTERPRETER => Datadog::Ext::Runtime::LANG_INTERPRETER,
|
|
61
|
+
Datadog::Ext::Transport::HTTP::HEADER_META_TRACER_VERSION => Datadog::Ext::Runtime::TRACER_VERSION
|
|
62
|
+
}.tap do |headers|
|
|
63
|
+
# Add container ID, if present.
|
|
64
|
+
container_id = Datadog::Runtime::Container.container_id
|
|
65
|
+
headers[Datadog::Ext::Transport::HTTP::HEADER_CONTAINER_ID] = container_id unless container_id.nil?
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def default_adapter
|
|
70
|
+
:net_http
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def default_hostname
|
|
74
|
+
ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_HOST, Datadog::Ext::Transport::HTTP::DEFAULT_HOST)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def default_port
|
|
78
|
+
ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_PORT, Datadog::Ext::Transport::HTTP::DEFAULT_PORT).to_i
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def configure_for_agent(transport, options = {})
|
|
82
|
+
apis = API.agent_defaults
|
|
83
|
+
|
|
84
|
+
hostname = options[:hostname] || default_hostname
|
|
85
|
+
port = options[:port] || default_port
|
|
86
|
+
|
|
87
|
+
adapter_options = {}
|
|
88
|
+
adapter_options[:timeout] = options[:timeout] if options.key?(:timeout)
|
|
89
|
+
adapter_options[:ssl] = options[:ssl] if options.key?(:ssl)
|
|
90
|
+
|
|
91
|
+
transport.adapter default_adapter, hostname, port, adapter_options
|
|
92
|
+
transport.api API::V1, apis[API::V1], default: true
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def configure_for_agentless(transport, options = {})
|
|
96
|
+
apis = API.api_defaults
|
|
97
|
+
|
|
98
|
+
site_uri = URI(format(Datadog::Ext::Profiling::Transport::HTTP::URI_TEMPLATE_DD_API, options[:site]))
|
|
99
|
+
hostname = options[:hostname] || site_uri.host
|
|
100
|
+
port = options[:port] || site_uri.port
|
|
101
|
+
|
|
102
|
+
adapter_options = {}
|
|
103
|
+
adapter_options[:timeout] = options[:timeout] if options.key?(:timeout)
|
|
104
|
+
adapter_options[:ssl] = options[:ssl] || (site_uri.scheme == 'https'.freeze)
|
|
105
|
+
|
|
106
|
+
transport.adapter default_adapter, hostname, port, adapter_options
|
|
107
|
+
transport.api API::V1, apis[API::V1], default: true
|
|
108
|
+
transport.headers(Datadog::Ext::Transport::HTTP::HEADER_DD_API_KEY => options[:api_key])
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Add adapters to registry
|
|
112
|
+
Builder::REGISTRY.set(Datadog::Transport::HTTP::Adapters::Net, :net_http)
|
|
113
|
+
Builder::REGISTRY.set(Datadog::Transport::HTTP::Adapters::Test, :test)
|
|
114
|
+
Builder::REGISTRY.set(Datadog::Transport::HTTP::Adapters::UnixSocket, :unix)
|
|
115
|
+
|
|
116
|
+
private \
|
|
117
|
+
:configure_for_agent,
|
|
118
|
+
:configure_for_agentless
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|