ddtrace 1.12.1 → 1.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +613 -9
- data/LICENSE-3rdparty.csv +1 -1
- data/bin/ddprofrb +15 -0
- data/bin/ddtracerb +3 -1
- data/ext/{ddtrace_profiling_loader/ddtrace_profiling_loader.c → datadog_profiling_loader/datadog_profiling_loader.c} +2 -2
- data/ext/{ddtrace_profiling_loader → datadog_profiling_loader}/extconf.rb +3 -3
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/NativeExtensionDesign.md +3 -5
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id.h +0 -3
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id_from_pthread.c +3 -22
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/clock_id_noop.c +0 -1
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_cpu_and_wall_time_worker.c +338 -108
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c +422 -0
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.h +101 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_dynamic_sampling_rate.c +22 -14
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_dynamic_sampling_rate.h +4 -0
- data/ext/datadog_profiling_native_extension/collectors_gc_profiling_helper.c +156 -0
- data/ext/datadog_profiling_native_extension/collectors_gc_profiling_helper.h +5 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_idle_sampling_helper.c +3 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_stack.c +111 -118
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_stack.h +11 -4
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_thread_context.c +545 -144
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_thread_context.h +3 -2
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/extconf.rb +68 -17
- data/ext/datadog_profiling_native_extension/heap_recorder.c +1047 -0
- data/ext/datadog_profiling_native_extension/heap_recorder.h +166 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/helpers.h +6 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/http_transport.c +60 -32
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.c +62 -0
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.h +42 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/native_extension_helpers.rb +50 -4
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/private_vm_api_access.c +155 -32
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/private_vm_api_access.h +16 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/profiling.c +19 -3
- data/ext/datadog_profiling_native_extension/ruby_helpers.c +267 -0
- data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/ruby_helpers.h +33 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +1040 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.h +27 -0
- data/ext/datadog_profiling_native_extension/time_helpers.c +53 -0
- data/ext/datadog_profiling_native_extension/time_helpers.h +26 -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 +57 -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 +77 -27
- 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/auto_instrument.rb +3 -0
- 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 +20 -7
- data/lib/datadog/core/configuration/ext.rb +28 -5
- data/lib/datadog/core/configuration/option.rb +271 -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 +398 -119
- data/lib/datadog/core/configuration.rb +24 -4
- data/lib/datadog/core/diagnostics/environment_logger.rb +132 -235
- data/lib/datadog/core/environment/class_count.rb +6 -6
- data/lib/datadog/core/environment/execution.rb +103 -0
- data/lib/datadog/core/environment/ext.rb +13 -11
- data/lib/datadog/core/environment/git.rb +25 -0
- data/lib/datadog/core/environment/identity.rb +18 -48
- data/lib/datadog/core/environment/platform.rb +7 -1
- 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 +6 -23
- 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 +7 -2
- data/lib/datadog/core/remote/client.rb +3 -0
- data/lib/datadog/core/remote/component.rb +52 -48
- 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 +2 -1
- data/lib/datadog/core/remote/negotiation.rb +20 -7
- data/lib/datadog/core/remote/tie/tracing.rb +39 -0
- data/lib/datadog/core/remote/tie.rb +27 -0
- 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 +11 -5
- 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 +28 -10
- data/lib/datadog/core/telemetry/emitter.rb +9 -11
- data/lib/datadog/core/telemetry/event.rb +250 -44
- data/lib/datadog/core/telemetry/ext.rb +8 -1
- data/lib/datadog/core/telemetry/heartbeat.rb +3 -7
- data/lib/datadog/core/telemetry/http/ext.rb +13 -8
- data/lib/datadog/core/telemetry/http/response.rb +4 -0
- data/lib/datadog/core/telemetry/http/transport.rb +10 -3
- data/lib/datadog/core/telemetry/request.rb +59 -0
- data/lib/datadog/core/transport/ext.rb +49 -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/url.rb +25 -0
- 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 +5 -3
- 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 +4 -0
- data/lib/datadog/opentracer/text_map_propagator.rb +2 -1
- data/lib/datadog/opentracer.rb +9 -0
- data/lib/datadog/profiling/collectors/code_provenance.rb +10 -4
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +43 -20
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +3 -1
- data/lib/datadog/profiling/collectors/info.rb +101 -0
- data/lib/datadog/profiling/collectors/thread_context.rb +17 -2
- data/lib/datadog/profiling/component.rb +248 -97
- data/lib/datadog/profiling/exporter.rb +26 -5
- data/lib/datadog/profiling/ext.rb +2 -12
- data/lib/datadog/profiling/flush.rb +10 -5
- data/lib/datadog/profiling/http_transport.rb +23 -6
- data/lib/datadog/profiling/load_native_extension.rb +25 -6
- data/lib/datadog/profiling/native_extension.rb +1 -22
- data/lib/datadog/profiling/profiler.rb +36 -13
- data/lib/datadog/profiling/scheduler.rb +20 -15
- data/lib/datadog/profiling/stack_recorder.rb +19 -4
- data/lib/datadog/profiling/tag_builder.rb +5 -0
- data/lib/datadog/profiling/tasks/exec.rb +3 -3
- data/lib/datadog/profiling/tasks/help.rb +3 -3
- data/lib/datadog/profiling.rb +28 -79
- 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 -33
- data/lib/datadog/tracing/configuration/http.rb +74 -0
- data/lib/datadog/tracing/configuration/settings.rb +136 -99
- data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +10 -6
- data/lib/datadog/tracing/contrib/action_cable/ext.rb +21 -18
- data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +10 -6
- data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +1 -1
- data/lib/datadog/tracing/contrib/action_mailer/ext.rb +21 -18
- data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +10 -7
- data/lib/datadog/tracing/contrib/action_pack/ext.rb +11 -8
- data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +10 -6
- data/lib/datadog/tracing/contrib/action_view/ext.rb +13 -10
- data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/active_job/ext.rb +26 -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 +10 -6
- data/lib/datadog/tracing/contrib/active_model_serializers/ext.rb +13 -10
- data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +29 -15
- data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +10 -7
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +2 -6
- data/lib/datadog/tracing/contrib/active_record/ext.rb +18 -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 +10 -7
- data/lib/datadog/tracing/contrib/active_support/ext.rb +19 -16
- data/lib/datadog/tracing/contrib/analytics.rb +0 -1
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +15 -7
- data/lib/datadog/tracing/contrib/aws/ext.rb +38 -24
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +16 -5
- data/lib/datadog/tracing/contrib/concurrent_ruby/async_patch.rb +20 -0
- 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 +19 -2
- data/lib/datadog/tracing/contrib/concurrent_ruby/promises_future_patch.rb +22 -0
- data/lib/datadog/tracing/contrib/configurable.rb +1 -1
- data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +21 -7
- data/lib/datadog/tracing/contrib/dalli/ext.rb +27 -11
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +17 -8
- data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +14 -7
- data/lib/datadog/tracing/contrib/delayed_job/ext.rb +17 -14
- data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +15 -7
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +22 -15
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +104 -99
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +17 -9
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +48 -3
- data/lib/datadog/tracing/contrib/ethon/ext.rb +20 -11
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +6 -3
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +20 -10
- data/lib/datadog/tracing/contrib/excon/ext.rb +17 -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 +38 -2
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +27 -10
- data/lib/datadog/tracing/contrib/faraday/ext.rb +17 -8
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +22 -6
- data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/grape/ext.rb +17 -14
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +9 -6
- data/lib/datadog/tracing/contrib/graphql/ext.rb +8 -5
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +40 -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 +17 -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 +34 -11
- data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +2 -2
- data/lib/datadog/tracing/contrib/http/ext.rb +17 -9
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +27 -7
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +34 -11
- data/lib/datadog/tracing/contrib/httpclient/ext.rb +18 -9
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +22 -5
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +34 -11
- data/lib/datadog/tracing/contrib/httprb/ext.rb +17 -9
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +22 -5
- data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +10 -6
- data/lib/datadog/tracing/contrib/kafka/ext.rb +43 -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 +15 -7
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +21 -16
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +16 -5
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +22 -14
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +16 -10
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +22 -7
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +53 -0
- data/lib/datadog/tracing/contrib/opensearch/ext.rb +38 -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 +23 -14
- data/lib/datadog/tracing/contrib/pg/ext.rb +23 -19
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +49 -9
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +15 -7
- data/lib/datadog/tracing/contrib/presto/ext.rb +26 -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 +13 -8
- data/lib/datadog/tracing/contrib/qless/ext.rb +15 -12
- data/lib/datadog/tracing/contrib/que/configuration/settings.rb +22 -12
- data/lib/datadog/tracing/contrib/que/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +10 -7
- data/lib/datadog/tracing/contrib/racecar/event.rb +5 -5
- data/lib/datadog/tracing/contrib/racecar/ext.rb +21 -18
- data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +17 -12
- data/lib/datadog/tracing/contrib/rack/ext.rb +19 -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 +16 -50
- data/lib/datadog/tracing/contrib/rails/auto_instrument_railtie.rb +0 -2
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +20 -15
- data/lib/datadog/tracing/contrib/rails/ext.rb +8 -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 +14 -10
- data/lib/datadog/tracing/contrib/rake/ext.rb +15 -12
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +18 -9
- data/lib/datadog/tracing/contrib/redis/ext.rb +23 -15
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +5 -40
- data/lib/datadog/tracing/contrib/redis/patcher.rb +34 -21
- 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 +14 -7
- data/lib/datadog/tracing/contrib/resque/ext.rb +10 -7
- data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +17 -9
- data/lib/datadog/tracing/contrib/rest_client/ext.rb +16 -8
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +25 -5
- data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +10 -6
- data/lib/datadog/tracing/contrib/roda/ext.rb +1 -0
- 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 +10 -6
- data/lib/datadog/tracing/contrib/sequel/ext.rb +11 -8
- data/lib/datadog/tracing/contrib/sequel/utils.rb +7 -7
- data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +15 -8
- data/lib/datadog/tracing/contrib/shoryuken/ext.rb +15 -12
- data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +19 -11
- data/lib/datadog/tracing/contrib/sidekiq/ext.rb +33 -30
- data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +12 -9
- data/lib/datadog/tracing/contrib/sinatra/env.rb +0 -17
- data/lib/datadog/tracing/contrib/sinatra/ext.rb +22 -19
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +3 -14
- data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +15 -8
- data/lib/datadog/tracing/contrib/sneakers/ext.rb +2 -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 +10 -6
- data/lib/datadog/tracing/contrib/stripe/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +10 -6
- data/lib/datadog/tracing/contrib/sucker_punch/ext.rb +16 -13
- data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +58 -0
- data/lib/datadog/tracing/contrib/trilogy/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +94 -0
- data/lib/datadog/tracing/contrib/trilogy/integration.rb +43 -0
- data/lib/datadog/{ci/contrib/cucumber → tracing/contrib/trilogy}/patcher.rb +10 -6
- 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 +2 -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/matcher.rb +23 -3
- data/lib/datadog/tracing/sampling/rule.rb +7 -2
- data/lib/datadog/tracing/sampling/rule_sampler.rb +31 -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 +17 -5
- 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 +125 -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 +240 -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/datadog/tracing.rb +8 -2
- data/lib/ddtrace/transport/ext.rb +22 -14
- data/lib/ddtrace/version.rb +9 -12
- data/lib/ddtrace.rb +1 -1
- metadata +157 -139
- data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +0 -25
- data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +0 -110
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +0 -591
- data/ext/ddtrace_profiling_native_extension/stack_recorder.h +0 -14
- data/ext/ddtrace_profiling_native_extension/time_helpers.c +0 -17
- data/ext/ddtrace_profiling_native_extension/time_helpers.h +0 -10
- 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/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/telemetry/collector.rb +0 -231
- data/lib/datadog/core/telemetry/v1/app_event.rb +0 -52
- data/lib/datadog/core/telemetry/v1/application.rb +0 -92
- data/lib/datadog/core/telemetry/v1/configuration.rb +0 -25
- data/lib/datadog/core/telemetry/v1/dependency.rb +0 -43
- data/lib/datadog/core/telemetry/v1/host.rb +0 -59
- data/lib/datadog/core/telemetry/v1/integration.rb +0 -64
- data/lib/datadog/core/telemetry/v1/product.rb +0 -36
- data/lib/datadog/core/telemetry/v1/telemetry_request.rb +0 -106
- 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
- /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/collectors_idle_sampling_helper.h +0 -0
- /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/setup_signal_handler.c +0 -0
- /data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/setup_signal_handler.h +0 -0
|
@@ -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
|
|
@@ -446,6 +471,11 @@ int ddtrace_rb_profile_frames(VALUE thread, int start, int limit, VALUE *buff, i
|
|
|
446
471
|
// it from https://github.com/ruby/ruby/pull/7116 in a "just in case" kind of mindset.
|
|
447
472
|
if (cfp == NULL) return 0;
|
|
448
473
|
|
|
474
|
+
// As of this writing, we don't support profiling with MN enabled, and this only happens in that mode, but as we
|
|
475
|
+
// probably want to experiment with it in the future, I've decided to import https://github.com/ruby/ruby/pull/9310
|
|
476
|
+
// here.
|
|
477
|
+
if (ec == NULL) return 0;
|
|
478
|
+
|
|
449
479
|
// Fix: Skip dummy frame that shows up in main thread.
|
|
450
480
|
//
|
|
451
481
|
// According to a comment in `backtrace_each` (`vm_backtrace.c`), there's two dummy frames that we should ignore
|
|
@@ -507,7 +537,20 @@ int ddtrace_rb_profile_frames(VALUE thread, int start, int limit, VALUE *buff, i
|
|
|
507
537
|
buff[i] = (VALUE)cfp->iseq;
|
|
508
538
|
}
|
|
509
539
|
|
|
510
|
-
|
|
540
|
+
// The topmost frame may not have an updated PC because the JIT
|
|
541
|
+
// may not have set one. The JIT compiler will update the PC
|
|
542
|
+
// before entering a new function (so that `caller` will work),
|
|
543
|
+
// so only the topmost frame could possibly have an out of date PC
|
|
544
|
+
#ifndef NO_JIT_RETURN
|
|
545
|
+
if (cfp == top && cfp->jit_return) {
|
|
546
|
+
lines[i] = 0;
|
|
547
|
+
} else {
|
|
548
|
+
lines[i] = calc_lineno(cfp->iseq, cfp->pc);
|
|
549
|
+
}
|
|
550
|
+
#else // Ruby < 3.1
|
|
551
|
+
lines[i] = calc_lineno(cfp->iseq, cfp->pc);
|
|
552
|
+
#endif
|
|
553
|
+
|
|
511
554
|
is_ruby_frame[i] = true;
|
|
512
555
|
i++;
|
|
513
556
|
}
|
|
@@ -731,15 +774,10 @@ check_method_entry(VALUE obj, int can_be_svar)
|
|
|
731
774
|
// versions, so we need to do a bit more work.
|
|
732
775
|
struct rb_ractor_struct *ruby_single_main_ractor = NULL;
|
|
733
776
|
|
|
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;
|
|
777
|
+
// Alternative implementation of rb_ractor_main_p_ that avoids relying on non-public symbols
|
|
778
|
+
bool rb_ractor_main_p_(void) {
|
|
779
|
+
// We need to get the main ractor in a bit of a roundabout way, since Ruby >= 3.3 hid `GET_VM()`
|
|
780
|
+
return ddtrace_get_ractor() == thread_struct_from_object(rb_thread_current())->vm->ractor.main_ractor;
|
|
743
781
|
}
|
|
744
782
|
#else
|
|
745
783
|
// Directly access Ruby internal fast path for detecting multiple Ractors.
|
|
@@ -767,3 +805,88 @@ check_method_entry(VALUE obj, int can_be_svar)
|
|
|
767
805
|
// they're always on the main Ractor
|
|
768
806
|
bool ddtrace_rb_ractor_main_p(void) { return true; }
|
|
769
807
|
#endif // NO_RACTORS
|
|
808
|
+
|
|
809
|
+
// This is a tweaked and inlined version of
|
|
810
|
+
// threadptr_invoke_proc_location + rb_proc_location + iseq_location .
|
|
811
|
+
//
|
|
812
|
+
// It's useful to have here because not all of the methods above are accessible to extensions + to avoid the
|
|
813
|
+
// array allocation that iseq_location did to contain its return value.
|
|
814
|
+
static const rb_iseq_t *maybe_thread_invoke_proc_iseq(VALUE thread_value) {
|
|
815
|
+
rb_thread_t *thread = thread_struct_from_object(thread_value);
|
|
816
|
+
|
|
817
|
+
#ifndef NO_THREAD_INVOKE_ARG // Ruby 2.6+
|
|
818
|
+
if (thread->invoke_type != thread_invoke_type_proc) return NULL;
|
|
819
|
+
|
|
820
|
+
VALUE proc = thread->invoke_arg.proc.proc;
|
|
821
|
+
#else
|
|
822
|
+
if (thread->first_func || !thread->first_proc) return NULL;
|
|
823
|
+
|
|
824
|
+
VALUE proc = thread->first_proc;
|
|
825
|
+
#endif
|
|
826
|
+
|
|
827
|
+
const rb_iseq_t *iseq = rb_proc_get_iseq(proc, 0);
|
|
828
|
+
if (iseq == NULL) return NULL;
|
|
829
|
+
|
|
830
|
+
rb_iseq_check(iseq);
|
|
831
|
+
return iseq;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
VALUE invoke_location_for(VALUE thread, int *line_location) {
|
|
835
|
+
const rb_iseq_t *iseq = maybe_thread_invoke_proc_iseq(thread);
|
|
836
|
+
|
|
837
|
+
if (iseq == NULL) return Qnil;
|
|
838
|
+
|
|
839
|
+
*line_location = NUM2INT(rb_iseq_first_lineno(iseq));
|
|
840
|
+
return rb_iseq_path(iseq);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
void self_test_mn_enabled(void) {
|
|
844
|
+
#ifdef NO_MN_THREADS_AVAILABLE
|
|
845
|
+
return;
|
|
846
|
+
#else
|
|
847
|
+
if (ddtrace_get_ractor()->threads.sched.enable_mn_threads == true) {
|
|
848
|
+
rb_raise(rb_eRuntimeError, "Ruby VM is running with RUBY_MN_THREADS=1. This is not yet supported");
|
|
849
|
+
}
|
|
850
|
+
#endif
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// Taken from upstream imemo.h at commit 6ebcf25de2859b5b6402b7e8b181066c32d0e0bf (November 2023, master branch)
|
|
854
|
+
// (See the Ruby project copyright and license above)
|
|
855
|
+
// to enable calling rb_imemo_name
|
|
856
|
+
//
|
|
857
|
+
// Modifications:
|
|
858
|
+
// * Added IMEMO_MASK define
|
|
859
|
+
// * Changed return type to int to avoid having to define `enum imemo_type`
|
|
860
|
+
static inline int ddtrace_imemo_type(VALUE imemo) {
|
|
861
|
+
// This mask is the same between Ruby 2.5 and 3.3-preview3. Furthermore, the intention of this method is to be used
|
|
862
|
+
// to call `rb_imemo_name` which correctly handles invalid numbers so even if the mask changes in the future, at most
|
|
863
|
+
// we'll get incorrect results (and never a VM crash)
|
|
864
|
+
#define IMEMO_MASK 0x0f
|
|
865
|
+
return (RBASIC(imemo)->flags >> FL_USHIFT) & IMEMO_MASK;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// Safety: This function assumes the object passed in is of the imemo type. But in the worst case, you'll just get
|
|
869
|
+
// a string that doesn't make any sense.
|
|
870
|
+
#ifndef NO_IMEMO_NAME
|
|
871
|
+
const char *imemo_kind(VALUE imemo) {
|
|
872
|
+
return rb_imemo_name(ddtrace_imemo_type(imemo));
|
|
873
|
+
}
|
|
874
|
+
#else
|
|
875
|
+
const char *imemo_kind(__attribute__((unused)) VALUE imemo) {
|
|
876
|
+
return NULL;
|
|
877
|
+
}
|
|
878
|
+
#endif
|
|
879
|
+
|
|
880
|
+
// This is used to workaround a VM bug. See "handle_sampling_signal" in "collectors_cpu_and_wall_time_worker" for details.
|
|
881
|
+
#ifdef NO_POSTPONED_TRIGGER
|
|
882
|
+
void *objspace_ptr_for_gc_finalize_deferred_workaround(void) {
|
|
883
|
+
rb_vm_t *vm =
|
|
884
|
+
#ifndef NO_GET_VM // TODO: Inline GET_VM below once we drop support in dd-trace-rb 2.x for < Ruby 2.5
|
|
885
|
+
GET_VM();
|
|
886
|
+
#else
|
|
887
|
+
thread_struct_from_object(rb_thread_current())->vm;
|
|
888
|
+
#endif
|
|
889
|
+
|
|
890
|
+
return vm->objspace;
|
|
891
|
+
}
|
|
892
|
+
#endif
|
|
@@ -43,3 +43,19 @@ 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);
|
|
58
|
+
|
|
59
|
+
#ifdef NO_POSTPONED_TRIGGER
|
|
60
|
+
void *objspace_ptr_for_gc_finalize_deferred_workaround(void);
|
|
61
|
+
#endif
|
data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/profiling.c
RENAMED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
2
|
#include <ruby/thread.h>
|
|
3
3
|
#include <errno.h>
|
|
4
|
+
#ifdef HAVE_MALLOC_STATS
|
|
5
|
+
#include <malloc.h>
|
|
6
|
+
#endif
|
|
4
7
|
|
|
5
8
|
#include "clock_id.h"
|
|
6
9
|
#include "helpers.h"
|
|
@@ -11,6 +14,7 @@
|
|
|
11
14
|
|
|
12
15
|
// Each class/module here is implemented in their separate file
|
|
13
16
|
void collectors_cpu_and_wall_time_worker_init(VALUE profiling_module);
|
|
17
|
+
void collectors_discrete_dynamic_sampler_init(VALUE profiling_module);
|
|
14
18
|
void collectors_dynamic_sampling_rate_init(VALUE profiling_module);
|
|
15
19
|
void collectors_idle_sampling_helper_init(VALUE profiling_module);
|
|
16
20
|
void collectors_stack_init(VALUE profiling_module);
|
|
@@ -32,8 +36,9 @@ static void holding_the_gvl_signal_handler(DDTRACE_UNUSED int _signal, DDTRACE_U
|
|
|
32
36
|
static VALUE _native_trigger_holding_the_gvl_signal_handler_on(DDTRACE_UNUSED VALUE _self, VALUE background_thread);
|
|
33
37
|
static VALUE _native_enforce_success(DDTRACE_UNUSED VALUE _self, VALUE syserr_errno, VALUE with_gvl);
|
|
34
38
|
static void *trigger_enforce_success(void *trigger_args);
|
|
39
|
+
static VALUE _native_malloc_stats(DDTRACE_UNUSED VALUE _self);
|
|
35
40
|
|
|
36
|
-
void DDTRACE_EXPORT
|
|
41
|
+
void DDTRACE_EXPORT Init_datadog_profiling_native_extension(void) {
|
|
37
42
|
VALUE datadog_module = rb_define_module("Datadog");
|
|
38
43
|
VALUE profiling_module = rb_define_module_under(datadog_module, "Profiling");
|
|
39
44
|
VALUE native_extension_module = rb_define_module_under(profiling_module, "NativeExtension");
|
|
@@ -41,9 +46,9 @@ void DDTRACE_EXPORT Init_ddtrace_profiling_native_extension(void) {
|
|
|
41
46
|
rb_define_singleton_method(native_extension_module, "native_working?", native_working_p, 0);
|
|
42
47
|
rb_funcall(native_extension_module, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("native_working?")));
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
ruby_helpers_init();
|
|
46
50
|
collectors_cpu_and_wall_time_worker_init(profiling_module);
|
|
51
|
+
collectors_discrete_dynamic_sampler_init(profiling_module);
|
|
47
52
|
collectors_dynamic_sampling_rate_init(profiling_module);
|
|
48
53
|
collectors_idle_sampling_helper_init(profiling_module);
|
|
49
54
|
collectors_stack_init(profiling_module);
|
|
@@ -66,10 +71,12 @@ void DDTRACE_EXPORT Init_ddtrace_profiling_native_extension(void) {
|
|
|
66
71
|
rb_define_singleton_method(testing_module, "_native_install_holding_the_gvl_signal_handler", _native_install_holding_the_gvl_signal_handler, 0);
|
|
67
72
|
rb_define_singleton_method(testing_module, "_native_trigger_holding_the_gvl_signal_handler_on", _native_trigger_holding_the_gvl_signal_handler_on, 1);
|
|
68
73
|
rb_define_singleton_method(testing_module, "_native_enforce_success", _native_enforce_success, 2);
|
|
74
|
+
rb_define_singleton_method(testing_module, "_native_malloc_stats", _native_malloc_stats, 0);
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
static VALUE native_working_p(DDTRACE_UNUSED VALUE _self) {
|
|
72
78
|
self_test_clock_id();
|
|
79
|
+
self_test_mn_enabled();
|
|
73
80
|
|
|
74
81
|
return Qtrue;
|
|
75
82
|
}
|
|
@@ -249,3 +256,12 @@ static void *trigger_enforce_success(void *trigger_args) {
|
|
|
249
256
|
ENFORCE_SUCCESS_NO_GVL(syserr_errno);
|
|
250
257
|
return NULL;
|
|
251
258
|
}
|
|
259
|
+
|
|
260
|
+
static VALUE _native_malloc_stats(DDTRACE_UNUSED VALUE _self) {
|
|
261
|
+
#ifdef HAVE_MALLOC_STATS
|
|
262
|
+
malloc_stats();
|
|
263
|
+
return Qtrue;
|
|
264
|
+
#else
|
|
265
|
+
return Qfalse;
|
|
266
|
+
#endif
|
|
267
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#include <ruby.h>
|
|
2
|
+
#include <ruby/thread.h>
|
|
3
|
+
|
|
4
|
+
#include "ruby_helpers.h"
|
|
5
|
+
#include "private_vm_api_access.h"
|
|
6
|
+
|
|
7
|
+
// The following global variables are initialized at startup to save expensive lookups later.
|
|
8
|
+
// They are not expected to be mutated outside of init.
|
|
9
|
+
static VALUE module_object_space = Qnil;
|
|
10
|
+
static ID _id2ref_id = Qnil;
|
|
11
|
+
static ID inspect_id = Qnil;
|
|
12
|
+
static ID to_s_id = Qnil;
|
|
13
|
+
|
|
14
|
+
void ruby_helpers_init(void) {
|
|
15
|
+
rb_global_variable(&module_object_space);
|
|
16
|
+
|
|
17
|
+
module_object_space = rb_const_get(rb_cObject, rb_intern("ObjectSpace"));
|
|
18
|
+
_id2ref_id = rb_intern("_id2ref");
|
|
19
|
+
inspect_id = rb_intern("inspect");
|
|
20
|
+
to_s_id = rb_intern("to_s");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void raise_unexpected_type(
|
|
24
|
+
VALUE value,
|
|
25
|
+
const char *value_name,
|
|
26
|
+
const char *type_name,
|
|
27
|
+
const char *file,
|
|
28
|
+
int line,
|
|
29
|
+
const char* function_name
|
|
30
|
+
) {
|
|
31
|
+
rb_exc_raise(
|
|
32
|
+
rb_exc_new_str(
|
|
33
|
+
rb_eTypeError,
|
|
34
|
+
rb_sprintf("wrong argument %"PRIsVALUE" for '%s' (expected a %s) at %s:%d:in `%s'",
|
|
35
|
+
rb_inspect(value),
|
|
36
|
+
value_name,
|
|
37
|
+
type_name,
|
|
38
|
+
file,
|
|
39
|
+
line,
|
|
40
|
+
function_name
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#define MAX_RAISE_MESSAGE_SIZE 256
|
|
47
|
+
|
|
48
|
+
struct raise_arguments {
|
|
49
|
+
VALUE exception_class;
|
|
50
|
+
char exception_message[MAX_RAISE_MESSAGE_SIZE];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
static void *trigger_raise(void *raise_arguments) {
|
|
54
|
+
struct raise_arguments *args = (struct raise_arguments *) raise_arguments;
|
|
55
|
+
rb_raise(args->exception_class, "%s", args->exception_message);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void grab_gvl_and_raise(VALUE exception_class, const char *format_string, ...) {
|
|
59
|
+
struct raise_arguments args;
|
|
60
|
+
|
|
61
|
+
args.exception_class = exception_class;
|
|
62
|
+
|
|
63
|
+
va_list format_string_arguments;
|
|
64
|
+
va_start(format_string_arguments, format_string);
|
|
65
|
+
vsnprintf(args.exception_message, MAX_RAISE_MESSAGE_SIZE, format_string, format_string_arguments);
|
|
66
|
+
|
|
67
|
+
if (is_current_thread_holding_the_gvl()) {
|
|
68
|
+
rb_raise(
|
|
69
|
+
rb_eRuntimeError,
|
|
70
|
+
"grab_gvl_and_raise called by thread holding the global VM lock. exception_message: '%s'",
|
|
71
|
+
args.exception_message
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
rb_thread_call_with_gvl(trigger_raise, &args);
|
|
76
|
+
|
|
77
|
+
rb_bug("[ddtrace] Unexpected: Reached the end of grab_gvl_and_raise while raising '%s'\n", args.exception_message);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
struct syserr_raise_arguments {
|
|
81
|
+
int syserr_errno;
|
|
82
|
+
char exception_message[MAX_RAISE_MESSAGE_SIZE];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
static void *trigger_syserr_raise(void *syserr_raise_arguments) {
|
|
86
|
+
struct syserr_raise_arguments *args = (struct syserr_raise_arguments *) syserr_raise_arguments;
|
|
87
|
+
rb_syserr_fail(args->syserr_errno, args->exception_message);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void grab_gvl_and_raise_syserr(int syserr_errno, const char *format_string, ...) {
|
|
91
|
+
struct syserr_raise_arguments args;
|
|
92
|
+
|
|
93
|
+
args.syserr_errno = syserr_errno;
|
|
94
|
+
|
|
95
|
+
va_list format_string_arguments;
|
|
96
|
+
va_start(format_string_arguments, format_string);
|
|
97
|
+
vsnprintf(args.exception_message, MAX_RAISE_MESSAGE_SIZE, format_string, format_string_arguments);
|
|
98
|
+
|
|
99
|
+
if (is_current_thread_holding_the_gvl()) {
|
|
100
|
+
rb_raise(
|
|
101
|
+
rb_eRuntimeError,
|
|
102
|
+
"grab_gvl_and_raise_syserr called by thread holding the global VM lock. syserr_errno: %d, exception_message: '%s'",
|
|
103
|
+
syserr_errno,
|
|
104
|
+
args.exception_message
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
rb_thread_call_with_gvl(trigger_syserr_raise, &args);
|
|
109
|
+
|
|
110
|
+
rb_bug("[ddtrace] Unexpected: Reached the end of grab_gvl_and_raise_syserr while raising '%s'\n", args.exception_message);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void raise_syserr(
|
|
114
|
+
int syserr_errno,
|
|
115
|
+
bool have_gvl,
|
|
116
|
+
const char *expression,
|
|
117
|
+
const char *file,
|
|
118
|
+
int line,
|
|
119
|
+
const char *function_name
|
|
120
|
+
) {
|
|
121
|
+
if (have_gvl) {
|
|
122
|
+
rb_exc_raise(rb_syserr_new_str(syserr_errno, rb_sprintf("Failure returned by '%s' at %s:%d:in `%s'", expression, file, line, function_name)));
|
|
123
|
+
} else {
|
|
124
|
+
grab_gvl_and_raise_syserr(syserr_errno, "Failure returned by '%s' at %s:%d:in `%s'", expression, file, line, function_name);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
char* ruby_strndup(const char *str, size_t size) {
|
|
129
|
+
char *dup;
|
|
130
|
+
|
|
131
|
+
dup = xmalloc(size + 1);
|
|
132
|
+
memcpy(dup, str, size);
|
|
133
|
+
dup[size] = '\0';
|
|
134
|
+
|
|
135
|
+
return dup;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static VALUE _id2ref(VALUE obj_id) {
|
|
139
|
+
// Call ::ObjectSpace._id2ref natively. It will raise if the id is no longer valid
|
|
140
|
+
return rb_funcall(module_object_space, _id2ref_id, 1, obj_id);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static VALUE _id2ref_failure(DDTRACE_UNUSED VALUE _unused1, DDTRACE_UNUSED VALUE _unused2) {
|
|
144
|
+
return Qfalse;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Native wrapper to get an object ref from an id. Returns true on success and
|
|
148
|
+
// writes the ref to the value pointer parameter if !NULL. False if id doesn't
|
|
149
|
+
// reference a valid object (in which case value is not changed).
|
|
150
|
+
bool ruby_ref_from_id(VALUE obj_id, VALUE *value) {
|
|
151
|
+
// Call ::ObjectSpace._id2ref natively. It will raise if the id is no longer valid
|
|
152
|
+
// so we need to call it via rb_rescue2
|
|
153
|
+
// TODO: Benchmark rb_rescue2 vs rb_protect here
|
|
154
|
+
VALUE result = rb_rescue2(
|
|
155
|
+
_id2ref,
|
|
156
|
+
obj_id,
|
|
157
|
+
_id2ref_failure,
|
|
158
|
+
Qnil,
|
|
159
|
+
rb_eRangeError, // rb_eRangeError is the error used to flag invalid ids
|
|
160
|
+
0 // Required by API to be the last argument
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
if (result == Qfalse) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (value != NULL) {
|
|
168
|
+
(*value) = result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Not part of public headers but is externed from Ruby
|
|
175
|
+
size_t rb_obj_memsize_of(VALUE obj);
|
|
176
|
+
|
|
177
|
+
// Wrapper around rb_obj_memsize_of to avoid hitting crashing paths.
|
|
178
|
+
//
|
|
179
|
+
// The crashing paths are due to calls to rb_bug so should hopefully
|
|
180
|
+
// be situations that can't happen. But given that rb_obj_memsize_of
|
|
181
|
+
// isn't fully public (it's externed but not part of public headers)
|
|
182
|
+
// there is a possibility that it is just assumed that whoever calls
|
|
183
|
+
// it, will do proper checking for those cases. We want to be cautious
|
|
184
|
+
// so we'll assume that's the case and will skip over known crashing
|
|
185
|
+
// paths in this wrapper.
|
|
186
|
+
size_t ruby_obj_memsize_of(VALUE obj) {
|
|
187
|
+
switch (rb_type(obj)) {
|
|
188
|
+
case T_OBJECT:
|
|
189
|
+
case T_MODULE:
|
|
190
|
+
case T_CLASS:
|
|
191
|
+
case T_ICLASS:
|
|
192
|
+
case T_STRING:
|
|
193
|
+
case T_ARRAY:
|
|
194
|
+
case T_HASH:
|
|
195
|
+
case T_REGEXP:
|
|
196
|
+
case T_DATA:
|
|
197
|
+
case T_MATCH:
|
|
198
|
+
case T_FILE:
|
|
199
|
+
case T_RATIONAL:
|
|
200
|
+
case T_COMPLEX:
|
|
201
|
+
case T_IMEMO:
|
|
202
|
+
case T_FLOAT:
|
|
203
|
+
case T_SYMBOL:
|
|
204
|
+
case T_BIGNUM:
|
|
205
|
+
// case T_NODE: -> Crashes the vm in rb_obj_memsize_of
|
|
206
|
+
case T_STRUCT:
|
|
207
|
+
case T_ZOMBIE:
|
|
208
|
+
#ifndef NO_T_MOVED
|
|
209
|
+
case T_MOVED:
|
|
210
|
+
#endif
|
|
211
|
+
return rb_obj_memsize_of(obj);
|
|
212
|
+
default:
|
|
213
|
+
// Unsupported, return 0 instead of erroring like rb_obj_memsize_of likes doing
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Inspired by rb_class_of but without actually returning classes or potentially doing assertions
|
|
219
|
+
static bool ruby_is_obj_with_class(VALUE obj) {
|
|
220
|
+
if (!RB_SPECIAL_CONST_P(obj)) {
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
if (obj == RUBY_Qfalse) {
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
else if (obj == RUBY_Qnil) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
else if (obj == RUBY_Qtrue) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
else if (RB_FIXNUM_P(obj)) {
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
else if (RB_STATIC_SYM_P(obj)) {
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
else if (RB_FLONUM_P(obj)) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
VALUE ruby_safe_inspect(VALUE obj) {
|
|
246
|
+
if (!ruby_is_obj_with_class(obj)) {
|
|
247
|
+
return rb_str_new_cstr("(Not an object)");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (rb_respond_to(obj, inspect_id)) {
|
|
251
|
+
return rb_sprintf("%+"PRIsVALUE, obj);
|
|
252
|
+
} else if (rb_respond_to(obj, to_s_id)) {
|
|
253
|
+
return rb_sprintf("%"PRIsVALUE, obj);
|
|
254
|
+
} else {
|
|
255
|
+
return rb_str_new_cstr("(Not inspectable)");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
VALUE ddtrace_version(void) {
|
|
260
|
+
VALUE ddtrace_module = rb_const_get(rb_cObject, rb_intern("DDTrace"));
|
|
261
|
+
ENFORCE_TYPE(ddtrace_module, T_MODULE);
|
|
262
|
+
VALUE version_module = rb_const_get(ddtrace_module, rb_intern("VERSION"));
|
|
263
|
+
ENFORCE_TYPE(version_module, T_MODULE);
|
|
264
|
+
VALUE version_string = rb_const_get(version_module, rb_intern("STRING"));
|
|
265
|
+
ENFORCE_TYPE(version_string, T_STRING);
|
|
266
|
+
return version_string;
|
|
267
|
+
}
|
data/ext/{ddtrace_profiling_native_extension → datadog_profiling_native_extension}/ruby_helpers.h
RENAMED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
#include "helpers.h"
|
|
7
7
|
|
|
8
|
+
// Initialize internal data needed by some ruby helpers. Should be called during start, before any actual
|
|
9
|
+
// usage of ruby helpers.
|
|
10
|
+
void ruby_helpers_init(void);
|
|
11
|
+
|
|
8
12
|
// Processes any pending interruptions, including exceptions to be raised.
|
|
9
13
|
// If there's an exception to be raised, it raises it. In that case, this function does not return.
|
|
10
14
|
static inline VALUE process_pending_interruptions(DDTRACE_UNUSED VALUE _) {
|
|
@@ -78,6 +82,9 @@ NORETURN(
|
|
|
78
82
|
#define ENFORCE_SUCCESS_HELPER(expression, have_gvl) \
|
|
79
83
|
{ int result_syserr_errno = expression; if (RB_UNLIKELY(result_syserr_errno)) raise_syserr(result_syserr_errno, have_gvl, ADD_QUOTES(expression), __FILE__, __LINE__, __func__); }
|
|
80
84
|
|
|
85
|
+
#define RUBY_NUM_OR_NIL(val, condition, conv) ((val condition) ? conv(val) : Qnil)
|
|
86
|
+
#define RUBY_AVG_OR_NIL(total, count) ((count == 0) ? Qnil : DBL2NUM(((double) total) / count))
|
|
87
|
+
|
|
81
88
|
// Called by ENFORCE_SUCCESS_HELPER; should not be used directly
|
|
82
89
|
NORETURN(void raise_syserr(
|
|
83
90
|
int syserr_errno,
|
|
@@ -87,3 +94,29 @@ NORETURN(void raise_syserr(
|
|
|
87
94
|
int line,
|
|
88
95
|
const char *function_name
|
|
89
96
|
));
|
|
97
|
+
|
|
98
|
+
// Alternative to ruby_strdup that takes a size argument.
|
|
99
|
+
// Similar to C's strndup but slightly less smart as size is expected to
|
|
100
|
+
// be smaller or equal to the real size of str (minus null termination if it
|
|
101
|
+
// exists).
|
|
102
|
+
// A new string will be returned with size+1 bytes and last byte set to '\0'.
|
|
103
|
+
// The returned string must be freed explicitly.
|
|
104
|
+
//
|
|
105
|
+
// WARN: Cannot be used during GC or outside the GVL.
|
|
106
|
+
char* ruby_strndup(const char *str, size_t size);
|
|
107
|
+
|
|
108
|
+
// Native wrapper to get an object ref from an id. Returns true on success and
|
|
109
|
+
// writes the ref to the value pointer parameter if !NULL. False if id doesn't
|
|
110
|
+
// reference a valid object (in which case value is not changed).
|
|
111
|
+
bool ruby_ref_from_id(size_t id, VALUE *value);
|
|
112
|
+
|
|
113
|
+
// Native wrapper to get the approximate/estimated current size of the passed
|
|
114
|
+
// object.
|
|
115
|
+
size_t ruby_obj_memsize_of(VALUE obj);
|
|
116
|
+
|
|
117
|
+
// Safely inspect any ruby object. If the object responds to 'inspect',
|
|
118
|
+
// return a string with the result of that call. Elsif the object responds to
|
|
119
|
+
// 'to_s', return a string with the result of that call. Otherwise, return Qnil.
|
|
120
|
+
VALUE ruby_safe_inspect(VALUE obj);
|
|
121
|
+
|
|
122
|
+
VALUE ddtrace_version(void);
|