ddtrace 0.41.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 +223 -126
- data/.circleci/images/primary/Dockerfile-3.0.0 +73 -0
- data/.github/workflows/add-milestone-to-pull-requests.yml +42 -0
- data/.github/workflows/create-next-milestone.yml +20 -0
- data/.rubocop.yml +250 -7
- data/.rubocop_todo.yml +396 -0
- data/.simplecov +3 -0
- data/Appraisals +429 -135
- data/CHANGELOG.md +1158 -354
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +40 -3
- data/README.md +1 -0
- data/Rakefile +236 -29
- data/ddtrace.gemspec +4 -35
- data/docker-compose.yml +30 -0
- data/docs/DevelopmentGuide.md +40 -2
- data/docs/GettingStarted.md +186 -16
- 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 +10 -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 +230 -134
- data/lib/ddtrace/configuration.rb +21 -5
- 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 +21 -5
- data/lib/ddtrace/context.rb +23 -6
- data/lib/ddtrace/context_provider.rb +18 -5
- 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 -5
- data/lib/ddtrace/contrib/action_view/events/render_partial.rb +1 -0
- data/lib/ddtrace/contrib/action_view/events/render_template.rb +1 -0
- 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/resolver.rb +17 -5
- data/lib/ddtrace/contrib/active_record/integration.rb +7 -0
- data/lib/ddtrace/contrib/active_record/utils.rb +68 -21
- data/lib/ddtrace/contrib/active_support/cache/instrumentation.rb +104 -3
- data/lib/ddtrace/contrib/active_support/cache/patcher.rb +21 -0
- data/lib/ddtrace/contrib/active_support/ext.rb +3 -0
- data/lib/ddtrace/contrib/active_support/integration.rb +7 -1
- data/lib/ddtrace/contrib/active_support/notifications/event.rb +12 -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/instrumentation.rb +2 -1
- data/lib/ddtrace/contrib/aws/patcher.rb +1 -1
- data/lib/ddtrace/contrib/aws/services.rb +2 -0
- data/lib/ddtrace/contrib/configurable.rb +2 -0
- data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +6 -8
- data/lib/ddtrace/contrib/cucumber/configuration/settings.rb +28 -0
- data/lib/ddtrace/contrib/cucumber/ext.rb +17 -0
- data/lib/ddtrace/contrib/cucumber/formatter.rb +98 -0
- data/lib/ddtrace/contrib/cucumber/instrumentation.rb +24 -0
- data/lib/ddtrace/contrib/cucumber/integration.rb +45 -0
- data/lib/ddtrace/contrib/cucumber/patcher.rb +23 -0
- data/lib/ddtrace/contrib/dalli/patcher.rb +0 -38
- data/lib/ddtrace/contrib/delayed_job/configuration/settings.rb +2 -0
- data/lib/ddtrace/contrib/delayed_job/ext.rb +2 -0
- data/lib/ddtrace/contrib/delayed_job/plugin.rb +38 -15
- data/lib/ddtrace/contrib/elasticsearch/quantize.rb +3 -2
- data/lib/ddtrace/contrib/ethon/easy_patch.rb +11 -10
- data/lib/ddtrace/contrib/ethon/ext.rb +1 -0
- data/lib/ddtrace/contrib/excon/middleware.rb +9 -7
- data/lib/ddtrace/contrib/extensions.rb +28 -1
- data/lib/ddtrace/contrib/faraday/middleware.rb +1 -3
- data/lib/ddtrace/contrib/faraday/patcher.rb +0 -36
- data/lib/ddtrace/contrib/grape/configuration/settings.rb +7 -0
- data/lib/ddtrace/contrib/grape/endpoint.rb +47 -21
- data/lib/ddtrace/contrib/grape/ext.rb +1 -0
- 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/client.rb +1 -1
- 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 +7 -7
- 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 +151 -0
- data/lib/ddtrace/contrib/httpclient/integration.rb +43 -0
- data/lib/ddtrace/contrib/httpclient/patcher.rb +35 -0
- data/lib/ddtrace/contrib/httprb/instrumentation.rb +5 -6
- data/lib/ddtrace/contrib/kafka/event.rb +1 -1
- 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 +1 -1
- data/lib/ddtrace/contrib/qless/configuration/settings.rb +35 -0
- data/lib/ddtrace/contrib/qless/ext.rb +20 -0
- data/lib/ddtrace/contrib/qless/integration.rb +38 -0
- data/lib/ddtrace/contrib/qless/patcher.rb +35 -0
- data/lib/ddtrace/contrib/qless/qless_job.rb +73 -0
- data/lib/ddtrace/contrib/qless/tracer_cleaner.rb +33 -0
- data/lib/ddtrace/contrib/que/configuration/settings.rb +1 -0
- data/lib/ddtrace/contrib/que/ext.rb +19 -19
- data/lib/ddtrace/contrib/que/tracer.rb +3 -2
- 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 +19 -5
- 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 +3 -1
- data/lib/ddtrace/contrib/redis/configuration/settings.rb +5 -0
- data/lib/ddtrace/contrib/redis/ext.rb +1 -0
- data/lib/ddtrace/contrib/redis/patcher.rb +20 -3
- data/lib/ddtrace/contrib/redis/quantize.rb +28 -0
- data/lib/ddtrace/contrib/redis/tags.rb +5 -1
- 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 +1 -0
- data/lib/ddtrace/contrib/resque/integration.rb +1 -1
- data/lib/ddtrace/contrib/resque/resque_job.rb +3 -1
- data/lib/ddtrace/contrib/rest_client/request_patch.rb +1 -3
- data/lib/ddtrace/contrib/rspec/configuration/settings.rb +28 -0
- data/lib/ddtrace/contrib/rspec/example.rb +75 -0
- data/lib/ddtrace/contrib/rspec/ext.rb +16 -0
- data/lib/ddtrace/contrib/rspec/integration.rb +46 -0
- data/lib/ddtrace/contrib/rspec/patcher.rb +23 -0
- 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 +3 -1
- data/lib/ddtrace/contrib/sidekiq/configuration/settings.rb +1 -0
- data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +5 -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 +5 -5
- data/lib/ddtrace/contrib/sneakers/configuration/settings.rb +1 -0
- data/lib/ddtrace/contrib/sneakers/ext.rb +11 -11
- data/lib/ddtrace/contrib/sneakers/tracer.rb +16 -21
- data/lib/ddtrace/contrib/status_code_matcher.rb +69 -0
- 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/app_types.rb +1 -0
- data/lib/ddtrace/ext/ci.rb +297 -0
- data/lib/ddtrace/ext/distributed.rb +8 -2
- data/lib/ddtrace/ext/git.rb +11 -0
- data/lib/ddtrace/ext/http.rb +1 -1
- data/lib/ddtrace/ext/runtime.rb +2 -1
- data/lib/ddtrace/ext/test.rb +24 -0
- 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 +17 -4
- data/lib/ddtrace/propagation/http_propagator.rb +17 -2
- 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/runtime/identity.rb +4 -5
- data/lib/ddtrace/sampler.rb +1 -1
- data/lib/ddtrace/sampling/rate_limiter.rb +65 -16
- 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 +23 -10
- 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.rb +10 -11
- data/lib/ddtrace/utils/forking.rb +52 -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/runtime_metrics.rb +7 -3
- data/lib/ddtrace/workers/trace_writer.rb +9 -10
- data/lib/ddtrace/writer.rb +22 -4
- metadata +168 -358
- 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/monkey.rb +0 -58
data/lib/ddtrace/sampler.rb
CHANGED
|
@@ -81,7 +81,7 @@ module Datadog
|
|
|
81
81
|
:default_key
|
|
82
82
|
|
|
83
83
|
def initialize(default_key, default_rate = 1.0, &block)
|
|
84
|
-
raise ArgumentError, 'No resolver given!' unless
|
|
84
|
+
raise ArgumentError, 'No resolver given!' unless block
|
|
85
85
|
|
|
86
86
|
@default_key = default_key
|
|
87
87
|
@resolver = block
|
|
@@ -38,6 +38,10 @@ module Datadog
|
|
|
38
38
|
@tokens = max_tokens
|
|
39
39
|
@total_messages = 0
|
|
40
40
|
@conforming_messages = 0
|
|
41
|
+
@prev_conforming_messages = nil
|
|
42
|
+
@prev_total_messages = nil
|
|
43
|
+
@current_window = nil
|
|
44
|
+
|
|
41
45
|
@last_refill = Utils::Time.get_time
|
|
42
46
|
end
|
|
43
47
|
|
|
@@ -47,28 +51,17 @@ module Datadog
|
|
|
47
51
|
# If it does, return +true+ and remove +size+
|
|
48
52
|
# tokens from the bucket.
|
|
49
53
|
# If it does not, return +false+ without affecting
|
|
50
|
-
# the tokens
|
|
54
|
+
# the tokens from the bucket.
|
|
51
55
|
#
|
|
52
56
|
# @return [Boolean] +true+ if message conforms with current bucket limit
|
|
53
57
|
def allow?(size)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
refill_since_last_message
|
|
58
|
-
|
|
59
|
-
increment_total_count
|
|
60
|
-
|
|
61
|
-
return false if @tokens < size
|
|
62
|
-
|
|
63
|
-
increment_conforming_count
|
|
64
|
-
|
|
65
|
-
@tokens -= size
|
|
66
|
-
|
|
67
|
-
true
|
|
58
|
+
allowed = should_allow?(size)
|
|
59
|
+
update_rate_counts(allowed)
|
|
60
|
+
allowed
|
|
68
61
|
end
|
|
69
62
|
|
|
70
63
|
# Ratio of 'conformance' per 'total messages' checked
|
|
71
|
-
#
|
|
64
|
+
# averaged for the past 2 buckets
|
|
72
65
|
#
|
|
73
66
|
# Returns +1.0+ when no messages have been checked yet.
|
|
74
67
|
#
|
|
@@ -77,6 +70,20 @@ module Datadog
|
|
|
77
70
|
return 0.0 if @rate.zero?
|
|
78
71
|
return 1.0 if @rate < 0 || @total_messages.zero?
|
|
79
72
|
|
|
73
|
+
return current_window_rate if @prev_conforming_messages.nil? || @prev_total_messages.nil?
|
|
74
|
+
|
|
75
|
+
(@conforming_messages.to_f + @prev_conforming_messages.to_f) / (@total_messages + @prev_total_messages)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Ratio of 'conformance' per 'total messages' checked
|
|
79
|
+
# on this bucket
|
|
80
|
+
#
|
|
81
|
+
# Returns +1.0+ when no messages have been checked yet.
|
|
82
|
+
#
|
|
83
|
+
# @return [Float] Conformance ratio, between +[0,1]+
|
|
84
|
+
def current_window_rate
|
|
85
|
+
return 1.0 if @total_messages.zero?
|
|
86
|
+
|
|
80
87
|
@conforming_messages.to_f / @total_messages
|
|
81
88
|
end
|
|
82
89
|
|
|
@@ -91,6 +98,8 @@ module Datadog
|
|
|
91
98
|
now = Utils::Time.get_time
|
|
92
99
|
elapsed = now - @last_refill
|
|
93
100
|
|
|
101
|
+
# Update the number of available tokens, but ensure we do not exceed the max
|
|
102
|
+
# we return the min of tokens + rate*elapsed, or max tokens
|
|
94
103
|
refill_tokens(@rate * elapsed)
|
|
95
104
|
|
|
96
105
|
@last_refill = now
|
|
@@ -108,6 +117,46 @@ module Datadog
|
|
|
108
117
|
def increment_conforming_count
|
|
109
118
|
@conforming_messages += 1
|
|
110
119
|
end
|
|
120
|
+
|
|
121
|
+
def should_allow?(size)
|
|
122
|
+
# rate limit of 0 blocks everything
|
|
123
|
+
return false if @rate.zero?
|
|
124
|
+
|
|
125
|
+
# negative rate limit disables rate limiting
|
|
126
|
+
return true if @rate < 0
|
|
127
|
+
|
|
128
|
+
refill_since_last_message
|
|
129
|
+
|
|
130
|
+
# if tokens < 1 we don't allow?
|
|
131
|
+
return false if @tokens < size
|
|
132
|
+
|
|
133
|
+
@tokens -= size
|
|
134
|
+
|
|
135
|
+
true
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Sets and Updates the past two 1 second windows for which
|
|
139
|
+
# the rate limiter must compute it's rate over and updates
|
|
140
|
+
# the total count, and conforming message count if +allowed+
|
|
141
|
+
def update_rate_counts(allowed)
|
|
142
|
+
now = Utils::Time.get_time
|
|
143
|
+
|
|
144
|
+
# No tokens have been seen yet, start a new window
|
|
145
|
+
if @current_window.nil?
|
|
146
|
+
@current_window = now
|
|
147
|
+
# If more than 1 second has past since last window, reset
|
|
148
|
+
elsif now - @current_window >= 1
|
|
149
|
+
@prev_conforming_messages = @conforming_messages
|
|
150
|
+
@prev_total_messages = @total_messages
|
|
151
|
+
@conforming_messages = 0
|
|
152
|
+
@total_messages = 0
|
|
153
|
+
@current_window = now
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
increment_conforming_count if allowed
|
|
157
|
+
|
|
158
|
+
increment_total_count
|
|
159
|
+
end
|
|
111
160
|
end
|
|
112
161
|
|
|
113
162
|
# \RateLimiter that accepts all resources,
|
data/lib/ddtrace/span.rb
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'time'
|
|
4
|
-
require 'thread'
|
|
5
|
-
|
|
6
4
|
require 'ddtrace/utils'
|
|
7
5
|
require 'ddtrace/ext/errors'
|
|
8
6
|
require 'ddtrace/ext/priority'
|
|
@@ -38,14 +36,16 @@ module Datadog
|
|
|
38
36
|
EXTERNAL_MAX_ID = 1 << 64
|
|
39
37
|
|
|
40
38
|
# This limit is for numeric tags because uint64 could end up rounded.
|
|
41
|
-
NUMERIC_TAG_SIZE_RANGE = (-1 << 53..1 << 53)
|
|
39
|
+
NUMERIC_TAG_SIZE_RANGE = (-1 << 53..1 << 53).freeze
|
|
42
40
|
|
|
43
41
|
attr_accessor :name, :service, :resource, :span_type,
|
|
44
42
|
:span_id, :trace_id, :parent_id,
|
|
45
43
|
:status, :sampled,
|
|
46
|
-
:tracer, :context
|
|
44
|
+
:tracer, :context
|
|
45
|
+
|
|
46
|
+
attr_reader :parent, :start_time, :end_time
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
attr_writer :duration
|
|
49
49
|
|
|
50
50
|
# Create a new span linked to the given tracer. Call the \Tracer method <tt>start_span()</tt>
|
|
51
51
|
# and then <tt>finish()</tt> once the tracer operation is over.
|
|
@@ -180,7 +180,7 @@ module Datadog
|
|
|
180
180
|
# behavior and so we maintain it for backward compatibility for those
|
|
181
181
|
# who are using async manual instrumentation that may rely on this
|
|
182
182
|
|
|
183
|
-
@start_time = start_time || Time.now.utc
|
|
183
|
+
@start_time = start_time || Utils::Time.now.utc
|
|
184
184
|
@duration_start = start_time.nil? ? duration_marker : nil
|
|
185
185
|
|
|
186
186
|
self
|
|
@@ -206,7 +206,7 @@ module Datadog
|
|
|
206
206
|
|
|
207
207
|
@allocation_count_finish = now_allocations
|
|
208
208
|
|
|
209
|
-
now = Time.now.utc
|
|
209
|
+
now = Utils::Time.now.utc
|
|
210
210
|
|
|
211
211
|
# Provide a default start_time if unset.
|
|
212
212
|
# Using `now` here causes duration to be 0; this is expected
|
data/lib/ddtrace/sync_writer.rb
CHANGED
|
@@ -5,6 +5,10 @@ require 'ddtrace/runtime/metrics'
|
|
|
5
5
|
module Datadog
|
|
6
6
|
# SyncWriter flushes both services and traces synchronously
|
|
7
7
|
# DEV: To be replaced by Datadog::Workers::TraceWriter.
|
|
8
|
+
#
|
|
9
|
+
# Note: If you're wondering if this class is used at all, since there are no other references to it on the codebase,
|
|
10
|
+
# the separate `datadog-lambda` uses it as of February 2021:
|
|
11
|
+
# <https://github.com/DataDog/datadog-lambda-rb/blob/c15f0f0916c90123416dc44e7d6800ef4a7cfdbf/lib/datadog/lambda.rb#L38>
|
|
8
12
|
class SyncWriter
|
|
9
13
|
attr_reader \
|
|
10
14
|
:priority_sampler,
|
|
@@ -29,9 +33,7 @@ module Datadog
|
|
|
29
33
|
end
|
|
30
34
|
end
|
|
31
35
|
|
|
32
|
-
|
|
33
|
-
proc { flush_trace(trace) }
|
|
34
|
-
)
|
|
36
|
+
flush_trace(trace)
|
|
35
37
|
rescue => e
|
|
36
38
|
Datadog.logger.debug(e)
|
|
37
39
|
end
|
|
@@ -44,13 +46,10 @@ module Datadog
|
|
|
44
46
|
|
|
45
47
|
private
|
|
46
48
|
|
|
47
|
-
def perform_concurrently(*tasks)
|
|
48
|
-
tasks.map { |task| Thread.new(&task) }.each(&:join)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
49
|
def flush_trace(trace)
|
|
52
50
|
processed_traces = Pipeline.process!([trace])
|
|
53
51
|
return if processed_traces.empty?
|
|
52
|
+
|
|
54
53
|
inject_hostname!(processed_traces.first) if Datadog.configuration.report_hostname
|
|
55
54
|
transport.send_traces(processed_traces)
|
|
56
55
|
end
|
|
@@ -58,9 +57,7 @@ module Datadog
|
|
|
58
57
|
def inject_hostname!(trace)
|
|
59
58
|
unless trace.first.nil?
|
|
60
59
|
hostname = Datadog::Runtime::Socket.hostname
|
|
61
|
-
unless hostname.nil? || hostname.empty?
|
|
62
|
-
trace.first.set_tag(Ext::NET::TAG_HOSTNAME, hostname)
|
|
63
|
-
end
|
|
60
|
+
trace.first.set_tag(Ext::NET::TAG_HOSTNAME, hostname) unless hostname.nil? || hostname.empty?
|
|
64
61
|
end
|
|
65
62
|
end
|
|
66
63
|
end
|
data/lib/ddtrace/tracer.rb
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require 'thread'
|
|
2
1
|
require 'logger'
|
|
3
2
|
require 'pathname'
|
|
4
3
|
|
|
@@ -7,6 +6,7 @@ require 'ddtrace/span'
|
|
|
7
6
|
require 'ddtrace/context'
|
|
8
7
|
require 'ddtrace/logger'
|
|
9
8
|
require 'ddtrace/writer'
|
|
9
|
+
require 'ddtrace/runtime/identity'
|
|
10
10
|
require 'ddtrace/sampler'
|
|
11
11
|
require 'ddtrace/sampling'
|
|
12
12
|
require 'ddtrace/correlation'
|
|
@@ -59,8 +59,8 @@ module Datadog
|
|
|
59
59
|
#
|
|
60
60
|
# This method makes use of a \ContextProvider that is automatically set during the tracer
|
|
61
61
|
# initialization, or while using a library instrumentation.
|
|
62
|
-
def call_context
|
|
63
|
-
@provider.context
|
|
62
|
+
def call_context(key = nil)
|
|
63
|
+
@provider.context(key)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
# Initialize a new \Tracer used to create, sample and submit spans that measure the
|
|
@@ -143,6 +143,7 @@ module Datadog
|
|
|
143
143
|
# a service would be invalid and rejected.
|
|
144
144
|
def default_service
|
|
145
145
|
return @default_service if instance_variable_defined?(:@default_service) && @default_service
|
|
146
|
+
|
|
146
147
|
begin
|
|
147
148
|
@default_service = File.basename($PROGRAM_NAME, '.*')
|
|
148
149
|
rescue StandardError => e
|
|
@@ -201,6 +202,7 @@ module Datadog
|
|
|
201
202
|
# root span
|
|
202
203
|
@sampler.sample!(span)
|
|
203
204
|
span.set_tag('system.pid', Process.pid)
|
|
205
|
+
span.set_tag(Datadog::Ext::Runtime::TAG_ID, Datadog::Runtime::Identity.id)
|
|
204
206
|
|
|
205
207
|
if ctx && ctx.trace_id
|
|
206
208
|
span.trace_id = ctx.trace_id
|
|
@@ -287,8 +289,19 @@ module Datadog
|
|
|
287
289
|
# and it is user code which should be executed no matter what.
|
|
288
290
|
# It's not a problem since we re-raise it afterwards so for example a
|
|
289
291
|
# SignalException::Interrupt would still bubble up.
|
|
292
|
+
# rubocop:disable Metrics/BlockNesting
|
|
290
293
|
rescue Exception => e
|
|
291
|
-
(options[:on_error]
|
|
294
|
+
if (on_error_handler = options[:on_error]) && on_error_handler.respond_to?(:call)
|
|
295
|
+
begin
|
|
296
|
+
on_error_handler.call(span, e)
|
|
297
|
+
rescue
|
|
298
|
+
Datadog.logger.debug('Custom on_error handler failed, falling back to default')
|
|
299
|
+
DEFAULT_ON_ERROR.call(span, e)
|
|
300
|
+
end
|
|
301
|
+
else
|
|
302
|
+
Datadog.logger.debug('Custom on_error handler must be a callable, falling back to default') if on_error_handler
|
|
303
|
+
DEFAULT_ON_ERROR.call(span, e)
|
|
304
|
+
end
|
|
292
305
|
raise e
|
|
293
306
|
ensure
|
|
294
307
|
span.finish unless span.nil?
|
|
@@ -324,18 +337,18 @@ module Datadog
|
|
|
324
337
|
end
|
|
325
338
|
|
|
326
339
|
# Return the current active span or +nil+.
|
|
327
|
-
def active_span
|
|
328
|
-
call_context.current_span
|
|
340
|
+
def active_span(key = nil)
|
|
341
|
+
call_context(key).current_span
|
|
329
342
|
end
|
|
330
343
|
|
|
331
344
|
# Return the current active root span or +nil+.
|
|
332
|
-
def active_root_span
|
|
333
|
-
call_context.current_root_span
|
|
345
|
+
def active_root_span(key = nil)
|
|
346
|
+
call_context(key).current_root_span
|
|
334
347
|
end
|
|
335
348
|
|
|
336
349
|
# Return a CorrelationIdentifier for active span
|
|
337
|
-
def active_correlation
|
|
338
|
-
Datadog::Correlation.identifier_from_context(call_context)
|
|
350
|
+
def active_correlation(key = nil)
|
|
351
|
+
Datadog::Correlation.identifier_from_context(call_context(key))
|
|
339
352
|
end
|
|
340
353
|
|
|
341
354
|
# Send the trace to the writer to enqueue the spans list in the agent
|
|
@@ -69,9 +69,7 @@ module Datadog
|
|
|
69
69
|
}.tap do |headers|
|
|
70
70
|
# Add container ID, if present.
|
|
71
71
|
container_id = Datadog::Runtime::Container.container_id
|
|
72
|
-
unless container_id.nil?
|
|
73
|
-
headers[Datadog::Ext::Transport::HTTP::HEADER_CONTAINER_ID] = container_id
|
|
74
|
-
end
|
|
72
|
+
headers[Datadog::Ext::Transport::HTTP::HEADER_CONTAINER_ID] = container_id unless container_id.nil?
|
|
75
73
|
end
|
|
76
74
|
end
|
|
77
75
|
|
|
@@ -19,7 +19,7 @@ module Datadog
|
|
|
19
19
|
@timeout = options[:timeout] || DEFAULT_TIMEOUT
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def open
|
|
22
|
+
def open(&block)
|
|
23
23
|
# DEV Initializing +Net::HTTP+ directly help us avoid expensive
|
|
24
24
|
# options processing done in +Net::HTTP.start+:
|
|
25
25
|
# https://github.com/ruby/ruby/blob/b2d96abb42abbe2e01f010ffc9ac51f0f9a50002/lib/net/http.rb#L614-L618
|
|
@@ -27,9 +27,7 @@ module Datadog
|
|
|
27
27
|
|
|
28
28
|
req.open_timeout = req.read_timeout = timeout
|
|
29
29
|
|
|
30
|
-
req.start
|
|
31
|
-
yield(http)
|
|
32
|
-
end
|
|
30
|
+
req.start(&block)
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
def call(env)
|
|
@@ -82,36 +80,43 @@ module Datadog
|
|
|
82
80
|
|
|
83
81
|
def payload
|
|
84
82
|
return super if http_response.nil?
|
|
83
|
+
|
|
85
84
|
http_response.body
|
|
86
85
|
end
|
|
87
86
|
|
|
88
87
|
def code
|
|
89
88
|
return super if http_response.nil?
|
|
89
|
+
|
|
90
90
|
http_response.code.to_i
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def ok?
|
|
94
94
|
return super if http_response.nil?
|
|
95
|
+
|
|
95
96
|
code.between?(200, 299)
|
|
96
97
|
end
|
|
97
98
|
|
|
98
99
|
def unsupported?
|
|
99
100
|
return super if http_response.nil?
|
|
101
|
+
|
|
100
102
|
code == 415
|
|
101
103
|
end
|
|
102
104
|
|
|
103
105
|
def not_found?
|
|
104
106
|
return super if http_response.nil?
|
|
107
|
+
|
|
105
108
|
code == 404
|
|
106
109
|
end
|
|
107
110
|
|
|
108
111
|
def client_error?
|
|
109
112
|
return super if http_response.nil?
|
|
113
|
+
|
|
110
114
|
code.between?(400, 499)
|
|
111
115
|
end
|
|
112
116
|
|
|
113
117
|
def server_error?
|
|
114
118
|
return super if http_response.nil?
|
|
119
|
+
|
|
115
120
|
code.between?(500, 599)
|
|
116
121
|
end
|
|
117
122
|
|
|
@@ -18,7 +18,7 @@ module Datadog
|
|
|
18
18
|
@timeout = options.fetch(:timeout, DEFAULT_TIMEOUT)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def open
|
|
21
|
+
def open(&block)
|
|
22
22
|
# Open connection
|
|
23
23
|
connection = HTTP.new(
|
|
24
24
|
filepath,
|
|
@@ -26,9 +26,7 @@ module Datadog
|
|
|
26
26
|
continue_timeout: timeout
|
|
27
27
|
)
|
|
28
28
|
|
|
29
|
-
connection.start
|
|
30
|
-
yield(http)
|
|
31
|
-
end
|
|
29
|
+
connection.start(&block)
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
def url
|
|
@@ -36,6 +36,7 @@ module Datadog
|
|
|
36
36
|
@default_adapter = if type.is_a?(Symbol)
|
|
37
37
|
registry_klass = REGISTRY.get(type)
|
|
38
38
|
raise UnknownAdapterError, type if registry_klass.nil?
|
|
39
|
+
|
|
39
40
|
registry_klass.new(*args)
|
|
40
41
|
else
|
|
41
42
|
type
|
|
@@ -67,6 +68,7 @@ module Datadog
|
|
|
67
68
|
|
|
68
69
|
def default_api=(key)
|
|
69
70
|
raise UnknownApiError, key unless @apis.key?(key)
|
|
71
|
+
|
|
70
72
|
@default_api = key
|
|
71
73
|
end
|
|
72
74
|
|
|
@@ -41,6 +41,7 @@ module Datadog
|
|
|
41
41
|
|
|
42
42
|
def send_traces(env, &block)
|
|
43
43
|
raise NoTraceEndpointDefinedError, self if traces.nil?
|
|
44
|
+
|
|
44
45
|
traces.call(env, &block)
|
|
45
46
|
end
|
|
46
47
|
|
|
@@ -121,9 +122,7 @@ module Datadog
|
|
|
121
122
|
# Parse service rates, if configured to do so.
|
|
122
123
|
if service_rates? && !http_response.payload.to_s.empty?
|
|
123
124
|
body = JSON.parse(http_response.payload)
|
|
124
|
-
if body.is_a?(Hash) && body.key?(SERVICE_RATE_KEY)
|
|
125
|
-
options[:service_rates] = body[SERVICE_RATE_KEY]
|
|
126
|
-
end
|
|
125
|
+
options[:service_rates] = body[SERVICE_RATE_KEY] if body.is_a?(Hash) && body.key?(SERVICE_RATE_KEY)
|
|
127
126
|
end
|
|
128
127
|
end
|
|
129
128
|
|