ddtrace 1.10.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +125 -1
- data/README.md +8 -10
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +110 -18
- data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +26 -3
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +3 -0
- data/lib/datadog/appsec/component.rb +40 -6
- data/lib/datadog/appsec/configuration/settings.rb +20 -4
- data/lib/datadog/appsec/configuration.rb +8 -0
- data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -0
- data/lib/datadog/appsec/contrib/configuration/settings.rb +2 -0
- data/lib/datadog/appsec/contrib/integration.rb +2 -0
- data/lib/datadog/appsec/contrib/patcher.rb +2 -0
- data/lib/datadog/appsec/contrib/rack/configuration/settings.rb +2 -0
- data/lib/datadog/appsec/contrib/rack/gateway/request.rb +4 -15
- data/lib/datadog/appsec/contrib/rack/gateway/response.rb +1 -1
- data/lib/datadog/appsec/contrib/rack/patcher.rb +2 -0
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +6 -0
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +17 -4
- data/lib/datadog/appsec/contrib/rails/configuration/settings.rb +2 -0
- data/lib/datadog/appsec/contrib/rails/framework.rb +2 -0
- data/lib/datadog/appsec/contrib/rails/gateway/request.rb +1 -1
- data/lib/datadog/appsec/contrib/rails/request.rb +2 -0
- data/lib/datadog/appsec/contrib/rails/request_middleware.rb +2 -0
- data/lib/datadog/appsec/contrib/sinatra/configuration/settings.rb +2 -0
- data/lib/datadog/appsec/contrib/sinatra/framework.rb +2 -0
- data/lib/datadog/appsec/contrib/sinatra/gateway/route_params.rb +1 -1
- data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +2 -0
- data/lib/datadog/appsec/extensions.rb +2 -0
- data/lib/datadog/appsec/instrumentation/gateway/argument.rb +2 -4
- data/lib/datadog/appsec/processor/rule_loader.rb +63 -0
- data/lib/datadog/appsec/processor/rule_merger.rb +146 -0
- data/lib/datadog/appsec/processor.rb +15 -70
- data/lib/datadog/appsec/remote.rb +121 -0
- data/lib/datadog/appsec/utils/http.rb +2 -0
- data/lib/datadog/appsec/utils.rb +2 -0
- data/lib/datadog/appsec.rb +18 -4
- data/lib/datadog/ci/configuration/components.rb +2 -0
- data/lib/datadog/ci/configuration/settings.rb +2 -0
- data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +2 -0
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +2 -0
- data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +2 -0
- data/lib/datadog/ci/contrib/cucumber/patcher.rb +2 -0
- data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +2 -0
- data/lib/datadog/ci/contrib/rspec/patcher.rb +2 -0
- data/lib/datadog/ci/extensions.rb +2 -0
- data/lib/datadog/ci/flush.rb +2 -0
- data/lib/datadog/ci.rb +2 -0
- data/lib/datadog/core/buffer/cruby.rb +2 -0
- data/lib/datadog/core/buffer/random.rb +2 -0
- data/lib/datadog/core/buffer/thread_safe.rb +2 -0
- data/lib/datadog/core/chunker.rb +2 -0
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +68 -17
- data/lib/datadog/core/configuration/components.rb +11 -14
- data/lib/datadog/core/configuration/dependency_resolver.rb +2 -0
- data/lib/datadog/core/configuration/option.rb +2 -0
- data/lib/datadog/core/configuration/option_definition.rb +2 -0
- data/lib/datadog/core/configuration/option_definition_set.rb +2 -0
- data/lib/datadog/core/configuration/option_set.rb +2 -0
- data/lib/datadog/core/configuration/settings.rb +70 -16
- data/lib/datadog/core/diagnostics/health.rb +2 -0
- data/lib/datadog/core/environment/class_count.rb +2 -0
- data/lib/datadog/core/environment/gc.rb +2 -0
- data/lib/datadog/core/environment/identity.rb +58 -0
- data/lib/datadog/core/environment/socket.rb +2 -0
- data/lib/datadog/core/environment/thread_count.rb +2 -0
- data/lib/datadog/core/environment/variable_helpers.rb +10 -2
- data/lib/datadog/core/environment/vm_cache.rb +2 -0
- data/lib/datadog/core/extensions.rb +2 -0
- data/lib/datadog/core/header_collection.rb +2 -0
- data/lib/datadog/core/metrics/helpers.rb +2 -0
- data/lib/datadog/core/metrics/metric.rb +2 -0
- data/lib/datadog/core/remote/client/capabilities.rb +57 -0
- data/lib/datadog/core/remote/client.rb +225 -0
- data/lib/datadog/core/remote/component.rb +158 -0
- data/lib/datadog/core/remote/configuration/content.rb +84 -0
- data/lib/datadog/core/remote/configuration/digest.rb +62 -0
- data/lib/datadog/core/remote/configuration/path.rb +90 -0
- data/lib/datadog/core/remote/configuration/repository.rb +292 -0
- data/lib/datadog/core/remote/configuration/target.rb +74 -0
- data/lib/datadog/core/remote/configuration.rb +18 -0
- data/lib/datadog/core/remote/dispatcher.rb +59 -0
- data/lib/datadog/core/remote/ext.rb +12 -0
- data/lib/datadog/core/remote/negotiation.rb +57 -0
- data/lib/datadog/core/remote/worker.rb +96 -0
- data/lib/datadog/core/remote.rb +24 -0
- data/lib/datadog/core/telemetry/collector.rb +8 -9
- data/lib/datadog/core/telemetry/heartbeat.rb +2 -0
- data/lib/datadog/core/telemetry/http/env.rb +2 -0
- data/lib/datadog/core/telemetry/http/transport.rb +2 -0
- data/lib/datadog/core/telemetry/v1/app_event.rb +2 -0
- data/lib/datadog/core/telemetry/v1/application.rb +7 -1
- data/lib/datadog/core/telemetry/v1/dependency.rb +7 -1
- data/lib/datadog/core/telemetry/v1/host.rb +9 -1
- data/lib/datadog/core/telemetry/v1/integration.rb +7 -1
- data/lib/datadog/core/telemetry/v1/product.rb +9 -1
- data/lib/datadog/core/telemetry/v1/telemetry_request.rb +7 -1
- data/lib/datadog/core/transport/config.rb +58 -0
- data/lib/datadog/core/transport/http/api/instance.rb +37 -0
- data/lib/datadog/core/transport/http/api/spec.rb +19 -0
- data/lib/datadog/core/transport/http/api.rb +57 -0
- data/lib/datadog/core/transport/http/builder.rb +217 -0
- data/lib/datadog/core/transport/http/client.rb +45 -0
- data/lib/datadog/core/transport/http/config.rb +268 -0
- data/lib/datadog/core/transport/http/negotiation.rb +144 -0
- data/lib/datadog/core/transport/http.rb +169 -0
- data/lib/datadog/core/transport/negotiation.rb +60 -0
- data/lib/datadog/core/utils/compression.rb +2 -0
- data/lib/datadog/core/utils/hash.rb +32 -0
- data/lib/datadog/core/utils/object_set.rb +2 -0
- data/lib/datadog/core/utils/safe_dup.rb +20 -2
- data/lib/datadog/core/utils/sequence.rb +2 -0
- data/lib/datadog/core/utils/time.rb +2 -0
- data/lib/datadog/core/worker.rb +2 -0
- data/lib/datadog/core/workers/async.rb +6 -2
- data/lib/datadog/core/workers/interval_loop.rb +7 -1
- data/lib/datadog/core/workers/queue.rb +2 -0
- data/lib/datadog/core/workers/runtime_metrics.rb +2 -0
- data/lib/datadog/kit.rb +2 -0
- data/lib/datadog/opentracer/binary_propagator.rb +2 -0
- data/lib/datadog/opentracer/carrier.rb +2 -0
- data/lib/datadog/opentracer/global_tracer.rb +2 -0
- data/lib/datadog/opentracer/propagator.rb +2 -0
- data/lib/datadog/opentracer/scope.rb +2 -0
- data/lib/datadog/opentracer/scope_manager.rb +2 -0
- data/lib/datadog/opentracer/span_context.rb +2 -0
- data/lib/datadog/opentracer/span_context_factory.rb +2 -0
- data/lib/datadog/opentracer/thread_local_scope.rb +2 -0
- data/lib/datadog/opentracer.rb +2 -0
- data/lib/datadog/profiling/backtrace_location.rb +2 -0
- data/lib/datadog/profiling/buffer.rb +2 -0
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +19 -3
- data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +2 -0
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
- data/lib/datadog/profiling/collectors/stack.rb +2 -0
- data/lib/datadog/profiling/collectors/thread_context.rb +2 -2
- data/lib/datadog/profiling/component.rb +103 -29
- data/lib/datadog/profiling/event.rb +2 -0
- data/lib/datadog/profiling/events/stack.rb +2 -0
- data/lib/datadog/profiling/ext.rb +28 -26
- data/lib/datadog/profiling/flush.rb +2 -0
- data/lib/datadog/profiling/native_extension.rb +2 -0
- data/lib/datadog/profiling/pprof/message_set.rb +2 -0
- data/lib/datadog/profiling/pprof/payload.rb +2 -0
- data/lib/datadog/profiling/pprof/string_table.rb +2 -0
- data/lib/datadog/profiling/preload.rb +2 -0
- data/lib/datadog/profiling/scheduler.rb +3 -1
- data/lib/datadog/profiling/stack_recorder.rb +0 -18
- data/lib/datadog/profiling/tag_builder.rb +2 -0
- data/lib/datadog/profiling/tasks/setup.rb +0 -26
- data/lib/datadog/profiling.rb +2 -1
- data/lib/datadog/tracing/analytics.rb +2 -0
- data/lib/datadog/tracing/configuration/ext.rb +7 -0
- data/lib/datadog/tracing/configuration/settings.rb +14 -0
- data/lib/datadog/tracing/context.rb +2 -0
- data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/action_cable/event.rb +2 -0
- data/lib/datadog/tracing/contrib/action_cable/events.rb +2 -0
- data/lib/datadog/tracing/contrib/action_cable/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/action_mailer/event.rb +2 -0
- data/lib/datadog/tracing/contrib/action_mailer/events.rb +2 -0
- data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +2 -24
- data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +14 -1
- data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/action_view/event.rb +2 -0
- data/lib/datadog/tracing/contrib/action_view/events.rb +2 -0
- data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/active_job/event.rb +2 -0
- data/lib/datadog/tracing/contrib/active_job/events.rb +2 -0
- data/lib/datadog/tracing/contrib/active_job/log_injection.rb +2 -0
- data/lib/datadog/tracing/contrib/active_job/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/event.rb +2 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +2 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/active_record/event.rb +2 -0
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -1
- data/lib/datadog/tracing/contrib/active_record/events.rb +2 -0
- data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +6 -2
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -0
- data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +2 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +2 -0
- data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/analytics.rb +2 -0
- data/lib/datadog/tracing/contrib/auto_instrument.rb +2 -0
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +9 -1
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +8 -1
- data/lib/datadog/tracing/contrib/aws/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +2 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/configurable.rb +2 -0
- data/lib/datadog/tracing/contrib/configuration/resolver.rb +2 -0
- data/lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb +2 -0
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +4 -1
- data/lib/datadog/tracing/contrib/dalli/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +2 -0
- data/lib/datadog/tracing/contrib/delayed_job/server_internal_tracer/worker.rb +2 -0
- data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +4 -1
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -3
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +6 -2
- data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -2
- data/lib/datadog/tracing/contrib/excon/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/faraday/connection.rb +2 -0
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -2
- data/lib/datadog/tracing/contrib/faraday/rack_builder.rb +2 -0
- data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +5 -2
- data/lib/datadog/tracing/contrib/grpc/intercept_with_datadog.rb +2 -0
- data/lib/datadog/tracing/contrib/grpc/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/plugin.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +2 -0
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +2 -0
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +8 -1
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -2
- data/lib/datadog/tracing/contrib/http/integration.rb +2 -0
- data/lib/datadog/tracing/contrib/http/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/http_annotation_helper.rb +2 -0
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/integration.rb +2 -0
- data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +2 -0
- data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +2 -0
- data/lib/datadog/tracing/contrib/kafka/event.rb +2 -0
- data/lib/datadog/tracing/contrib/kafka/events.rb +2 -0
- data/lib/datadog/tracing/contrib/kafka/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/mongodb/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/mongodb/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/mysql2/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/patchable.rb +2 -0
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/pg/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +2 -0
- data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/qless/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/qless/tracer_cleaner.rb +2 -0
- data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/racecar/event.rb +2 -0
- data/lib/datadog/tracing/contrib/racecar/events.rb +2 -0
- data/lib/datadog/tracing/contrib/racecar/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +9 -2
- data/lib/datadog/tracing/contrib/rails/framework.rb +2 -0
- data/lib/datadog/tracing/contrib/rails/middlewares.rb +2 -0
- data/lib/datadog/tracing/contrib/rails/utils.rb +3 -1
- data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/rake/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/redis/tags.rb +2 -0
- data/lib/datadog/tracing/contrib/registerable.rb +2 -0
- data/lib/datadog/tracing/contrib/registry.rb +2 -0
- data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/resque/resque_job.rb +2 -0
- data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +34 -0
- data/lib/datadog/tracing/contrib/roda/ext.rb +18 -0
- data/lib/datadog/tracing/contrib/roda/instrumentation.rb +76 -0
- data/lib/datadog/tracing/contrib/roda/integration.rb +45 -0
- data/lib/datadog/tracing/contrib/roda/patcher.rb +30 -0
- data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +3 -0
- data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/sequel/dataset.rb +2 -0
- data/lib/datadog/tracing/contrib/sequel/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +2 -0
- data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +12 -3
- data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +3 -0
- data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +38 -0
- data/lib/datadog/tracing/contrib/sidekiq/integration.rb +8 -0
- data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +16 -2
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/heartbeat.rb +11 -4
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/job_fetch.rb +2 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/redis_info.rb +2 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/scheduled_poller.rb +2 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/stop.rb +34 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +18 -2
- data/lib/datadog/tracing/contrib/sidekiq/{tracing.rb → utils.rb} +3 -1
- data/lib/datadog/tracing/contrib/sinatra/headers.rb +2 -0
- data/lib/datadog/tracing/contrib/sinatra/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +2 -0
- data/lib/datadog/tracing/contrib/span_attribute_schema.rb +28 -0
- data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +2 -0
- data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
- data/lib/datadog/tracing/contrib.rb +3 -0
- data/lib/datadog/tracing/correlation.rb +10 -10
- data/lib/datadog/tracing/diagnostics/health.rb +2 -0
- data/lib/datadog/tracing/distributed/trace_context.rb +22 -15
- data/lib/datadog/tracing/flush.rb +2 -0
- data/lib/datadog/tracing/metadata/analytics.rb +2 -0
- data/lib/datadog/tracing/metadata/errors.rb +2 -0
- data/lib/datadog/tracing/metadata/ext.rb +6 -0
- data/lib/datadog/tracing/metadata.rb +2 -0
- data/lib/datadog/tracing/pipeline/span_filter.rb +2 -0
- data/lib/datadog/tracing/pipeline/span_processor.rb +2 -0
- data/lib/datadog/tracing/propagation/http.rb +2 -0
- data/lib/datadog/tracing/runtime/metrics.rb +2 -0
- data/lib/datadog/tracing/sampling/all_sampler.rb +2 -0
- data/lib/datadog/tracing/sampling/matcher.rb +2 -0
- data/lib/datadog/tracing/sampling/priority_sampler.rb +2 -0
- data/lib/datadog/tracing/sampling/span/sampler.rb +2 -0
- data/lib/datadog/tracing/sync_writer.rb +2 -0
- data/lib/datadog/tracing/trace_digest.rb +2 -0
- data/lib/datadog/tracing/utils.rb +2 -0
- data/lib/datadog/tracing.rb +2 -0
- data/lib/ddtrace/auto_instrument.rb +2 -0
- data/lib/ddtrace/auto_instrument_base.rb +2 -0
- data/lib/ddtrace/transport/http/adapters/net.rb +12 -0
- data/lib/ddtrace/transport/http/adapters/registry.rb +2 -0
- data/lib/ddtrace/transport/http/api/endpoint.rb +2 -0
- data/lib/ddtrace/transport/http/api/fallbacks.rb +2 -0
- data/lib/ddtrace/transport/http/api/instance.rb +2 -0
- data/lib/ddtrace/transport/http/api/map.rb +2 -0
- data/lib/ddtrace/transport/http/api/spec.rb +2 -0
- data/lib/ddtrace/transport/http/env.rb +2 -0
- data/lib/ddtrace/transport/http/response.rb +2 -0
- data/lib/ddtrace/transport/io/response.rb +2 -0
- data/lib/ddtrace/transport/io/traces.rb +2 -0
- data/lib/ddtrace/transport/io.rb +2 -0
- data/lib/ddtrace/transport/parcel.rb +2 -0
- data/lib/ddtrace/transport/request.rb +3 -1
- data/lib/ddtrace/transport/statistics.rb +2 -0
- data/lib/ddtrace/transport/trace_formatter.rb +2 -0
- data/lib/ddtrace/version.rb +9 -5
- data/lib/ddtrace.rb +2 -0
- metadata +43 -6
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Core
|
5
|
+
module Transport
|
6
|
+
module HTTP
|
7
|
+
module API
|
8
|
+
# An API configured with adapter and routes
|
9
|
+
class Instance
|
10
|
+
attr_reader \
|
11
|
+
:adapter,
|
12
|
+
:headers,
|
13
|
+
:spec
|
14
|
+
|
15
|
+
def initialize(spec, adapter, options = {})
|
16
|
+
@spec = spec
|
17
|
+
@adapter = adapter
|
18
|
+
@headers = options.fetch(:headers, {})
|
19
|
+
end
|
20
|
+
|
21
|
+
def encoder
|
22
|
+
spec.encoder
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
# Add headers to request env, unless empty.
|
27
|
+
env.headers.merge!(headers) unless headers.empty?
|
28
|
+
|
29
|
+
# Send request env to the adapter.
|
30
|
+
adapter.call(env)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Core
|
5
|
+
module Transport
|
6
|
+
module HTTP
|
7
|
+
module API
|
8
|
+
# Specification for an HTTP API
|
9
|
+
# Defines behaviors without specific configuration details.
|
10
|
+
class Spec
|
11
|
+
def initialize
|
12
|
+
yield(self) if block_given?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../encoding'
|
4
|
+
|
5
|
+
require_relative '../../../../ddtrace/transport/http/api/map'
|
6
|
+
|
7
|
+
# TODO: Decouple standard transport/http/api/instance
|
8
|
+
#
|
9
|
+
# Separate classes are needed because transport/http/traces includes
|
10
|
+
# Trace::API::Instance which closes over and uses a single spec, which is
|
11
|
+
# negotiated as either /v3 or /v4 for the whole API at the spec level, but we
|
12
|
+
# need an independent toplevel path at the endpoint level.
|
13
|
+
#
|
14
|
+
# Separate classes are needed because of `include Trace::API::Instance`.
|
15
|
+
#
|
16
|
+
# Below should be:
|
17
|
+
# require_relative '../../../../ddtrace/transport/http/api/spec'
|
18
|
+
require_relative 'api/spec'
|
19
|
+
|
20
|
+
# TODO: only needed for Negotiation::API::Endpoint
|
21
|
+
require_relative 'negotiation'
|
22
|
+
|
23
|
+
# TODO: only needed for Config::API::Endpoint
|
24
|
+
require_relative 'config'
|
25
|
+
|
26
|
+
module Datadog
|
27
|
+
module Core
|
28
|
+
module Transport
|
29
|
+
module HTTP
|
30
|
+
# Namespace for API components
|
31
|
+
module API
|
32
|
+
# Default API versions
|
33
|
+
ROOT = 'root'
|
34
|
+
V7 = 'v0.7'
|
35
|
+
|
36
|
+
module_function
|
37
|
+
|
38
|
+
def defaults
|
39
|
+
Datadog::Transport::HTTP::API::Map[
|
40
|
+
ROOT => Spec.new do |s|
|
41
|
+
s.info = Negotiation::API::Endpoint.new(
|
42
|
+
'/info',
|
43
|
+
)
|
44
|
+
end,
|
45
|
+
V7 => Spec.new do |s|
|
46
|
+
s.config = Config::API::Endpoint.new(
|
47
|
+
'/v0.7/config',
|
48
|
+
Core::Encoding::JSONEncoder,
|
49
|
+
)
|
50
|
+
end,
|
51
|
+
]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../configuration/agent_settings_resolver'
|
4
|
+
require_relative '../../../../ddtrace/transport/http/adapters/registry'
|
5
|
+
require_relative '../../../../ddtrace/transport/http/api/map'
|
6
|
+
|
7
|
+
# TODO: Decouple standard transport/http/api/instance
|
8
|
+
#
|
9
|
+
# Separate classes are needed because transport/http/trace includes
|
10
|
+
# Trace::API::Instance which closes over and uses a single spec, which is
|
11
|
+
# negotiated as either /v3 or /v4 for the whole API at the spec level, but we
|
12
|
+
# need an independent toplevel path at the endpoint level.
|
13
|
+
#
|
14
|
+
# Separate classes are needed because of `include Trace::API::Instance`.
|
15
|
+
#
|
16
|
+
# Below should be:
|
17
|
+
# require_relative '../../../../ddtrace/transport/http/api/instance'
|
18
|
+
require_relative 'api/instance'
|
19
|
+
|
20
|
+
# TODO: Decouple transport/http/client
|
21
|
+
#
|
22
|
+
# The standard one does `include Transport::HTTP::Statistics` and performs
|
23
|
+
# stats updates, which may or may not be desirable in general.
|
24
|
+
#
|
25
|
+
# Below should be:
|
26
|
+
# require_relative '../../../../ddtrace/transport/http/client'
|
27
|
+
require_relative 'client'
|
28
|
+
|
29
|
+
# TODO: Decouple transport/http/builder
|
30
|
+
#
|
31
|
+
# This class is duplicated even though it is tantalisingly close to the
|
32
|
+
# one in ddtrace/transport mostly because it refers to a different
|
33
|
+
# `API::Instance` in `#api_instance_class` but also because it operates on a
|
34
|
+
# different `HTTP::Client`, as well as de-hardcoding the transport class
|
35
|
+
# `Transport::Traces::Transport` in `#to_transport`
|
36
|
+
#
|
37
|
+
# Additionally, its design makes it so there can be only one (API, Client,
|
38
|
+
# Transport) triplet, requiring a new transport instance for any varying
|
39
|
+
# element of the triplet.
|
40
|
+
|
41
|
+
module Datadog
|
42
|
+
module Core
|
43
|
+
module Transport
|
44
|
+
module HTTP
|
45
|
+
# Builds new instances of Transport::HTTP::Client
|
46
|
+
class Builder
|
47
|
+
REGISTRY = Datadog::Transport::HTTP::Adapters::Registry.new
|
48
|
+
|
49
|
+
attr_reader \
|
50
|
+
:apis,
|
51
|
+
:api_options,
|
52
|
+
:default_adapter,
|
53
|
+
:default_api,
|
54
|
+
:default_headers
|
55
|
+
|
56
|
+
def initialize
|
57
|
+
# Global settings
|
58
|
+
@default_adapter = nil
|
59
|
+
@default_headers = {}
|
60
|
+
|
61
|
+
# Client settings
|
62
|
+
@apis = Datadog::Transport::HTTP::API::Map.new
|
63
|
+
@default_api = nil
|
64
|
+
|
65
|
+
# API settings
|
66
|
+
@api_options = {}
|
67
|
+
|
68
|
+
yield(self) if block_given?
|
69
|
+
end
|
70
|
+
|
71
|
+
def adapter(config, *args, **kwargs)
|
72
|
+
@default_adapter = case config
|
73
|
+
when Core::Configuration::AgentSettingsResolver::AgentSettings
|
74
|
+
registry_klass = REGISTRY.get(config.adapter)
|
75
|
+
raise UnknownAdapterError, config.adapter if registry_klass.nil?
|
76
|
+
|
77
|
+
registry_klass.build(config)
|
78
|
+
when Symbol
|
79
|
+
registry_klass = REGISTRY.get(config)
|
80
|
+
raise UnknownAdapterError, config if registry_klass.nil?
|
81
|
+
|
82
|
+
registry_klass.new(*args, **kwargs)
|
83
|
+
else
|
84
|
+
config
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def headers(values = {})
|
89
|
+
@default_headers.merge!(values)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Adds a new API to the client
|
93
|
+
# Valid options:
|
94
|
+
# - :adapter
|
95
|
+
# - :default
|
96
|
+
# - :fallback
|
97
|
+
# - :headers
|
98
|
+
def api(key, spec, options = {})
|
99
|
+
options = options.dup
|
100
|
+
|
101
|
+
# Copy spec into API map
|
102
|
+
@apis[key] = spec
|
103
|
+
|
104
|
+
# Apply as default API, if specified to do so.
|
105
|
+
@default_api = key if options.delete(:default) || @default_api.nil?
|
106
|
+
|
107
|
+
# Save all other settings for initialization
|
108
|
+
(@api_options[key] ||= {}).merge!(options)
|
109
|
+
end
|
110
|
+
|
111
|
+
def default_api=(key)
|
112
|
+
raise UnknownApiError, key unless @apis.key?(key)
|
113
|
+
|
114
|
+
@default_api = key
|
115
|
+
end
|
116
|
+
|
117
|
+
def to_transport(klass)
|
118
|
+
raise NoDefaultApiError if @default_api.nil?
|
119
|
+
|
120
|
+
klass.new(to_api_instances, @default_api)
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_api_instances
|
124
|
+
raise NoApisError if @apis.empty?
|
125
|
+
|
126
|
+
@apis.inject(Datadog::Transport::HTTP::API::Map.new) do |instances, (key, spec)|
|
127
|
+
instances.tap do
|
128
|
+
api_options = @api_options[key].dup
|
129
|
+
|
130
|
+
# Resolve the adapter to use for this API
|
131
|
+
adapter = api_options.delete(:adapter) || @default_adapter
|
132
|
+
raise NoAdapterForApiError, key if adapter.nil?
|
133
|
+
|
134
|
+
# Resolve fallback and merge headers
|
135
|
+
fallback = api_options.delete(:fallback)
|
136
|
+
api_options[:headers] = @default_headers.merge((api_options[:headers] || {}))
|
137
|
+
|
138
|
+
# Add API::Instance with all settings
|
139
|
+
instances[key] = api_instance_class.new(
|
140
|
+
spec,
|
141
|
+
adapter,
|
142
|
+
api_options
|
143
|
+
)
|
144
|
+
|
145
|
+
# Configure fallback, if provided.
|
146
|
+
instances.with_fallbacks(key => fallback) unless fallback.nil?
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def api_instance_class
|
152
|
+
API::Instance
|
153
|
+
end
|
154
|
+
|
155
|
+
# Raised when the API key does not match known APIs.
|
156
|
+
class UnknownApiError < StandardError
|
157
|
+
attr_reader :key
|
158
|
+
|
159
|
+
def initialize(key)
|
160
|
+
super()
|
161
|
+
|
162
|
+
@key = key
|
163
|
+
end
|
164
|
+
|
165
|
+
def message
|
166
|
+
"Unknown transport API '#{key}'!"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Raised when the identifier cannot be matched to an adapter.
|
171
|
+
class UnknownAdapterError < StandardError
|
172
|
+
attr_reader :type
|
173
|
+
|
174
|
+
def initialize(type)
|
175
|
+
super()
|
176
|
+
|
177
|
+
@type = type
|
178
|
+
end
|
179
|
+
|
180
|
+
def message
|
181
|
+
"Unknown transport adapter '#{type}'!"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# Raised when an adapter cannot be resolved for an API instance.
|
186
|
+
class NoAdapterForApiError < StandardError
|
187
|
+
attr_reader :key
|
188
|
+
|
189
|
+
def initialize(key)
|
190
|
+
super()
|
191
|
+
|
192
|
+
@key = key
|
193
|
+
end
|
194
|
+
|
195
|
+
def message
|
196
|
+
"No adapter resolved for transport API '#{key}'!"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# Raised when built without defining APIs.
|
201
|
+
class NoApisError < StandardError
|
202
|
+
def message
|
203
|
+
'No APIs configured for transport!'
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
# Raised when client built without defining a default API.
|
208
|
+
class NoDefaultApiError < StandardError
|
209
|
+
def message
|
210
|
+
'No default API configured for transport!'
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../ddtrace/transport/http/env'
|
4
|
+
|
5
|
+
# TODO: Decouple transport/http/client
|
6
|
+
#
|
7
|
+
# The standard one does `include Transport::HTTP::Statistics` and performs
|
8
|
+
# stats updates, which may or may not be desirable in general.
|
9
|
+
|
10
|
+
module Datadog
|
11
|
+
module Core
|
12
|
+
module Transport
|
13
|
+
module HTTP
|
14
|
+
# Routes, encodes, and sends tracer data to the trace agent via HTTP.
|
15
|
+
class Client
|
16
|
+
attr_reader :api
|
17
|
+
|
18
|
+
def initialize(api)
|
19
|
+
@api = api
|
20
|
+
end
|
21
|
+
|
22
|
+
def send_request(request, &block)
|
23
|
+
# Build request into env
|
24
|
+
env = build_env(request)
|
25
|
+
|
26
|
+
# Get responses from API
|
27
|
+
yield(api, env)
|
28
|
+
rescue StandardError => e
|
29
|
+
message =
|
30
|
+
"Internal error during #{self.class.name} request. Cause: #{e.class.name} #{e.message} " \
|
31
|
+
"Location: #{Array(e.backtrace).first}"
|
32
|
+
|
33
|
+
Datadog.logger.error(message)
|
34
|
+
|
35
|
+
Datadog::Transport::InternalErrorResponse.new(e)
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_env(request)
|
39
|
+
Datadog::Transport::HTTP::Env.new(request)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,268 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
require_relative '../config'
|
7
|
+
require_relative 'client'
|
8
|
+
require_relative '../../../../ddtrace/transport/http/response'
|
9
|
+
require_relative '../../../../ddtrace/transport/http/api/endpoint'
|
10
|
+
|
11
|
+
# TODO: Decouple standard transport/http/api/instance
|
12
|
+
#
|
13
|
+
# Separate classes are needed because transport/http/trace includes
|
14
|
+
# Trace::API::Instance which closes over and uses a single spec, which is
|
15
|
+
# negotiated as either /v3 or /v4 for the whole API at the spec level, but we
|
16
|
+
# need an independent toplevel path at the endpoint level.
|
17
|
+
#
|
18
|
+
# Separate classes are needed because of `include Trace::API::Instance`.
|
19
|
+
#
|
20
|
+
# Below should be:
|
21
|
+
# require_relative '../../../../ddtrace/transport/http/api/instance'
|
22
|
+
require_relative 'api/instance'
|
23
|
+
# Below should be:
|
24
|
+
# require_relative '../../../../ddtrace/transport/http/api/spec'
|
25
|
+
require_relative 'api/spec'
|
26
|
+
|
27
|
+
module Datadog
|
28
|
+
module Core
|
29
|
+
module Transport
|
30
|
+
module HTTP
|
31
|
+
# HTTP transport behavior for remote configuration
|
32
|
+
module Config
|
33
|
+
# Response from HTTP transport for remote configuration
|
34
|
+
class Response
|
35
|
+
include Datadog::Transport::HTTP::Response
|
36
|
+
include Core::Transport::Config::Response
|
37
|
+
|
38
|
+
def initialize(http_response, options = {}) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
39
|
+
super(http_response)
|
40
|
+
|
41
|
+
begin
|
42
|
+
payload = JSON.parse(http_response.payload, symbolize_names: true)
|
43
|
+
rescue JSON::ParserError => e
|
44
|
+
raise ParseError.new(:roots, e)
|
45
|
+
end
|
46
|
+
|
47
|
+
raise TypeError.new(Hash, payload) unless payload.is_a?(Hash)
|
48
|
+
|
49
|
+
@empty = true if payload.empty?
|
50
|
+
|
51
|
+
# TODO: these fallbacks should be improved
|
52
|
+
roots = payload[:roots] || []
|
53
|
+
targets = payload[:targets] || Base64.encode64('{}').chomp
|
54
|
+
target_files = payload[:target_files] || []
|
55
|
+
client_configs = payload[:client_configs] || []
|
56
|
+
|
57
|
+
raise TypeError.new(Array, roots) unless roots.is_a?(Array)
|
58
|
+
|
59
|
+
@roots = roots.map do |root|
|
60
|
+
raise TypeError.new(String, root) unless root.is_a?(String)
|
61
|
+
|
62
|
+
decoded = begin
|
63
|
+
Base64.strict_decode64(root) # TODO: unprocessed, don't symbolize_names
|
64
|
+
rescue ArgumentError
|
65
|
+
raise DecodeError.new(:roots, root)
|
66
|
+
end
|
67
|
+
|
68
|
+
parsed = begin
|
69
|
+
JSON.parse(decoded)
|
70
|
+
rescue JSON::ParserError
|
71
|
+
raise ParseError.new(:roots, decoded)
|
72
|
+
end
|
73
|
+
|
74
|
+
# TODO: perform more processing to validate content. til then, no freeze
|
75
|
+
|
76
|
+
parsed
|
77
|
+
end
|
78
|
+
|
79
|
+
raise TypeError.new(String, targets) unless targets.is_a?(String)
|
80
|
+
|
81
|
+
@targets = begin
|
82
|
+
decoded = begin
|
83
|
+
Base64.strict_decode64(targets)
|
84
|
+
rescue ArgumentError
|
85
|
+
raise DecodeError.new(:targets, targets)
|
86
|
+
end
|
87
|
+
|
88
|
+
parsed = begin
|
89
|
+
JSON.parse(decoded) # TODO: unprocessed, don't symbolize_names
|
90
|
+
rescue JSON::ParserError
|
91
|
+
raise ParseError.new(:targets, decoded)
|
92
|
+
end
|
93
|
+
|
94
|
+
# TODO: perform more processing to validate content. til then, no freeze
|
95
|
+
|
96
|
+
parsed
|
97
|
+
end
|
98
|
+
|
99
|
+
raise TypeError.new(Array, target_files) unless target_files.is_a?(Array)
|
100
|
+
|
101
|
+
@target_files = target_files.map do |h|
|
102
|
+
raise TypeError.new(Hash, h) unless h.is_a?(Hash)
|
103
|
+
raise KeyError.new(:raw) unless h.key?(:raw) # rubocop:disable Style/RaiseArgs
|
104
|
+
raise KeyError.new(:path) unless h.key?(:path) # rubocop:disable Style/RaiseArgs
|
105
|
+
|
106
|
+
raw = h[:raw]
|
107
|
+
|
108
|
+
raise TypeError.new(String, raw) unless raw.is_a?(String)
|
109
|
+
|
110
|
+
content = begin
|
111
|
+
Base64.strict_decode64(raw)
|
112
|
+
rescue ArgumentError
|
113
|
+
raise DecodeError.new(:target_files, raw)
|
114
|
+
end
|
115
|
+
|
116
|
+
{
|
117
|
+
path: h[:path].freeze,
|
118
|
+
content: StringIO.new(content.freeze),
|
119
|
+
}
|
120
|
+
end.freeze
|
121
|
+
|
122
|
+
@client_configs = client_configs.map do |s|
|
123
|
+
raise TypeError.new(String, s) unless s.is_a?(String)
|
124
|
+
|
125
|
+
s.freeze
|
126
|
+
end.freeze
|
127
|
+
end
|
128
|
+
|
129
|
+
# When an expected key is missing
|
130
|
+
class KeyError < StandardError
|
131
|
+
def initialize(key)
|
132
|
+
message = "key not found: #{key.inspect}"
|
133
|
+
|
134
|
+
super(message)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# When an expected value type is incorrect
|
139
|
+
class TypeError < StandardError
|
140
|
+
def initialize(type, value)
|
141
|
+
message = "not a #{type}: #{value.inspect}"
|
142
|
+
|
143
|
+
super(message)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# When value decoding fails
|
148
|
+
class DecodeError < StandardError
|
149
|
+
def initialize(key, value)
|
150
|
+
message = "could not decode key #{key.inspect}: #{value.inspect}"
|
151
|
+
|
152
|
+
super(message)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
# When value parsing fails
|
157
|
+
class ParseError < StandardError
|
158
|
+
def initialize(key, value)
|
159
|
+
message = "could not parse key #{key.inspect}: #{value.inspect}"
|
160
|
+
|
161
|
+
super(message)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Extensions for HTTP client
|
167
|
+
module Client
|
168
|
+
def send_config_payload(request)
|
169
|
+
send_request(request) do |api, env|
|
170
|
+
api.send_config(env)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
module API
|
176
|
+
# Extensions for HTTP API Spec
|
177
|
+
module Spec
|
178
|
+
attr_reader :config
|
179
|
+
|
180
|
+
def config=(endpoint)
|
181
|
+
@config = endpoint
|
182
|
+
end
|
183
|
+
|
184
|
+
def send_config(env, &block)
|
185
|
+
raise NoConfigEndpointDefinedError, self if config.nil?
|
186
|
+
|
187
|
+
config.call(env, &block)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Raised when traces sent but no traces endpoint is defined
|
191
|
+
class NoConfigEndpointDefinedError < StandardError
|
192
|
+
attr_reader :spec
|
193
|
+
|
194
|
+
def initialize(spec)
|
195
|
+
super()
|
196
|
+
|
197
|
+
@spec = spec
|
198
|
+
end
|
199
|
+
|
200
|
+
def message
|
201
|
+
'No config endpoint is defined for API specification!'
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Extensions for HTTP API Instance
|
207
|
+
module Instance
|
208
|
+
def send_config(env)
|
209
|
+
raise ConfigNotSupportedError, spec unless spec.is_a?(Config::API::Spec)
|
210
|
+
|
211
|
+
spec.send_config(env) do |request_env|
|
212
|
+
call(request_env)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# Raised when traces sent to API that does not support traces
|
217
|
+
class ConfigNotSupportedError < StandardError
|
218
|
+
attr_reader :spec
|
219
|
+
|
220
|
+
def initialize(spec)
|
221
|
+
super()
|
222
|
+
|
223
|
+
@spec = spec
|
224
|
+
end
|
225
|
+
|
226
|
+
def message
|
227
|
+
'Config not supported for this API!'
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# Endpoint for remote configuration
|
233
|
+
class Endpoint < Datadog::Transport::HTTP::API::Endpoint
|
234
|
+
HEADER_CONTENT_TYPE = 'Content-Type'
|
235
|
+
|
236
|
+
attr_reader :encoder
|
237
|
+
|
238
|
+
def initialize(path, encoder)
|
239
|
+
super(:post, path)
|
240
|
+
@encoder = encoder
|
241
|
+
end
|
242
|
+
|
243
|
+
def call(env, &block)
|
244
|
+
# Encode body & type
|
245
|
+
env.headers[HEADER_CONTENT_TYPE] = encoder.content_type
|
246
|
+
env.body = env.request.parcel.data
|
247
|
+
|
248
|
+
# Query for response
|
249
|
+
http_response = super(env, &block)
|
250
|
+
|
251
|
+
response_options = {}
|
252
|
+
|
253
|
+
# Build and return a response
|
254
|
+
Config::Response.new(http_response, response_options)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
# Add remote configuration behavior to transport components
|
260
|
+
###### overrides send_payload! which calls send_<endpoint>! kills any other possible endpoint!
|
261
|
+
HTTP::Client.include(Config::Client)
|
262
|
+
HTTP::API::Spec.include(Config::API::Spec)
|
263
|
+
HTTP::API::Instance.include(Config::API::Instance)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|