ddtrace 1.12.1 → 1.18.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 +388 -10
- data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +3 -5
- data/ext/ddtrace_profiling_native_extension/clock_id.h +0 -3
- data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +3 -22
- data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +0 -1
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +41 -6
- data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +3 -0
- data/ext/ddtrace_profiling_native_extension/collectors_stack.c +76 -24
- data/ext/ddtrace_profiling_native_extension/collectors_stack.h +1 -1
- data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +292 -27
- data/ext/ddtrace_profiling_native_extension/collectors_thread_context.h +1 -1
- data/ext/ddtrace_profiling_native_extension/extconf.rb +40 -10
- data/ext/ddtrace_profiling_native_extension/http_transport.c +48 -16
- data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.c +42 -0
- data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +6 -0
- data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -1
- data/ext/ddtrace_profiling_native_extension/pid_controller.c +57 -0
- data/ext/ddtrace_profiling_native_extension/pid_controller.h +45 -0
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +136 -32
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +12 -0
- data/ext/ddtrace_profiling_native_extension/profiling.c +1 -2
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +81 -50
- data/ext/ddtrace_profiling_native_extension/stack_recorder.h +13 -3
- data/ext/ddtrace_profiling_native_extension/time_helpers.c +40 -4
- data/ext/ddtrace_profiling_native_extension/time_helpers.h +14 -0
- data/lib/datadog/appsec/assets/waf_rules/processors.json +92 -0
- data/lib/datadog/appsec/assets/waf_rules/recommended.json +698 -75
- data/lib/datadog/appsec/assets/waf_rules/scanners.json +114 -0
- data/lib/datadog/appsec/assets/waf_rules/strict.json +98 -8
- data/lib/datadog/appsec/assets.rb +8 -0
- data/lib/datadog/appsec/component.rb +21 -2
- data/lib/datadog/appsec/configuration/settings.rb +167 -189
- data/lib/datadog/appsec/configuration.rb +0 -79
- data/lib/datadog/appsec/contrib/auto_instrument.rb +2 -4
- data/lib/datadog/appsec/contrib/devise/event.rb +57 -0
- data/lib/datadog/appsec/contrib/devise/ext.rb +13 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +42 -0
- data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +76 -0
- data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +54 -0
- data/lib/datadog/appsec/contrib/devise/patcher.rb +45 -0
- data/lib/datadog/appsec/contrib/devise/resource.rb +35 -0
- data/lib/datadog/appsec/contrib/devise/tracking.rb +49 -0
- data/lib/datadog/appsec/contrib/rack/ext.rb +2 -1
- data/lib/datadog/appsec/contrib/rack/gateway/request.rb +6 -2
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +3 -8
- data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +3 -6
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +3 -6
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +36 -17
- data/lib/datadog/appsec/contrib/rails/ext.rb +3 -2
- data/lib/datadog/appsec/contrib/rails/framework.rb +1 -3
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
- data/lib/datadog/appsec/contrib/rails/patcher.rb +17 -11
- data/lib/datadog/appsec/contrib/rails/reactive/action.rb +3 -6
- data/lib/datadog/appsec/contrib/sinatra/ext.rb +2 -1
- data/lib/datadog/appsec/contrib/sinatra/framework.rb +1 -3
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
- data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +3 -6
- data/lib/datadog/appsec/event.rb +106 -50
- data/lib/datadog/appsec/extensions.rb +1 -130
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
- data/lib/datadog/appsec/monitor/reactive/set_user.rb +3 -6
- data/lib/datadog/appsec/processor/actions.rb +49 -0
- data/lib/datadog/appsec/processor/rule_loader.rb +60 -0
- data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
- data/lib/datadog/appsec/processor.rb +35 -7
- data/lib/datadog/appsec/rate_limiter.rb +1 -1
- data/lib/datadog/appsec/remote.rb +17 -11
- data/lib/datadog/appsec/response.rb +82 -4
- data/lib/datadog/appsec/sample_rate.rb +21 -0
- data/lib/datadog/appsec.rb +3 -4
- data/lib/datadog/core/backport.rb +51 -0
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +38 -29
- data/lib/datadog/core/configuration/base.rb +6 -16
- data/lib/datadog/core/configuration/components.rb +15 -3
- data/lib/datadog/core/configuration/ext.rb +28 -5
- data/lib/datadog/core/configuration/option.rb +269 -21
- data/lib/datadog/core/configuration/option_definition.rb +73 -32
- data/lib/datadog/core/configuration/options.rb +27 -15
- data/lib/datadog/core/configuration/settings.rb +182 -102
- data/lib/datadog/core/configuration.rb +4 -0
- data/lib/datadog/core/diagnostics/environment_logger.rb +130 -234
- data/lib/datadog/core/environment/execution.rb +103 -0
- data/lib/datadog/core/environment/ext.rb +13 -11
- data/lib/datadog/core/environment/variable_helpers.rb +0 -69
- data/lib/datadog/core/environment/yjit.rb +58 -0
- data/lib/datadog/core/error.rb +1 -0
- data/lib/datadog/core/git/ext.rb +26 -22
- data/lib/datadog/core/logging/ext.rb +3 -1
- data/lib/datadog/core/metrics/ext.rb +7 -5
- data/lib/datadog/core/remote/client/capabilities.rb +6 -1
- data/lib/datadog/core/remote/client.rb +3 -0
- data/lib/datadog/core/remote/component.rb +27 -36
- data/lib/datadog/core/remote/configuration/content.rb +28 -1
- data/lib/datadog/core/remote/configuration/repository.rb +3 -1
- data/lib/datadog/core/remote/ext.rb +1 -1
- data/lib/datadog/core/remote/negotiation.rb +19 -6
- data/lib/datadog/core/remote/transport/config.rb +60 -0
- data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
- data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
- data/lib/datadog/core/remote/transport/http/api.rb +58 -0
- data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
- data/lib/datadog/core/remote/transport/http/client.rb +48 -0
- data/lib/datadog/core/remote/transport/http/config.rb +280 -0
- data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
- data/lib/datadog/core/remote/transport/http.rb +179 -0
- data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
- data/lib/datadog/core/remote/worker.rb +4 -1
- data/lib/datadog/core/runtime/ext.rb +22 -12
- data/lib/datadog/core/runtime/metrics.rb +43 -0
- data/lib/datadog/core/telemetry/client.rb +12 -2
- data/lib/datadog/core/telemetry/collector.rb +13 -4
- data/lib/datadog/core/telemetry/emitter.rb +4 -2
- data/lib/datadog/core/telemetry/event.rb +19 -4
- data/lib/datadog/core/telemetry/ext.rb +4 -1
- data/lib/datadog/core/telemetry/heartbeat.rb +2 -4
- data/lib/datadog/core/telemetry/http/ext.rb +10 -8
- data/lib/datadog/core/telemetry/http/transport.rb +2 -0
- data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +41 -0
- data/lib/datadog/core/telemetry/v2/request.rb +29 -0
- data/lib/datadog/core/transport/ext.rb +47 -0
- data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
- data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
- data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
- data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
- data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
- data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
- data/lib/datadog/core/transport/http/api/map.rb +18 -0
- data/lib/datadog/core/transport/http/env.rb +62 -0
- data/lib/datadog/core/transport/http/response.rb +60 -0
- data/lib/datadog/core/transport/parcel.rb +22 -0
- data/lib/datadog/core/transport/request.rb +17 -0
- data/lib/datadog/core/transport/response.rb +64 -0
- data/lib/datadog/core/utils/duration.rb +52 -0
- data/lib/datadog/core/utils/hash.rb +47 -0
- data/lib/datadog/core/utils/network.rb +1 -1
- data/lib/datadog/core/utils/safe_dup.rb +27 -20
- data/lib/datadog/core/utils.rb +1 -1
- data/lib/datadog/core/workers/async.rb +3 -2
- data/lib/datadog/core/workers/polling.rb +2 -2
- data/lib/datadog/kit/appsec/events.rb +139 -89
- data/lib/datadog/kit/enable_core_dumps.rb +5 -6
- data/lib/datadog/kit/identity.rb +80 -65
- data/lib/datadog/opentelemetry/api/context.rb +10 -3
- data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +48 -5
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +167 -0
- data/lib/datadog/opentelemetry/trace.rb +58 -0
- data/lib/datadog/opentelemetry.rb +1 -0
- data/lib/datadog/opentracer/text_map_propagator.rb +2 -1
- data/lib/datadog/opentracer.rb +9 -0
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +16 -17
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +3 -1
- data/lib/datadog/profiling/collectors/thread_context.rb +17 -2
- data/lib/datadog/profiling/component.rb +69 -94
- data/lib/datadog/profiling/diagnostics/environment_logger.rb +39 -0
- data/lib/datadog/profiling/exporter.rb +5 -1
- data/lib/datadog/profiling/ext.rb +0 -12
- data/lib/datadog/profiling/flush.rb +7 -5
- data/lib/datadog/profiling/http_transport.rb +19 -6
- data/lib/datadog/profiling/load_native_extension.rb +7 -1
- data/lib/datadog/profiling/native_extension.rb +0 -21
- data/lib/datadog/profiling/profiler.rb +36 -13
- data/lib/datadog/profiling/scheduler.rb +16 -9
- data/lib/datadog/profiling.rb +16 -78
- data/lib/datadog/tracing/component.rb +70 -11
- data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
- data/lib/datadog/tracing/configuration/dynamic/option.rb +71 -0
- data/lib/datadog/tracing/configuration/dynamic.rb +64 -0
- data/lib/datadog/tracing/configuration/ext.rb +40 -32
- data/lib/datadog/tracing/configuration/http.rb +74 -0
- data/lib/datadog/tracing/configuration/settings.rb +134 -98
- data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/action_cable/ext.rb +20 -18
- data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/action_mailer/ext.rb +20 -18
- data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +9 -7
- data/lib/datadog/tracing/contrib/action_pack/ext.rb +10 -8
- data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/action_view/ext.rb +12 -10
- data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +13 -7
- data/lib/datadog/tracing/contrib/active_job/ext.rb +25 -23
- data/lib/datadog/tracing/contrib/active_job/log_injection.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/patcher.rb +1 -1
- data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/active_model_serializers/ext.rb +12 -10
- data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +18 -11
- data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +9 -7
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +2 -6
- data/lib/datadog/tracing/contrib/active_record/ext.rb +17 -15
- data/lib/datadog/tracing/contrib/active_record/utils.rb +1 -1
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +106 -202
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
- data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +9 -7
- data/lib/datadog/tracing/contrib/active_support/ext.rb +18 -16
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/aws/ext.rb +37 -24
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +16 -5
- data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +14 -14
- data/lib/datadog/tracing/contrib/concurrent_ruby/ext.rb +4 -2
- data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +3 -10
- data/lib/datadog/tracing/contrib/concurrent_ruby/integration.rb +2 -1
- data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +8 -1
- data/lib/datadog/tracing/contrib/concurrent_ruby/promises_future_patch.rb +22 -0
- data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +20 -7
- data/lib/datadog/tracing/contrib/dalli/ext.rb +26 -11
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +17 -8
- data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +13 -7
- data/lib/datadog/tracing/contrib/delayed_job/ext.rb +16 -14
- data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +21 -15
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +104 -99
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +16 -9
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +48 -3
- data/lib/datadog/tracing/contrib/ethon/ext.rb +19 -11
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +6 -3
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +19 -10
- data/lib/datadog/tracing/contrib/excon/ext.rb +16 -8
- data/lib/datadog/tracing/contrib/excon/middleware.rb +25 -5
- data/lib/datadog/tracing/contrib/ext.rb +26 -1
- data/lib/datadog/tracing/contrib/extensions.rb +32 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +20 -10
- data/lib/datadog/tracing/contrib/faraday/ext.rb +16 -8
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +21 -5
- data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +8 -6
- data/lib/datadog/tracing/contrib/grape/ext.rb +16 -14
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +8 -6
- data/lib/datadog/tracing/contrib/graphql/ext.rb +7 -5
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +39 -9
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +39 -20
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +37 -18
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
- data/lib/datadog/tracing/contrib/grpc/ext.rb +16 -13
- data/lib/datadog/tracing/contrib/grpc/formatting.rb +127 -0
- data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/hanami/ext.rb +10 -8
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +5 -8
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +33 -11
- data/lib/datadog/tracing/contrib/http/ext.rb +16 -9
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +27 -7
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +33 -11
- data/lib/datadog/tracing/contrib/httpclient/ext.rb +17 -9
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +22 -5
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +33 -11
- data/lib/datadog/tracing/contrib/httprb/ext.rb +16 -9
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +22 -5
- data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/kafka/ext.rb +42 -39
- data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/lograge/ext.rb +3 -1
- data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +2 -17
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +20 -16
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +16 -5
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +17 -14
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +15 -10
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +20 -6
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +52 -0
- data/lib/datadog/tracing/contrib/opensearch/ext.rb +37 -0
- data/lib/datadog/tracing/contrib/opensearch/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +135 -0
- data/lib/datadog/tracing/contrib/opensearch/quantize.rb +81 -0
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +22 -14
- data/lib/datadog/tracing/contrib/pg/ext.rb +22 -19
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +38 -5
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/presto/ext.rb +25 -20
- data/lib/datadog/tracing/contrib/presto/instrumentation.rb +14 -5
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +12 -10
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
- data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +12 -8
- data/lib/datadog/tracing/contrib/qless/ext.rb +14 -12
- data/lib/datadog/tracing/contrib/que/configuration/settings.rb +21 -12
- data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +9 -7
- data/lib/datadog/tracing/contrib/racecar/event.rb +5 -5
- data/lib/datadog/tracing/contrib/racecar/ext.rb +20 -18
- data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +16 -12
- data/lib/datadog/tracing/contrib/rack/ext.rb +18 -16
- data/lib/datadog/tracing/contrib/rack/header_collection.rb +3 -0
- data/lib/datadog/tracing/contrib/rack/header_tagging.rb +63 -0
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +8 -49
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +19 -15
- data/lib/datadog/tracing/contrib/rails/ext.rb +7 -5
- data/lib/datadog/tracing/contrib/rails/log_injection.rb +7 -10
- data/lib/datadog/tracing/contrib/rails/patcher.rb +10 -41
- data/lib/datadog/tracing/contrib/rails/railtie.rb +3 -3
- data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +13 -10
- data/lib/datadog/tracing/contrib/rake/ext.rb +14 -12
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +17 -9
- data/lib/datadog/tracing/contrib/redis/ext.rb +22 -15
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +3 -38
- data/lib/datadog/tracing/contrib/redis/tags.rb +16 -7
- data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +46 -33
- data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +13 -7
- data/lib/datadog/tracing/contrib/resque/ext.rb +9 -7
- data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +16 -9
- data/lib/datadog/tracing/contrib/rest_client/ext.rb +15 -8
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +25 -5
- data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +3 -2
- data/lib/datadog/tracing/contrib/semantic_logger/ext.rb +3 -1
- data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +4 -20
- data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/sequel/ext.rb +10 -8
- data/lib/datadog/tracing/contrib/sequel/utils.rb +7 -7
- data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +14 -8
- data/lib/datadog/tracing/contrib/shoryuken/ext.rb +14 -12
- data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +18 -11
- data/lib/datadog/tracing/contrib/sidekiq/ext.rb +32 -30
- data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +11 -9
- data/lib/datadog/tracing/contrib/sinatra/env.rb +0 -17
- data/lib/datadog/tracing/contrib/sinatra/ext.rb +21 -19
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +3 -14
- data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +14 -8
- data/lib/datadog/tracing/contrib/sneakers/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/sneakers/tracer.rb +1 -1
- data/lib/datadog/tracing/contrib/span_attribute_schema.rb +74 -10
- data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/sucker_punch/ext.rb +15 -13
- data/lib/datadog/tracing/contrib/utils/database.rb +5 -3
- data/lib/datadog/tracing/contrib/utils/quantization/http.rb +11 -11
- data/lib/datadog/tracing/contrib.rb +1 -0
- data/lib/datadog/tracing/correlation.rb +29 -12
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +165 -0
- data/lib/datadog/tracing/diagnostics/ext.rb +21 -19
- data/lib/datadog/tracing/distributed/b3_multi.rb +2 -2
- data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
- data/lib/datadog/tracing/distributed/datadog.rb +0 -1
- data/lib/datadog/tracing/distributed/propagation.rb +35 -34
- data/lib/datadog/tracing/distributed/trace_context.rb +52 -17
- data/lib/datadog/tracing/metadata/ext.rb +9 -6
- data/lib/datadog/tracing/metadata/tagging.rb +3 -3
- data/lib/datadog/tracing/remote.rb +78 -0
- data/lib/datadog/tracing/sampling/rule_sampler.rb +29 -0
- data/lib/datadog/tracing/span_operation.rb +3 -15
- data/lib/datadog/tracing/sync_writer.rb +3 -3
- data/lib/datadog/tracing/trace_digest.rb +31 -0
- data/lib/datadog/tracing/trace_operation.rb +16 -3
- data/lib/datadog/tracing/trace_segment.rb +5 -2
- data/lib/datadog/tracing/tracer.rb +12 -1
- data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
- data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
- data/lib/datadog/tracing/transport/http/api.rb +43 -0
- data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
- data/lib/datadog/tracing/transport/http/client.rb +57 -0
- data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
- data/lib/datadog/tracing/transport/http/traces.rb +152 -0
- data/lib/datadog/tracing/transport/http.rb +124 -0
- data/lib/datadog/tracing/transport/io/client.rb +89 -0
- data/lib/datadog/tracing/transport/io/response.rb +27 -0
- data/lib/datadog/tracing/transport/io/traces.rb +101 -0
- data/lib/datadog/tracing/transport/io.rb +30 -0
- data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
- data/lib/datadog/tracing/transport/statistics.rb +77 -0
- data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
- data/lib/datadog/tracing/transport/traces.rb +224 -0
- data/lib/datadog/tracing/workers/trace_writer.rb +6 -4
- data/lib/datadog/tracing/workers.rb +4 -2
- data/lib/datadog/tracing/writer.rb +5 -2
- data/lib/ddtrace/transport/ext.rb +22 -14
- data/lib/ddtrace/version.rb +9 -12
- data/lib/ddtrace.rb +1 -1
- metadata +101 -93
- data/lib/datadog/ci/configuration/components.rb +0 -32
- data/lib/datadog/ci/configuration/settings.rb +0 -53
- data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -33
- data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -20
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
- data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
- data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
- data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
- data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -33
- data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
- data/lib/datadog/ci/contrib/rspec/ext.rb +0 -19
- data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
- data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
- data/lib/datadog/ci/ext/app_types.rb +0 -9
- data/lib/datadog/ci/ext/environment.rb +0 -575
- data/lib/datadog/ci/ext/settings.rb +0 -10
- data/lib/datadog/ci/ext/test.rb +0 -35
- data/lib/datadog/ci/extensions.rb +0 -19
- data/lib/datadog/ci/flush.rb +0 -38
- data/lib/datadog/ci/test.rb +0 -81
- data/lib/datadog/ci.rb +0 -20
- data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
- data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
- data/lib/datadog/core/configuration/option_set.rb +0 -10
- data/lib/datadog/core/transport/config.rb +0 -58
- data/lib/datadog/core/transport/http/api.rb +0 -57
- data/lib/datadog/core/transport/http/client.rb +0 -45
- data/lib/datadog/core/transport/http/config.rb +0 -268
- data/lib/datadog/core/transport/http/negotiation.rb +0 -144
- data/lib/datadog/core/transport/http.rb +0 -169
- data/lib/datadog/core/utils/object_set.rb +0 -43
- data/lib/datadog/core/utils/string_table.rb +0 -47
- data/lib/datadog/profiling/backtrace_location.rb +0 -34
- data/lib/datadog/profiling/buffer.rb +0 -43
- data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
- data/lib/datadog/profiling/encoding/profile.rb +0 -41
- data/lib/datadog/profiling/event.rb +0 -15
- data/lib/datadog/profiling/events/stack.rb +0 -82
- data/lib/datadog/profiling/old_recorder.rb +0 -107
- data/lib/datadog/profiling/pprof/builder.rb +0 -125
- data/lib/datadog/profiling/pprof/converter.rb +0 -102
- data/lib/datadog/profiling/pprof/message_set.rb +0 -16
- data/lib/datadog/profiling/pprof/payload.rb +0 -20
- data/lib/datadog/profiling/pprof/pprof.proto +0 -212
- data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
- data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
- data/lib/datadog/profiling/pprof/string_table.rb +0 -12
- data/lib/datadog/profiling/pprof/template.rb +0 -118
- data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
- data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
- data/lib/datadog/tracing/contrib/sinatra/headers.rb +0 -35
- data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
- data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
- data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
- data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
- data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
- data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
- data/lib/ddtrace/transport/http/api/instance.rb +0 -35
- data/lib/ddtrace/transport/http/api/map.rb +0 -16
- data/lib/ddtrace/transport/http/api/spec.rb +0 -17
- data/lib/ddtrace/transport/http/api.rb +0 -39
- data/lib/ddtrace/transport/http/builder.rb +0 -176
- data/lib/ddtrace/transport/http/client.rb +0 -52
- data/lib/ddtrace/transport/http/env.rb +0 -58
- data/lib/ddtrace/transport/http/response.rb +0 -58
- data/lib/ddtrace/transport/http/statistics.rb +0 -43
- data/lib/ddtrace/transport/http/traces.rb +0 -144
- data/lib/ddtrace/transport/http.rb +0 -117
- data/lib/ddtrace/transport/io/client.rb +0 -85
- data/lib/ddtrace/transport/io/response.rb +0 -25
- data/lib/ddtrace/transport/io/traces.rb +0 -99
- data/lib/ddtrace/transport/io.rb +0 -28
- data/lib/ddtrace/transport/parcel.rb +0 -20
- data/lib/ddtrace/transport/request.rb +0 -15
- data/lib/ddtrace/transport/response.rb +0 -60
- data/lib/ddtrace/transport/serializable_trace.rb +0 -122
- data/lib/ddtrace/transport/statistics.rb +0 -75
- data/lib/ddtrace/transport/trace_formatter.rb +0 -198
- data/lib/ddtrace/transport/traces.rb +0 -216
@@ -16,7 +16,6 @@ static ID agent_id; // id of :agent in Ruby
|
|
16
16
|
|
17
17
|
static ID log_failure_to_process_tag_id; // id of :log_failure_to_process_tag in Ruby
|
18
18
|
|
19
|
-
static VALUE http_transport_class = Qnil;
|
20
19
|
static VALUE library_version_string = Qnil;
|
21
20
|
|
22
21
|
struct call_exporter_without_gvl_arguments {
|
@@ -46,17 +45,18 @@ static VALUE _native_do_export(
|
|
46
45
|
VALUE pprof_data,
|
47
46
|
VALUE code_provenance_file_name,
|
48
47
|
VALUE code_provenance_data,
|
49
|
-
VALUE tags_as_array
|
48
|
+
VALUE tags_as_array,
|
49
|
+
VALUE internal_metadata_json
|
50
50
|
);
|
51
51
|
static void *call_exporter_without_gvl(void *call_args);
|
52
52
|
static void interrupt_exporter_call(void *cancel_token);
|
53
53
|
static VALUE ddtrace_version(void);
|
54
54
|
|
55
55
|
void http_transport_init(VALUE profiling_module) {
|
56
|
-
http_transport_class = rb_define_class_under(profiling_module, "HttpTransport", rb_cObject);
|
56
|
+
VALUE http_transport_class = rb_define_class_under(profiling_module, "HttpTransport", rb_cObject);
|
57
57
|
|
58
58
|
rb_define_singleton_method(http_transport_class, "_native_validate_exporter", _native_validate_exporter, 1);
|
59
|
-
rb_define_singleton_method(http_transport_class, "_native_do_export", _native_do_export,
|
59
|
+
rb_define_singleton_method(http_transport_class, "_native_do_export", _native_do_export, 12);
|
60
60
|
|
61
61
|
ok_symbol = ID2SYM(rb_intern_const("ok"));
|
62
62
|
error_symbol = ID2SYM(rb_intern_const("error"));
|
@@ -179,6 +179,10 @@ static ddog_Vec_Tag convert_tags(VALUE tags_as_array) {
|
|
179
179
|
}
|
180
180
|
|
181
181
|
static VALUE log_failure_to_process_tag(VALUE err_details) {
|
182
|
+
VALUE datadog_module = rb_const_get(rb_cObject, rb_intern("Datadog"));
|
183
|
+
VALUE profiling_module = rb_const_get(datadog_module, rb_intern("Profiling"));
|
184
|
+
VALUE http_transport_class = rb_const_get(profiling_module, rb_intern("HttpTransport"));
|
185
|
+
|
182
186
|
return rb_funcall(http_transport_class, log_failure_to_process_tag_id, 1, err_details);
|
183
187
|
}
|
184
188
|
|
@@ -200,13 +204,24 @@ static VALUE perform_export(
|
|
200
204
|
ddog_prof_Exporter *exporter,
|
201
205
|
ddog_Timespec start,
|
202
206
|
ddog_Timespec finish,
|
203
|
-
ddog_prof_Exporter_Slice_File
|
207
|
+
ddog_prof_Exporter_Slice_File files_to_compress_and_export,
|
208
|
+
ddog_prof_Exporter_Slice_File files_to_export_unmodified,
|
204
209
|
ddog_Vec_Tag *additional_tags,
|
210
|
+
ddog_CharSlice internal_metadata,
|
205
211
|
uint64_t timeout_milliseconds
|
206
212
|
) {
|
207
213
|
ddog_prof_ProfiledEndpointsStats *endpoints_stats = NULL; // Not in use yet
|
208
|
-
ddog_prof_Exporter_Request_BuildResult build_result =
|
209
|
-
|
214
|
+
ddog_prof_Exporter_Request_BuildResult build_result = ddog_prof_Exporter_Request_build(
|
215
|
+
exporter,
|
216
|
+
start,
|
217
|
+
finish,
|
218
|
+
files_to_compress_and_export,
|
219
|
+
files_to_export_unmodified,
|
220
|
+
additional_tags,
|
221
|
+
endpoints_stats,
|
222
|
+
&internal_metadata,
|
223
|
+
timeout_milliseconds
|
224
|
+
);
|
210
225
|
|
211
226
|
if (build_result.tag == DDOG_PROF_EXPORTER_REQUEST_BUILD_RESULT_ERR) {
|
212
227
|
ddog_prof_Exporter_drop(exporter);
|
@@ -274,7 +289,8 @@ static VALUE _native_do_export(
|
|
274
289
|
VALUE pprof_data,
|
275
290
|
VALUE code_provenance_file_name,
|
276
291
|
VALUE code_provenance_data,
|
277
|
-
VALUE tags_as_array
|
292
|
+
VALUE tags_as_array,
|
293
|
+
VALUE internal_metadata_json
|
278
294
|
) {
|
279
295
|
ENFORCE_TYPE(upload_timeout_milliseconds, T_FIXNUM);
|
280
296
|
ENFORCE_TYPE(start_timespec_seconds, T_FIXNUM);
|
@@ -284,6 +300,7 @@ static VALUE _native_do_export(
|
|
284
300
|
ENFORCE_TYPE(pprof_file_name, T_STRING);
|
285
301
|
ENFORCE_TYPE(pprof_data, T_STRING);
|
286
302
|
ENFORCE_TYPE(code_provenance_file_name, T_STRING);
|
303
|
+
ENFORCE_TYPE(internal_metadata_json, T_STRING);
|
287
304
|
|
288
305
|
// Code provenance can be disabled and in that case will be set to nil
|
289
306
|
bool have_code_provenance = !NIL_P(code_provenance_data);
|
@@ -296,22 +313,28 @@ static VALUE _native_do_export(
|
|
296
313
|
ddog_Timespec finish =
|
297
314
|
{.seconds = NUM2LONG(finish_timespec_seconds), .nanoseconds = NUM2UINT(finish_timespec_nanoseconds)};
|
298
315
|
|
299
|
-
int
|
300
|
-
ddog_prof_Exporter_File
|
301
|
-
|
316
|
+
int to_compress_length = have_code_provenance ? 1 : 0;
|
317
|
+
ddog_prof_Exporter_File to_compress[to_compress_length];
|
318
|
+
int already_compressed_length = 1; // pprof
|
319
|
+
ddog_prof_Exporter_File already_compressed[already_compressed_length];
|
320
|
+
|
321
|
+
ddog_prof_Exporter_Slice_File files_to_compress_and_export = {.ptr = to_compress, .len = to_compress_length};
|
322
|
+
ddog_prof_Exporter_Slice_File files_to_export_unmodified = {.ptr = already_compressed, .len = already_compressed_length};
|
302
323
|
|
303
|
-
|
324
|
+
already_compressed[0] = (ddog_prof_Exporter_File) {
|
304
325
|
.name = char_slice_from_ruby_string(pprof_file_name),
|
305
|
-
.file = byte_slice_from_ruby_string(pprof_data)
|
326
|
+
.file = byte_slice_from_ruby_string(pprof_data),
|
306
327
|
};
|
328
|
+
|
307
329
|
if (have_code_provenance) {
|
308
|
-
|
330
|
+
to_compress[0] = (ddog_prof_Exporter_File) {
|
309
331
|
.name = char_slice_from_ruby_string(code_provenance_file_name),
|
310
|
-
.file = byte_slice_from_ruby_string(code_provenance_data)
|
332
|
+
.file = byte_slice_from_ruby_string(code_provenance_data),
|
311
333
|
};
|
312
334
|
}
|
313
335
|
|
314
336
|
ddog_Vec_Tag *null_additional_tags = NULL;
|
337
|
+
ddog_CharSlice internal_metadata = char_slice_from_ruby_string(internal_metadata_json);
|
315
338
|
|
316
339
|
ddog_prof_Exporter_NewResult exporter_result = create_exporter(exporter_configuration, tags_as_array);
|
317
340
|
// Note: Do not add anything that can raise exceptions after this line, as otherwise the exporter memory will leak
|
@@ -319,7 +342,16 @@ static VALUE _native_do_export(
|
|
319
342
|
VALUE failure_tuple = handle_exporter_failure(exporter_result);
|
320
343
|
if (!NIL_P(failure_tuple)) return failure_tuple;
|
321
344
|
|
322
|
-
return perform_export(
|
345
|
+
return perform_export(
|
346
|
+
exporter_result.ok,
|
347
|
+
start,
|
348
|
+
finish,
|
349
|
+
files_to_compress_and_export,
|
350
|
+
files_to_export_unmodified,
|
351
|
+
null_additional_tags,
|
352
|
+
internal_metadata,
|
353
|
+
timeout_milliseconds
|
354
|
+
);
|
323
355
|
}
|
324
356
|
|
325
357
|
static void *call_exporter_without_gvl(void *call_args) {
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#include "libdatadog_helpers.h"
|
2
|
+
|
3
|
+
#include <ruby.h>
|
4
|
+
|
5
|
+
const char *ruby_value_type_to_string(enum ruby_value_type type) {
|
6
|
+
return ruby_value_type_to_char_slice(type).ptr;
|
7
|
+
}
|
8
|
+
|
9
|
+
ddog_CharSlice ruby_value_type_to_char_slice(enum ruby_value_type type) {
|
10
|
+
switch (type) {
|
11
|
+
case(RUBY_T_NONE ): return DDOG_CHARSLICE_C("T_NONE");
|
12
|
+
case(RUBY_T_OBJECT ): return DDOG_CHARSLICE_C("T_OBJECT");
|
13
|
+
case(RUBY_T_CLASS ): return DDOG_CHARSLICE_C("T_CLASS");
|
14
|
+
case(RUBY_T_MODULE ): return DDOG_CHARSLICE_C("T_MODULE");
|
15
|
+
case(RUBY_T_FLOAT ): return DDOG_CHARSLICE_C("T_FLOAT");
|
16
|
+
case(RUBY_T_STRING ): return DDOG_CHARSLICE_C("T_STRING");
|
17
|
+
case(RUBY_T_REGEXP ): return DDOG_CHARSLICE_C("T_REGEXP");
|
18
|
+
case(RUBY_T_ARRAY ): return DDOG_CHARSLICE_C("T_ARRAY");
|
19
|
+
case(RUBY_T_HASH ): return DDOG_CHARSLICE_C("T_HASH");
|
20
|
+
case(RUBY_T_STRUCT ): return DDOG_CHARSLICE_C("T_STRUCT");
|
21
|
+
case(RUBY_T_BIGNUM ): return DDOG_CHARSLICE_C("T_BIGNUM");
|
22
|
+
case(RUBY_T_FILE ): return DDOG_CHARSLICE_C("T_FILE");
|
23
|
+
case(RUBY_T_DATA ): return DDOG_CHARSLICE_C("T_DATA");
|
24
|
+
case(RUBY_T_MATCH ): return DDOG_CHARSLICE_C("T_MATCH");
|
25
|
+
case(RUBY_T_COMPLEX ): return DDOG_CHARSLICE_C("T_COMPLEX");
|
26
|
+
case(RUBY_T_RATIONAL): return DDOG_CHARSLICE_C("T_RATIONAL");
|
27
|
+
case(RUBY_T_NIL ): return DDOG_CHARSLICE_C("T_NIL");
|
28
|
+
case(RUBY_T_TRUE ): return DDOG_CHARSLICE_C("T_TRUE");
|
29
|
+
case(RUBY_T_FALSE ): return DDOG_CHARSLICE_C("T_FALSE");
|
30
|
+
case(RUBY_T_SYMBOL ): return DDOG_CHARSLICE_C("T_SYMBOL");
|
31
|
+
case(RUBY_T_FIXNUM ): return DDOG_CHARSLICE_C("T_FIXNUM");
|
32
|
+
case(RUBY_T_UNDEF ): return DDOG_CHARSLICE_C("T_UNDEF");
|
33
|
+
case(RUBY_T_IMEMO ): return DDOG_CHARSLICE_C("T_IMEMO");
|
34
|
+
case(RUBY_T_NODE ): return DDOG_CHARSLICE_C("T_NODE");
|
35
|
+
case(RUBY_T_ICLASS ): return DDOG_CHARSLICE_C("T_ICLASS");
|
36
|
+
case(RUBY_T_ZOMBIE ): return DDOG_CHARSLICE_C("T_ZOMBIE");
|
37
|
+
#ifndef NO_T_MOVED
|
38
|
+
case(RUBY_T_MOVED ): return DDOG_CHARSLICE_C("T_MOVED");
|
39
|
+
#endif
|
40
|
+
default: return DDOG_CHARSLICE_C("BUG: Unknown value for ruby_value_type");
|
41
|
+
}
|
42
|
+
}
|
@@ -23,3 +23,9 @@ inline static VALUE get_error_details_and_drop(ddog_Error *error) {
|
|
23
23
|
ddog_Error_drop(error);
|
24
24
|
return result;
|
25
25
|
}
|
26
|
+
|
27
|
+
// Used for pretty printing this Ruby enum. Returns "T_UNKNOWN_OR_MISSING_RUBY_VALUE_TYPE_ENTRY" for unknown elements.
|
28
|
+
// In practice, there's a few types that the profiler will probably never encounter, but I've added all entries of
|
29
|
+
// ruby_value_type that Ruby uses so that we can also use this for debugging.
|
30
|
+
const char *ruby_value_type_to_string(enum ruby_value_type type);
|
31
|
+
ddog_CharSlice ruby_value_type_to_char_slice(enum ruby_value_type type);
|
@@ -15,7 +15,7 @@ module Datadog
|
|
15
15
|
# The MJIT header was introduced on 2.6 and removed on 3.3; for other Rubies we rely on debase-ruby_core_source
|
16
16
|
CAN_USE_MJIT_HEADER = RUBY_VERSION.start_with?('2.6', '2.7', '3.0.', '3.1.', '3.2.')
|
17
17
|
|
18
|
-
LIBDATADOG_VERSION = '~>
|
18
|
+
LIBDATADOG_VERSION = '~> 5.0.0.1.0'
|
19
19
|
|
20
20
|
def self.fail_install_if_missing_extension?
|
21
21
|
ENV[ENV_FAIL_INSTALL_IF_MISSING_EXTENSION].to_s.strip.downcase == 'true'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2023 Datadog, Inc
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
// Originally imported from https://github.com/DataDog/java-profiler/blob/11fe6206c31a14c6e5134e8401eaec8b22c618d7/ddprof-lib/src/main/cpp/pidController.cpp
|
18
|
+
|
19
|
+
#include "pid_controller.h"
|
20
|
+
|
21
|
+
#include <math.h>
|
22
|
+
|
23
|
+
inline static double computeAlpha(float cutoff) {
|
24
|
+
if (cutoff <= 0)
|
25
|
+
return 1;
|
26
|
+
// α(fₙ) = cos(2πfₙ) - 1 + √( cos(2πfₙ)² - 4 cos(2πfₙ) + 3 )
|
27
|
+
const double c = cos(2 * ((double) M_PI) * cutoff);
|
28
|
+
return c - 1 + sqrt(c * c - 4 * c + 3);
|
29
|
+
}
|
30
|
+
|
31
|
+
void pid_controller_init(pid_controller *controller, u64 target_per_second, double proportional_gain, double integral_gain, double derivative_gain, int sampling_window, double cutoff_secs) {
|
32
|
+
controller->_target = target_per_second * sampling_window;
|
33
|
+
controller->_proportional_gain = proportional_gain;
|
34
|
+
controller->_integral_gain = integral_gain * sampling_window;
|
35
|
+
controller->_derivative_gain = derivative_gain / sampling_window;
|
36
|
+
controller->_alpha = computeAlpha(sampling_window / cutoff_secs);
|
37
|
+
controller->_avg_error= 0;
|
38
|
+
controller->_integral_value = 0;
|
39
|
+
}
|
40
|
+
|
41
|
+
double pid_controller_compute(pid_controller *controller, u64 input, double time_delta_coefficient) {
|
42
|
+
// time_delta_coefficient allows variable sampling window
|
43
|
+
// the values are linearly scaled using that coefficient to reinterpret the given value within the expected sampling window
|
44
|
+
double absolute_error = (((double) controller->_target) - ((double) input)) * time_delta_coefficient;
|
45
|
+
|
46
|
+
double avg_error = (controller->_alpha * absolute_error) + ((1 - controller->_alpha) * controller->_avg_error);
|
47
|
+
double derivative = avg_error - controller->_avg_error;
|
48
|
+
|
49
|
+
// PID formula:
|
50
|
+
// u[k] = Kp e[k] + Ki e_i[k] + Kd e_d[k], control signal
|
51
|
+
double signal = controller->_proportional_gain * absolute_error + controller->_integral_gain * controller->_integral_value + controller->_derivative_gain * derivative;
|
52
|
+
|
53
|
+
controller->_integral_value += absolute_error;
|
54
|
+
controller->_avg_error = avg_error;
|
55
|
+
|
56
|
+
return signal;
|
57
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2023 Datadog, Inc
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
// Originally imported from https://github.com/DataDog/java-profiler/blob/11fe6206c31a14c6e5134e8401eaec8b22c618d7/ddprof-lib/src/main/cpp/pidController.h
|
18
|
+
|
19
|
+
#ifndef _PIDCONTROLLER_H
|
20
|
+
#define _PIDCONTROLLER_H
|
21
|
+
|
22
|
+
// From arch.h in java-profiler
|
23
|
+
typedef unsigned long long u64;
|
24
|
+
|
25
|
+
/*
|
26
|
+
* A simple implementation of a PID controller.
|
27
|
+
* Heavily influenced by https://tttapa.github.io/Pages/Arduino/Control-Theory/Motor-Fader/PID-Cpp-Implementation.html
|
28
|
+
*/
|
29
|
+
|
30
|
+
typedef struct {
|
31
|
+
u64 _target;
|
32
|
+
double _proportional_gain;
|
33
|
+
double _derivative_gain;
|
34
|
+
double _integral_gain;
|
35
|
+
double _alpha;
|
36
|
+
|
37
|
+
double _avg_error;
|
38
|
+
long long _integral_value;
|
39
|
+
} pid_controller;
|
40
|
+
|
41
|
+
void pid_controller_init(pid_controller *controller, u64 target_per_second, double proportional_gain, double integral_gain, double derivative_gain, int sampling_window, double cutoff_secs);
|
42
|
+
|
43
|
+
double pid_controller_compute(pid_controller *controller, u64 input, double time_delta_seconds);
|
44
|
+
|
45
|
+
#endif
|
@@ -58,9 +58,12 @@ static inline rb_thread_t *thread_struct_from_object(VALUE thread) {
|
|
58
58
|
}
|
59
59
|
|
60
60
|
rb_nativethread_id_t pthread_id_for(VALUE thread) {
|
61
|
-
// struct rb_native_thread was introduced in Ruby 3.2
|
61
|
+
// struct rb_native_thread was introduced in Ruby 3.2: https://github.com/ruby/ruby/pull/5836
|
62
62
|
#ifndef NO_RB_NATIVE_THREAD
|
63
|
-
|
63
|
+
struct rb_native_thread* native_thread = thread_struct_from_object(thread)->nt;
|
64
|
+
// This can be NULL on Ruby 3.3 with MN threads (RUBY_MN_THREADS=1)
|
65
|
+
if (native_thread == NULL) return 0;
|
66
|
+
return native_thread->thread_id;
|
64
67
|
#else
|
65
68
|
return thread_struct_from_object(thread)->thread_id;
|
66
69
|
#endif
|
@@ -82,6 +85,16 @@ bool is_current_thread_holding_the_gvl(void) {
|
|
82
85
|
return owner.valid && pthread_equal(pthread_self(), owner.owner);
|
83
86
|
}
|
84
87
|
|
88
|
+
#ifdef HAVE_RUBY_RACTOR_H
|
89
|
+
static inline rb_ractor_t *ddtrace_get_ractor(void) {
|
90
|
+
#ifndef USE_RACTOR_INTERNAL_APIS_DIRECTLY // Ruby >= 3.3
|
91
|
+
return thread_struct_from_object(rb_thread_current())->ractor;
|
92
|
+
#else
|
93
|
+
return GET_RACTOR();
|
94
|
+
#endif
|
95
|
+
}
|
96
|
+
#endif
|
97
|
+
|
85
98
|
#ifndef NO_GVL_OWNER // Ruby < 2.6 doesn't have the owner/running field
|
86
99
|
// NOTE: Reading the owner in this is a racy read, because we're not grabbing the lock that Ruby uses to protect it.
|
87
100
|
//
|
@@ -94,24 +107,25 @@ bool is_current_thread_holding_the_gvl(void) {
|
|
94
107
|
current_gvl_owner gvl_owner(void) {
|
95
108
|
const rb_thread_t *current_owner =
|
96
109
|
#ifndef NO_RB_THREAD_SCHED // Introduced in Ruby 3.2 as a replacement for struct rb_global_vm_lock_struct
|
97
|
-
|
110
|
+
ddtrace_get_ractor()->threads.sched.running;
|
98
111
|
#elif HAVE_RUBY_RACTOR_H
|
99
|
-
|
112
|
+
ddtrace_get_ractor()->threads.gvl.owner;
|
100
113
|
#else
|
101
114
|
GET_VM()->gvl.owner;
|
102
115
|
#endif
|
103
116
|
|
104
117
|
if (current_owner == NULL) return (current_gvl_owner) {.valid = false};
|
105
118
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
119
|
+
#ifndef NO_RB_NATIVE_THREAD
|
120
|
+
struct rb_native_thread* current_owner_native_thread = current_owner->nt;
|
121
|
+
|
122
|
+
// This can be NULL on Ruby 3.3 with MN threads (RUBY_MN_THREADS=1)
|
123
|
+
if (current_owner_native_thread == NULL) return (current_gvl_owner) {.valid = false};
|
124
|
+
|
125
|
+
return (current_gvl_owner) {.valid = true, .owner = current_owner_native_thread->thread_id};
|
126
|
+
#else
|
127
|
+
return (current_gvl_owner) {.valid = true, .owner = current_owner->thread_id};
|
128
|
+
#endif
|
115
129
|
}
|
116
130
|
#else
|
117
131
|
current_gvl_owner gvl_owner(void) {
|
@@ -172,7 +186,9 @@ uint64_t native_thread_id_for(VALUE thread) {
|
|
172
186
|
// The tid is only available on Ruby >= 3.1 + Linux (and FreeBSD). It's the same as `gettid()` aka the task id as seen in /proc
|
173
187
|
#if !defined(NO_THREAD_TID) && defined(RB_THREAD_T_HAS_NATIVE_ID)
|
174
188
|
#ifndef NO_RB_NATIVE_THREAD
|
175
|
-
|
189
|
+
struct rb_native_thread* native_thread = thread_struct_from_object(thread)->nt;
|
190
|
+
if (native_thread == NULL) rb_raise(rb_eRuntimeError, "BUG: rb_native_thread* is null. Is this Ruby running with RUBY_MN_THREADS=1?");
|
191
|
+
return native_thread->tid;
|
176
192
|
#else
|
177
193
|
return thread_struct_from_object(thread)->tid;
|
178
194
|
#endif
|
@@ -234,7 +250,7 @@ void ddtrace_thread_list(VALUE result_array) {
|
|
234
250
|
// I suspect the design in `rb_ractor_thread_list` may be done that way to perhaps in the future expose it to be
|
235
251
|
// called from a different Ractor, but I'm not sure...
|
236
252
|
#ifdef HAVE_RUBY_RACTOR_H
|
237
|
-
rb_ractor_t *current_ractor =
|
253
|
+
rb_ractor_t *current_ractor = ddtrace_get_ractor();
|
238
254
|
ccan_list_for_each(¤t_ractor->threads.set, thread, lt_node) {
|
239
255
|
#else
|
240
256
|
rb_vm_t *vm =
|
@@ -302,7 +318,8 @@ VALUE thread_name_for(VALUE thread) {
|
|
302
318
|
// Taken from upstream vm_backtrace.c at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
303
319
|
// Copyright (C) 1993-2012 Yukihiro Matsumoto
|
304
320
|
// to support our custom rb_profile_frames (see below)
|
305
|
-
// Modifications:
|
321
|
+
// Modifications:
|
322
|
+
// * Support int first_lineno for Ruby 3.2.0+ (https://github.com/ruby/ruby/pull/6430)
|
306
323
|
//
|
307
324
|
// `node_id` gets used depending on Ruby VM compilation settings (USE_ISEQ_NODE_ID being defined).
|
308
325
|
// To avoid getting false "unused argument" warnings in setups where it's not used, we need to do this weird dance
|
@@ -322,7 +339,11 @@ calc_pos(const rb_iseq_t *iseq, const VALUE *pc, int *lineno, int *node_id)
|
|
322
339
|
VM_ASSERT(! ISEQ_BODY(iseq)->local_table_size);
|
323
340
|
return 0;
|
324
341
|
}
|
325
|
-
|
342
|
+
# ifndef NO_INT_FIRST_LINENO // Ruby 3.2+
|
343
|
+
if (lineno) *lineno = ISEQ_BODY(iseq)->location.first_lineno;
|
344
|
+
# else
|
345
|
+
if (lineno) *lineno = FIX2INT(ISEQ_BODY(iseq)->location.first_lineno);
|
346
|
+
#endif
|
326
347
|
#ifdef USE_ISEQ_NODE_ID
|
327
348
|
if (node_id) *node_id = -1;
|
328
349
|
#endif
|
@@ -392,6 +413,7 @@ calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
|
|
392
413
|
// the `VALUE` returned by rb_profile_frames returns `(eval)` instead of the path of the file where the `eval`
|
393
414
|
// was called from.
|
394
415
|
// * Imported fix from https://github.com/ruby/ruby/pull/7116 to avoid sampling threads that are still being created
|
416
|
+
// * Imported fix from https://github.com/ruby/ruby/pull/8415 to avoid potential crash when using YJIT.
|
395
417
|
//
|
396
418
|
// What is rb_profile_frames?
|
397
419
|
// `rb_profile_frames` is a Ruby VM debug API added for use by profilers for sampling the stack trace of a Ruby thread.
|
@@ -427,12 +449,15 @@ int ddtrace_rb_profile_frames(VALUE thread, int start, int limit, VALUE *buff, i
|
|
427
449
|
// Modified from upstream: Instead of using `GET_EC` to collect info from the current thread,
|
428
450
|
// support sampling any thread (including the current) passed as an argument
|
429
451
|
rb_thread_t *th = thread_struct_from_object(thread);
|
430
|
-
#ifndef USE_THREAD_INSTEAD_OF_EXECUTION_CONTEXT // Modern Rubies
|
431
|
-
|
432
|
-
#else // Ruby < 2.5
|
433
|
-
|
434
|
-
#endif
|
452
|
+
#ifndef USE_THREAD_INSTEAD_OF_EXECUTION_CONTEXT // Modern Rubies
|
453
|
+
const rb_execution_context_t *ec = th->ec;
|
454
|
+
#else // Ruby < 2.5
|
455
|
+
const rb_thread_t *ec = th;
|
456
|
+
#endif
|
435
457
|
const rb_control_frame_t *cfp = ec->cfp, *end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
|
458
|
+
#ifndef NO_JIT_RETURN
|
459
|
+
const rb_control_frame_t *top = cfp;
|
460
|
+
#endif
|
436
461
|
const rb_callable_method_entry_t *cme;
|
437
462
|
|
438
463
|
// Avoid sampling dead threads
|
@@ -507,7 +532,20 @@ int ddtrace_rb_profile_frames(VALUE thread, int start, int limit, VALUE *buff, i
|
|
507
532
|
buff[i] = (VALUE)cfp->iseq;
|
508
533
|
}
|
509
534
|
|
510
|
-
|
535
|
+
// The topmost frame may not have an updated PC because the JIT
|
536
|
+
// may not have set one. The JIT compiler will update the PC
|
537
|
+
// before entering a new function (so that `caller` will work),
|
538
|
+
// so only the topmost frame could possibly have an out of date PC
|
539
|
+
#ifndef NO_JIT_RETURN
|
540
|
+
if (cfp == top && cfp->jit_return) {
|
541
|
+
lines[i] = 0;
|
542
|
+
} else {
|
543
|
+
lines[i] = calc_lineno(cfp->iseq, cfp->pc);
|
544
|
+
}
|
545
|
+
#else // Ruby < 3.1
|
546
|
+
lines[i] = calc_lineno(cfp->iseq, cfp->pc);
|
547
|
+
#endif
|
548
|
+
|
511
549
|
is_ruby_frame[i] = true;
|
512
550
|
i++;
|
513
551
|
}
|
@@ -731,15 +769,10 @@ check_method_entry(VALUE obj, int can_be_svar)
|
|
731
769
|
// versions, so we need to do a bit more work.
|
732
770
|
struct rb_ractor_struct *ruby_single_main_ractor = NULL;
|
733
771
|
|
734
|
-
//
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
bool rb_ractor_main_p_(void)
|
739
|
-
{
|
740
|
-
VM_ASSERT(rb_multi_ractor_p());
|
741
|
-
rb_execution_context_t *ec = GET_EC();
|
742
|
-
return rb_ec_ractor_ptr(ec) == rb_ec_vm_ptr(ec)->ractor.main_ractor;
|
772
|
+
// Alternative implementation of rb_ractor_main_p_ that avoids relying on non-public symbols
|
773
|
+
bool rb_ractor_main_p_(void) {
|
774
|
+
// We need to get the main ractor in a bit of a roundabout way, since Ruby >= 3.3 hid `GET_VM()`
|
775
|
+
return ddtrace_get_ractor() == thread_struct_from_object(rb_thread_current())->vm->ractor.main_ractor;
|
743
776
|
}
|
744
777
|
#else
|
745
778
|
// Directly access Ruby internal fast path for detecting multiple Ractors.
|
@@ -767,3 +800,74 @@ check_method_entry(VALUE obj, int can_be_svar)
|
|
767
800
|
// they're always on the main Ractor
|
768
801
|
bool ddtrace_rb_ractor_main_p(void) { return true; }
|
769
802
|
#endif // NO_RACTORS
|
803
|
+
|
804
|
+
// This is a tweaked and inlined version of
|
805
|
+
// threadptr_invoke_proc_location + rb_proc_location + iseq_location .
|
806
|
+
//
|
807
|
+
// It's useful to have here because not all of the methods above are accessible to extensions + to avoid the
|
808
|
+
// array allocation that iseq_location did to contain its return value.
|
809
|
+
static const rb_iseq_t *maybe_thread_invoke_proc_iseq(VALUE thread_value) {
|
810
|
+
rb_thread_t *thread = thread_struct_from_object(thread_value);
|
811
|
+
|
812
|
+
#ifndef NO_THREAD_INVOKE_ARG // Ruby 2.6+
|
813
|
+
if (thread->invoke_type != thread_invoke_type_proc) return NULL;
|
814
|
+
|
815
|
+
VALUE proc = thread->invoke_arg.proc.proc;
|
816
|
+
#else
|
817
|
+
if (thread->first_func || !thread->first_proc) return NULL;
|
818
|
+
|
819
|
+
VALUE proc = thread->first_proc;
|
820
|
+
#endif
|
821
|
+
|
822
|
+
const rb_iseq_t *iseq = rb_proc_get_iseq(proc, 0);
|
823
|
+
if (iseq == NULL) return NULL;
|
824
|
+
|
825
|
+
rb_iseq_check(iseq);
|
826
|
+
return iseq;
|
827
|
+
}
|
828
|
+
|
829
|
+
VALUE invoke_location_for(VALUE thread, int *line_location) {
|
830
|
+
const rb_iseq_t *iseq = maybe_thread_invoke_proc_iseq(thread);
|
831
|
+
|
832
|
+
if (iseq == NULL) return Qnil;
|
833
|
+
|
834
|
+
*line_location = NUM2INT(rb_iseq_first_lineno(iseq));
|
835
|
+
return rb_iseq_path(iseq);
|
836
|
+
}
|
837
|
+
|
838
|
+
void self_test_mn_enabled(void) {
|
839
|
+
#ifdef NO_MN_THREADS_AVAILABLE
|
840
|
+
return;
|
841
|
+
#else
|
842
|
+
if (ddtrace_get_ractor()->threads.sched.enable_mn_threads == true) {
|
843
|
+
rb_raise(rb_eRuntimeError, "Ruby VM is running with RUBY_MN_THREADS=1. This is not yet supported");
|
844
|
+
}
|
845
|
+
#endif
|
846
|
+
}
|
847
|
+
|
848
|
+
// Taken from upstream imemo.h at commit 6ebcf25de2859b5b6402b7e8b181066c32d0e0bf (November 2023, master branch)
|
849
|
+
// (See the Ruby project copyright and license above)
|
850
|
+
// to enable calling rb_imemo_name
|
851
|
+
//
|
852
|
+
// Modifications:
|
853
|
+
// * Added IMEMO_MASK define
|
854
|
+
// * Changed return type to int to avoid having to define `enum imemo_type`
|
855
|
+
static inline int ddtrace_imemo_type(VALUE imemo) {
|
856
|
+
// This mask is the same between Ruby 2.5 and 3.3-preview3. Furthermore, the intention of this method is to be used
|
857
|
+
// to call `rb_imemo_name` which correctly handles invalid numbers so even if the mask changes in the future, at most
|
858
|
+
// we'll get incorrect results (and never a VM crash)
|
859
|
+
#define IMEMO_MASK 0x0f
|
860
|
+
return (RBASIC(imemo)->flags >> FL_USHIFT) & IMEMO_MASK;
|
861
|
+
}
|
862
|
+
|
863
|
+
// Safety: This function assumes the object passed in is of the imemo type. But in the worst case, you'll just get
|
864
|
+
// a string that doesn't make any sense.
|
865
|
+
#ifndef NO_IMEMO_NAME
|
866
|
+
const char *imemo_kind(VALUE imemo) {
|
867
|
+
return rb_imemo_name(ddtrace_imemo_type(imemo));
|
868
|
+
}
|
869
|
+
#else
|
870
|
+
const char *imemo_kind(__attribute__((unused)) VALUE imemo) {
|
871
|
+
return NULL;
|
872
|
+
}
|
873
|
+
#endif
|
@@ -43,3 +43,15 @@ bool ddtrace_rb_ractor_main_p(void);
|
|
43
43
|
|
44
44
|
// See comment on `record_placeholder_stack_in_native_code` for a full explanation of what this means (and why we don't just return 0)
|
45
45
|
#define PLACEHOLDER_STACK_IN_NATIVE_CODE -1
|
46
|
+
|
47
|
+
// This method provides the file and line of the "invoke location" of a thread (first file:line of the block used to
|
48
|
+
// start the thread), if any.
|
49
|
+
// This is what Ruby shows in `Thread#to_s`.
|
50
|
+
// The file is returned directly, and the line is recorded onto *line_location.
|
51
|
+
VALUE invoke_location_for(VALUE thread, int *line_location);
|
52
|
+
|
53
|
+
// Check if RUBY_MN_THREADS is enabled (aka main Ractor is not doing 1:1 threads)
|
54
|
+
void self_test_mn_enabled(void);
|
55
|
+
|
56
|
+
// Provides more specific information on what kind an imemo is
|
57
|
+
const char *imemo_kind(VALUE imemo);
|
@@ -41,8 +41,6 @@ void DDTRACE_EXPORT Init_ddtrace_profiling_native_extension(void) {
|
|
41
41
|
rb_define_singleton_method(native_extension_module, "native_working?", native_working_p, 0);
|
42
42
|
rb_funcall(native_extension_module, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("native_working?")));
|
43
43
|
|
44
|
-
rb_define_singleton_method(native_extension_module, "clock_id_for", clock_id_for, 1); // from clock_id.h
|
45
|
-
|
46
44
|
collectors_cpu_and_wall_time_worker_init(profiling_module);
|
47
45
|
collectors_dynamic_sampling_rate_init(profiling_module);
|
48
46
|
collectors_idle_sampling_helper_init(profiling_module);
|
@@ -70,6 +68,7 @@ void DDTRACE_EXPORT Init_ddtrace_profiling_native_extension(void) {
|
|
70
68
|
|
71
69
|
static VALUE native_working_p(DDTRACE_UNUSED VALUE _self) {
|
72
70
|
self_test_clock_id();
|
71
|
+
self_test_mn_enabled();
|
73
72
|
|
74
73
|
return Qtrue;
|
75
74
|
}
|