ddtrace 0.44.0 → 0.48.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,54 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Profiling
|
3
|
+
module Ext
|
4
|
+
# Monkey patches Ruby's `Thread` with our `Ext::CThread` to enable CPU-time profiling
|
5
|
+
module CPU
|
6
|
+
# We cannot apply our CPU extension if a broken rollbar is around because that can cause customer apps to fail
|
7
|
+
# with a SystemStackError: stack level too deep.
|
8
|
+
#
|
9
|
+
# This occurs whenever our extensions to Thread are applied BEFORE rollbar applies its own. This happens
|
10
|
+
# because a loop forms: our extension tries to call Thread#initialize, but it's intercepted by rollbar, which
|
11
|
+
# then tries to call the original Thread#initialize as well, but instead alls our extension, leading to stack
|
12
|
+
# exhaustion.
|
13
|
+
#
|
14
|
+
# See https://github.com/rollbar/rollbar-gem/pull/1018 for more details on the issue
|
15
|
+
ROLLBAR_INCOMPATIBLE_VERSIONS = Gem::Requirement.new('<= 3.1.1')
|
16
|
+
|
17
|
+
def self.supported?
|
18
|
+
unsupported_reason.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.apply!
|
22
|
+
return false unless supported?
|
23
|
+
|
24
|
+
# Applying CThread to Thread will ensure any new threads
|
25
|
+
# will provide a thread/clock ID for CPU timing.
|
26
|
+
require 'ddtrace/profiling/ext/cthread'
|
27
|
+
::Thread.send(:prepend, Profiling::Ext::CThread)
|
28
|
+
::Thread.singleton_class.send(:prepend, Datadog::Profiling::Ext::WrapThreadStartFork)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.unsupported_reason
|
32
|
+
# NOTE: Only the first matching reason is returned, so try to keep a nice order on reasons -- e.g. tell users
|
33
|
+
# first that they can't use this on macOS before telling them that they have the wrong ffi version
|
34
|
+
|
35
|
+
if RUBY_ENGINE == 'jruby'
|
36
|
+
'JRuby is not supported'
|
37
|
+
elsif RUBY_PLATFORM.include?('darwin')
|
38
|
+
'Feature requires Linux; macOS is not supported'
|
39
|
+
elsif RUBY_PLATFORM =~ /(mswin|mingw)/
|
40
|
+
'Feature requires Linux; Windows is not supported'
|
41
|
+
elsif !RUBY_PLATFORM.include?('linux')
|
42
|
+
"Feature requires Linux; #{RUBY_PLATFORM} is not supported"
|
43
|
+
elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1')
|
44
|
+
'Ruby >= 2.1 is required'
|
45
|
+
elsif Gem::Specification.find_all_by_name('rollbar', ROLLBAR_INCOMPATIBLE_VERSIONS).any?
|
46
|
+
'You have an incompatible rollbar gem version installed; ensure that you have rollbar >= 3.1.2 by ' \
|
47
|
+
"adding `gem 'rollbar', '>= 3.1.2'` to your Gemfile or gems.rb file. " \
|
48
|
+
'See https://github.com/rollbar/rollbar-gem/pull/1018 for details.'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Profiling
|
5
|
+
module Ext
|
6
|
+
# C-struct for retrieving clock ID from pthread
|
7
|
+
class CClockId < FFI::Struct
|
8
|
+
layout :value, :int
|
9
|
+
end
|
10
|
+
|
11
|
+
# Extension used to enable CPU-time profiling via use of Pthread's `getcpuclockid`.
|
12
|
+
module CThread
|
13
|
+
extend FFI::Library
|
14
|
+
ffi_lib ['pthread', 'libpthread.so.0']
|
15
|
+
attach_function :pthread_self, [], :ulong
|
16
|
+
attach_function :pthread_getcpuclockid, [:ulong, CClockId], :int
|
17
|
+
|
18
|
+
def self.prepended(base)
|
19
|
+
# Threads that have already been created, will not have resolved
|
20
|
+
# a thread/clock ID. This is because these IDs can only be resolved
|
21
|
+
# from within the thread's execution context, which we do not control.
|
22
|
+
#
|
23
|
+
# We can mitigate this for the current thread via #update_native_ids,
|
24
|
+
# since we are currently running within its execution context. We cannot
|
25
|
+
# do this for any other threads that may have been created already.
|
26
|
+
# (This is why it's important that CThread is applied before anything else runs.)
|
27
|
+
base.current.send(:update_native_ids) if base.current.is_a?(CThread)
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader \
|
31
|
+
:native_thread_id
|
32
|
+
|
33
|
+
def initialize(*args)
|
34
|
+
@pid = ::Process.pid
|
35
|
+
@native_thread_id = nil
|
36
|
+
@clock_id = nil
|
37
|
+
|
38
|
+
# Wrap the work block with our own
|
39
|
+
# so we can retrieve the native thread ID within the thread's context.
|
40
|
+
wrapped_block = proc do |*t_args|
|
41
|
+
# Set native thread ID & clock ID
|
42
|
+
update_native_ids
|
43
|
+
yield(*t_args)
|
44
|
+
end
|
45
|
+
wrapped_block.ruby2_keywords if wrapped_block.respond_to?(:ruby2_keywords, true)
|
46
|
+
|
47
|
+
super(*args, &wrapped_block)
|
48
|
+
end
|
49
|
+
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
|
50
|
+
|
51
|
+
def clock_id
|
52
|
+
update_native_ids if forked?
|
53
|
+
defined?(@clock_id) && @clock_id
|
54
|
+
end
|
55
|
+
|
56
|
+
def cpu_time(unit = :float_second)
|
57
|
+
return unless clock_id && ::Process.respond_to?(:clock_gettime)
|
58
|
+
|
59
|
+
::Process.clock_gettime(clock_id, unit)
|
60
|
+
end
|
61
|
+
|
62
|
+
def cpu_time_instrumentation_installed?
|
63
|
+
# If this thread was started before this module was added to Thread OR if something caused the initialize
|
64
|
+
# method above not to be properly called on new threads, this instance variable is never defined (never set to
|
65
|
+
# any value at all, including nil).
|
66
|
+
#
|
67
|
+
# Thus, we can use @clock_id as a canary to detect a thread that has missing instrumentation, because we
|
68
|
+
# know that in initialize above we always set this variable to nil.
|
69
|
+
defined?(@clock_id) != nil
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
# Retrieves number of classes from runtime
|
75
|
+
def forked?
|
76
|
+
::Process.pid != (@pid ||= nil)
|
77
|
+
end
|
78
|
+
|
79
|
+
def update_native_ids
|
80
|
+
# Can only resolve if invoked from same thread.
|
81
|
+
return unless ::Thread.current == self
|
82
|
+
|
83
|
+
@pid = ::Process.pid
|
84
|
+
@native_thread_id = get_native_thread_id
|
85
|
+
@clock_id = get_clock_id(@native_thread_id)
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_native_thread_id
|
89
|
+
return unless ::Thread.current == self
|
90
|
+
|
91
|
+
# NOTE: Only returns thread ID for thread that evaluates this call.
|
92
|
+
# a.k.a. evaluating `thread_a.get_native_thread_id` from within
|
93
|
+
# `thread_b` will return `thread_b`'s thread ID, not `thread_a`'s.
|
94
|
+
pthread_self
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_clock_id(pthread_id)
|
98
|
+
return unless pthread_id && alive?
|
99
|
+
|
100
|
+
# Build a struct, pass it to Pthread's getcpuclockid function.
|
101
|
+
clock = CClockId.new
|
102
|
+
clock[:value] = 0
|
103
|
+
pthread_getcpuclockid(pthread_id, clock).zero? ? clock[:value] : nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Threads in Ruby can be started by creating a new instance of `Thread` (or a subclass) OR by calling
|
108
|
+
# `start`/`fork` on `Thread` (or a subclass).
|
109
|
+
#
|
110
|
+
# This module intercepts calls to `start`/`fork`, ensuring that the `update_native_ids` operation is correctly
|
111
|
+
# called once the new thread starts.
|
112
|
+
#
|
113
|
+
# Note that unlike CThread above, this module should be prepended to the `Thread`'s singleton class, not to
|
114
|
+
# the class.
|
115
|
+
module WrapThreadStartFork
|
116
|
+
def start(*args)
|
117
|
+
# Wrap the work block with our own
|
118
|
+
# so we can retrieve the native thread ID within the thread's context.
|
119
|
+
wrapped_block = proc do |*t_args|
|
120
|
+
# Set native thread ID & clock ID
|
121
|
+
::Thread.current.send(:update_native_ids)
|
122
|
+
yield(*t_args)
|
123
|
+
end
|
124
|
+
wrapped_block.ruby2_keywords if wrapped_block.respond_to?(:ruby2_keywords, true)
|
125
|
+
|
126
|
+
super(*args, &wrapped_block)
|
127
|
+
end
|
128
|
+
ruby2_keywords :start if respond_to?(:ruby2_keywords, true)
|
129
|
+
|
130
|
+
alias fork start
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Datadog
|
2
|
+
module Profiling
|
3
|
+
module Ext
|
4
|
+
# Monkey patches `Kernel#fork`, adding a `Kernel#at_fork` callback mechanism which is used to restore
|
5
|
+
# profiling abilities after the VM forks.
|
6
|
+
module Forking
|
7
|
+
def self.supported?
|
8
|
+
Process.respond_to?(:fork)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.apply!
|
12
|
+
return false unless supported?
|
13
|
+
|
14
|
+
modules = [::Process, ::Kernel]
|
15
|
+
# TODO: Ruby < 2.3 doesn't support Binding#receiver.
|
16
|
+
# Remove "else #eval" clause when Ruby < 2.3 support is dropped.
|
17
|
+
# NOTE: Modifying the "main" object as we do here is (as far as I know) irreversible. During tests, this change
|
18
|
+
# will stick around even if we otherwise stub `Process` and `Kernel`.
|
19
|
+
modules << (TOPLEVEL_BINDING.respond_to?(:receiver) ? TOPLEVEL_BINDING.receiver : TOPLEVEL_BINDING.eval('self'))
|
20
|
+
|
21
|
+
# Patch top-level binding, Kernel, Process.
|
22
|
+
# NOTE: We could instead do Kernel.module_eval { def fork; ... end }
|
23
|
+
# however, this method rewrite is more invasive and irreversible.
|
24
|
+
# It could also have collisions with other libraries that patch.
|
25
|
+
# Opt to modify the inheritance of each relevant target instead.
|
26
|
+
modules.each do |mod|
|
27
|
+
if mod.class <= Module
|
28
|
+
mod.singleton_class.class_eval do
|
29
|
+
prepend Kernel
|
30
|
+
end
|
31
|
+
else
|
32
|
+
mod.class.send(:prepend, Kernel)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Extensions for kernel
|
38
|
+
module Kernel
|
39
|
+
FORK_STAGES = [:prepare, :parent, :child].freeze
|
40
|
+
|
41
|
+
def fork
|
42
|
+
# If a block is provided, it must be wrapped to trigger callbacks.
|
43
|
+
child_block = if block_given?
|
44
|
+
proc do
|
45
|
+
# Trigger :child callback
|
46
|
+
at_fork_blocks[:child].each(&:call) if at_fork_blocks.key?(:child)
|
47
|
+
|
48
|
+
# Invoke original block
|
49
|
+
yield
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Trigger :prepare callback
|
54
|
+
at_fork_blocks[:prepare].each(&:call) if at_fork_blocks.key?(:prepare)
|
55
|
+
|
56
|
+
# Start fork
|
57
|
+
# If a block is provided, use the wrapped version.
|
58
|
+
result = child_block.nil? ? super : super(&child_block)
|
59
|
+
|
60
|
+
# Trigger correct callbacks depending on whether we're in the parent or child.
|
61
|
+
# If we're in the fork, result = nil: trigger child callbacks.
|
62
|
+
# If we're in the parent, result = fork PID: trigger parent callbacks.
|
63
|
+
# rubocop:disable Style/IfInsideElse
|
64
|
+
if result.nil?
|
65
|
+
# Trigger :child callback
|
66
|
+
at_fork_blocks[:child].each(&:call) if at_fork_blocks.key?(:child)
|
67
|
+
else
|
68
|
+
# Trigger :parent callback
|
69
|
+
at_fork_blocks[:parent].each(&:call) if at_fork_blocks.key?(:parent)
|
70
|
+
end
|
71
|
+
# rubocop:enable Style/IfInsideElse
|
72
|
+
|
73
|
+
# Return PID from #fork
|
74
|
+
result
|
75
|
+
end
|
76
|
+
|
77
|
+
def at_fork(stage = :prepare, &block)
|
78
|
+
raise ArgumentError, 'Bad \'stage\' for ::at_fork' unless FORK_STAGES.include?(stage)
|
79
|
+
|
80
|
+
at_fork_blocks[stage] = [] unless at_fork_blocks.key?(stage)
|
81
|
+
at_fork_blocks[stage] << block
|
82
|
+
end
|
83
|
+
|
84
|
+
module_function
|
85
|
+
|
86
|
+
def at_fork_blocks
|
87
|
+
# Blocks should be shared across all users of this module,
|
88
|
+
# e.g. Process#fork, Kernel#fork, etc. should all invoke the same callbacks.
|
89
|
+
# rubocop:disable Style/ClassVars
|
90
|
+
@@at_fork_blocks ||= {}
|
91
|
+
# rubocop:enable Style/ClassVars
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'ddtrace/runtime/identity'
|
2
|
+
require 'ddtrace/runtime/socket'
|
3
|
+
|
4
|
+
module Datadog
|
5
|
+
module Profiling
|
6
|
+
# Entity class used to represent metadata for a given profile
|
7
|
+
Flush = Struct.new(
|
8
|
+
:start,
|
9
|
+
:finish,
|
10
|
+
:event_groups,
|
11
|
+
:event_count,
|
12
|
+
:runtime_id,
|
13
|
+
:service,
|
14
|
+
:env,
|
15
|
+
:version,
|
16
|
+
:host,
|
17
|
+
:language,
|
18
|
+
:runtime_engine,
|
19
|
+
:runtime_platform,
|
20
|
+
:runtime_version,
|
21
|
+
:profiler_version
|
22
|
+
) do
|
23
|
+
def initialize(*args)
|
24
|
+
super
|
25
|
+
self.runtime_id = runtime_id || Datadog::Runtime::Identity.id
|
26
|
+
self.service = service || Datadog.configuration.service
|
27
|
+
self.env = env || Datadog.configuration.env
|
28
|
+
self.version = version || Datadog.configuration.version
|
29
|
+
self.host = host || Datadog::Runtime::Socket.hostname
|
30
|
+
self.language = language || Datadog::Runtime::Identity.lang
|
31
|
+
self.runtime_engine = runtime_engine || Datadog::Runtime::Identity.lang_engine
|
32
|
+
self.runtime_platform = runtime_platform || Datadog::Runtime::Identity.lang_platform
|
33
|
+
self.runtime_version = runtime_version || Datadog::Runtime::Identity.lang_version
|
34
|
+
self.profiler_version = profiler_version || Datadog::Runtime::Identity.tracer_version
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Represents a collection of events of a specific type being flushed.
|
39
|
+
EventGroup = Struct.new(:event_class, :events).freeze
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'ddtrace/profiling/flush'
|
2
|
+
require 'ddtrace/profiling/pprof/message_set'
|
3
|
+
require 'ddtrace/profiling/pprof/string_table'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Profiling
|
7
|
+
module Pprof
|
8
|
+
# Accumulates profile data and produces a Perftools::Profiles::Profile
|
9
|
+
class Builder
|
10
|
+
DEFAULT_ENCODING = 'UTF-8'.freeze
|
11
|
+
DESC_FRAME_OMITTED = 'frame omitted'.freeze
|
12
|
+
DESC_FRAMES_OMITTED = 'frames omitted'.freeze
|
13
|
+
|
14
|
+
attr_reader \
|
15
|
+
:functions,
|
16
|
+
:locations,
|
17
|
+
:mappings,
|
18
|
+
:sample_types,
|
19
|
+
:samples,
|
20
|
+
:string_table
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@functions = MessageSet.new(1)
|
24
|
+
@locations = MessageSet.new(1)
|
25
|
+
@mappings = MessageSet.new(1)
|
26
|
+
@sample_types = MessageSet.new
|
27
|
+
@samples = []
|
28
|
+
@string_table = StringTable.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def encode_profile(profile)
|
32
|
+
Perftools::Profiles::Profile.encode(profile).force_encoding(DEFAULT_ENCODING)
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_profile
|
36
|
+
Perftools::Profiles::Profile.new(
|
37
|
+
sample_type: @sample_types.messages,
|
38
|
+
sample: @samples,
|
39
|
+
mapping: @mappings.messages,
|
40
|
+
location: @locations.messages,
|
41
|
+
function: @functions.messages,
|
42
|
+
string_table: @string_table.strings
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_value_type(type, unit)
|
47
|
+
Perftools::Profiles::ValueType.new(
|
48
|
+
type: @string_table.fetch(type),
|
49
|
+
unit: @string_table.fetch(unit)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_locations(backtrace_locations, length)
|
54
|
+
locations = backtrace_locations.collect do |backtrace_location|
|
55
|
+
@locations.fetch(
|
56
|
+
# Filename
|
57
|
+
backtrace_location.path,
|
58
|
+
# Line number
|
59
|
+
backtrace_location.lineno,
|
60
|
+
# Function name
|
61
|
+
backtrace_location.base_label,
|
62
|
+
# Build function
|
63
|
+
&method(:build_location)
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
omitted = length - backtrace_locations.length
|
68
|
+
|
69
|
+
# Add placeholder stack frame if frames were truncated
|
70
|
+
if omitted > 0
|
71
|
+
desc = omitted == 1 ? DESC_FRAME_OMITTED : DESC_FRAMES_OMITTED
|
72
|
+
locations << @locations.fetch(
|
73
|
+
''.freeze,
|
74
|
+
0,
|
75
|
+
"#{omitted} #{desc}",
|
76
|
+
&method(:build_location)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
locations
|
81
|
+
end
|
82
|
+
|
83
|
+
def build_location(id, filename, line_number, function_name = nil)
|
84
|
+
Perftools::Profiles::Location.new(
|
85
|
+
id: id,
|
86
|
+
line: [build_line(
|
87
|
+
@functions.fetch(
|
88
|
+
filename,
|
89
|
+
function_name,
|
90
|
+
&method(:build_function)
|
91
|
+
).id,
|
92
|
+
line_number
|
93
|
+
)]
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
def build_line(function_id, line_number)
|
98
|
+
Perftools::Profiles::Line.new(
|
99
|
+
function_id: function_id,
|
100
|
+
line: line_number
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
def build_function(id, filename, function_name)
|
105
|
+
Perftools::Profiles::Function.new(
|
106
|
+
id: id,
|
107
|
+
name: @string_table.fetch(function_name),
|
108
|
+
filename: @string_table.fetch(filename)
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
def build_mapping(id, filename)
|
113
|
+
Perftools::Profiles::Mapping.new(
|
114
|
+
id: id,
|
115
|
+
filename: @string_table.fetch(filename)
|
116
|
+
)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|