ddtrace 1.10.0 → 1.11.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +86 -2
- data/LICENSE-3rdparty.csv +1 -0
- data/README.md +8 -9
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +76 -11
- 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 +41 -7
- 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 +7 -25
- 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 -3
- 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/ext/environment.rb +2 -20
- 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 +6 -6
- data/lib/datadog/core/configuration/components.rb +12 -15
- 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 +68 -13
- 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 +2 -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 +146 -0
- data/lib/datadog/core/remote/component.rb +150 -0
- data/lib/datadog/core/remote/configuration/content.rb +82 -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 +278 -0
- data/lib/datadog/core/remote/configuration/target.rb +72 -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/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/network.rb +140 -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/vendor/ipaddr.rb +78 -0
- data/lib/datadog/core/worker.rb +2 -0
- data/lib/datadog/core/workers/interval_loop.rb +2 -0
- data/lib/datadog/core/workers/queue.rb +2 -0
- data/lib/datadog/core/workers/runtime_metrics.rb +2 -0
- data/lib/datadog/kit/appsec/events.rb +1 -1
- 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/client_ip.rb +39 -140
- 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 +2 -0
- data/lib/datadog/tracing/contrib/active_record/event.rb +2 -0
- 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 +2 -0
- 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 -2
- 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 +2 -0
- 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 +2 -0
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/excon/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +2 -0
- data/lib/datadog/tracing/contrib/faraday/connection.rb +2 -0
- 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 +2 -0
- 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 +2 -0
- 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/patcher.rb +2 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/heartbeat.rb +2 -0
- 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_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/http/traces.rb +1 -1
- 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/transport/traces.rb +1 -1
- data/lib/ddtrace/version.rb +6 -4
- data/lib/ddtrace.rb +2 -0
- metadata +45 -9
@@ -2,9 +2,12 @@
|
|
2
2
|
|
3
3
|
module Datadog
|
4
4
|
module Profiling
|
5
|
-
#
|
5
|
+
# Responsible for wiring up the Profiler for execution
|
6
6
|
module Component
|
7
|
-
|
7
|
+
# Passing in a `nil` tracer is supported and will disable the following profiling features:
|
8
|
+
# * Code Hotspots panel in the trace viewer, as well as scoping a profile down to a span
|
9
|
+
# * Endpoint aggregation in the profiler UX, including normalization (resource per endpoint call)
|
10
|
+
def self.build_profiler_component(settings:, agent_settings:, optional_tracer:)
|
8
11
|
return unless settings.profiling.enabled
|
9
12
|
|
10
13
|
# Workaround for weird dependency direction: the Core::Configuration::Components class currently has a
|
@@ -61,7 +64,7 @@ module Datadog
|
|
61
64
|
|
62
65
|
# NOTE: Please update the Initialization section of ProfilingDevelopment.md with any changes to this method
|
63
66
|
|
64
|
-
if settings
|
67
|
+
if enable_new_profiler?(settings)
|
65
68
|
print_new_profiler_warnings
|
66
69
|
|
67
70
|
recorder = Datadog::Profiling::StackRecorder.new(
|
@@ -71,18 +74,14 @@ module Datadog
|
|
71
74
|
collector = Datadog::Profiling::Collectors::CpuAndWallTimeWorker.new(
|
72
75
|
recorder: recorder,
|
73
76
|
max_frames: settings.profiling.advanced.max_frames,
|
74
|
-
tracer:
|
75
|
-
|
77
|
+
tracer: optional_tracer,
|
78
|
+
endpoint_collection_enabled: settings.profiling.advanced.endpoint.collection.enabled,
|
79
|
+
gc_profiling_enabled: enable_gc_profiling?(settings),
|
76
80
|
allocation_counting_enabled: settings.profiling.advanced.allocation_counting_enabled,
|
77
81
|
)
|
78
82
|
else
|
79
|
-
trace_identifiers_helper = Profiling::TraceIdentifiers::Helper.new(
|
80
|
-
tracer: tracer,
|
81
|
-
endpoint_collection_enabled: settings.profiling.advanced.endpoint.collection.enabled
|
82
|
-
)
|
83
|
-
|
84
83
|
recorder = build_profiler_old_recorder(settings)
|
85
|
-
collector = build_profiler_oldstack_collector(settings, recorder,
|
84
|
+
collector = build_profiler_oldstack_collector(settings, recorder, optional_tracer)
|
86
85
|
end
|
87
86
|
|
88
87
|
exporter = build_profiler_exporter(settings, recorder)
|
@@ -92,20 +91,23 @@ module Datadog
|
|
92
91
|
Profiling::Profiler.new([collector], scheduler)
|
93
92
|
end
|
94
93
|
|
95
|
-
|
96
|
-
|
97
|
-
def build_profiler_old_recorder(settings)
|
94
|
+
private_class_method def self.build_profiler_old_recorder(settings)
|
98
95
|
Profiling::OldRecorder.new([Profiling::Events::StackSample], settings.profiling.advanced.max_events)
|
99
96
|
end
|
100
97
|
|
101
|
-
def build_profiler_exporter(settings, recorder)
|
98
|
+
private_class_method def self.build_profiler_exporter(settings, recorder)
|
102
99
|
code_provenance_collector =
|
103
100
|
(Profiling::Collectors::CodeProvenance.new if settings.profiling.advanced.code_provenance_enabled)
|
104
101
|
|
105
102
|
Profiling::Exporter.new(pprof_recorder: recorder, code_provenance_collector: code_provenance_collector)
|
106
103
|
end
|
107
104
|
|
108
|
-
def build_profiler_oldstack_collector(settings, old_recorder,
|
105
|
+
private_class_method def self.build_profiler_oldstack_collector(settings, old_recorder, tracer)
|
106
|
+
trace_identifiers_helper = Profiling::TraceIdentifiers::Helper.new(
|
107
|
+
tracer: tracer,
|
108
|
+
endpoint_collection_enabled: settings.profiling.advanced.endpoint.collection.enabled
|
109
|
+
)
|
110
|
+
|
109
111
|
Profiling::Collectors::OldStack.new(
|
110
112
|
old_recorder,
|
111
113
|
trace_identifiers_helper: trace_identifiers_helper,
|
@@ -113,7 +115,7 @@ module Datadog
|
|
113
115
|
)
|
114
116
|
end
|
115
117
|
|
116
|
-
def build_profiler_transport(settings, agent_settings)
|
118
|
+
private_class_method def self.build_profiler_transport(settings, agent_settings)
|
117
119
|
settings.profiling.exporter.transport ||
|
118
120
|
Profiling::HttpTransport.new(
|
119
121
|
agent_settings: agent_settings,
|
@@ -123,7 +125,7 @@ module Datadog
|
|
123
125
|
)
|
124
126
|
end
|
125
127
|
|
126
|
-
def
|
128
|
+
private_class_method def self.enable_gc_profiling?(settings)
|
127
129
|
# See comments on the setting definition for more context on why it exists.
|
128
130
|
if settings.profiling.advanced.force_enable_gc_profiling
|
129
131
|
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3')
|
@@ -139,21 +141,93 @@ module Datadog
|
|
139
141
|
end
|
140
142
|
end
|
141
143
|
|
142
|
-
def print_new_profiler_warnings
|
143
|
-
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
|
144
|
+
private_class_method def self.print_new_profiler_warnings
|
145
|
+
return if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6')
|
146
|
+
|
147
|
+
# For more details on the issue, see the "BIG Issue" comment on `gvl_owner` function in
|
148
|
+
# `private_vm_api_access.c`.
|
149
|
+
Datadog.logger.warn(
|
150
|
+
'The new CPU Profiling 2.0 profiler has been force-enabled on a legacy Ruby version (< 2.6). This is not ' \
|
151
|
+
'recommended in production environments, as due to limitations in Ruby APIs, we suspect it may lead to crashes ' \
|
152
|
+
'in very rare situations. Please report any issues you run into to Datadog support or ' \
|
153
|
+
'via <https://github.com/datadog/dd-trace-rb/issues/new>!'
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
157
|
+
private_class_method def self.enable_new_profiler?(settings)
|
158
|
+
if settings.profiling.advanced.force_enable_legacy_profiler
|
144
159
|
Datadog.logger.warn(
|
145
|
-
'
|
146
|
-
'you run into to Datadog support or via <https://github.com/datadog/dd-trace-rb/issues/new>!'
|
160
|
+
'Legacy profiler has been force-enabled via configuration. Do not use unless instructed to by support.'
|
147
161
|
)
|
148
|
-
|
149
|
-
|
150
|
-
|
162
|
+
return false
|
163
|
+
end
|
164
|
+
|
165
|
+
return true if settings.profiling.advanced.force_enable_new_profiler
|
166
|
+
|
167
|
+
return false if RUBY_VERSION.start_with?('2.3.', '2.4.', '2.5.')
|
168
|
+
|
169
|
+
if Gem.loaded_specs['mysql2'] && incompatible_libmysqlclient_version?(settings)
|
170
|
+
Datadog.logger.warn(
|
171
|
+
'Falling back to legacy profiler because an incompatible version of the mysql2 gem is installed. ' \
|
172
|
+
'Older versions of libmysqlclient (the C ' \
|
173
|
+
'library used by the mysql2 gem) have a bug in their signal handling code that the new profiler can trigger. ' \
|
174
|
+
'This bug (https://bugs.mysql.com/bug.php?id=83109) is fixed in libmysqlclient versions 8.0.0 and above. '
|
175
|
+
)
|
176
|
+
return false
|
177
|
+
end
|
178
|
+
|
179
|
+
if Gem.loaded_specs['rugged']
|
151
180
|
Datadog.logger.warn(
|
152
|
-
'
|
153
|
-
'
|
154
|
-
'
|
155
|
-
'
|
181
|
+
'Falling back to legacy profiler because rugged gem is installed. Some operations on this gem are ' \
|
182
|
+
'currently incompatible with the new CPU Profiling 2.0 profiler, as detailed in ' \
|
183
|
+
'<https://github.com/datadog/dd-trace-rb/issues/2721>. If you still want to try out the new profiler, you ' \
|
184
|
+
'can force-enable it by using the `DD_PROFILING_FORCE_ENABLE_NEW` environment variable or the ' \
|
185
|
+
'`c.profiling.advanced.force_enable_new_profiler` setting.'
|
156
186
|
)
|
187
|
+
return false
|
188
|
+
end
|
189
|
+
|
190
|
+
true
|
191
|
+
end
|
192
|
+
|
193
|
+
# Versions of libmysqlclient prior to 8.0.0 are known to have buggy handling of system call interruptions.
|
194
|
+
# The profiler can sometimes cause system call interruptions, and so this combination can cause queries to fail.
|
195
|
+
#
|
196
|
+
# See https://bugs.mysql.com/bug.php?id=83109 and
|
197
|
+
# https://docs.datadoghq.com/profiler/profiler_troubleshooting/ruby/#unexpected-run-time-failures-and-errors-from-ruby-gems-that-use-native-extensions-in-dd-trace-rb-1110
|
198
|
+
# for details.
|
199
|
+
#
|
200
|
+
# The `mysql2` gem's `info` method can be used to determine which `libmysqlclient` version is in use, and thus to
|
201
|
+
# detect if it's safe for the profiler to use signals or if we need to employ a fallback.
|
202
|
+
private_class_method def self.incompatible_libmysqlclient_version?(settings)
|
203
|
+
return true if settings.profiling.advanced.skip_mysql2_check
|
204
|
+
|
205
|
+
Datadog.logger.debug(
|
206
|
+
'Requiring `mysql2` to check if the `libmysqlclient` version it uses is compatible with profiling'
|
207
|
+
)
|
208
|
+
|
209
|
+
begin
|
210
|
+
require 'mysql2'
|
211
|
+
|
212
|
+
return true unless defined?(Mysql2::Client) && Mysql2::Client.respond_to?(:info)
|
213
|
+
|
214
|
+
libmysqlclient_version = Gem::Version.new(Mysql2::Client.info[:version])
|
215
|
+
|
216
|
+
compatible = libmysqlclient_version >= Gem::Version.new('8.0.0')
|
217
|
+
|
218
|
+
Datadog.logger.debug(
|
219
|
+
"The `mysql2` gem is using #{compatible ? 'a compatible' : 'an incompatible'} version of " \
|
220
|
+
"the `libmysqlclient` library (#{libmysqlclient_version})"
|
221
|
+
)
|
222
|
+
|
223
|
+
!compatible
|
224
|
+
rescue StandardError, LoadError => e
|
225
|
+
Datadog.logger.warn(
|
226
|
+
'Failed to probe `mysql2` gem information. ' \
|
227
|
+
"Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
|
228
|
+
)
|
229
|
+
|
230
|
+
true
|
157
231
|
end
|
158
232
|
end
|
159
233
|
end
|
@@ -1,41 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Datadog
|
2
4
|
module Profiling
|
3
5
|
module Ext
|
4
|
-
ENV_ENABLED = 'DD_PROFILING_ENABLED'
|
5
|
-
ENV_UPLOAD_TIMEOUT = 'DD_PROFILING_UPLOAD_TIMEOUT'
|
6
|
-
ENV_MAX_FRAMES = 'DD_PROFILING_MAX_FRAMES'
|
7
|
-
ENV_AGENTLESS = 'DD_PROFILING_AGENTLESS'
|
8
|
-
ENV_ENDPOINT_COLLECTION_ENABLED = 'DD_PROFILING_ENDPOINT_COLLECTION_ENABLED'
|
6
|
+
ENV_ENABLED = 'DD_PROFILING_ENABLED'
|
7
|
+
ENV_UPLOAD_TIMEOUT = 'DD_PROFILING_UPLOAD_TIMEOUT'
|
8
|
+
ENV_MAX_FRAMES = 'DD_PROFILING_MAX_FRAMES'
|
9
|
+
ENV_AGENTLESS = 'DD_PROFILING_AGENTLESS'
|
10
|
+
ENV_ENDPOINT_COLLECTION_ENABLED = 'DD_PROFILING_ENDPOINT_COLLECTION_ENABLED'
|
9
11
|
|
10
12
|
# TODO: Consider removing this once the Ruby-based pprof encoding is removed and replaced by libdatadog
|
11
13
|
module Pprof
|
12
|
-
LABEL_KEY_LOCAL_ROOT_SPAN_ID = 'local root span id'
|
13
|
-
LABEL_KEY_SPAN_ID = 'span id'
|
14
|
-
LABEL_KEY_THREAD_ID = 'thread id'
|
15
|
-
LABEL_KEY_TRACE_ENDPOINT = 'trace endpoint'
|
14
|
+
LABEL_KEY_LOCAL_ROOT_SPAN_ID = 'local root span id'
|
15
|
+
LABEL_KEY_SPAN_ID = 'span id'
|
16
|
+
LABEL_KEY_THREAD_ID = 'thread id'
|
17
|
+
LABEL_KEY_TRACE_ENDPOINT = 'trace endpoint'
|
16
18
|
SAMPLE_VALUE_NO_VALUE = 0
|
17
|
-
VALUE_TYPE_CPU = 'cpu-time'
|
18
|
-
VALUE_TYPE_WALL = 'wall-time'
|
19
|
-
VALUE_UNIT_NANOSECONDS = 'nanoseconds'
|
19
|
+
VALUE_TYPE_CPU = 'cpu-time'
|
20
|
+
VALUE_TYPE_WALL = 'wall-time'
|
21
|
+
VALUE_UNIT_NANOSECONDS = 'nanoseconds'
|
20
22
|
end
|
21
23
|
|
22
24
|
module Transport
|
23
25
|
module HTTP
|
24
|
-
FORM_FIELD_TAG_ENV = 'env'
|
25
|
-
FORM_FIELD_TAG_HOST = 'host'
|
26
|
-
FORM_FIELD_TAG_LANGUAGE = 'language'
|
27
|
-
FORM_FIELD_TAG_PID = 'process_id'
|
28
|
-
FORM_FIELD_TAG_PROFILER_VERSION = 'profiler_version'
|
29
|
-
FORM_FIELD_TAG_RUNTIME = 'runtime'
|
30
|
-
FORM_FIELD_TAG_RUNTIME_ENGINE = 'runtime_engine'
|
31
|
-
FORM_FIELD_TAG_RUNTIME_ID = 'runtime-id'
|
32
|
-
FORM_FIELD_TAG_RUNTIME_PLATFORM = 'runtime_platform'
|
33
|
-
FORM_FIELD_TAG_RUNTIME_VERSION = 'runtime_version'
|
34
|
-
FORM_FIELD_TAG_SERVICE = 'service'
|
35
|
-
FORM_FIELD_TAG_VERSION = 'version'
|
26
|
+
FORM_FIELD_TAG_ENV = 'env'
|
27
|
+
FORM_FIELD_TAG_HOST = 'host'
|
28
|
+
FORM_FIELD_TAG_LANGUAGE = 'language'
|
29
|
+
FORM_FIELD_TAG_PID = 'process_id'
|
30
|
+
FORM_FIELD_TAG_PROFILER_VERSION = 'profiler_version'
|
31
|
+
FORM_FIELD_TAG_RUNTIME = 'runtime'
|
32
|
+
FORM_FIELD_TAG_RUNTIME_ENGINE = 'runtime_engine'
|
33
|
+
FORM_FIELD_TAG_RUNTIME_ID = 'runtime-id'
|
34
|
+
FORM_FIELD_TAG_RUNTIME_PLATFORM = 'runtime_platform'
|
35
|
+
FORM_FIELD_TAG_RUNTIME_VERSION = 'runtime_version'
|
36
|
+
FORM_FIELD_TAG_SERVICE = 'service'
|
37
|
+
FORM_FIELD_TAG_VERSION = 'version'
|
36
38
|
|
37
|
-
PPROF_DEFAULT_FILENAME = 'rubyprofile.pprof'
|
38
|
-
CODE_PROVENANCE_FILENAME = 'code-provenance.json'
|
39
|
+
PPROF_DEFAULT_FILENAME = 'rubyprofile.pprof'
|
40
|
+
CODE_PROVENANCE_FILENAME = 'code-provenance.json'
|
39
41
|
end
|
40
42
|
end
|
41
43
|
end
|
@@ -118,7 +118,9 @@ module Datadog
|
|
118
118
|
begin
|
119
119
|
transport.export(flush)
|
120
120
|
rescue StandardError => e
|
121
|
-
Datadog.logger.error(
|
121
|
+
Datadog.logger.error(
|
122
|
+
"Unable to report profile. Cause: #{e.class.name} #{e.message} Location: #{Array(e.backtrace).first}"
|
123
|
+
)
|
122
124
|
end
|
123
125
|
|
124
126
|
true
|
@@ -48,24 +48,6 @@ module Datadog
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def clear
|
52
|
-
status, result = @no_concurrent_synchronize_mutex.synchronize { self.class._native_clear(self) }
|
53
|
-
|
54
|
-
if status == :ok
|
55
|
-
finish_timestamp = result
|
56
|
-
|
57
|
-
Datadog.logger.debug { "Cleared profile at #{finish_timestamp}" }
|
58
|
-
|
59
|
-
finish_timestamp
|
60
|
-
else
|
61
|
-
error_message = result
|
62
|
-
|
63
|
-
Datadog.logger.error("Failed to clear profiling data: #{error_message}")
|
64
|
-
|
65
|
-
nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
51
|
def reset_after_fork
|
70
52
|
self.class._native_reset_after_fork(self)
|
71
53
|
end
|
@@ -11,7 +11,6 @@ module Datadog
|
|
11
11
|
def run
|
12
12
|
ACTIVATE_EXTENSIONS_ONLY_ONCE.run do
|
13
13
|
begin
|
14
|
-
check_if_cpu_time_profiling_is_supported
|
15
14
|
activate_forking_extensions
|
16
15
|
setup_at_fork_hooks
|
17
16
|
rescue StandardError, ScriptError => e
|
@@ -38,17 +37,6 @@ module Datadog
|
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
def check_if_cpu_time_profiling_is_supported
|
42
|
-
unsupported = cpu_time_profiling_unsupported_reason
|
43
|
-
|
44
|
-
if unsupported
|
45
|
-
Datadog.logger.info do
|
46
|
-
'CPU time profiling skipped because native CPU time is not supported: ' \
|
47
|
-
"#{unsupported}. Profiles containing 'Wall time' data will still be reported."
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
40
|
def setup_at_fork_hooks
|
53
41
|
if Process.respond_to?(:at_fork)
|
54
42
|
Process.at_fork(:child) do
|
@@ -64,20 +52,6 @@ module Datadog
|
|
64
52
|
end
|
65
53
|
end
|
66
54
|
end
|
67
|
-
|
68
|
-
def cpu_time_profiling_unsupported_reason
|
69
|
-
# NOTE: Only the first matching reason is returned, so try to keep a nice order on reasons
|
70
|
-
|
71
|
-
if RUBY_ENGINE == 'jruby'
|
72
|
-
'JRuby is not supported'
|
73
|
-
elsif RUBY_PLATFORM.include?('darwin')
|
74
|
-
'Feature requires Linux; macOS is not supported'
|
75
|
-
elsif RUBY_PLATFORM =~ /(mswin|mingw)/
|
76
|
-
'Feature requires Linux; Windows is not supported'
|
77
|
-
elsif !RUBY_PLATFORM.include?('linux')
|
78
|
-
"Feature requires Linux; #{RUBY_PLATFORM} is not supported"
|
79
|
-
end
|
80
|
-
end
|
81
55
|
end
|
82
56
|
end
|
83
57
|
end
|
data/lib/datadog/profiling.rb
CHANGED
@@ -113,6 +113,7 @@ module Datadog
|
|
113
113
|
|
114
114
|
private_class_method def self.protobuf_already_loaded?
|
115
115
|
defined?(::Google::Protobuf) && !defined?(::Protobuf)
|
116
|
+
!!(defined?(::Google::Protobuf) && !defined?(::Protobuf))
|
116
117
|
end
|
117
118
|
|
118
119
|
private_class_method def self.protobuf_failed_to_load?
|
@@ -157,7 +158,7 @@ module Datadog
|
|
157
158
|
unless success
|
158
159
|
if exception
|
159
160
|
'There was an error loading the profiling native extension due to ' \
|
160
|
-
"'#{exception.class.name} #{exception.message}' at '#{exception.backtrace.first}'"
|
161
|
+
"'#{exception.class.name} #{exception.message}' at '#{Array(exception.backtrace).first}'"
|
161
162
|
else
|
162
163
|
'The profiling native extension did not load correctly. ' \
|
163
164
|
'For help solving this issue, please contact Datadog support at <https://docs.datadoghq.com/help/>.' \
|
@@ -1,162 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../core/configuration'
|
4
|
+
require_relative '../core/utils/network'
|
2
5
|
require_relative 'metadata/ext'
|
3
6
|
require_relative 'span'
|
4
7
|
|
5
|
-
require 'ipaddr'
|
6
|
-
|
7
8
|
module Datadog
|
8
9
|
module Tracing
|
9
10
|
# Common functions for supporting the `http.client_ip` span attribute.
|
10
11
|
module ClientIp
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# Sets the `http.client_ip` tag on the given span.
|
26
|
-
#
|
27
|
-
# This function respects the user's settings: if they disable the client IP tagging,
|
28
|
-
# or provide a different IP header name.
|
29
|
-
#
|
30
|
-
# If multiple IP headers are present in the request, this function will instead set
|
31
|
-
# the `_dd.multiple-ip-headers` tag with the names of the present headers,
|
32
|
-
# and **NOT** set the `http.client_ip` tag.
|
33
|
-
#
|
34
|
-
# @param [Span] span The span that's associated with the request.
|
35
|
-
# @param [HeaderCollection, #get, nil] headers A collection with the request headers.
|
36
|
-
# @param [String, nil] remote_ip The remote IP the request associated with the span is sent to.
|
37
|
-
def self.set_client_ip_tag(span, headers: nil, remote_ip: nil)
|
38
|
-
return unless configuration.enabled
|
39
|
-
|
40
|
-
set_client_ip_tag!(span, headers: headers, remote_ip: remote_ip)
|
41
|
-
end
|
42
|
-
|
43
|
-
# Forcefully sets the `http.client_ip` tag on the given span.
|
44
|
-
#
|
45
|
-
# This function ignores the user's `enabled` setting.
|
46
|
-
#
|
47
|
-
# @param [Span] span The span that's associated with the request.
|
48
|
-
# @param [HeaderCollection, #get, nil] headers A collection with the request headers.
|
49
|
-
# @param [String, nil] remote_ip The remote IP the request associated with the span is sent to.
|
50
|
-
def self.set_client_ip_tag!(span, headers: nil, remote_ip: nil)
|
51
|
-
result = raw_ip_from_request(headers, remote_ip)
|
52
|
-
|
53
|
-
if result.raw_ip
|
54
|
-
ip = strip_decorations(result.raw_ip)
|
55
|
-
return unless valid_ip?(ip)
|
56
|
-
|
57
|
-
span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_CLIENT_IP, ip)
|
58
|
-
elsif result.multiple_ip_headers
|
59
|
-
span.set_tag(TAG_MULTIPLE_IP_HEADERS, result.multiple_ip_headers.keys.join(','))
|
12
|
+
class << self
|
13
|
+
# Sets the `http.client_ip` tag on the given span.
|
14
|
+
#
|
15
|
+
# This function respects the user's settings: if they disable the client IP tagging,
|
16
|
+
# or provide a different IP header name.
|
17
|
+
#
|
18
|
+
# @param [Span] span The span that's associated with the request.
|
19
|
+
# @param [HeaderCollection, #get, nil] headers A collection with the request headers.
|
20
|
+
# @param [String, nil] remote_ip The remote IP the request associated with the span is sent to.
|
21
|
+
def set_client_ip_tag(span, headers: nil, remote_ip: nil)
|
22
|
+
return unless configuration.enabled
|
23
|
+
|
24
|
+
set_client_ip_tag!(span, headers: headers, remote_ip: remote_ip)
|
60
25
|
end
|
61
|
-
end
|
62
|
-
|
63
|
-
IpExtractionResult = Struct.new(:raw_ip, :multiple_ip_headers)
|
64
|
-
|
65
|
-
# Returns a result struct that holds the raw client IP associated with the request if it was
|
66
|
-
# retrieved successfully.
|
67
|
-
#
|
68
|
-
# The client IP is looked up by the following logic:
|
69
|
-
# * If the user has configured a header name, return that header's value.
|
70
|
-
# * If exactly one of the known IP headers is present, return that header's value.
|
71
|
-
# * If none of the known IP headers are present, return the remote IP from the request.
|
72
|
-
#
|
73
|
-
# If more than one of the known IP headers is present, the result will have a `multiple_ip_headers`
|
74
|
-
# field with the name of the present IP headers.
|
75
|
-
#
|
76
|
-
# @param [Datadog::Core::HeaderCollection, #get, nil] headers The request headers
|
77
|
-
# @param [String] remote_ip The remote IP of the request.
|
78
|
-
# @return [IpExtractionResult] A struct that holds the unprocessed IP value,
|
79
|
-
# or `nil` if it wasn't found. Additionally, the `multiple_ip_headers` fields will hold the
|
80
|
-
# name of known IP headers present in the request if more than one of these were found.
|
81
|
-
def self.raw_ip_from_request(headers, remote_ip)
|
82
|
-
return IpExtractionResult.new(headers && headers.get(configuration.header_name), nil) if configuration.header_name
|
83
26
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
27
|
+
# Forcefully sets the `http.client_ip` tag on the given span.
|
28
|
+
#
|
29
|
+
# This function ignores the user's `enabled` setting.
|
30
|
+
#
|
31
|
+
# @param [Span] span The span that's associated with the request.
|
32
|
+
# @param [HeaderCollection, #get, nil] headers A collection with the request headers.
|
33
|
+
# @param [String, nil] remote_ip The remote IP the request associated with the span is sent to.
|
34
|
+
def set_client_ip_tag!(span, headers: nil, remote_ip: nil)
|
35
|
+
ip = extract_client_ip(headers, remote_ip)
|
36
|
+
|
37
|
+
span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_CLIENT_IP, ip) if ip
|
93
38
|
end
|
94
|
-
end
|
95
39
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
40
|
+
def extract_client_ip(headers, remote_ip)
|
41
|
+
if headers && configuration.header_name
|
42
|
+
return Datadog::Core::Utils::Network.stripped_ip_from_request_headers(
|
43
|
+
headers,
|
44
|
+
ip_headers_to_check: Array(configuration.header_name)
|
45
|
+
)
|
46
|
+
end
|
100
47
|
|
101
|
-
|
102
|
-
|
103
|
-
strip_zone_specifier(address)
|
104
|
-
end
|
48
|
+
ip_from_headers = Datadog::Core::Utils::Network.stripped_ip_from_request_headers(headers) if headers
|
105
49
|
|
106
|
-
|
107
|
-
ipv6.gsub(/%.*/, '')
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.strip_ipv4_port(ip)
|
111
|
-
ip.gsub(/:\d+\z/, '')
|
112
|
-
end
|
113
|
-
|
114
|
-
def self.strip_ipv6_port(ip)
|
115
|
-
if /\[(.*)\](?::\d+)?/ =~ ip
|
116
|
-
Regexp.last_match(1)
|
117
|
-
else
|
118
|
-
ip
|
50
|
+
ip_from_headers || Datadog::Core::Utils::Network.stripped_ip(remote_ip)
|
119
51
|
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# Returns whether the given value is more likely to be an IPv4 than an IPv6 address.
|
123
|
-
#
|
124
|
-
# This is done by checking if a dot (`'.'`) character appears before a colon (`':'`) in the value.
|
125
|
-
# The rationale is that in valid IPv6 addresses, colons will always preced dots,
|
126
|
-
# and in valid IPv4 addresses dots will always preced colons.
|
127
|
-
def self.likely_ipv4?(value)
|
128
|
-
dot_index = value.index('.') || value.size
|
129
|
-
colon_index = value.index(':') || value.size
|
130
|
-
|
131
|
-
dot_index < colon_index
|
132
|
-
end
|
133
52
|
|
134
|
-
|
135
|
-
def self.valid_ip?(ip)
|
136
|
-
# Client IPs should not have subnet masks even though IPAddr can parse them.
|
137
|
-
return false if ip.include?('/')
|
53
|
+
private
|
138
54
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
true
|
143
|
-
rescue IPAddr::Error
|
144
|
-
false
|
55
|
+
def configuration
|
56
|
+
Datadog.configuration.tracing.client_ip
|
145
57
|
end
|
146
58
|
end
|
147
|
-
|
148
|
-
def self.ip_headers(headers)
|
149
|
-
return {} unless headers
|
150
|
-
|
151
|
-
DEFAULT_IP_HEADERS_NAMES.each_with_object({}) do |name, result|
|
152
|
-
value = headers.get(name)
|
153
|
-
result[name] = value unless value.nil?
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.configuration
|
158
|
-
Datadog.configuration.tracing.client_ip
|
159
|
-
end
|
160
59
|
end
|
161
60
|
end
|
162
61
|
end
|
@@ -7,6 +7,13 @@ module Datadog
|
|
7
7
|
ENV_ENABLED = 'DD_TRACE_ENABLED'.freeze
|
8
8
|
ENV_TRACE_ID_128_BIT_GENERATION_ENABLED = 'DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED'.freeze
|
9
9
|
|
10
|
+
# @public_api
|
11
|
+
module SpanAttributeSchema
|
12
|
+
ENV_SPAN_ATTRIBUTE_SCHEMA = 'DD_TRACE_SPAN_ATTRIBUTE_SCHEMA'.freeze
|
13
|
+
DEFAULT_VERSION = 'v0'.freeze
|
14
|
+
VERSION_ONE = 'v1'.freeze
|
15
|
+
end
|
16
|
+
|
10
17
|
# @public_api
|
11
18
|
module Analytics
|
12
19
|
ENV_TRACE_ANALYTICS_ENABLED = 'DD_TRACE_ANALYTICS_ENABLED'.freeze
|