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
@@ -63,8 +63,8 @@
|
|
63
63
|
// allowed to happen during Ruby's garbage collection start/finish hooks.
|
64
64
|
// ---
|
65
65
|
|
66
|
-
#define INVALID_TIME -1
|
67
66
|
#define THREAD_ID_LIMIT_CHARS 44 // Why 44? "#{2**64} (#{2**64})".size + 1 for \0
|
67
|
+
#define THREAD_INVOKE_LOCATION_LIMIT_CHARS 512
|
68
68
|
#define IS_WALL_TIME true
|
69
69
|
#define IS_NOT_WALL_TIME false
|
70
70
|
#define MISSING_TRACER_CONTEXT_KEY 0
|
@@ -99,6 +99,14 @@ struct thread_context_collector_state {
|
|
99
99
|
VALUE thread_list_buffer;
|
100
100
|
// Used to omit endpoint names (retrieved from tracer) from collected data
|
101
101
|
bool endpoint_collection_enabled;
|
102
|
+
// Used to omit timestamps / timeline events from collected data
|
103
|
+
bool timeline_enabled;
|
104
|
+
// Used to omit class information from collected allocation data
|
105
|
+
bool allocation_type_enabled;
|
106
|
+
// Used when calling monotonic_to_system_epoch_ns
|
107
|
+
monotonic_to_system_epoch_state time_converter_state;
|
108
|
+
// Used to identify the main thread, to give it a fallback name
|
109
|
+
VALUE main_thread;
|
102
110
|
|
103
111
|
struct stats {
|
104
112
|
// Track how many garbage collection samples we've taken.
|
@@ -112,6 +120,8 @@ struct thread_context_collector_state {
|
|
112
120
|
struct per_thread_context {
|
113
121
|
char thread_id[THREAD_ID_LIMIT_CHARS];
|
114
122
|
ddog_CharSlice thread_id_char_slice;
|
123
|
+
char thread_invoke_location[THREAD_INVOKE_LOCATION_LIMIT_CHARS];
|
124
|
+
ddog_CharSlice thread_invoke_location_char_slice;
|
115
125
|
thread_cpu_time_id thread_cpu_time_id;
|
116
126
|
long cpu_time_at_previous_sample_ns; // Can be INVALID_TIME until initialized or if getting it fails for another reason
|
117
127
|
long wall_time_at_previous_sample_ns; // Can be INVALID_TIME until initialized
|
@@ -148,7 +158,9 @@ static VALUE _native_initialize(
|
|
148
158
|
VALUE recorder_instance,
|
149
159
|
VALUE max_frames,
|
150
160
|
VALUE tracer_context_key,
|
151
|
-
VALUE endpoint_collection_enabled
|
161
|
+
VALUE endpoint_collection_enabled,
|
162
|
+
VALUE timeline_enabled,
|
163
|
+
VALUE allocation_type_enabled
|
152
164
|
);
|
153
165
|
static VALUE _native_sample(VALUE self, VALUE collector_instance, VALUE profiler_overhead_stack_thread);
|
154
166
|
static VALUE _native_on_gc_start(VALUE self, VALUE collector_instance);
|
@@ -168,12 +180,15 @@ static void trigger_sample_for_thread(
|
|
168
180
|
VALUE stack_from_thread,
|
169
181
|
struct per_thread_context *thread_context,
|
170
182
|
sample_values values,
|
171
|
-
sample_type type
|
183
|
+
sample_type type,
|
184
|
+
long current_monotonic_wall_time_ns,
|
185
|
+
ddog_CharSlice *ruby_vm_type,
|
186
|
+
ddog_CharSlice *class_name
|
172
187
|
);
|
173
188
|
static VALUE _native_thread_list(VALUE self);
|
174
189
|
static struct per_thread_context *get_or_create_context_for(VALUE thread, struct thread_context_collector_state *state);
|
175
190
|
static struct per_thread_context *get_context_for(VALUE thread, struct thread_context_collector_state *state);
|
176
|
-
static void initialize_context(VALUE thread, struct per_thread_context *thread_context);
|
191
|
+
static void initialize_context(VALUE thread, struct per_thread_context *thread_context, struct thread_context_collector_state *state);
|
177
192
|
static VALUE _native_inspect(VALUE self, VALUE collector_instance);
|
178
193
|
static VALUE per_thread_context_st_table_as_ruby_hash(struct thread_context_collector_state *state);
|
179
194
|
static int per_thread_context_as_ruby_hash(st_data_t key_thread, st_data_t value_context, st_data_t result_hash);
|
@@ -186,10 +201,12 @@ static long cpu_time_now_ns(struct per_thread_context *thread_context);
|
|
186
201
|
static long thread_id_for(VALUE thread);
|
187
202
|
static VALUE _native_stats(VALUE self, VALUE collector_instance);
|
188
203
|
static void trace_identifiers_for(struct thread_context_collector_state *state, VALUE thread, struct trace_identifiers *trace_identifiers_result);
|
189
|
-
static bool
|
204
|
+
static bool should_collect_resource(VALUE root_span_type);
|
190
205
|
static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE collector_instance);
|
191
206
|
static VALUE thread_list(struct thread_context_collector_state *state);
|
192
|
-
static VALUE _native_sample_allocation(VALUE self, VALUE collector_instance, VALUE sample_weight);
|
207
|
+
static VALUE _native_sample_allocation(DDTRACE_UNUSED VALUE self, VALUE collector_instance, VALUE sample_weight, VALUE new_object);
|
208
|
+
static VALUE _native_new_empty_thread(VALUE self);
|
209
|
+
ddog_CharSlice ruby_value_type_to_class_name(enum ruby_value_type type);
|
193
210
|
|
194
211
|
void collectors_thread_context_init(VALUE profiling_module) {
|
195
212
|
VALUE collectors_module = rb_define_module_under(profiling_module, "Collectors");
|
@@ -207,17 +224,18 @@ void collectors_thread_context_init(VALUE profiling_module) {
|
|
207
224
|
// https://bugs.ruby-lang.org/issues/18007 for a discussion around this.
|
208
225
|
rb_define_alloc_func(collectors_thread_context_class, _native_new);
|
209
226
|
|
210
|
-
rb_define_singleton_method(collectors_thread_context_class, "_native_initialize", _native_initialize,
|
227
|
+
rb_define_singleton_method(collectors_thread_context_class, "_native_initialize", _native_initialize, 7);
|
211
228
|
rb_define_singleton_method(collectors_thread_context_class, "_native_inspect", _native_inspect, 1);
|
212
229
|
rb_define_singleton_method(collectors_thread_context_class, "_native_reset_after_fork", _native_reset_after_fork, 1);
|
213
230
|
rb_define_singleton_method(testing_module, "_native_sample", _native_sample, 2);
|
214
|
-
rb_define_singleton_method(testing_module, "_native_sample_allocation", _native_sample_allocation,
|
231
|
+
rb_define_singleton_method(testing_module, "_native_sample_allocation", _native_sample_allocation, 3);
|
215
232
|
rb_define_singleton_method(testing_module, "_native_on_gc_start", _native_on_gc_start, 1);
|
216
233
|
rb_define_singleton_method(testing_module, "_native_on_gc_finish", _native_on_gc_finish, 1);
|
217
234
|
rb_define_singleton_method(testing_module, "_native_sample_after_gc", _native_sample_after_gc, 1);
|
218
235
|
rb_define_singleton_method(testing_module, "_native_thread_list", _native_thread_list, 0);
|
219
236
|
rb_define_singleton_method(testing_module, "_native_per_thread_context", _native_per_thread_context, 1);
|
220
237
|
rb_define_singleton_method(testing_module, "_native_stats", _native_stats, 1);
|
238
|
+
rb_define_singleton_method(testing_module, "_native_new_empty_thread", _native_new_empty_thread, 0);
|
221
239
|
|
222
240
|
at_active_span_id = rb_intern_const("@active_span");
|
223
241
|
at_active_trace_id = rb_intern_const("@active_trace");
|
@@ -249,6 +267,7 @@ static void thread_context_collector_typed_data_mark(void *state_ptr) {
|
|
249
267
|
rb_gc_mark(state->recorder_instance);
|
250
268
|
st_foreach(state->hash_map_per_thread_context, hash_map_per_thread_context_mark, 0 /* unused */);
|
251
269
|
rb_gc_mark(state->thread_list_buffer);
|
270
|
+
rb_gc_mark(state->main_thread);
|
252
271
|
}
|
253
272
|
|
254
273
|
static void thread_context_collector_typed_data_free(void *state_ptr) {
|
@@ -285,6 +304,9 @@ static int hash_map_per_thread_context_free_values(DDTRACE_UNUSED st_data_t _thr
|
|
285
304
|
static VALUE _native_new(VALUE klass) {
|
286
305
|
struct thread_context_collector_state *state = ruby_xcalloc(1, sizeof(struct thread_context_collector_state));
|
287
306
|
|
307
|
+
// Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory
|
308
|
+
// being leaked.
|
309
|
+
|
288
310
|
// Update this when modifying state struct
|
289
311
|
state->sampling_buffer = NULL;
|
290
312
|
state->hash_map_per_thread_context =
|
@@ -294,6 +316,10 @@ static VALUE _native_new(VALUE klass) {
|
|
294
316
|
state->tracer_context_key = MISSING_TRACER_CONTEXT_KEY;
|
295
317
|
state->thread_list_buffer = rb_ary_new();
|
296
318
|
state->endpoint_collection_enabled = true;
|
319
|
+
state->timeline_enabled = true;
|
320
|
+
state->allocation_type_enabled = true;
|
321
|
+
state->time_converter_state = (monotonic_to_system_epoch_state) MONOTONIC_TO_SYSTEM_EPOCH_INITIALIZER;
|
322
|
+
state->main_thread = rb_thread_main();
|
297
323
|
|
298
324
|
return TypedData_Wrap_Struct(klass, &thread_context_collector_typed_data, state);
|
299
325
|
}
|
@@ -304,9 +330,13 @@ static VALUE _native_initialize(
|
|
304
330
|
VALUE recorder_instance,
|
305
331
|
VALUE max_frames,
|
306
332
|
VALUE tracer_context_key,
|
307
|
-
VALUE endpoint_collection_enabled
|
333
|
+
VALUE endpoint_collection_enabled,
|
334
|
+
VALUE timeline_enabled,
|
335
|
+
VALUE allocation_type_enabled
|
308
336
|
) {
|
309
337
|
ENFORCE_BOOLEAN(endpoint_collection_enabled);
|
338
|
+
ENFORCE_BOOLEAN(timeline_enabled);
|
339
|
+
ENFORCE_BOOLEAN(allocation_type_enabled);
|
310
340
|
|
311
341
|
struct thread_context_collector_state *state;
|
312
342
|
TypedData_Get_Struct(collector_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
@@ -319,6 +349,8 @@ static VALUE _native_initialize(
|
|
319
349
|
// hash_map_per_thread_context is already initialized, nothing to do here
|
320
350
|
state->recorder_instance = enforce_recorder_instance(recorder_instance);
|
321
351
|
state->endpoint_collection_enabled = (endpoint_collection_enabled == Qtrue);
|
352
|
+
state->timeline_enabled = (timeline_enabled == Qtrue);
|
353
|
+
state->allocation_type_enabled = (allocation_type_enabled == Qtrue);
|
322
354
|
|
323
355
|
if (RTEST(tracer_context_key)) {
|
324
356
|
ENFORCE_TYPE(tracer_context_key, T_SYMBOL);
|
@@ -442,8 +474,11 @@ void update_metrics_and_sample(
|
|
442
474
|
thread_being_sampled,
|
443
475
|
stack_from_thread,
|
444
476
|
thread_context,
|
445
|
-
(sample_values) {.cpu_time_ns = cpu_time_elapsed_ns, .
|
446
|
-
SAMPLE_REGULAR
|
477
|
+
(sample_values) {.cpu_time_ns = cpu_time_elapsed_ns, .cpu_or_wall_samples = 1, .wall_time_ns = wall_time_elapsed_ns},
|
478
|
+
SAMPLE_REGULAR,
|
479
|
+
current_monotonic_wall_time_ns,
|
480
|
+
NULL,
|
481
|
+
NULL
|
447
482
|
);
|
448
483
|
}
|
449
484
|
|
@@ -584,8 +619,11 @@ VALUE thread_context_collector_sample_after_gc(VALUE self_instance) {
|
|
584
619
|
/* thread: */ thread,
|
585
620
|
/* stack_from_thread: */ thread,
|
586
621
|
thread_context,
|
587
|
-
(sample_values) {.cpu_time_ns = gc_cpu_time_elapsed_ns, .
|
588
|
-
SAMPLE_IN_GC
|
622
|
+
(sample_values) {.cpu_time_ns = gc_cpu_time_elapsed_ns, .cpu_or_wall_samples = 1, .wall_time_ns = gc_wall_time_elapsed_ns},
|
623
|
+
SAMPLE_IN_GC,
|
624
|
+
INVALID_TIME, // For now we're not collecting timestamps for these events
|
625
|
+
NULL,
|
626
|
+
NULL
|
589
627
|
);
|
590
628
|
|
591
629
|
// Mark thread as no longer in GC
|
@@ -615,12 +653,18 @@ static void trigger_sample_for_thread(
|
|
615
653
|
VALUE stack_from_thread, // This can be different when attributing profiler overhead using a different stack
|
616
654
|
struct per_thread_context *thread_context,
|
617
655
|
sample_values values,
|
618
|
-
sample_type type
|
656
|
+
sample_type type,
|
657
|
+
long current_monotonic_wall_time_ns,
|
658
|
+
// These two labels are only used for allocation profiling; @ivoanjo: may want to refactor this at some point?
|
659
|
+
ddog_CharSlice *ruby_vm_type,
|
660
|
+
ddog_CharSlice *class_name
|
619
661
|
) {
|
620
662
|
int max_label_count =
|
621
663
|
1 + // thread id
|
622
664
|
1 + // thread name
|
623
665
|
1 + // profiler overhead
|
666
|
+
2 + // ruby vm type and allocation class
|
667
|
+
1 + // state (only set for cpu/wall-time samples)
|
624
668
|
2; // local root span id and span id
|
625
669
|
ddog_prof_Label labels[max_label_count];
|
626
670
|
int label_pos = 0;
|
@@ -636,6 +680,19 @@ static void trigger_sample_for_thread(
|
|
636
680
|
.key = DDOG_CHARSLICE_C("thread name"),
|
637
681
|
.str = char_slice_from_ruby_string(thread_name)
|
638
682
|
};
|
683
|
+
} else if (thread == state->main_thread) { // Threads are often not named, but we can have a nice fallback for this special thread
|
684
|
+
ddog_CharSlice main_thread_name = DDOG_CHARSLICE_C("main");
|
685
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
686
|
+
.key = DDOG_CHARSLICE_C("thread name"),
|
687
|
+
.str = main_thread_name
|
688
|
+
};
|
689
|
+
} else {
|
690
|
+
// For other threads without name, we use the "invoke location" (first file:line of the block used to start the thread), if any.
|
691
|
+
// This is what Ruby shows in `Thread#to_s`.
|
692
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
693
|
+
.key = DDOG_CHARSLICE_C("thread name"),
|
694
|
+
.str = thread_context->thread_invoke_location_char_slice // This is an empty string if no invoke location was available
|
695
|
+
};
|
639
696
|
}
|
640
697
|
|
641
698
|
struct trace_identifiers trace_identifiers_result = {.valid = false, .trace_endpoint = Qnil};
|
@@ -670,20 +727,56 @@ static void trigger_sample_for_thread(
|
|
670
727
|
};
|
671
728
|
}
|
672
729
|
|
730
|
+
if (ruby_vm_type != NULL) {
|
731
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
732
|
+
.key = DDOG_CHARSLICE_C("ruby vm type"),
|
733
|
+
.str = *ruby_vm_type
|
734
|
+
};
|
735
|
+
}
|
736
|
+
|
737
|
+
if (class_name != NULL) {
|
738
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
739
|
+
.key = DDOG_CHARSLICE_C("allocation class"),
|
740
|
+
.str = *class_name
|
741
|
+
};
|
742
|
+
}
|
743
|
+
|
744
|
+
// This label is handled specially:
|
745
|
+
// 1. It's only set for cpu/wall-time samples
|
746
|
+
// 2. We set it here to its default state of "unknown", but the `Collectors::Stack` may choose to override it with
|
747
|
+
// something more interesting.
|
748
|
+
ddog_prof_Label *state_label = NULL;
|
749
|
+
if (values.cpu_or_wall_samples > 0) {
|
750
|
+
state_label = &labels[label_pos++];
|
751
|
+
*state_label = (ddog_prof_Label) {
|
752
|
+
.key = DDOG_CHARSLICE_C("state"),
|
753
|
+
.str = DDOG_CHARSLICE_C("unknown"),
|
754
|
+
.num = 0, // This shouldn't be needed but the tracer-2.7 docker image ships a buggy gcc that complains about this
|
755
|
+
};
|
756
|
+
}
|
757
|
+
|
673
758
|
// The number of times `label_pos++` shows up in this function needs to match `max_label_count`. To avoid "oops I
|
674
759
|
// forgot to update max_label_count" in the future, we've also added this validation.
|
675
|
-
// @ivoanjo: I wonder if C compilers are smart enough to statically prove
|
676
|
-
// remove it entirely
|
760
|
+
// @ivoanjo: I wonder if C compilers are smart enough to statically prove this check never triggers unless someone
|
761
|
+
// changes the code erroneously and remove it entirely?
|
677
762
|
if (label_pos > max_label_count) {
|
678
763
|
rb_raise(rb_eRuntimeError, "BUG: Unexpected label_pos (%d) > max_label_count (%d)", label_pos, max_label_count);
|
679
764
|
}
|
680
765
|
|
766
|
+
ddog_prof_Slice_Label slice_labels = {.ptr = labels, .len = label_pos};
|
767
|
+
|
768
|
+
// The end_timestamp_ns is treated specially by libdatadog and that's why it's not added as a ddog_prof_Label
|
769
|
+
int64_t end_timestamp_ns = 0;
|
770
|
+
if (state->timeline_enabled && current_monotonic_wall_time_ns != INVALID_TIME) {
|
771
|
+
end_timestamp_ns = monotonic_to_system_epoch_ns(&state->time_converter_state, current_monotonic_wall_time_ns);
|
772
|
+
}
|
773
|
+
|
681
774
|
sample_thread(
|
682
775
|
stack_from_thread,
|
683
776
|
state->sampling_buffer,
|
684
777
|
state->recorder_instance,
|
685
778
|
values,
|
686
|
-
(
|
779
|
+
(sample_labels) {.labels = slice_labels, .state_label = state_label, .end_timestamp_ns = end_timestamp_ns},
|
687
780
|
type
|
688
781
|
);
|
689
782
|
}
|
@@ -704,7 +797,7 @@ static struct per_thread_context *get_or_create_context_for(VALUE thread, struct
|
|
704
797
|
thread_context = (struct per_thread_context*) value_context;
|
705
798
|
} else {
|
706
799
|
thread_context = ruby_xcalloc(1, sizeof(struct per_thread_context));
|
707
|
-
initialize_context(thread, thread_context);
|
800
|
+
initialize_context(thread, thread_context, state);
|
708
801
|
st_insert(state->hash_map_per_thread_context, (st_data_t) thread, (st_data_t) thread_context);
|
709
802
|
}
|
710
803
|
|
@@ -722,10 +815,57 @@ static struct per_thread_context *get_context_for(VALUE thread, struct thread_co
|
|
722
815
|
return thread_context;
|
723
816
|
}
|
724
817
|
|
725
|
-
|
818
|
+
#define LOGGING_GEM_PATH "/lib/logging/diagnostic_context.rb"
|
819
|
+
|
820
|
+
// The `logging` gem monkey patches thread creation, which makes the `invoke_location_for` useless, since every thread
|
821
|
+
// will point to the `logging` gem. When that happens, we avoid using the invoke location.
|
822
|
+
//
|
823
|
+
// TODO: This approach is a bit brittle, since it matches on the specific gem path, and only works for the `logging`
|
824
|
+
// gem.
|
825
|
+
// In the future we should probably explore a more generic fix (e.g. using Thread.method(:new).source_location or
|
826
|
+
// something like that to detect redefinition of the `Thread` methods). One difficulty of doing it is that we need
|
827
|
+
// to either run Ruby code during sampling (not great), or otherwise use some of the VM private APIs to detect this.
|
828
|
+
//
|
829
|
+
static bool is_logging_gem_monkey_patch(VALUE invoke_file_location) {
|
830
|
+
int logging_gem_path_len = strlen(LOGGING_GEM_PATH);
|
831
|
+
char *invoke_file = StringValueCStr(invoke_file_location);
|
832
|
+
int invoke_file_len = strlen(invoke_file);
|
833
|
+
|
834
|
+
if (invoke_file_len < logging_gem_path_len) return false;
|
835
|
+
|
836
|
+
return strncmp(invoke_file + invoke_file_len - logging_gem_path_len, LOGGING_GEM_PATH, logging_gem_path_len) == 0;
|
837
|
+
}
|
838
|
+
|
839
|
+
static void initialize_context(VALUE thread, struct per_thread_context *thread_context, struct thread_context_collector_state *state) {
|
726
840
|
snprintf(thread_context->thread_id, THREAD_ID_LIMIT_CHARS, "%"PRIu64" (%lu)", native_thread_id_for(thread), (unsigned long) thread_id_for(thread));
|
727
841
|
thread_context->thread_id_char_slice = (ddog_CharSlice) {.ptr = thread_context->thread_id, .len = strlen(thread_context->thread_id)};
|
728
842
|
|
843
|
+
int invoke_line_location;
|
844
|
+
VALUE invoke_file_location = invoke_location_for(thread, &invoke_line_location);
|
845
|
+
if (invoke_file_location != Qnil) {
|
846
|
+
if (!is_logging_gem_monkey_patch(invoke_file_location)) {
|
847
|
+
snprintf(
|
848
|
+
thread_context->thread_invoke_location,
|
849
|
+
THREAD_INVOKE_LOCATION_LIMIT_CHARS,
|
850
|
+
"%s:%d",
|
851
|
+
StringValueCStr(invoke_file_location),
|
852
|
+
invoke_line_location
|
853
|
+
);
|
854
|
+
} else {
|
855
|
+
snprintf(thread_context->thread_invoke_location, THREAD_INVOKE_LOCATION_LIMIT_CHARS, "%s", "(Unnamed thread)");
|
856
|
+
}
|
857
|
+
} else if (thread != state->main_thread) {
|
858
|
+
// If the first function of a thread is native code, there won't be an invoke location, so we use this fallback.
|
859
|
+
// NOTE: In the future, I wonder if we could take the pointer to the native function, and try to see if there's a native
|
860
|
+
// symbol attached to it.
|
861
|
+
snprintf(thread_context->thread_invoke_location, THREAD_INVOKE_LOCATION_LIMIT_CHARS, "%s", "(Unnamed thread from native code)");
|
862
|
+
}
|
863
|
+
|
864
|
+
thread_context->thread_invoke_location_char_slice = (ddog_CharSlice) {
|
865
|
+
.ptr = thread_context->thread_invoke_location,
|
866
|
+
.len = strlen(thread_context->thread_invoke_location)
|
867
|
+
};
|
868
|
+
|
729
869
|
thread_context->thread_cpu_time_id = thread_cpu_time_id_for(thread);
|
730
870
|
|
731
871
|
// These will get initialized during actual sampling
|
@@ -753,6 +893,14 @@ static VALUE _native_inspect(DDTRACE_UNUSED VALUE _self, VALUE collector_instanc
|
|
753
893
|
rb_str_concat(result, rb_sprintf(" sample_count=%u", state->sample_count));
|
754
894
|
rb_str_concat(result, rb_sprintf(" stats=%"PRIsVALUE, stats_as_ruby_hash(state)));
|
755
895
|
rb_str_concat(result, rb_sprintf(" endpoint_collection_enabled=%"PRIsVALUE, state->endpoint_collection_enabled ? Qtrue : Qfalse));
|
896
|
+
rb_str_concat(result, rb_sprintf(" timeline_enabled=%"PRIsVALUE, state->timeline_enabled ? Qtrue : Qfalse));
|
897
|
+
rb_str_concat(result, rb_sprintf(" allocation_type_enabled=%"PRIsVALUE, state->allocation_type_enabled ? Qtrue : Qfalse));
|
898
|
+
rb_str_concat(result, rb_sprintf(
|
899
|
+
" time_converter_state={.system_epoch_ns_reference=%ld, .delta_to_epoch_ns=%ld}",
|
900
|
+
state->time_converter_state.system_epoch_ns_reference,
|
901
|
+
state->time_converter_state.delta_to_epoch_ns
|
902
|
+
));
|
903
|
+
rb_str_concat(result, rb_sprintf(" main_thread=%"PRIsVALUE, state->main_thread));
|
756
904
|
|
757
905
|
return result;
|
758
906
|
}
|
@@ -772,6 +920,7 @@ static int per_thread_context_as_ruby_hash(st_data_t key_thread, st_data_t value
|
|
772
920
|
|
773
921
|
VALUE arguments[] = {
|
774
922
|
ID2SYM(rb_intern("thread_id")), /* => */ rb_str_new2(thread_context->thread_id),
|
923
|
+
ID2SYM(rb_intern("thread_invoke_location")), /* => */ rb_str_new2(thread_context->thread_invoke_location),
|
775
924
|
ID2SYM(rb_intern("thread_cpu_time_id_valid?")), /* => */ thread_context->thread_cpu_time_id.valid ? Qtrue : Qfalse,
|
776
925
|
ID2SYM(rb_intern("thread_cpu_time_id")), /* => */ CLOCKID2NUM(thread_context->thread_cpu_time_id.clock_id),
|
777
926
|
ID2SYM(rb_intern("cpu_time_at_previous_sample_ns")), /* => */ LONG2NUM(thread_context->cpu_time_at_previous_sample_ns),
|
@@ -935,7 +1084,7 @@ static void trace_identifiers_for(struct thread_context_collector_state *state,
|
|
935
1084
|
if (!state->endpoint_collection_enabled) return;
|
936
1085
|
|
937
1086
|
VALUE root_span_type = rb_ivar_get(root_span, at_type_id /* @type */);
|
938
|
-
if (root_span_type == Qnil || !
|
1087
|
+
if (root_span_type == Qnil || !should_collect_resource(root_span_type)) return;
|
939
1088
|
|
940
1089
|
VALUE trace_resource = rb_ivar_get(active_trace, at_resource_id /* @resource */);
|
941
1090
|
if (RB_TYPE_P(trace_resource, T_STRING)) {
|
@@ -946,11 +1095,21 @@ static void trace_identifiers_for(struct thread_context_collector_state *state,
|
|
946
1095
|
}
|
947
1096
|
}
|
948
1097
|
|
949
|
-
|
1098
|
+
// We only collect the resource for spans of types:
|
1099
|
+
// * 'web', for web requests
|
1100
|
+
// * proxy', used by the rack integration with request_queuing: true (e.g. also represents a web request)
|
1101
|
+
//
|
1102
|
+
// NOTE: Currently we're only interested in HTTP service endpoints. Over time, this list may be expanded.
|
1103
|
+
// Resources MUST NOT include personal identifiable information (PII); this should not be the case with
|
1104
|
+
// ddtrace integrations, but worth mentioning just in case :)
|
1105
|
+
static bool should_collect_resource(VALUE root_span_type) {
|
950
1106
|
ENFORCE_TYPE(root_span_type, T_STRING);
|
951
1107
|
|
952
|
-
|
953
|
-
|
1108
|
+
int root_span_type_length = RSTRING_LEN(root_span_type);
|
1109
|
+
const char *root_span_type_value = StringValuePtr(root_span_type);
|
1110
|
+
|
1111
|
+
return (root_span_type_length == strlen("web") && (memcmp("web", root_span_type_value, strlen("web")) == 0)) ||
|
1112
|
+
(root_span_type_length == strlen("proxy") && (memcmp("proxy", root_span_type_value, strlen("proxy")) == 0));
|
954
1113
|
}
|
955
1114
|
|
956
1115
|
// After the Ruby VM forks, this method gets called in the child process to clean up any leftover state from the parent.
|
@@ -977,25 +1136,131 @@ static VALUE thread_list(struct thread_context_collector_state *state) {
|
|
977
1136
|
return result;
|
978
1137
|
}
|
979
1138
|
|
980
|
-
void thread_context_collector_sample_allocation(VALUE self_instance, unsigned int sample_weight) {
|
1139
|
+
void thread_context_collector_sample_allocation(VALUE self_instance, unsigned int sample_weight, VALUE new_object) {
|
981
1140
|
struct thread_context_collector_state *state;
|
982
1141
|
TypedData_Get_Struct(self_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
983
1142
|
|
984
1143
|
VALUE current_thread = rb_thread_current();
|
985
1144
|
|
1145
|
+
enum ruby_value_type type = rb_type(new_object);
|
1146
|
+
|
1147
|
+
// Tag samples with the VM internal types
|
1148
|
+
ddog_CharSlice ruby_vm_type = ruby_value_type_to_char_slice(type);
|
1149
|
+
|
1150
|
+
// Since this is stack allocated, be careful about moving it
|
1151
|
+
ddog_CharSlice class_name;
|
1152
|
+
ddog_CharSlice *optional_class_name = NULL;
|
1153
|
+
char imemo_type[100];
|
1154
|
+
|
1155
|
+
if (state->allocation_type_enabled) {
|
1156
|
+
optional_class_name = &class_name;
|
1157
|
+
|
1158
|
+
if (
|
1159
|
+
type == RUBY_T_OBJECT ||
|
1160
|
+
type == RUBY_T_CLASS ||
|
1161
|
+
type == RUBY_T_MODULE ||
|
1162
|
+
type == RUBY_T_FLOAT ||
|
1163
|
+
type == RUBY_T_STRING ||
|
1164
|
+
type == RUBY_T_REGEXP ||
|
1165
|
+
type == RUBY_T_ARRAY ||
|
1166
|
+
type == RUBY_T_HASH ||
|
1167
|
+
type == RUBY_T_STRUCT ||
|
1168
|
+
type == RUBY_T_BIGNUM ||
|
1169
|
+
type == RUBY_T_FILE ||
|
1170
|
+
type == RUBY_T_DATA ||
|
1171
|
+
type == RUBY_T_MATCH ||
|
1172
|
+
type == RUBY_T_COMPLEX ||
|
1173
|
+
type == RUBY_T_RATIONAL ||
|
1174
|
+
type == RUBY_T_NIL ||
|
1175
|
+
type == RUBY_T_TRUE ||
|
1176
|
+
type == RUBY_T_FALSE ||
|
1177
|
+
type == RUBY_T_SYMBOL ||
|
1178
|
+
type == RUBY_T_FIXNUM
|
1179
|
+
) {
|
1180
|
+
VALUE klass = rb_class_of(new_object);
|
1181
|
+
|
1182
|
+
// Ruby sometimes plays a bit fast and loose with some of its internal objects, e.g.
|
1183
|
+
// `rb_str_tmp_frozen_acquire` allocates a string with no class (klass=0).
|
1184
|
+
// Thus, we need to make sure there's actually a class before getting its name.
|
1185
|
+
|
1186
|
+
if (klass != 0) {
|
1187
|
+
const char *name = rb_obj_classname(new_object);
|
1188
|
+
size_t name_length = name != NULL ? strlen(name) : 0;
|
1189
|
+
|
1190
|
+
if (name_length > 0) {
|
1191
|
+
class_name = (ddog_CharSlice) {.ptr = name, .len = name_length};
|
1192
|
+
} else {
|
1193
|
+
// @ivoanjo: I'm not sure this can ever happen, but just-in-case
|
1194
|
+
class_name = ruby_value_type_to_class_name(type);
|
1195
|
+
}
|
1196
|
+
} else {
|
1197
|
+
// Fallback for objects with no class
|
1198
|
+
class_name = ruby_value_type_to_class_name(type);
|
1199
|
+
}
|
1200
|
+
} else if (type == RUBY_T_IMEMO) {
|
1201
|
+
const char *imemo_string = imemo_kind(new_object);
|
1202
|
+
if (imemo_string != NULL) {
|
1203
|
+
snprintf(imemo_type, 100, "(VM Internal, T_IMEMO, %s)", imemo_string);
|
1204
|
+
class_name = (ddog_CharSlice) {.ptr = imemo_type, .len = strlen(imemo_type)};
|
1205
|
+
} else { // Ruby < 3
|
1206
|
+
class_name = DDOG_CHARSLICE_C("(VM Internal, T_IMEMO)");
|
1207
|
+
}
|
1208
|
+
} else {
|
1209
|
+
class_name = ruby_vm_type; // For other weird internal things we just use the VM type
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
|
986
1213
|
trigger_sample_for_thread(
|
987
1214
|
state,
|
988
1215
|
/* thread: */ current_thread,
|
989
1216
|
/* stack_from_thread: */ current_thread,
|
990
1217
|
get_or_create_context_for(current_thread, state),
|
991
1218
|
(sample_values) {.alloc_samples = sample_weight},
|
992
|
-
SAMPLE_REGULAR
|
1219
|
+
SAMPLE_REGULAR,
|
1220
|
+
INVALID_TIME, // For now we're not collecting timestamps for allocation events, as per profiling team internal discussions
|
1221
|
+
&ruby_vm_type,
|
1222
|
+
optional_class_name
|
993
1223
|
);
|
994
1224
|
}
|
995
1225
|
|
996
1226
|
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
997
1227
|
// It SHOULD NOT be used for other purposes.
|
998
|
-
static VALUE _native_sample_allocation(DDTRACE_UNUSED VALUE self, VALUE collector_instance, VALUE sample_weight) {
|
999
|
-
thread_context_collector_sample_allocation(collector_instance, NUM2UINT(sample_weight));
|
1228
|
+
static VALUE _native_sample_allocation(DDTRACE_UNUSED VALUE self, VALUE collector_instance, VALUE sample_weight, VALUE new_object) {
|
1229
|
+
thread_context_collector_sample_allocation(collector_instance, NUM2UINT(sample_weight), new_object);
|
1000
1230
|
return Qtrue;
|
1001
1231
|
}
|
1232
|
+
|
1233
|
+
static VALUE new_empty_thread_inner(DDTRACE_UNUSED void *arg) { return Qnil; }
|
1234
|
+
|
1235
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
1236
|
+
// It SHOULD NOT be used for other purposes.
|
1237
|
+
// (It creates an empty native thread, so we can test our native thread naming fallback)
|
1238
|
+
static VALUE _native_new_empty_thread(DDTRACE_UNUSED VALUE self) {
|
1239
|
+
return rb_thread_create(new_empty_thread_inner, NULL);
|
1240
|
+
}
|
1241
|
+
|
1242
|
+
ddog_CharSlice ruby_value_type_to_class_name(enum ruby_value_type type) {
|
1243
|
+
switch (type) {
|
1244
|
+
case(RUBY_T_OBJECT ): return DDOG_CHARSLICE_C("Object");
|
1245
|
+
case(RUBY_T_CLASS ): return DDOG_CHARSLICE_C("Class");
|
1246
|
+
case(RUBY_T_MODULE ): return DDOG_CHARSLICE_C("Module");
|
1247
|
+
case(RUBY_T_FLOAT ): return DDOG_CHARSLICE_C("Float");
|
1248
|
+
case(RUBY_T_STRING ): return DDOG_CHARSLICE_C("String");
|
1249
|
+
case(RUBY_T_REGEXP ): return DDOG_CHARSLICE_C("Regexp");
|
1250
|
+
case(RUBY_T_ARRAY ): return DDOG_CHARSLICE_C("Array");
|
1251
|
+
case(RUBY_T_HASH ): return DDOG_CHARSLICE_C("Hash");
|
1252
|
+
case(RUBY_T_STRUCT ): return DDOG_CHARSLICE_C("Struct");
|
1253
|
+
case(RUBY_T_BIGNUM ): return DDOG_CHARSLICE_C("Integer");
|
1254
|
+
case(RUBY_T_FILE ): return DDOG_CHARSLICE_C("File");
|
1255
|
+
case(RUBY_T_DATA ): return DDOG_CHARSLICE_C("(VM Internal, T_DATA)");
|
1256
|
+
case(RUBY_T_MATCH ): return DDOG_CHARSLICE_C("MatchData");
|
1257
|
+
case(RUBY_T_COMPLEX ): return DDOG_CHARSLICE_C("Complex");
|
1258
|
+
case(RUBY_T_RATIONAL): return DDOG_CHARSLICE_C("Rational");
|
1259
|
+
case(RUBY_T_NIL ): return DDOG_CHARSLICE_C("NilClass");
|
1260
|
+
case(RUBY_T_TRUE ): return DDOG_CHARSLICE_C("TrueClass");
|
1261
|
+
case(RUBY_T_FALSE ): return DDOG_CHARSLICE_C("FalseClass");
|
1262
|
+
case(RUBY_T_SYMBOL ): return DDOG_CHARSLICE_C("Symbol");
|
1263
|
+
case(RUBY_T_FIXNUM ): return DDOG_CHARSLICE_C("Integer");
|
1264
|
+
default: return DDOG_CHARSLICE_C("(VM Internal, Missing class)");
|
1265
|
+
}
|
1266
|
+
}
|
@@ -7,7 +7,7 @@ void thread_context_collector_sample(
|
|
7
7
|
long current_monotonic_wall_time_ns,
|
8
8
|
VALUE profiler_overhead_stack_thread
|
9
9
|
);
|
10
|
-
void thread_context_collector_sample_allocation(VALUE self_instance, unsigned int sample_weight);
|
10
|
+
void thread_context_collector_sample_allocation(VALUE self_instance, unsigned int sample_weight, VALUE new_object);
|
11
11
|
VALUE thread_context_collector_sample_after_gc(VALUE self_instance);
|
12
12
|
void thread_context_collector_on_gc_start(VALUE self_instance);
|
13
13
|
void thread_context_collector_on_gc_finish(VALUE self_instance);
|
@@ -81,10 +81,7 @@ end
|
|
81
81
|
|
82
82
|
# Because we can't control what compiler versions our customers use, shipping with -Werror by default is a no-go.
|
83
83
|
# But we can enable it in CI, so that we quickly spot any new warnings that just got introduced.
|
84
|
-
|
85
|
-
# @ivoanjo TODO: Ruby 3.3.0-preview1 was causing issues in CI because `have_header('vm_core.h')` below triggers warnings;
|
86
|
-
# I've chosen to disable `-Werror` for this Ruby version for now, and we can revisit this on a later 3.3 release.
|
87
|
-
add_compiler_flag '-Werror' if ENV['DDTRACE_CI'] == 'true' && !RUBY_DESCRIPTION.include?('3.3.0preview1')
|
84
|
+
add_compiler_flag '-Werror' if ENV['DDTRACE_CI'] == 'true'
|
88
85
|
|
89
86
|
# Older gcc releases may not default to C99 and we need to ask for this. This is also used:
|
90
87
|
# * by upstream Ruby -- search for gnu99 in the codebase
|
@@ -102,9 +99,6 @@ add_compiler_flag '-Wno-declaration-after-statement'
|
|
102
99
|
# cause a segfault later. Let's ensure that never happens.
|
103
100
|
add_compiler_flag '-Werror-implicit-function-declaration'
|
104
101
|
|
105
|
-
# Warn on unused parameters to functions. Use `DDTRACE_UNUSED` to mark things as known-to-not-be-used.
|
106
|
-
add_compiler_flag '-Wunused-parameter'
|
107
|
-
|
108
102
|
# The native extension is not intended to expose any symbols/functions for other native libraries to use;
|
109
103
|
# the sole exception being `Init_ddtrace_profiling_native_extension` which needs to be visible for Ruby to call it when
|
110
104
|
# it `dlopen`s the library.
|
@@ -131,6 +125,9 @@ if RUBY_PLATFORM.include?('linux')
|
|
131
125
|
$defs << '-DHAVE_PTHREAD_GETCPUCLOCKID'
|
132
126
|
end
|
133
127
|
|
128
|
+
# On older Rubies, M:N threads were not available
|
129
|
+
$defs << '-DNO_MN_THREADS_AVAILABLE' if RUBY_VERSION < '3.3'
|
130
|
+
|
134
131
|
# On older Rubies, we did not need to include the ractor header (this was built into the MJIT header)
|
135
132
|
$defs << '-DNO_RACTOR_HEADER_INCLUDE' if RUBY_VERSION < '3.3'
|
136
133
|
|
@@ -143,18 +140,36 @@ $defs << '-DNO_RB_NATIVE_THREAD' if RUBY_VERSION < '3.2'
|
|
143
140
|
# On older Rubies, there was no struct rb_thread_sched (it was struct rb_global_vm_lock_struct)
|
144
141
|
$defs << '-DNO_RB_THREAD_SCHED' if RUBY_VERSION < '3.2'
|
145
142
|
|
143
|
+
# On older Rubies, the first_lineno inside a location was a VALUE and not a int (https://github.com/ruby/ruby/pull/6430)
|
144
|
+
$defs << '-DNO_INT_FIRST_LINENO' if RUBY_VERSION < '3.2'
|
145
|
+
|
146
|
+
# On older Rubies, "pop" was not a primitive operation
|
147
|
+
$defs << '-DNO_PRIMITIVE_POP' if RUBY_VERSION < '3.2'
|
148
|
+
|
146
149
|
# On older Rubies, there was no tid member in the internal thread structure
|
147
150
|
$defs << '-DNO_THREAD_TID' if RUBY_VERSION < '3.1'
|
148
151
|
|
152
|
+
# On older Rubies, there was no jit_return member on the rb_control_frame_t struct
|
153
|
+
$defs << '-DNO_JIT_RETURN' if RUBY_VERSION < '3.1'
|
154
|
+
|
149
155
|
# On older Rubies, we need to use a backported version of this function. See private_vm_api_access.h for details.
|
150
156
|
$defs << '-DUSE_BACKPORTED_RB_PROFILE_FRAME_METHOD_NAME' if RUBY_VERSION < '3'
|
151
157
|
|
152
158
|
# On older Rubies, there are no Ractors
|
153
159
|
$defs << '-DNO_RACTORS' if RUBY_VERSION < '3'
|
154
160
|
|
161
|
+
# On older Rubies, rb_imemo_name did not exist
|
162
|
+
$defs << '-DNO_IMEMO_NAME' if RUBY_VERSION < '3'
|
163
|
+
|
164
|
+
# On older Rubies, objects would not move
|
165
|
+
$defs << '-DNO_T_MOVED' if RUBY_VERSION < '2.7'
|
166
|
+
|
155
167
|
# On older Rubies, rb_global_vm_lock_struct did not include the owner field
|
156
168
|
$defs << '-DNO_GVL_OWNER' if RUBY_VERSION < '2.6'
|
157
169
|
|
170
|
+
# On older Rubies, there was no thread->invoke_arg
|
171
|
+
$defs << '-DNO_THREAD_INVOKE_ARG' if RUBY_VERSION < '2.6'
|
172
|
+
|
158
173
|
# On older Rubies, we need to use rb_thread_t instead of rb_execution_context_t
|
159
174
|
$defs << '-DUSE_THREAD_INSTEAD_OF_EXECUTION_CONTEXT' if RUBY_VERSION < '2.5'
|
160
175
|
|
@@ -226,6 +241,10 @@ if Datadog::Profiling::NativeExtensionHelpers::CAN_USE_MJIT_HEADER
|
|
226
241
|
# NOTE: This needs to come after all changes to $defs
|
227
242
|
create_header
|
228
243
|
|
244
|
+
# Warn on unused parameters to functions. Use `DDTRACE_UNUSED` to mark things as known-to-not-be-used.
|
245
|
+
# See the comment on the same flag below for why this is done last.
|
246
|
+
add_compiler_flag '-Wunused-parameter'
|
247
|
+
|
229
248
|
create_makefile EXTENSION_NAME
|
230
249
|
else
|
231
250
|
# The MJIT header was introduced on 2.6 and removed on 3.3; for other Rubies we rely on
|
@@ -241,9 +260,20 @@ else
|
|
241
260
|
Debase::RubyCoreSource
|
242
261
|
.create_makefile_with_core(
|
243
262
|
proc do
|
244
|
-
|
245
|
-
|
246
|
-
|
263
|
+
headers_available =
|
264
|
+
have_header('vm_core.h') &&
|
265
|
+
have_header('iseq.h') &&
|
266
|
+
(RUBY_VERSION < '3.3' || have_header('ractor_core.h'))
|
267
|
+
|
268
|
+
if headers_available
|
269
|
+
# Warn on unused parameters to functions. Use `DDTRACE_UNUSED` to mark things as known-to-not-be-used.
|
270
|
+
# This is added as late as possible because in some Rubies we support (e.g. 3.3), adding this flag before
|
271
|
+
# checking if internal VM headers are available causes those checks to fail because of this warning (and not
|
272
|
+
# because the headers are not available.)
|
273
|
+
add_compiler_flag '-Wunused-parameter'
|
274
|
+
end
|
275
|
+
|
276
|
+
headers_available
|
247
277
|
end,
|
248
278
|
EXTENSION_NAME,
|
249
279
|
)
|