cw-datadog 2.23.0.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 +7 -0
- data/CHANGELOG.md +5142 -0
- data/LICENSE +6 -0
- data/LICENSE-3rdparty.csv +7 -0
- data/LICENSE.Apache +200 -0
- data/LICENSE.BSD3 +24 -0
- data/NOTICE +4 -0
- data/README.md +24 -0
- data/bin/ddprofrb +15 -0
- data/ext/LIBDATADOG_DEVELOPMENT.md +3 -0
- data/ext/datadog_profiling_native_extension/NativeExtensionDesign.md +156 -0
- data/ext/datadog_profiling_native_extension/clock_id.h +23 -0
- data/ext/datadog_profiling_native_extension/clock_id_from_pthread.c +55 -0
- data/ext/datadog_profiling_native_extension/clock_id_noop.c +21 -0
- data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +1423 -0
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c +447 -0
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.h +131 -0
- data/ext/datadog_profiling_native_extension/collectors_dynamic_sampling_rate.c +150 -0
- data/ext/datadog_profiling_native_extension/collectors_dynamic_sampling_rate.h +18 -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/datadog_profiling_native_extension/collectors_idle_sampling_helper.c +248 -0
- data/ext/datadog_profiling_native_extension/collectors_idle_sampling_helper.h +3 -0
- data/ext/datadog_profiling_native_extension/collectors_stack.c +659 -0
- data/ext/datadog_profiling_native_extension/collectors_stack.h +44 -0
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +2221 -0
- data/ext/datadog_profiling_native_extension/collectors_thread_context.h +31 -0
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.c +80 -0
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +63 -0
- data/ext/datadog_profiling_native_extension/encoded_profile.c +79 -0
- data/ext/datadog_profiling_native_extension/encoded_profile.h +8 -0
- data/ext/datadog_profiling_native_extension/extconf.rb +321 -0
- data/ext/datadog_profiling_native_extension/gvl_profiling_helper.c +52 -0
- data/ext/datadog_profiling_native_extension/gvl_profiling_helper.h +67 -0
- data/ext/datadog_profiling_native_extension/heap_recorder.c +998 -0
- data/ext/datadog_profiling_native_extension/heap_recorder.h +177 -0
- data/ext/datadog_profiling_native_extension/helpers.h +12 -0
- data/ext/datadog_profiling_native_extension/http_transport.c +280 -0
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.c +84 -0
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.h +28 -0
- data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +244 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +881 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +81 -0
- data/ext/datadog_profiling_native_extension/profiling.c +284 -0
- data/ext/datadog_profiling_native_extension/ruby_helpers.c +235 -0
- data/ext/datadog_profiling_native_extension/ruby_helpers.h +88 -0
- data/ext/datadog_profiling_native_extension/setup_signal_handler.c +115 -0
- data/ext/datadog_profiling_native_extension/setup_signal_handler.h +12 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +1145 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.h +31 -0
- data/ext/datadog_profiling_native_extension/time_helpers.c +38 -0
- data/ext/datadog_profiling_native_extension/time_helpers.h +56 -0
- data/ext/datadog_profiling_native_extension/unsafe_api_calls_check.c +47 -0
- data/ext/datadog_profiling_native_extension/unsafe_api_calls_check.h +31 -0
- data/ext/libdatadog_api/crashtracker.c +125 -0
- data/ext/libdatadog_api/crashtracker.h +5 -0
- data/ext/libdatadog_api/datadog_ruby_common.c +80 -0
- data/ext/libdatadog_api/datadog_ruby_common.h +63 -0
- data/ext/libdatadog_api/ddsketch.c +106 -0
- data/ext/libdatadog_api/extconf.rb +110 -0
- data/ext/libdatadog_api/init.c +18 -0
- data/ext/libdatadog_api/library_config.c +172 -0
- data/ext/libdatadog_api/library_config.h +25 -0
- data/ext/libdatadog_api/process_discovery.c +118 -0
- data/ext/libdatadog_api/process_discovery.h +5 -0
- data/ext/libdatadog_extconf_helpers.rb +140 -0
- data/lib/datadog/appsec/actions_handler/serializable_backtrace.rb +89 -0
- data/lib/datadog/appsec/actions_handler.rb +49 -0
- data/lib/datadog/appsec/anonymizer.rb +16 -0
- data/lib/datadog/appsec/api_security/endpoint_collection/grape_route_serializer.rb +26 -0
- data/lib/datadog/appsec/api_security/endpoint_collection/rails_collector.rb +59 -0
- data/lib/datadog/appsec/api_security/endpoint_collection/rails_route_serializer.rb +29 -0
- data/lib/datadog/appsec/api_security/endpoint_collection/sinatra_route_serializer.rb +26 -0
- data/lib/datadog/appsec/api_security/endpoint_collection.rb +10 -0
- data/lib/datadog/appsec/api_security/route_extractor.rb +77 -0
- data/lib/datadog/appsec/api_security/sampler.rb +60 -0
- data/lib/datadog/appsec/api_security.rb +23 -0
- data/lib/datadog/appsec/assets/blocked.html +99 -0
- data/lib/datadog/appsec/assets/blocked.json +1 -0
- data/lib/datadog/appsec/assets/blocked.text +5 -0
- data/lib/datadog/appsec/assets/waf_rules/README.md +46 -0
- data/lib/datadog/appsec/assets/waf_rules/recommended.json +10504 -0
- data/lib/datadog/appsec/assets/waf_rules/strict.json +3066 -0
- data/lib/datadog/appsec/assets.rb +46 -0
- data/lib/datadog/appsec/autoload.rb +13 -0
- data/lib/datadog/appsec/component.rb +89 -0
- data/lib/datadog/appsec/compressed_json.rb +40 -0
- data/lib/datadog/appsec/configuration/settings.rb +409 -0
- data/lib/datadog/appsec/configuration.rb +11 -0
- data/lib/datadog/appsec/context.rb +97 -0
- data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +94 -0
- data/lib/datadog/appsec/contrib/active_record/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/active_record/patcher.rb +101 -0
- data/lib/datadog/appsec/contrib/auto_instrument.rb +25 -0
- data/lib/datadog/appsec/contrib/devise/configuration.rb +52 -0
- data/lib/datadog/appsec/contrib/devise/data_extractor.rb +78 -0
- data/lib/datadog/appsec/contrib/devise/ext.rb +35 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/devise/patcher.rb +63 -0
- data/lib/datadog/appsec/contrib/devise/patches/signin_tracking_patch.rb +103 -0
- data/lib/datadog/appsec/contrib/devise/patches/signup_tracking_patch.rb +70 -0
- data/lib/datadog/appsec/contrib/devise/patches/skip_signin_tracking_patch.rb +21 -0
- data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +106 -0
- data/lib/datadog/appsec/contrib/excon/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/excon/patcher.rb +28 -0
- data/lib/datadog/appsec/contrib/excon/ssrf_detection_middleware.rb +42 -0
- data/lib/datadog/appsec/contrib/faraday/connection_patch.rb +22 -0
- data/lib/datadog/appsec/contrib/faraday/integration.rb +42 -0
- data/lib/datadog/appsec/contrib/faraday/patcher.rb +53 -0
- data/lib/datadog/appsec/contrib/faraday/rack_builder_patch.rb +22 -0
- data/lib/datadog/appsec/contrib/faraday/ssrf_detection_middleware.rb +42 -0
- data/lib/datadog/appsec/contrib/graphql/appsec_trace.rb +29 -0
- data/lib/datadog/appsec/contrib/graphql/gateway/multiplex.rb +109 -0
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +56 -0
- data/lib/datadog/appsec/contrib/graphql/integration.rb +54 -0
- data/lib/datadog/appsec/contrib/graphql/patcher.rb +34 -0
- data/lib/datadog/appsec/contrib/integration.rb +37 -0
- data/lib/datadog/appsec/contrib/rack/ext.rb +47 -0
- data/lib/datadog/appsec/contrib/rack/gateway/request.rb +101 -0
- data/lib/datadog/appsec/contrib/rack/gateway/response.rb +30 -0
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +141 -0
- data/lib/datadog/appsec/contrib/rack/integration.rb +44 -0
- data/lib/datadog/appsec/contrib/rack/patcher.rb +31 -0
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +43 -0
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +218 -0
- data/lib/datadog/appsec/contrib/rails/ext.rb +13 -0
- data/lib/datadog/appsec/contrib/rails/framework.rb +16 -0
- data/lib/datadog/appsec/contrib/rails/gateway/request.rb +67 -0
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +78 -0
- data/lib/datadog/appsec/contrib/rails/integration.rb +43 -0
- data/lib/datadog/appsec/contrib/rails/patcher.rb +171 -0
- data/lib/datadog/appsec/contrib/rails/patches/process_action_patch.rb +27 -0
- data/lib/datadog/appsec/contrib/rails/patches/render_to_body_patch.rb +33 -0
- data/lib/datadog/appsec/contrib/rails/request.rb +36 -0
- data/lib/datadog/appsec/contrib/rails/request_middleware.rb +20 -0
- data/lib/datadog/appsec/contrib/rest_client/integration.rb +45 -0
- data/lib/datadog/appsec/contrib/rest_client/patcher.rb +28 -0
- data/lib/datadog/appsec/contrib/rest_client/request_ssrf_detection_patch.rb +39 -0
- data/lib/datadog/appsec/contrib/sinatra/framework.rb +20 -0
- data/lib/datadog/appsec/contrib/sinatra/gateway/request.rb +17 -0
- data/lib/datadog/appsec/contrib/sinatra/gateway/route_params.rb +23 -0
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +105 -0
- data/lib/datadog/appsec/contrib/sinatra/integration.rb +43 -0
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +132 -0
- data/lib/datadog/appsec/contrib/sinatra/patches/json_patch.rb +31 -0
- data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +20 -0
- data/lib/datadog/appsec/event.rb +139 -0
- data/lib/datadog/appsec/ext.rb +23 -0
- data/lib/datadog/appsec/extensions.rb +16 -0
- data/lib/datadog/appsec/instrumentation/gateway/argument.rb +43 -0
- data/lib/datadog/appsec/instrumentation/gateway/middleware.rb +24 -0
- data/lib/datadog/appsec/instrumentation/gateway.rb +59 -0
- data/lib/datadog/appsec/instrumentation.rb +9 -0
- data/lib/datadog/appsec/metrics/collector.rb +58 -0
- data/lib/datadog/appsec/metrics/exporter.rb +35 -0
- data/lib/datadog/appsec/metrics/telemetry.rb +23 -0
- data/lib/datadog/appsec/metrics/telemetry_exporter.rb +29 -0
- data/lib/datadog/appsec/metrics.rb +14 -0
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +85 -0
- data/lib/datadog/appsec/monitor.rb +11 -0
- data/lib/datadog/appsec/processor/rule_loader.rb +119 -0
- data/lib/datadog/appsec/rate_limiter.rb +45 -0
- data/lib/datadog/appsec/remote.rb +119 -0
- data/lib/datadog/appsec/response.rb +99 -0
- data/lib/datadog/appsec/sample_rate.rb +21 -0
- data/lib/datadog/appsec/security_engine/engine.rb +176 -0
- data/lib/datadog/appsec/security_engine/result.rb +102 -0
- data/lib/datadog/appsec/security_engine/runner.rb +111 -0
- data/lib/datadog/appsec/security_engine.rb +9 -0
- data/lib/datadog/appsec/security_event.rb +37 -0
- data/lib/datadog/appsec/thread_safe_ref.rb +61 -0
- data/lib/datadog/appsec/trace_keeper.rb +24 -0
- data/lib/datadog/appsec/utils/hash_coercion.rb +23 -0
- data/lib/datadog/appsec/utils/http/media_range.rb +201 -0
- data/lib/datadog/appsec/utils/http/media_type.rb +87 -0
- data/lib/datadog/appsec/utils/http.rb +11 -0
- data/lib/datadog/appsec/utils.rb +9 -0
- data/lib/datadog/appsec.rb +65 -0
- data/lib/datadog/auto_instrument.rb +19 -0
- data/lib/datadog/auto_instrument_base.rb +9 -0
- data/lib/datadog/core/buffer/cruby.rb +55 -0
- data/lib/datadog/core/buffer/random.rb +150 -0
- data/lib/datadog/core/buffer/thread_safe.rb +58 -0
- data/lib/datadog/core/chunker.rb +35 -0
- data/lib/datadog/core/cloudwise/IMPLEMENTATION_V2.md +517 -0
- data/lib/datadog/core/cloudwise/QUICKSTART.md +398 -0
- data/lib/datadog/core/cloudwise/README.md +722 -0
- data/lib/datadog/core/cloudwise/app_registration_worker.rb +90 -0
- data/lib/datadog/core/cloudwise/client.rb +490 -0
- data/lib/datadog/core/cloudwise/component.rb +351 -0
- data/lib/datadog/core/cloudwise/heartbeat_worker.rb +137 -0
- data/lib/datadog/core/cloudwise/host_id_worker.rb +85 -0
- data/lib/datadog/core/cloudwise/license_worker.rb +108 -0
- data/lib/datadog/core/cloudwise/probe_state.rb +160 -0
- data/lib/datadog/core/configuration/agent_settings.rb +52 -0
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +339 -0
- data/lib/datadog/core/configuration/agentless_settings_resolver.rb +176 -0
- data/lib/datadog/core/configuration/base.rb +91 -0
- data/lib/datadog/core/configuration/components.rb +386 -0
- data/lib/datadog/core/configuration/components_state.rb +23 -0
- data/lib/datadog/core/configuration/config_helper.rb +100 -0
- data/lib/datadog/core/configuration/deprecations.rb +36 -0
- data/lib/datadog/core/configuration/ext.rb +49 -0
- data/lib/datadog/core/configuration/option.rb +368 -0
- data/lib/datadog/core/configuration/option_definition.rb +158 -0
- data/lib/datadog/core/configuration/options.rb +134 -0
- data/lib/datadog/core/configuration/settings.rb +1087 -0
- data/lib/datadog/core/configuration/stable_config.rb +32 -0
- data/lib/datadog/core/configuration/supported_configurations.rb +347 -0
- data/lib/datadog/core/configuration.rb +328 -0
- data/lib/datadog/core/contrib/rails/utils.rb +24 -0
- data/lib/datadog/core/crashtracking/component.rb +105 -0
- data/lib/datadog/core/crashtracking/tag_builder.rb +21 -0
- data/lib/datadog/core/ddsketch.rb +19 -0
- data/lib/datadog/core/deprecations.rb +58 -0
- data/lib/datadog/core/diagnostics/environment_logger.rb +170 -0
- data/lib/datadog/core/diagnostics/health.rb +19 -0
- data/lib/datadog/core/encoding.rb +90 -0
- data/lib/datadog/core/environment/agent_info.rb +78 -0
- data/lib/datadog/core/environment/cgroup.rb +51 -0
- data/lib/datadog/core/environment/class_count.rb +21 -0
- data/lib/datadog/core/environment/container.rb +89 -0
- data/lib/datadog/core/environment/execution.rb +103 -0
- data/lib/datadog/core/environment/ext.rb +45 -0
- data/lib/datadog/core/environment/gc.rb +20 -0
- data/lib/datadog/core/environment/git.rb +26 -0
- data/lib/datadog/core/environment/identity.rb +84 -0
- data/lib/datadog/core/environment/platform.rb +46 -0
- data/lib/datadog/core/environment/socket.rb +24 -0
- data/lib/datadog/core/environment/thread_count.rb +20 -0
- data/lib/datadog/core/environment/variable_helpers.rb +53 -0
- data/lib/datadog/core/environment/vm_cache.rb +64 -0
- data/lib/datadog/core/environment/yjit.rb +69 -0
- data/lib/datadog/core/error.rb +102 -0
- data/lib/datadog/core/extensions.rb +16 -0
- data/lib/datadog/core/git/ext.rb +16 -0
- data/lib/datadog/core/header_collection.rb +43 -0
- data/lib/datadog/core/logger.rb +45 -0
- data/lib/datadog/core/logging/ext.rb +13 -0
- data/lib/datadog/core/metrics/client.rb +206 -0
- data/lib/datadog/core/metrics/ext.rb +18 -0
- data/lib/datadog/core/metrics/helpers.rb +25 -0
- data/lib/datadog/core/metrics/logging.rb +44 -0
- data/lib/datadog/core/metrics/metric.rb +14 -0
- data/lib/datadog/core/metrics/options.rb +52 -0
- data/lib/datadog/core/pin.rb +71 -0
- data/lib/datadog/core/process_discovery/tracer_memfd.rb +13 -0
- data/lib/datadog/core/process_discovery.rb +61 -0
- data/lib/datadog/core/rate_limiter.rb +185 -0
- data/lib/datadog/core/remote/client/capabilities.rb +70 -0
- data/lib/datadog/core/remote/client.rb +245 -0
- data/lib/datadog/core/remote/component.rb +161 -0
- data/lib/datadog/core/remote/configuration/content.rb +111 -0
- data/lib/datadog/core/remote/configuration/digest.rb +62 -0
- data/lib/datadog/core/remote/configuration/path.rb +90 -0
- data/lib/datadog/core/remote/configuration/repository.rb +307 -0
- data/lib/datadog/core/remote/configuration/target.rb +74 -0
- data/lib/datadog/core/remote/configuration.rb +18 -0
- data/lib/datadog/core/remote/dispatcher.rb +59 -0
- data/lib/datadog/core/remote/ext.rb +13 -0
- data/lib/datadog/core/remote/negotiation.rb +70 -0
- data/lib/datadog/core/remote/tie/tracing.rb +39 -0
- data/lib/datadog/core/remote/tie.rb +29 -0
- data/lib/datadog/core/remote/transport/config.rb +61 -0
- data/lib/datadog/core/remote/transport/http/api.rb +53 -0
- data/lib/datadog/core/remote/transport/http/client.rb +49 -0
- data/lib/datadog/core/remote/transport/http/config.rb +252 -0
- data/lib/datadog/core/remote/transport/http/negotiation.rb +103 -0
- data/lib/datadog/core/remote/transport/http.rb +83 -0
- data/lib/datadog/core/remote/transport/negotiation.rb +75 -0
- data/lib/datadog/core/remote/worker.rb +105 -0
- data/lib/datadog/core/remote.rb +24 -0
- data/lib/datadog/core/runtime/ext.rb +40 -0
- data/lib/datadog/core/runtime/metrics.rb +202 -0
- data/lib/datadog/core/semaphore.rb +35 -0
- data/lib/datadog/core/tag_builder.rb +52 -0
- data/lib/datadog/core/telemetry/component.rb +206 -0
- data/lib/datadog/core/telemetry/emitter.rb +56 -0
- data/lib/datadog/core/telemetry/event/app_client_configuration_change.rb +66 -0
- data/lib/datadog/core/telemetry/event/app_closing.rb +18 -0
- data/lib/datadog/core/telemetry/event/app_dependencies_loaded.rb +33 -0
- data/lib/datadog/core/telemetry/event/app_endpoints_loaded.rb +30 -0
- data/lib/datadog/core/telemetry/event/app_heartbeat.rb +18 -0
- data/lib/datadog/core/telemetry/event/app_integrations_change.rb +58 -0
- data/lib/datadog/core/telemetry/event/app_started.rb +287 -0
- data/lib/datadog/core/telemetry/event/base.rb +40 -0
- data/lib/datadog/core/telemetry/event/distributions.rb +18 -0
- data/lib/datadog/core/telemetry/event/generate_metrics.rb +43 -0
- data/lib/datadog/core/telemetry/event/log.rb +76 -0
- data/lib/datadog/core/telemetry/event/message_batch.rb +42 -0
- data/lib/datadog/core/telemetry/event/synth_app_client_configuration_change.rb +43 -0
- data/lib/datadog/core/telemetry/event.rb +37 -0
- data/lib/datadog/core/telemetry/ext.rb +20 -0
- data/lib/datadog/core/telemetry/http/adapters/net.rb +26 -0
- data/lib/datadog/core/telemetry/logger.rb +52 -0
- data/lib/datadog/core/telemetry/logging.rb +71 -0
- data/lib/datadog/core/telemetry/metric.rb +189 -0
- data/lib/datadog/core/telemetry/metrics_collection.rb +81 -0
- data/lib/datadog/core/telemetry/metrics_manager.rb +81 -0
- data/lib/datadog/core/telemetry/request.rb +71 -0
- data/lib/datadog/core/telemetry/transport/http/api.rb +43 -0
- data/lib/datadog/core/telemetry/transport/http/client.rb +49 -0
- data/lib/datadog/core/telemetry/transport/http/telemetry.rb +92 -0
- data/lib/datadog/core/telemetry/transport/http.rb +63 -0
- data/lib/datadog/core/telemetry/transport/telemetry.rb +51 -0
- data/lib/datadog/core/telemetry/worker.rb +276 -0
- data/lib/datadog/core/transport/ext.rb +44 -0
- data/lib/datadog/core/transport/http/adapters/net.rb +175 -0
- data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
- data/lib/datadog/core/transport/http/adapters/test.rb +90 -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/instance.rb +54 -0
- data/lib/datadog/core/transport/http/api/map.rb +18 -0
- data/lib/datadog/core/transport/http/api/spec.rb +36 -0
- data/lib/datadog/core/transport/http/builder.rb +184 -0
- data/lib/datadog/core/transport/http/env.rb +70 -0
- data/lib/datadog/core/transport/http/response.rb +60 -0
- data/lib/datadog/core/transport/http.rb +75 -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 +71 -0
- data/lib/datadog/core/utils/at_fork_monkey_patch.rb +102 -0
- data/lib/datadog/core/utils/base64.rb +22 -0
- data/lib/datadog/core/utils/duration.rb +52 -0
- data/lib/datadog/core/utils/forking.rb +63 -0
- data/lib/datadog/core/utils/hash.rb +79 -0
- data/lib/datadog/core/utils/lru_cache.rb +45 -0
- data/lib/datadog/core/utils/network.rb +142 -0
- data/lib/datadog/core/utils/only_once.rb +42 -0
- data/lib/datadog/core/utils/only_once_successful.rb +87 -0
- data/lib/datadog/core/utils/safe_dup.rb +40 -0
- data/lib/datadog/core/utils/sequence.rb +26 -0
- data/lib/datadog/core/utils/time.rb +84 -0
- data/lib/datadog/core/utils/truncation.rb +21 -0
- data/lib/datadog/core/utils/url.rb +25 -0
- data/lib/datadog/core/utils.rb +101 -0
- data/lib/datadog/core/vendor/multipart-post/LICENSE +11 -0
- data/lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb +118 -0
- data/lib/datadog/core/vendor/multipart-post/multipart/post/multipartable.rb +59 -0
- data/lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb +137 -0
- data/lib/datadog/core/vendor/multipart-post/multipart/post/version.rb +11 -0
- data/lib/datadog/core/vendor/multipart-post/multipart/post.rb +10 -0
- data/lib/datadog/core/vendor/multipart-post/multipart.rb +14 -0
- data/lib/datadog/core/vendor/multipart-post/net/http/post/multipart.rb +34 -0
- data/lib/datadog/core/worker.rb +24 -0
- data/lib/datadog/core/workers/async.rb +202 -0
- data/lib/datadog/core/workers/interval_loop.rb +134 -0
- data/lib/datadog/core/workers/polling.rb +59 -0
- data/lib/datadog/core/workers/queue.rb +44 -0
- data/lib/datadog/core/workers/runtime_metrics.rb +62 -0
- data/lib/datadog/core.rb +38 -0
- data/lib/datadog/data_streams/configuration/settings.rb +49 -0
- data/lib/datadog/data_streams/configuration.rb +11 -0
- data/lib/datadog/data_streams/ext.rb +11 -0
- data/lib/datadog/data_streams/extensions.rb +16 -0
- data/lib/datadog/data_streams/pathway_context.rb +169 -0
- data/lib/datadog/data_streams/processor.rb +509 -0
- data/lib/datadog/data_streams/transport/http/api.rb +33 -0
- data/lib/datadog/data_streams/transport/http/client.rb +49 -0
- data/lib/datadog/data_streams/transport/http/stats.rb +87 -0
- data/lib/datadog/data_streams/transport/http.rb +41 -0
- data/lib/datadog/data_streams/transport/stats.rb +60 -0
- data/lib/datadog/data_streams.rb +100 -0
- data/lib/datadog/di/base.rb +115 -0
- data/lib/datadog/di/boot.rb +43 -0
- data/lib/datadog/di/code_tracker.rb +204 -0
- data/lib/datadog/di/component.rb +122 -0
- data/lib/datadog/di/configuration/settings.rb +212 -0
- data/lib/datadog/di/configuration.rb +11 -0
- data/lib/datadog/di/context.rb +70 -0
- data/lib/datadog/di/contrib/active_record.rb +12 -0
- data/lib/datadog/di/contrib/railtie.rb +15 -0
- data/lib/datadog/di/contrib.rb +28 -0
- data/lib/datadog/di/el/compiler.rb +164 -0
- data/lib/datadog/di/el/evaluator.rb +159 -0
- data/lib/datadog/di/el/expression.rb +42 -0
- data/lib/datadog/di/el.rb +5 -0
- data/lib/datadog/di/error.rb +82 -0
- data/lib/datadog/di/extensions.rb +16 -0
- data/lib/datadog/di/instrumenter.rb +566 -0
- data/lib/datadog/di/logger.rb +30 -0
- data/lib/datadog/di/preload.rb +18 -0
- data/lib/datadog/di/probe.rb +231 -0
- data/lib/datadog/di/probe_builder.rb +86 -0
- data/lib/datadog/di/probe_file_loader/railtie.rb +15 -0
- data/lib/datadog/di/probe_file_loader.rb +82 -0
- data/lib/datadog/di/probe_manager.rb +261 -0
- data/lib/datadog/di/probe_notification_builder.rb +236 -0
- data/lib/datadog/di/probe_notifier_worker.rb +305 -0
- data/lib/datadog/di/proc_responder.rb +32 -0
- data/lib/datadog/di/redactor.rb +187 -0
- data/lib/datadog/di/remote.rb +145 -0
- data/lib/datadog/di/serializer.rb +422 -0
- data/lib/datadog/di/transport/diagnostics.rb +62 -0
- data/lib/datadog/di/transport/http/api.rb +42 -0
- data/lib/datadog/di/transport/http/client.rb +47 -0
- data/lib/datadog/di/transport/http/diagnostics.rb +65 -0
- data/lib/datadog/di/transport/http/input.rb +77 -0
- data/lib/datadog/di/transport/http.rb +57 -0
- data/lib/datadog/di/transport/input.rb +70 -0
- data/lib/datadog/di/utils.rb +142 -0
- data/lib/datadog/di.rb +36 -0
- data/lib/datadog/error_tracking/collector.rb +87 -0
- data/lib/datadog/error_tracking/component.rb +167 -0
- data/lib/datadog/error_tracking/configuration/settings.rb +63 -0
- data/lib/datadog/error_tracking/configuration.rb +11 -0
- data/lib/datadog/error_tracking/ext.rb +18 -0
- data/lib/datadog/error_tracking/extensions.rb +16 -0
- data/lib/datadog/error_tracking/filters.rb +77 -0
- data/lib/datadog/error_tracking.rb +18 -0
- data/lib/datadog/kit/appsec/events/v2.rb +196 -0
- data/lib/datadog/kit/appsec/events.rb +180 -0
- data/lib/datadog/kit/enable_core_dumps.rb +49 -0
- data/lib/datadog/kit/identity.rb +114 -0
- data/lib/datadog/kit.rb +11 -0
- data/lib/datadog/opentelemetry/api/baggage.rb +90 -0
- data/lib/datadog/opentelemetry/api/baggage.rbs +26 -0
- data/lib/datadog/opentelemetry/api/context.rb +208 -0
- data/lib/datadog/opentelemetry/api/trace/span.rb +14 -0
- data/lib/datadog/opentelemetry/sdk/configurator.rb +37 -0
- data/lib/datadog/opentelemetry/sdk/id_generator.rb +26 -0
- data/lib/datadog/opentelemetry/sdk/propagator.rb +89 -0
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +169 -0
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +182 -0
- data/lib/datadog/opentelemetry/trace.rb +59 -0
- data/lib/datadog/opentelemetry.rb +52 -0
- data/lib/datadog/profiling/collectors/code_provenance.rb +150 -0
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +147 -0
- data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +69 -0
- data/lib/datadog/profiling/collectors/info.rb +156 -0
- data/lib/datadog/profiling/collectors/stack.rb +13 -0
- data/lib/datadog/profiling/collectors/thread_context.rb +102 -0
- data/lib/datadog/profiling/component.rb +445 -0
- data/lib/datadog/profiling/encoded_profile.rb +11 -0
- data/lib/datadog/profiling/exporter.rb +111 -0
- data/lib/datadog/profiling/ext/dir_monkey_patches.rb +410 -0
- data/lib/datadog/profiling/ext.rb +22 -0
- data/lib/datadog/profiling/flush.rb +40 -0
- data/lib/datadog/profiling/http_transport.rb +67 -0
- data/lib/datadog/profiling/load_native_extension.rb +9 -0
- data/lib/datadog/profiling/native_extension.rb +20 -0
- data/lib/datadog/profiling/preload.rb +5 -0
- data/lib/datadog/profiling/profiler.rb +70 -0
- data/lib/datadog/profiling/scheduler.rb +153 -0
- data/lib/datadog/profiling/sequence_tracker.rb +44 -0
- data/lib/datadog/profiling/stack_recorder.rb +104 -0
- data/lib/datadog/profiling/tag_builder.rb +59 -0
- data/lib/datadog/profiling/tasks/exec.rb +50 -0
- data/lib/datadog/profiling/tasks/help.rb +18 -0
- data/lib/datadog/profiling/tasks/setup.rb +43 -0
- data/lib/datadog/profiling.rb +167 -0
- data/lib/datadog/single_step_instrument.rb +21 -0
- data/lib/datadog/tracing/analytics.rb +25 -0
- data/lib/datadog/tracing/buffer.rb +129 -0
- data/lib/datadog/tracing/client_ip.rb +61 -0
- data/lib/datadog/tracing/component.rb +216 -0
- data/lib/datadog/tracing/configuration/dynamic/option.rb +71 -0
- data/lib/datadog/tracing/configuration/dynamic.rb +100 -0
- data/lib/datadog/tracing/configuration/ext.rb +118 -0
- data/lib/datadog/tracing/configuration/http.rb +74 -0
- data/lib/datadog/tracing/configuration/settings.rb +579 -0
- data/lib/datadog/tracing/context.rb +68 -0
- data/lib/datadog/tracing/context_provider.rb +82 -0
- data/lib/datadog/tracing/contrib/action_cable/configuration/settings.rb +39 -0
- data/lib/datadog/tracing/contrib/action_cable/event.rb +71 -0
- data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +58 -0
- data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +63 -0
- data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +59 -0
- data/lib/datadog/tracing/contrib/action_cable/events.rb +37 -0
- data/lib/datadog/tracing/contrib/action_cable/ext.rb +33 -0
- data/lib/datadog/tracing/contrib/action_cable/instrumentation.rb +86 -0
- data/lib/datadog/tracing/contrib/action_cable/integration.rb +53 -0
- data/lib/datadog/tracing/contrib/action_cable/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +43 -0
- data/lib/datadog/tracing/contrib/action_mailer/event.rb +50 -0
- data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +65 -0
- data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +48 -0
- data/lib/datadog/tracing/contrib/action_mailer/events.rb +34 -0
- data/lib/datadog/tracing/contrib/action_mailer/ext.rb +34 -0
- data/lib/datadog/tracing/contrib/action_mailer/integration.rb +54 -0
- data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +158 -0
- data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb +85 -0
- data/lib/datadog/tracing/contrib/action_pack/action_dispatch/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +40 -0
- data/lib/datadog/tracing/contrib/action_pack/ext.rb +25 -0
- data/lib/datadog/tracing/contrib/action_pack/integration.rb +54 -0
- data/lib/datadog/tracing/contrib/action_pack/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/action_pack/utils.rb +39 -0
- data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +43 -0
- data/lib/datadog/tracing/contrib/action_view/event.rb +35 -0
- data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +50 -0
- data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +57 -0
- data/lib/datadog/tracing/contrib/action_view/events.rb +34 -0
- data/lib/datadog/tracing/contrib/action_view/ext.rb +25 -0
- data/lib/datadog/tracing/contrib/action_view/integration.rb +61 -0
- data/lib/datadog/tracing/contrib/action_view/patcher.rb +34 -0
- data/lib/datadog/tracing/contrib/action_view/utils.rb +36 -0
- data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +39 -0
- data/lib/datadog/tracing/contrib/active_job/event.rb +58 -0
- data/lib/datadog/tracing/contrib/active_job/events/discard.rb +50 -0
- data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +49 -0
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +49 -0
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +51 -0
- data/lib/datadog/tracing/contrib/active_job/events/perform.rb +49 -0
- data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +50 -0
- data/lib/datadog/tracing/contrib/active_job/events.rb +42 -0
- data/lib/datadog/tracing/contrib/active_job/ext.rb +40 -0
- data/lib/datadog/tracing/contrib/active_job/integration.rb +53 -0
- data/lib/datadog/tracing/contrib/active_job/log_injection.rb +38 -0
- data/lib/datadog/tracing/contrib/active_job/patcher.rb +40 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/configuration/settings.rb +37 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/event.rb +68 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +45 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +47 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +34 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/ext.rb +25 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +32 -0
- data/lib/datadog/tracing/contrib/active_record/configuration/makara_resolver.rb +36 -0
- data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +152 -0
- data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +48 -0
- data/lib/datadog/tracing/contrib/active_record/event.rb +30 -0
- data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +60 -0
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +80 -0
- data/lib/datadog/tracing/contrib/active_record/events.rb +34 -0
- data/lib/datadog/tracing/contrib/active_record/ext.rb +30 -0
- data/lib/datadog/tracing/contrib/active_record/integration.rb +71 -0
- data/lib/datadog/tracing/contrib/active_record/patcher.rb +27 -0
- data/lib/datadog/tracing/contrib/active_record/utils.rb +128 -0
- data/lib/datadog/tracing/contrib/active_support/cache/event.rb +32 -0
- data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +171 -0
- data/lib/datadog/tracing/contrib/active_support/cache/events.rb +34 -0
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +225 -0
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +57 -0
- data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +60 -0
- data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +70 -0
- data/lib/datadog/tracing/contrib/active_support/ext.rb +32 -0
- data/lib/datadog/tracing/contrib/active_support/integration.rb +55 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +95 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +83 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/subscription.rb +166 -0
- data/lib/datadog/tracing/contrib/active_support/patcher.rb +27 -0
- data/lib/datadog/tracing/contrib/analytics.rb +33 -0
- data/lib/datadog/tracing/contrib/auto_instrument.rb +53 -0
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +53 -0
- data/lib/datadog/tracing/contrib/aws/ext.rb +50 -0
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +136 -0
- data/lib/datadog/tracing/contrib/aws/integration.rb +50 -0
- data/lib/datadog/tracing/contrib/aws/parsed_context.rb +70 -0
- data/lib/datadog/tracing/contrib/aws/patcher.rb +61 -0
- data/lib/datadog/tracing/contrib/aws/service/base.rb +17 -0
- data/lib/datadog/tracing/contrib/aws/service/dynamodb.rb +22 -0
- data/lib/datadog/tracing/contrib/aws/service/eventbridge.rb +22 -0
- data/lib/datadog/tracing/contrib/aws/service/kinesis.rb +32 -0
- data/lib/datadog/tracing/contrib/aws/service/s3.rb +22 -0
- data/lib/datadog/tracing/contrib/aws/service/sns.rb +30 -0
- data/lib/datadog/tracing/contrib/aws/service/sqs.rb +27 -0
- data/lib/datadog/tracing/contrib/aws/service/states.rb +40 -0
- data/lib/datadog/tracing/contrib/aws/services.rb +139 -0
- data/lib/datadog/tracing/contrib/cloudwise/propagation.rb +315 -0
- data/lib/datadog/tracing/contrib/component.rb +41 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/async_patch.rb +20 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/configuration/settings.rb +24 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/context_composite_executor_service.rb +53 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/ext.rb +16 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/future_patch.rb +20 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/integration.rb +47 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +49 -0
- data/lib/datadog/tracing/contrib/concurrent_ruby/promises_future_patch.rb +22 -0
- data/lib/datadog/tracing/contrib/configurable.rb +102 -0
- data/lib/datadog/tracing/contrib/configuration/resolver.rb +128 -0
- data/lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb +43 -0
- data/lib/datadog/tracing/contrib/configuration/settings.rb +43 -0
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +58 -0
- data/lib/datadog/tracing/contrib/dalli/ext.rb +41 -0
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +75 -0
- data/lib/datadog/tracing/contrib/dalli/integration.rb +52 -0
- data/lib/datadog/tracing/contrib/dalli/patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/dalli/quantize.rb +26 -0
- data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +49 -0
- data/lib/datadog/tracing/contrib/delayed_job/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/delayed_job/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +37 -0
- data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +108 -0
- data/lib/datadog/tracing/contrib/delayed_job/server_internal_tracer/worker.rb +34 -0
- data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +61 -0
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +35 -0
- data/lib/datadog/tracing/contrib/elasticsearch/integration.rb +50 -0
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +172 -0
- data/lib/datadog/tracing/contrib/elasticsearch/quantize.rb +87 -0
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +56 -0
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +229 -0
- data/lib/datadog/tracing/contrib/ethon/ext.rb +33 -0
- data/lib/datadog/tracing/contrib/ethon/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +102 -0
- data/lib/datadog/tracing/contrib/ethon/patcher.rb +30 -0
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +82 -0
- data/lib/datadog/tracing/contrib/excon/ext.rb +31 -0
- data/lib/datadog/tracing/contrib/excon/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/excon/middleware.rb +201 -0
- data/lib/datadog/tracing/contrib/excon/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/ext.rb +70 -0
- data/lib/datadog/tracing/contrib/extensions.rb +255 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +81 -0
- data/lib/datadog/tracing/contrib/faraday/connection.rb +22 -0
- data/lib/datadog/tracing/contrib/faraday/ext.rb +31 -0
- data/lib/datadog/tracing/contrib/faraday/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +128 -0
- data/lib/datadog/tracing/contrib/faraday/patcher.rb +56 -0
- data/lib/datadog/tracing/contrib/faraday/rack_builder.rb +22 -0
- data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +59 -0
- data/lib/datadog/tracing/contrib/grape/endpoint.rb +316 -0
- data/lib/datadog/tracing/contrib/grape/ext.rb +30 -0
- data/lib/datadog/tracing/contrib/grape/instrumentation.rb +37 -0
- data/lib/datadog/tracing/contrib/grape/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/grape/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/error_extension_env_parser.rb +21 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +73 -0
- data/lib/datadog/tracing/contrib/graphql/ext.rb +26 -0
- data/lib/datadog/tracing/contrib/graphql/integration.rb +56 -0
- data/lib/datadog/tracing/contrib/graphql/patcher.rb +58 -0
- data/lib/datadog/tracing/contrib/graphql/trace_patcher.rb +24 -0
- data/lib/datadog/tracing/contrib/graphql/tracing_patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +297 -0
- data/lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +58 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +123 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +96 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +107 -0
- data/lib/datadog/tracing/contrib/grpc/distributed/fetcher.rb +26 -0
- data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +49 -0
- data/lib/datadog/tracing/contrib/grpc/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/grpc/formatting.rb +127 -0
- data/lib/datadog/tracing/contrib/grpc/integration.rb +50 -0
- data/lib/datadog/tracing/contrib/grpc/intercept_with_datadog.rb +53 -0
- data/lib/datadog/tracing/contrib/grpc/patcher.rb +34 -0
- data/lib/datadog/tracing/contrib/grpc.rb +45 -0
- data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +47 -0
- data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +23 -0
- data/lib/datadog/tracing/contrib/hanami/ext.rb +24 -0
- data/lib/datadog/tracing/contrib/hanami/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/hanami/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/hanami/plugin.rb +23 -0
- data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +41 -0
- data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +42 -0
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +34 -0
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +77 -0
- data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +38 -0
- data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +48 -0
- data/lib/datadog/tracing/contrib/http/ext.rb +30 -0
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +152 -0
- data/lib/datadog/tracing/contrib/http/integration.rb +52 -0
- data/lib/datadog/tracing/contrib/http/patcher.rb +30 -0
- data/lib/datadog/tracing/contrib/http.rb +45 -0
- data/lib/datadog/tracing/contrib/http_annotation_helper.rb +17 -0
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +76 -0
- data/lib/datadog/tracing/contrib/httpclient/ext.rb +31 -0
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +132 -0
- data/lib/datadog/tracing/contrib/httpclient/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/httpclient/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +76 -0
- data/lib/datadog/tracing/contrib/httprb/ext.rb +30 -0
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +146 -0
- data/lib/datadog/tracing/contrib/httprb/integration.rb +51 -0
- data/lib/datadog/tracing/contrib/httprb/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/integration.rb +78 -0
- data/lib/datadog/tracing/contrib/kafka/configuration/settings.rb +39 -0
- data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +19 -0
- data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +18 -0
- data/lib/datadog/tracing/contrib/kafka/event.rb +53 -0
- data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +42 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +49 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +47 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +47 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/join_group.rb +37 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/leave_group.rb +37 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/sync_group.rb +37 -0
- data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +41 -0
- data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +44 -0
- data/lib/datadog/tracing/contrib/kafka/events.rb +48 -0
- data/lib/datadog/tracing/contrib/kafka/ext.rb +55 -0
- data/lib/datadog/tracing/contrib/kafka/instrumentation/consumer.rb +66 -0
- data/lib/datadog/tracing/contrib/kafka/instrumentation/producer.rb +66 -0
- data/lib/datadog/tracing/contrib/kafka/integration.rb +47 -0
- data/lib/datadog/tracing/contrib/kafka/patcher.rb +43 -0
- data/lib/datadog/tracing/contrib/karafka/configuration/settings.rb +27 -0
- data/lib/datadog/tracing/contrib/karafka/distributed/propagation.rb +48 -0
- data/lib/datadog/tracing/contrib/karafka/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/karafka/integration.rb +45 -0
- data/lib/datadog/tracing/contrib/karafka/monitor.rb +77 -0
- data/lib/datadog/tracing/contrib/karafka/patcher.rb +89 -0
- data/lib/datadog/tracing/contrib/karafka.rb +37 -0
- data/lib/datadog/tracing/contrib/lograge/configuration/settings.rb +24 -0
- data/lib/datadog/tracing/contrib/lograge/ext.rb +15 -0
- data/lib/datadog/tracing/contrib/lograge/instrumentation.rb +31 -0
- data/lib/datadog/tracing/contrib/lograge/integration.rb +50 -0
- data/lib/datadog/tracing/contrib/lograge/patcher.rb +46 -0
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +64 -0
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +39 -0
- data/lib/datadog/tracing/contrib/mongodb/instrumentation.rb +47 -0
- data/lib/datadog/tracing/contrib/mongodb/integration.rb +51 -0
- data/lib/datadog/tracing/contrib/mongodb/parsers.rb +49 -0
- data/lib/datadog/tracing/contrib/mongodb/patcher.rb +34 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +160 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +69 -0
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +28 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +109 -0
- data/lib/datadog/tracing/contrib/mysql2/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/mysql2/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +71 -0
- data/lib/datadog/tracing/contrib/opensearch/ext.rb +48 -0
- data/lib/datadog/tracing/contrib/opensearch/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +144 -0
- data/lib/datadog/tracing/contrib/opensearch/quantize.rb +81 -0
- data/lib/datadog/tracing/contrib/patchable.rb +109 -0
- data/lib/datadog/tracing/contrib/patcher.rb +87 -0
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +69 -0
- data/lib/datadog/tracing/contrib/pg/ext.rb +35 -0
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +214 -0
- data/lib/datadog/tracing/contrib/pg/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/pg/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +52 -0
- data/lib/datadog/tracing/contrib/presto/ext.rb +38 -0
- data/lib/datadog/tracing/contrib/presto/instrumentation.rb +138 -0
- data/lib/datadog/tracing/contrib/presto/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/presto/patcher.rb +25 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb +41 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +61 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +32 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +67 -0
- data/lib/datadog/tracing/contrib/que/configuration/settings.rb +55 -0
- data/lib/datadog/tracing/contrib/que/ext.rb +33 -0
- data/lib/datadog/tracing/contrib/que/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/que/patcher.rb +26 -0
- data/lib/datadog/tracing/contrib/que/tracer.rb +63 -0
- data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +47 -0
- data/lib/datadog/tracing/contrib/racecar/event.rb +81 -0
- data/lib/datadog/tracing/contrib/racecar/events/batch.rb +38 -0
- data/lib/datadog/tracing/contrib/racecar/events/consume.rb +35 -0
- data/lib/datadog/tracing/contrib/racecar/events/message.rb +38 -0
- data/lib/datadog/tracing/contrib/racecar/events.rb +36 -0
- data/lib/datadog/tracing/contrib/racecar/ext.rb +33 -0
- data/lib/datadog/tracing/contrib/racecar/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/racecar/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +59 -0
- data/lib/datadog/tracing/contrib/rack/ext.rb +30 -0
- data/lib/datadog/tracing/contrib/rack/header_collection.rb +50 -0
- data/lib/datadog/tracing/contrib/rack/header_tagging.rb +63 -0
- data/lib/datadog/tracing/contrib/rack/integration.rb +50 -0
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +475 -0
- data/lib/datadog/tracing/contrib/rack/patcher.rb +119 -0
- data/lib/datadog/tracing/contrib/rack/request_queue.rb +49 -0
- data/lib/datadog/tracing/contrib/rack/route_inference.rb +53 -0
- data/lib/datadog/tracing/contrib/rack/trace_proxy_middleware.rb +58 -0
- data/lib/datadog/tracing/contrib/rails/auto_instrument_railtie.rb +10 -0
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +76 -0
- data/lib/datadog/tracing/contrib/rails/ext.rb +33 -0
- data/lib/datadog/tracing/contrib/rails/framework.rb +148 -0
- data/lib/datadog/tracing/contrib/rails/integration.rb +52 -0
- data/lib/datadog/tracing/contrib/rails/log_injection.rb +29 -0
- data/lib/datadog/tracing/contrib/rails/middlewares.rb +46 -0
- data/lib/datadog/tracing/contrib/rails/patcher.rb +98 -0
- data/lib/datadog/tracing/contrib/rails/railtie.rb +19 -0
- data/lib/datadog/tracing/contrib/rails/runner.rb +117 -0
- data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +55 -0
- data/lib/datadog/tracing/contrib/rake/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/rake/instrumentation.rb +103 -0
- data/lib/datadog/tracing/contrib/rake/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/rake/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/redis/configuration/resolver.rb +49 -0
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +57 -0
- data/lib/datadog/tracing/contrib/redis/ext.rb +36 -0
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +53 -0
- data/lib/datadog/tracing/contrib/redis/integration.rb +80 -0
- data/lib/datadog/tracing/contrib/redis/patcher.rb +92 -0
- data/lib/datadog/tracing/contrib/redis/quantize.rb +80 -0
- data/lib/datadog/tracing/contrib/redis/tags.rb +72 -0
- data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +85 -0
- data/lib/datadog/tracing/contrib/redis/vendor/LICENSE +20 -0
- data/lib/datadog/tracing/contrib/redis/vendor/resolver.rb +160 -0
- data/lib/datadog/tracing/contrib/registerable.rb +50 -0
- data/lib/datadog/tracing/contrib/registry.rb +52 -0
- data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +42 -0
- data/lib/datadog/tracing/contrib/resque/ext.rb +22 -0
- data/lib/datadog/tracing/contrib/resque/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/resque/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/resque/resque_job.rb +106 -0
- data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +55 -0
- data/lib/datadog/tracing/contrib/rest_client/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/rest_client/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/rest_client/patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +137 -0
- data/lib/datadog/tracing/contrib/roda/configuration/settings.rb +38 -0
- data/lib/datadog/tracing/contrib/roda/ext.rb +19 -0
- data/lib/datadog/tracing/contrib/roda/instrumentation.rb +78 -0
- data/lib/datadog/tracing/contrib/roda/integration.rb +45 -0
- data/lib/datadog/tracing/contrib/roda/patcher.rb +30 -0
- data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +24 -0
- data/lib/datadog/tracing/contrib/semantic_logger/ext.rb +15 -0
- data/lib/datadog/tracing/contrib/semantic_logger/instrumentation.rb +35 -0
- data/lib/datadog/tracing/contrib/semantic_logger/integration.rb +52 -0
- data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/sequel/configuration/settings.rb +37 -0
- data/lib/datadog/tracing/contrib/sequel/database.rb +62 -0
- data/lib/datadog/tracing/contrib/sequel/dataset.rb +67 -0
- data/lib/datadog/tracing/contrib/sequel/ext.rb +23 -0
- data/lib/datadog/tracing/contrib/sequel/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/sequel/patcher.rb +37 -0
- data/lib/datadog/tracing/contrib/sequel/utils.rb +90 -0
- data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +43 -0
- data/lib/datadog/tracing/contrib/shoryuken/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/shoryuken/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +65 -0
- data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +67 -0
- data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +47 -0
- data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +49 -0
- data/lib/datadog/tracing/contrib/sidekiq/ext.rb +45 -0
- data/lib/datadog/tracing/contrib/sidekiq/integration.rb +61 -0
- data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +90 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/heartbeat.rb +61 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/job_fetch.rb +36 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/redis_info.rb +34 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/scheduled_poller.rb +57 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_internal_tracer/stop.rb +34 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +91 -0
- data/lib/datadog/tracing/contrib/sidekiq/utils.rb +44 -0
- data/lib/datadog/tracing/contrib/sidekiq.rb +37 -0
- data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +46 -0
- data/lib/datadog/tracing/contrib/sinatra/env.rb +38 -0
- data/lib/datadog/tracing/contrib/sinatra/ext.rb +31 -0
- data/lib/datadog/tracing/contrib/sinatra/framework.rb +116 -0
- data/lib/datadog/tracing/contrib/sinatra/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/sinatra/patcher.rb +75 -0
- data/lib/datadog/tracing/contrib/sinatra/tracer.rb +90 -0
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +109 -0
- data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +43 -0
- data/lib/datadog/tracing/contrib/sneakers/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/sneakers/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/sneakers/patcher.rb +27 -0
- data/lib/datadog/tracing/contrib/sneakers/tracer.rb +60 -0
- data/lib/datadog/tracing/contrib/span_attribute_schema.rb +97 -0
- data/lib/datadog/tracing/contrib/status_range_env_parser.rb +33 -0
- data/lib/datadog/tracing/contrib/status_range_matcher.rb +32 -0
- data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +37 -0
- data/lib/datadog/tracing/contrib/stripe/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/stripe/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/stripe/patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/stripe/request.rb +68 -0
- data/lib/datadog/tracing/contrib/sucker_punch/configuration/settings.rb +39 -0
- data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +28 -0
- data/lib/datadog/tracing/contrib/sucker_punch/ext.rb +28 -0
- data/lib/datadog/tracing/contrib/sucker_punch/instrumentation.rb +104 -0
- data/lib/datadog/tracing/contrib/sucker_punch/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +35 -0
- data/lib/datadog/tracing/contrib/support.rb +28 -0
- data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +63 -0
- data/lib/datadog/tracing/contrib/trilogy/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +97 -0
- data/lib/datadog/tracing/contrib/trilogy/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/trilogy/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/utils/database.rb +31 -0
- data/lib/datadog/tracing/contrib/utils/quantization/hash.rb +111 -0
- data/lib/datadog/tracing/contrib/utils/quantization/http.rb +179 -0
- data/lib/datadog/tracing/contrib.rb +82 -0
- data/lib/datadog/tracing/correlation.rb +113 -0
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +163 -0
- data/lib/datadog/tracing/diagnostics/ext.rb +36 -0
- data/lib/datadog/tracing/diagnostics/health.rb +40 -0
- data/lib/datadog/tracing/distributed/b3_multi.rb +73 -0
- data/lib/datadog/tracing/distributed/b3_single.rb +71 -0
- data/lib/datadog/tracing/distributed/baggage.rb +196 -0
- data/lib/datadog/tracing/distributed/datadog.rb +201 -0
- data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +82 -0
- data/lib/datadog/tracing/distributed/fetcher.rb +21 -0
- data/lib/datadog/tracing/distributed/helpers.rb +65 -0
- data/lib/datadog/tracing/distributed/none.rb +20 -0
- data/lib/datadog/tracing/distributed/propagation.rb +187 -0
- data/lib/datadog/tracing/distributed/propagation_policy.rb +42 -0
- data/lib/datadog/tracing/distributed/trace_context.rb +444 -0
- data/lib/datadog/tracing/event.rb +74 -0
- data/lib/datadog/tracing/flush.rb +96 -0
- data/lib/datadog/tracing/metadata/analytics.rb +26 -0
- data/lib/datadog/tracing/metadata/errors.rb +32 -0
- data/lib/datadog/tracing/metadata/ext.rb +213 -0
- data/lib/datadog/tracing/metadata/metastruct.rb +36 -0
- data/lib/datadog/tracing/metadata/metastruct_tagging.rb +42 -0
- data/lib/datadog/tracing/metadata/tagging.rb +131 -0
- data/lib/datadog/tracing/metadata.rb +22 -0
- data/lib/datadog/tracing/pipeline/span_filter.rb +48 -0
- data/lib/datadog/tracing/pipeline/span_processor.rb +41 -0
- data/lib/datadog/tracing/pipeline.rb +63 -0
- data/lib/datadog/tracing/remote.rb +85 -0
- data/lib/datadog/tracing/runtime/metrics.rb +17 -0
- data/lib/datadog/tracing/sampling/all_sampler.rb +24 -0
- data/lib/datadog/tracing/sampling/ext.rb +58 -0
- data/lib/datadog/tracing/sampling/matcher.rb +119 -0
- data/lib/datadog/tracing/sampling/priority_sampler.rb +160 -0
- data/lib/datadog/tracing/sampling/rate_by_key_sampler.rb +87 -0
- data/lib/datadog/tracing/sampling/rate_by_service_sampler.rb +63 -0
- data/lib/datadog/tracing/sampling/rate_sampler.rb +59 -0
- data/lib/datadog/tracing/sampling/rule.rb +86 -0
- data/lib/datadog/tracing/sampling/rule_sampler.rb +172 -0
- data/lib/datadog/tracing/sampling/sampler.rb +32 -0
- data/lib/datadog/tracing/sampling/span/ext.rb +25 -0
- data/lib/datadog/tracing/sampling/span/matcher.rb +61 -0
- data/lib/datadog/tracing/sampling/span/rule.rb +77 -0
- data/lib/datadog/tracing/sampling/span/rule_parser.rb +104 -0
- data/lib/datadog/tracing/sampling/span/sampler.rb +70 -0
- data/lib/datadog/tracing/span.rb +236 -0
- data/lib/datadog/tracing/span_event.rb +161 -0
- data/lib/datadog/tracing/span_link.rb +92 -0
- data/lib/datadog/tracing/span_operation.rb +561 -0
- data/lib/datadog/tracing/sync_writer.rb +71 -0
- data/lib/datadog/tracing/trace_digest.rb +190 -0
- data/lib/datadog/tracing/trace_operation.rb +556 -0
- data/lib/datadog/tracing/trace_segment.rb +227 -0
- data/lib/datadog/tracing/tracer.rb +644 -0
- data/lib/datadog/tracing/transport/http/api.rb +44 -0
- data/lib/datadog/tracing/transport/http/client.rb +59 -0
- data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
- data/lib/datadog/tracing/transport/http/traces.rb +155 -0
- data/lib/datadog/tracing/transport/http.rb +44 -0
- data/lib/datadog/tracing/transport/io/client.rb +90 -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 +155 -0
- data/lib/datadog/tracing/transport/statistics.rb +77 -0
- data/lib/datadog/tracing/transport/trace_formatter.rb +276 -0
- data/lib/datadog/tracing/transport/traces.rb +258 -0
- data/lib/datadog/tracing/utils.rb +99 -0
- data/lib/datadog/tracing/workers/trace_writer.rb +199 -0
- data/lib/datadog/tracing/workers.rb +126 -0
- data/lib/datadog/tracing/writer.rb +190 -0
- data/lib/datadog/tracing.rb +214 -0
- data/lib/datadog/version.rb +27 -0
- data/lib/datadog.rb +20 -0
- metadata +1074 -0
|
@@ -0,0 +1,881 @@
|
|
|
1
|
+
#include "extconf.h"
|
|
2
|
+
|
|
3
|
+
// This file exports functions used to access private Ruby VM APIs and internals.
|
|
4
|
+
// To do this, it imports a few VM internal (private) headers.
|
|
5
|
+
//
|
|
6
|
+
// **Important Note**: Our medium/long-term plan is to stop relying on all private Ruby headers, and instead request and
|
|
7
|
+
// contribute upstream changes so that they become official public VM APIs.
|
|
8
|
+
//
|
|
9
|
+
// In the meanwhile, be very careful when changing things here :)
|
|
10
|
+
|
|
11
|
+
#ifdef RUBY_MJIT_HEADER
|
|
12
|
+
// Pick up internal structures from the private Ruby MJIT header file
|
|
13
|
+
#include RUBY_MJIT_HEADER
|
|
14
|
+
#else
|
|
15
|
+
// The MJIT header was introduced on 2.6 and removed on 3.3; for other Rubies we rely on
|
|
16
|
+
// the datadog-ruby_core_source gem to get access to private VM headers.
|
|
17
|
+
|
|
18
|
+
// We can't do anything about warnings in VM headers, so we just use this technique to suppress them.
|
|
19
|
+
// See https://nelkinda.com/blog/suppress-warnings-in-gcc-and-clang/#d11e364 for details.
|
|
20
|
+
#pragma GCC diagnostic push
|
|
21
|
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
22
|
+
#pragma GCC diagnostic ignored "-Wattributes"
|
|
23
|
+
#pragma GCC diagnostic ignored "-Wpragmas"
|
|
24
|
+
#pragma GCC diagnostic ignored "-Wexpansion-to-defined"
|
|
25
|
+
#include <vm_core.h>
|
|
26
|
+
#pragma GCC diagnostic pop
|
|
27
|
+
|
|
28
|
+
#pragma GCC diagnostic push
|
|
29
|
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
30
|
+
#include <iseq.h>
|
|
31
|
+
#pragma GCC diagnostic pop
|
|
32
|
+
|
|
33
|
+
#include <ruby.h>
|
|
34
|
+
|
|
35
|
+
#ifndef NO_RACTOR_HEADER_INCLUDE
|
|
36
|
+
#pragma GCC diagnostic push
|
|
37
|
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
38
|
+
#include <ractor_core.h>
|
|
39
|
+
#pragma GCC diagnostic pop
|
|
40
|
+
#endif
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
// This file can't include datadog_ruby_common.h so we replicate this here
|
|
44
|
+
#ifdef __GNUC__
|
|
45
|
+
#define DDTRACE_UNUSED __attribute__((unused))
|
|
46
|
+
#else
|
|
47
|
+
#define DDTRACE_UNUSED
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
#define PRIVATE_VM_API_ACCESS_SKIP_RUBY_INCLUDES
|
|
51
|
+
#include "private_vm_api_access.h"
|
|
52
|
+
|
|
53
|
+
// MRI has a similar rb_thread_ptr() function which we can't call it directly
|
|
54
|
+
// because Ruby does not expose the thread_data_type publicly.
|
|
55
|
+
// Instead, we have our own version of that function, and we lazily initialize the thread_data_type pointer
|
|
56
|
+
// from a known-correct object: the current thread.
|
|
57
|
+
//
|
|
58
|
+
// Note that beyond returning the rb_thread_struct*, rb_check_typeddata() raises an exception
|
|
59
|
+
// if the argument passed in is not actually a `Thread` instance.
|
|
60
|
+
static inline rb_thread_t *thread_struct_from_object(VALUE thread) {
|
|
61
|
+
static const rb_data_type_t *thread_data_type = NULL;
|
|
62
|
+
if (UNLIKELY(thread_data_type == NULL)) thread_data_type = RTYPEDDATA_TYPE(rb_thread_current());
|
|
63
|
+
|
|
64
|
+
return (rb_thread_t *) rb_check_typeddata(thread, thread_data_type);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
rb_nativethread_id_t pthread_id_for(VALUE thread) {
|
|
68
|
+
// struct rb_native_thread was introduced in Ruby 3.2: https://github.com/ruby/ruby/pull/5836
|
|
69
|
+
#ifndef NO_RB_NATIVE_THREAD
|
|
70
|
+
struct rb_native_thread* native_thread = thread_struct_from_object(thread)->nt;
|
|
71
|
+
// This can be NULL on Ruby 3.3 with MN threads (RUBY_MN_THREADS=1)
|
|
72
|
+
if (native_thread == NULL) return 0;
|
|
73
|
+
return native_thread->thread_id;
|
|
74
|
+
#else
|
|
75
|
+
return thread_struct_from_object(thread)->thread_id;
|
|
76
|
+
#endif
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Queries if the current thread is the owner of the global VM lock.
|
|
80
|
+
//
|
|
81
|
+
// @ivoanjo: Ruby has a similarly-named `ruby_thread_has_gvl_p` but that API is insufficient for our needs because it can
|
|
82
|
+
// still return `true` even when a thread DOES NOT HAVE the global VM lock.
|
|
83
|
+
// In particular, looking at the implementation, that API assumes that if a thread is not in a "blocking region" then it
|
|
84
|
+
// will have the GVL which is probably true for the situations that API was designed to be called from BUT this assumption
|
|
85
|
+
// does not hold true when calling `ruby_thread_has_gvl_p` from a signal handler. (Because the thread may have lost the
|
|
86
|
+
// GVL due to a scheduler decision, not because it decided to block.)
|
|
87
|
+
// I have also submitted https://bugs.ruby-lang.org/issues/19172 to discuss this with upstream Ruby developers.
|
|
88
|
+
//
|
|
89
|
+
// Thus we need our own gvl-checking method which actually looks at the gvl structure to determine if it is the owner.
|
|
90
|
+
bool is_current_thread_holding_the_gvl(void) {
|
|
91
|
+
current_gvl_owner owner = gvl_owner();
|
|
92
|
+
return owner.valid && pthread_equal(pthread_self(), owner.owner);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#ifdef HAVE_RUBY_RACTOR_H
|
|
96
|
+
static inline rb_ractor_t *ddtrace_get_ractor(void) {
|
|
97
|
+
#ifndef USE_RACTOR_INTERNAL_APIS_DIRECTLY // Ruby >= 3.3
|
|
98
|
+
return thread_struct_from_object(rb_thread_current())->ractor;
|
|
99
|
+
#else
|
|
100
|
+
return GET_RACTOR();
|
|
101
|
+
#endif
|
|
102
|
+
}
|
|
103
|
+
#endif
|
|
104
|
+
|
|
105
|
+
#ifndef NO_GVL_OWNER // Ruby < 2.6 doesn't have the owner/running field
|
|
106
|
+
// NOTE: Reading the owner in this is a racy read, because we're not grabbing the lock that Ruby uses to protect it.
|
|
107
|
+
//
|
|
108
|
+
// While we could potentially grab this lock, I (@ivoanjo) think we actually don't need it because:
|
|
109
|
+
// * In the case where a thread owns the GVL and calls `gvl_owner`, it will always see the correct value. That's
|
|
110
|
+
// because every thread sets itself as the owner when it grabs the GVL and unsets itself at the end.
|
|
111
|
+
// That means that `is_current_thread_holding_the_gvl` is always accurate.
|
|
112
|
+
// * In a case where we observe a different thread, then this may change by the time we do something with this value
|
|
113
|
+
// anyway. So unless we want to prevent the Ruby scheduler from switching threads, we need to deal with races here.
|
|
114
|
+
current_gvl_owner gvl_owner(void) {
|
|
115
|
+
const rb_thread_t *current_owner =
|
|
116
|
+
#ifndef NO_RB_THREAD_SCHED // Introduced in Ruby 3.2 as a replacement for struct rb_global_vm_lock_struct
|
|
117
|
+
ddtrace_get_ractor()->threads.sched.running;
|
|
118
|
+
#elif HAVE_RUBY_RACTOR_H
|
|
119
|
+
ddtrace_get_ractor()->threads.gvl.owner;
|
|
120
|
+
#else
|
|
121
|
+
GET_VM()->gvl.owner;
|
|
122
|
+
#endif
|
|
123
|
+
|
|
124
|
+
if (current_owner == NULL) return (current_gvl_owner) {.valid = false};
|
|
125
|
+
|
|
126
|
+
#ifndef NO_RB_NATIVE_THREAD
|
|
127
|
+
struct rb_native_thread* current_owner_native_thread = current_owner->nt;
|
|
128
|
+
|
|
129
|
+
// This can be NULL on Ruby 3.3 with MN threads (RUBY_MN_THREADS=1)
|
|
130
|
+
if (current_owner_native_thread == NULL) return (current_gvl_owner) {.valid = false};
|
|
131
|
+
|
|
132
|
+
return (current_gvl_owner) {.valid = true, .owner = current_owner_native_thread->thread_id};
|
|
133
|
+
#else
|
|
134
|
+
return (current_gvl_owner) {.valid = true, .owner = current_owner->thread_id};
|
|
135
|
+
#endif
|
|
136
|
+
}
|
|
137
|
+
#else
|
|
138
|
+
current_gvl_owner gvl_owner(void) {
|
|
139
|
+
rb_vm_t *vm = GET_VM();
|
|
140
|
+
|
|
141
|
+
// BIG Issue: Ruby < 2.6 did not have the owner field. The really nice thing about the owner field is that it's
|
|
142
|
+
// "atomic" -- when a thread sets it, it "declares" two things in a single step
|
|
143
|
+
// * Declaration 1: Someone has the GVL
|
|
144
|
+
// * Declaration 2: That someone is the specific thread
|
|
145
|
+
//
|
|
146
|
+
// Observation 1: On older versions of Ruby, this ownership concept is actually split. Specifically, `gvl.acquired`
|
|
147
|
+
// is a boolean that represents declaration 1 above, and `vm->running_thread` (or `ruby_current_thread`/
|
|
148
|
+
// `ruby_current_execution_context_ptr`) represents declaration 2.
|
|
149
|
+
//
|
|
150
|
+
// Observation 2: In addition, when a thread releases the GVL, it only sets `gvl.acquired` back to 0 **BUT CRUCIALLY
|
|
151
|
+
// DOES NOT CHANGE THE OTHER global variables**.
|
|
152
|
+
//
|
|
153
|
+
// Observation 1+2 above lead to the following possible race:
|
|
154
|
+
// * Thread A grabs the GVL (`gvl.acquired == 1`)
|
|
155
|
+
// * Thread A sets `running_thread` (`gvl.acquired == 1` + `running_thread == Thread A`)
|
|
156
|
+
// * Thread A releases the GVL (`gvl.acquired == 0` + `running_thread == Thread A`)
|
|
157
|
+
// * Thread B grabs the GVL (`gvl.acquired == 1` + `running_thread == Thread A`)
|
|
158
|
+
// * Thread A calls gvl_owner. Due to the current state (`gvl.acquired == 1` + `running_thread == Thread A`), this
|
|
159
|
+
// function returns an incorrect result.
|
|
160
|
+
// * Thread B finally sets `running_thread` (`gvl.acquired == 1` + `running_thread == Thread B`)
|
|
161
|
+
//
|
|
162
|
+
// This is especially problematic because we use `gvl_owner` to implement `is_current_thread_holding_the_gvl` which
|
|
163
|
+
// is called in a signal handler to decide "is it safe for me to call `rb_postponed_job_register_one` or not".
|
|
164
|
+
// (See constraints in `collectors_cpu_and_wall_time_worker.c` comments for why).
|
|
165
|
+
//
|
|
166
|
+
// Thus an incorrect `is_current_thread_holding_the_gvl` result may lead to issues inside `rb_postponed_job_register_one`.
|
|
167
|
+
//
|
|
168
|
+
// For this reason we default to use the "no signals workaround" on Ruby 2.5 by default, and we print a
|
|
169
|
+
// warning when customers force-enable it.
|
|
170
|
+
bool gvl_acquired = vm->gvl.acquired != 0;
|
|
171
|
+
rb_thread_t *current_owner = vm->running_thread;
|
|
172
|
+
|
|
173
|
+
if (!gvl_acquired || current_owner == NULL) return (current_gvl_owner) {.valid = false};
|
|
174
|
+
|
|
175
|
+
return (current_gvl_owner) {.valid = true, .owner = current_owner->thread_id};
|
|
176
|
+
}
|
|
177
|
+
#endif // NO_GVL_OWNER
|
|
178
|
+
|
|
179
|
+
// Taken from upstream vm_core.h at commit d9cf0388599a3234b9f3c06ddd006cd59a58ab8b (November 2022, Ruby 3.2 trunk)
|
|
180
|
+
// Copyright (C) 2004-2007 Koichi Sasada
|
|
181
|
+
// to support tid_for (see below)
|
|
182
|
+
// Modifications: None
|
|
183
|
+
#if defined(__linux__) || defined(__FreeBSD__)
|
|
184
|
+
# define RB_THREAD_T_HAS_NATIVE_ID
|
|
185
|
+
#endif
|
|
186
|
+
|
|
187
|
+
uint64_t native_thread_id_for(VALUE thread) {
|
|
188
|
+
// 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
|
|
189
|
+
#if !defined(NO_THREAD_TID) && defined(RB_THREAD_T_HAS_NATIVE_ID)
|
|
190
|
+
#ifndef NO_RB_NATIVE_THREAD
|
|
191
|
+
struct rb_native_thread* native_thread = thread_struct_from_object(thread)->nt;
|
|
192
|
+
if (native_thread == NULL) return 0;
|
|
193
|
+
return native_thread->tid;
|
|
194
|
+
#else
|
|
195
|
+
return thread_struct_from_object(thread)->tid;
|
|
196
|
+
#endif
|
|
197
|
+
#else
|
|
198
|
+
rb_nativethread_id_t pthread_id = pthread_id_for(thread);
|
|
199
|
+
|
|
200
|
+
#ifdef __APPLE__
|
|
201
|
+
uint64_t result;
|
|
202
|
+
// On macOS, this gives us the same identifier that shows up in activity monitor
|
|
203
|
+
int error = pthread_threadid_np(pthread_id, &result);
|
|
204
|
+
if (error) rb_syserr_fail(error, "Unexpected failure in pthread_threadid_np");
|
|
205
|
+
return result;
|
|
206
|
+
#else
|
|
207
|
+
// Fallback, when we have nothing better (e.g. on Ruby < 3.1 on Linux)
|
|
208
|
+
// @ivoanjo: In the future we may want to explore some potential hacks to get the actual tid on linux
|
|
209
|
+
// (e.g. https://stackoverflow.com/questions/558469/how-do-i-get-a-thread-id-from-an-arbitrary-pthread-t )
|
|
210
|
+
return (uint64_t) pthread_id;
|
|
211
|
+
#endif
|
|
212
|
+
#endif
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// This was renamed in Ruby 3.2
|
|
216
|
+
#if !defined(ccan_list_for_each) && defined(list_for_each)
|
|
217
|
+
#define ccan_list_for_each list_for_each
|
|
218
|
+
#endif
|
|
219
|
+
|
|
220
|
+
// Tries to match rb_thread_list() but that method isn't accessible to extensions
|
|
221
|
+
void ddtrace_thread_list(VALUE result_array) {
|
|
222
|
+
rb_thread_t *thread = NULL;
|
|
223
|
+
|
|
224
|
+
// Ruby 3 Safety: Our implementation is inspired by `rb_ractor_thread_list` BUT that method wraps the operations below
|
|
225
|
+
// with `RACTOR_LOCK` and `RACTOR_UNLOCK`.
|
|
226
|
+
//
|
|
227
|
+
// This initially made me believe that one MUST grab the ractor lock (which is different from the ractor-scoped Global
|
|
228
|
+
// VM Lock) in able to iterate the `threads.set`. This turned out not to be the case: upon further study of the VM
|
|
229
|
+
// codebase in 3.2-master, 3.1 and 3.0, there's quite a few places where `threads.set` is accessed without grabbing
|
|
230
|
+
// the ractor lock: `ractor_mark` (ractor.c), `thgroup_list` (thread.c), `rb_check_deadlock` (thread.c), etc.
|
|
231
|
+
//
|
|
232
|
+
// I suspect the design in `rb_ractor_thread_list` may be done that way to perhaps in the future expose it to be
|
|
233
|
+
// called from a different Ractor, but I'm not sure...
|
|
234
|
+
#ifdef HAVE_RUBY_RACTOR_H
|
|
235
|
+
rb_ractor_t *current_ractor = ddtrace_get_ractor();
|
|
236
|
+
ccan_list_for_each(¤t_ractor->threads.set, thread, lt_node) {
|
|
237
|
+
#else
|
|
238
|
+
rb_vm_t *vm = GET_VM();
|
|
239
|
+
list_for_each(&vm->living_threads, thread, vmlt_node) {
|
|
240
|
+
#endif
|
|
241
|
+
switch (thread->status) {
|
|
242
|
+
case THREAD_RUNNABLE:
|
|
243
|
+
case THREAD_STOPPED:
|
|
244
|
+
case THREAD_STOPPED_FOREVER:
|
|
245
|
+
rb_ary_push(result_array, thread->self);
|
|
246
|
+
default:
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
bool is_thread_alive(VALUE thread) {
|
|
253
|
+
return thread_struct_from_object(thread)->status != THREAD_KILLED;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
VALUE thread_name_for(VALUE thread) {
|
|
257
|
+
return thread_struct_from_object(thread)->name;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// -----------------------------------------------------------------------------
|
|
261
|
+
// The sources below are modified versions of code extracted from the Ruby project.
|
|
262
|
+
// Each function is annotated with its origin, why we imported it, and the changes made.
|
|
263
|
+
//
|
|
264
|
+
// The Ruby project copyright and license follow:
|
|
265
|
+
// -----------------------------------------------------------------------------
|
|
266
|
+
// Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
|
267
|
+
//
|
|
268
|
+
// Redistribution and use in source and binary forms, with or without
|
|
269
|
+
// modification, are permitted provided that the following conditions
|
|
270
|
+
// are met:
|
|
271
|
+
// 1. Redistributions of source code must retain the above copyright
|
|
272
|
+
// notice, this list of conditions and the following disclaimer.
|
|
273
|
+
// 2. Redistributions in binary form must reproduce the above copyright
|
|
274
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
275
|
+
// documentation and/or other materials provided with the distribution.
|
|
276
|
+
//
|
|
277
|
+
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
278
|
+
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
279
|
+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
280
|
+
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
281
|
+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
282
|
+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
283
|
+
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
284
|
+
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
285
|
+
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
286
|
+
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
287
|
+
// SUCH DAMAGE.
|
|
288
|
+
|
|
289
|
+
// Taken from upstream vm_core.h at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
|
290
|
+
// Copyright (C) 2004-2007 Koichi Sasada
|
|
291
|
+
// to support our custom rb_profile_frames (see below)
|
|
292
|
+
// Modifications: None
|
|
293
|
+
#define ISEQ_BODY(iseq) ((iseq)->body)
|
|
294
|
+
|
|
295
|
+
// Taken from upstream vm_backtrace.c at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
|
296
|
+
// Copyright (C) 1993-2012 Yukihiro Matsumoto
|
|
297
|
+
// to support our custom rb_profile_frames (see below)
|
|
298
|
+
// Modifications:
|
|
299
|
+
// * Support int first_lineno for Ruby 3.2.0+ (https://github.com/ruby/ruby/pull/6430)
|
|
300
|
+
// * Validate iseq and pos before calling `rb_iseq_line_no` as a safety measure (see comment below for details)
|
|
301
|
+
//
|
|
302
|
+
// `node_id` gets used depending on Ruby VM compilation settings (USE_ISEQ_NODE_ID being defined).
|
|
303
|
+
// To avoid getting false "unused argument" warnings in setups where it's not used, we need to do this weird dance
|
|
304
|
+
// with diagnostic stuff. See https://nelkinda.com/blog/suppress-warnings-in-gcc-and-clang/#d11e364 for details.
|
|
305
|
+
#pragma GCC diagnostic push
|
|
306
|
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
|
307
|
+
static inline int
|
|
308
|
+
calc_pos(const rb_iseq_t *iseq, const VALUE *pc, int *lineno, int *node_id)
|
|
309
|
+
{
|
|
310
|
+
VM_ASSERT(iseq);
|
|
311
|
+
VM_ASSERT(ISEQ_BODY(iseq));
|
|
312
|
+
VM_ASSERT(ISEQ_BODY(iseq)->iseq_encoded);
|
|
313
|
+
VM_ASSERT(ISEQ_BODY(iseq)->iseq_size);
|
|
314
|
+
if (! pc) {
|
|
315
|
+
if (ISEQ_BODY(iseq)->type == ISEQ_TYPE_TOP) {
|
|
316
|
+
VM_ASSERT(! ISEQ_BODY(iseq)->local_table);
|
|
317
|
+
VM_ASSERT(! ISEQ_BODY(iseq)->local_table_size);
|
|
318
|
+
return 0;
|
|
319
|
+
}
|
|
320
|
+
# ifndef NO_INT_FIRST_LINENO // Ruby 3.2+
|
|
321
|
+
if (lineno) *lineno = ISEQ_BODY(iseq)->location.first_lineno;
|
|
322
|
+
# else
|
|
323
|
+
if (lineno) *lineno = FIX2INT(ISEQ_BODY(iseq)->location.first_lineno);
|
|
324
|
+
#endif
|
|
325
|
+
#ifdef USE_ISEQ_NODE_ID
|
|
326
|
+
if (node_id) *node_id = -1;
|
|
327
|
+
#endif
|
|
328
|
+
return 1;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
ptrdiff_t n = pc - ISEQ_BODY(iseq)->iseq_encoded;
|
|
332
|
+
VM_ASSERT(n <= ISEQ_BODY(iseq)->iseq_size);
|
|
333
|
+
VM_ASSERT(n >= 0);
|
|
334
|
+
ASSUME(n >= 0);
|
|
335
|
+
size_t pos = n; /* no overflow */
|
|
336
|
+
if (LIKELY(pos)) {
|
|
337
|
+
/* use pos-1 because PC points next instruction at the beginning of instruction */
|
|
338
|
+
pos--;
|
|
339
|
+
}
|
|
340
|
+
#if VMDEBUG && defined(HAVE_BUILTIN___BUILTIN_TRAP)
|
|
341
|
+
else {
|
|
342
|
+
/* SDR() is not possible; that causes infinite loop. */
|
|
343
|
+
rb_print_backtrace();
|
|
344
|
+
__builtin_trap();
|
|
345
|
+
}
|
|
346
|
+
#endif
|
|
347
|
+
|
|
348
|
+
// In PROF-11475 we spotted a crash when calling `rb_iseq_line_no` from this method.
|
|
349
|
+
// We were only able to reproduce this issue on Ruby 2.6 and 2.7, not 2.5 or the 3.x series (tried 3.0, 3.2 and 3.4).
|
|
350
|
+
// Note that going out of bounds doesn't crash every time, as usual with C we may just read garbage or get lucky.
|
|
351
|
+
//
|
|
352
|
+
// For those problematic Rubies, we observed that when we try to take a sample in the middle of processing the
|
|
353
|
+
// VM `LEAVE` instruction, the value of `n` can violate the documented assumptions above and be
|
|
354
|
+
// `n > ISEQ_BODY(iseq)->iseq_size)`.
|
|
355
|
+
//
|
|
356
|
+
// To work around this and any other potential issues, we validate here that the bytecode position is sane.
|
|
357
|
+
if (RB_UNLIKELY(n < 0 || n > ISEQ_BODY(iseq)->iseq_size)) return 0;
|
|
358
|
+
|
|
359
|
+
if (lineno) *lineno = rb_iseq_line_no(iseq, pos);
|
|
360
|
+
#ifdef USE_ISEQ_NODE_ID
|
|
361
|
+
if (node_id) *node_id = rb_iseq_node_id(iseq, pos);
|
|
362
|
+
#endif
|
|
363
|
+
return 1;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
#pragma GCC diagnostic pop
|
|
367
|
+
|
|
368
|
+
// Taken from upstream vm_backtrace.c at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
|
369
|
+
// Copyright (C) 1993-2012 Yukihiro Matsumoto
|
|
370
|
+
// to support our custom rb_profile_frames (see below)
|
|
371
|
+
// Modifications: None
|
|
372
|
+
static inline int
|
|
373
|
+
calc_lineno(const rb_iseq_t *iseq, const VALUE *pc)
|
|
374
|
+
{
|
|
375
|
+
int lineno;
|
|
376
|
+
if (calc_pos(iseq, pc, &lineno, NULL)) return lineno;
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// Taken from upstream vm_backtrace.c at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
|
381
|
+
// Copyright (C) 1993-2012 Yukihiro Matsumoto
|
|
382
|
+
// Modifications:
|
|
383
|
+
// * Renamed rb_profile_frames => ddtrace_rb_profile_frames
|
|
384
|
+
// * Add thread argument (this is now upstream, actually!)
|
|
385
|
+
// * Add frame_flags.is_ruby_frame argument
|
|
386
|
+
// * Removed `if (lines)` tests -- require/assume that like `buff`, `lines` is always specified
|
|
387
|
+
// * Skip dummy frame that shows up in main thread
|
|
388
|
+
// * Add `end_cfp == NULL` and `end_cfp <= cfp` safety checks. These are used in a bunch of places in
|
|
389
|
+
// `vm_backtrace.c` (`backtrace_each`, `backtrace_size`, `rb_ec_partial_backtrace_object`) but are conspicuously
|
|
390
|
+
// absent from `rb_profile_frames`. Oversight?
|
|
391
|
+
// * Skip frames where `cfp->iseq && !cfp->pc`. These seem to be internal and are skipped by `backtrace_each` in
|
|
392
|
+
// `vm_backtrace.c`.
|
|
393
|
+
// * Check thread status and do not sample if thread has been killed.
|
|
394
|
+
// * Match Ruby reference stack trace APIs that use the iseq instead of the callable method entry to get information
|
|
395
|
+
// for iseqs created from calls to `eval` and `instance_eval`. This makes it so that `rb_profile_frame_path` on
|
|
396
|
+
// the `VALUE` returned by rb_profile_frames returns `(eval)` instead of the path of the file where the `eval`
|
|
397
|
+
// was called from.
|
|
398
|
+
// * Imported fix from https://github.com/ruby/ruby/pull/7116 to avoid sampling threads that are still being created
|
|
399
|
+
// * Imported fix from https://github.com/ruby/ruby/pull/8415 to avoid potential crash when using YJIT.
|
|
400
|
+
// * Add frame_flags.same_frame and logic to skip redoing work if the buffer already contains the same data we're collecting
|
|
401
|
+
// * Skipped use of rb_callable_method_entry_t (cme) for Ruby frames as it doesn't impact us.
|
|
402
|
+
// * Imported fix from https://github.com/ruby/ruby/pull/8280 to keep us closer to upstream
|
|
403
|
+
// * Added potential fix for https://github.com/ruby/ruby/pull/13643 (this one is a just-in-case, unclear if it happens
|
|
404
|
+
// for ddtrace)
|
|
405
|
+
// * Reversed order of iteration to better enable caching
|
|
406
|
+
//
|
|
407
|
+
// What is rb_profile_frames?
|
|
408
|
+
// `rb_profile_frames` is a Ruby VM debug API added for use by profilers for sampling the stack trace of a Ruby thread.
|
|
409
|
+
// Its main other user is the stackprof profiler: https://github.com/tmm1/stackprof .
|
|
410
|
+
//
|
|
411
|
+
// Why do we need a custom version of rb_profile_frames?
|
|
412
|
+
//
|
|
413
|
+
// There are a few reasons:
|
|
414
|
+
// 1. To backport improved behavior to older Rubies. Prior to Ruby 3.0 (https://github.com/ruby/ruby/pull/3299),
|
|
415
|
+
// rb_profile_frames skipped CFUNC frames, aka frames that are implemented with native code, and thus the resulting
|
|
416
|
+
// stacks were quite incomplete as a big part of the Ruby standard library is implemented with native code.
|
|
417
|
+
//
|
|
418
|
+
// 2. To extend this function to work with any thread. The upstream rb_profile_frames function only targets the current
|
|
419
|
+
// thread, and to support wall-clock profiling we require sampling other threads. This is only safe because of the
|
|
420
|
+
// Global VM Lock. (We don't yet support sampling Ractors beyond the main one; we'll need to find a way to do it
|
|
421
|
+
// safely first.)
|
|
422
|
+
//
|
|
423
|
+
// 3. To get more information out of the Ruby VM. The Ruby VM has a lot more information than is exposed through
|
|
424
|
+
// rb_profile_frames, and by making our own copy of this function we can extract more of this information.
|
|
425
|
+
// See for backtracie gem (https://github.com/ivoanjo/backtracie) for an exploration of what can potentially be done.
|
|
426
|
+
//
|
|
427
|
+
// 4. Because we haven't yet submitted patches to upstream Ruby. As with any changes on the `private_vm_api_access.c`,
|
|
428
|
+
// our medium/long-term plan is to contribute upstream changes and make it so that we don't need any of this
|
|
429
|
+
// on modern Rubies.
|
|
430
|
+
//
|
|
431
|
+
// 5. To make rb_profile_frames behave more like the Ruby-level reference stack trace APIs (`Thread#backtrace_locations`
|
|
432
|
+
// and friends). We've found quite a few situations where the data from rb_profile_frames and the reference APIs
|
|
433
|
+
// disagree, and quite a few of them seem oversights/bugs (speculation from my part) rather than deliberate
|
|
434
|
+
// decisions.
|
|
435
|
+
int ddtrace_rb_profile_frames(VALUE thread, int start, int limit, frame_info *stack_buffer) {
|
|
436
|
+
int i;
|
|
437
|
+
// Modified from upstream: Instead of using `GET_EC` to collect info from the current thread,
|
|
438
|
+
// support sampling any thread (including the current) passed as an argument
|
|
439
|
+
rb_thread_t *th = thread_struct_from_object(thread);
|
|
440
|
+
const rb_execution_context_t *ec = th->ec;
|
|
441
|
+
|
|
442
|
+
// As of this writing, we don't support profiling with MN enabled, and this only happens in that mode, but as we
|
|
443
|
+
// probably want to experiment with it in the future, I've decided to import https://github.com/ruby/ruby/pull/9310
|
|
444
|
+
// here.
|
|
445
|
+
if (ec == NULL) return 0;
|
|
446
|
+
|
|
447
|
+
// I suspect this won't happen for ddtrace, but just-in-case we've imported a potential fix for
|
|
448
|
+
// https://github.com/ruby/ruby/pull/13643 by assuming that these can be NULL/zero with the cfp being non-NULL yet.
|
|
449
|
+
if (ec->vm_stack == NULL || ec->vm_stack_size == 0) return 0;
|
|
450
|
+
|
|
451
|
+
const rb_control_frame_t *cfp = ec->cfp, *end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
|
|
452
|
+
#ifndef NO_JIT_RETURN
|
|
453
|
+
const rb_control_frame_t *top = cfp;
|
|
454
|
+
#endif
|
|
455
|
+
const rb_callable_method_entry_t *cme;
|
|
456
|
+
|
|
457
|
+
// Avoid sampling dead threads
|
|
458
|
+
if (th->status == THREAD_KILLED) return 0;
|
|
459
|
+
|
|
460
|
+
// `vm_backtrace.c` includes this check in several methods. This happens on newly-created threads, and may
|
|
461
|
+
// also (not entirely sure) happen on dead threads
|
|
462
|
+
if (end_cfp == NULL) return PLACEHOLDER_STACK_IN_NATIVE_CODE;
|
|
463
|
+
|
|
464
|
+
// This should not happen for ddtrace (it can only happen when a thread is still being created), but I've imported
|
|
465
|
+
// it from https://github.com/ruby/ruby/pull/7116 in a "just in case" kind of mindset.
|
|
466
|
+
if (cfp == NULL) return 0;
|
|
467
|
+
|
|
468
|
+
// Fix: Skip dummy frame that shows up in main thread.
|
|
469
|
+
//
|
|
470
|
+
// According to a comment in `backtrace_each` (`vm_backtrace.c`), there's two dummy frames that we should ignore
|
|
471
|
+
// at the base of every thread's stack.
|
|
472
|
+
// (see https://github.com/ruby/ruby/blob/4bd38e8120f2fdfdd47a34211720e048502377f1/vm_backtrace.c#L890-L914 )
|
|
473
|
+
//
|
|
474
|
+
// One is being pointed to by `RUBY_VM_END_CONTROL_FRAME(ec)`, and so we need to advance to the next one, and
|
|
475
|
+
// reaching it will be used as a condition to break out of the loop below.
|
|
476
|
+
//
|
|
477
|
+
// Note that in `backtrace_each` there's two calls to `RUBY_VM_NEXT_CONTROL_FRAME`, but the loop bounds there
|
|
478
|
+
// are computed in a different way, so the two calls really are equivalent to one here.
|
|
479
|
+
end_cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);
|
|
480
|
+
|
|
481
|
+
// 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)
|
|
482
|
+
if (end_cfp <= cfp) return PLACEHOLDER_STACK_IN_NATIVE_CODE;
|
|
483
|
+
|
|
484
|
+
// This is the position just after the top of the stack -- e.g. where a new frame pushed on the stack would end up.
|
|
485
|
+
const rb_control_frame_t *top_sentinel = RUBY_VM_NEXT_CONTROL_FRAME(cfp);
|
|
486
|
+
|
|
487
|
+
// We iterate the stack from bottom (beginning of thread) to the top (currently-active frame). This is different
|
|
488
|
+
// from upstream rb_profile_frames, but actually matches what `backtrace_each` does (yes, different Ruby VM APIs
|
|
489
|
+
// iterate in different directions).
|
|
490
|
+
// We do this to better take advantage of the `same_frame` caching mechanism: By starting from the bottom of the
|
|
491
|
+
// stack towards the top, we can usually keep most of the stack intact when the code is only going up and down
|
|
492
|
+
// a few methods at the top. Before this change, the cache was really only useful if between samples the app had
|
|
493
|
+
// not moved from the current stack, as adding or removing one frame would invalidate the existing cache (because
|
|
494
|
+
// every position would shift).
|
|
495
|
+
cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);
|
|
496
|
+
|
|
497
|
+
for (i=0; i<limit && cfp != top_sentinel; cfp = RUBY_VM_NEXT_CONTROL_FRAME(cfp)) {
|
|
498
|
+
if (cfp->iseq && !cfp->pc) {
|
|
499
|
+
// Fix: Do nothing -- this frame should not be used
|
|
500
|
+
//
|
|
501
|
+
// rb_profile_frames does not do this check, but `backtrace_each` (`vm_backtrace.c`) does. This frame is not
|
|
502
|
+
// exposed by the Ruby backtrace APIs and for now we want to match its behavior 1:1
|
|
503
|
+
}
|
|
504
|
+
else if (VM_FRAME_RUBYFRAME_P(cfp)) {
|
|
505
|
+
if (start > 0) {
|
|
506
|
+
start--;
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
stack_buffer[i].same_frame =
|
|
511
|
+
stack_buffer[i].is_ruby_frame &&
|
|
512
|
+
stack_buffer[i].as.ruby_frame.iseq == (VALUE) cfp->iseq &&
|
|
513
|
+
stack_buffer[i].as.ruby_frame.caching_pc == cfp->pc;
|
|
514
|
+
|
|
515
|
+
if (stack_buffer[i].same_frame) { // Nothing to do, buffer already contains this frame
|
|
516
|
+
i++;
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// dd-trace-rb NOTE:
|
|
521
|
+
// Upstream Ruby has code here to retrieve the rb_callable_method_entry_t (cme) and in some cases to use it
|
|
522
|
+
// instead of the iseq.
|
|
523
|
+
// In practice, they are usually the same; the difference is that when you have e.g. block, one gets you a
|
|
524
|
+
// reference to the block, and the other to the method containing the block.
|
|
525
|
+
// This would be important if we used `rb_profile_frame_label` and wanted the "block in foo" label instead
|
|
526
|
+
// of just "foo". But we're currently using `rb_profile_frame_base_label` which I believe is always the same
|
|
527
|
+
// between the rb_callable_method_entry_t and the iseq. Thus, to simplify a bit our logic and reduce a bit
|
|
528
|
+
// the overhead, we always use the iseq here.
|
|
529
|
+
//
|
|
530
|
+
// @ivoanjo: I've left the upstream Ruby code commented out below for reference, so it's more obvious that
|
|
531
|
+
// we're diverging, and we can easily compare and experiment with the upstream version in the future.
|
|
532
|
+
//
|
|
533
|
+
// cme = rb_vm_frame_method_entry(cfp);
|
|
534
|
+
|
|
535
|
+
// if (cme && cme->def->type == VM_METHOD_TYPE_ISEQ &&
|
|
536
|
+
// // Fix: Do not use callable method entry when iseq is for an eval.
|
|
537
|
+
// // TL;DR: This fix is needed for us to match the Ruby reference API information in the
|
|
538
|
+
// // "when sampling an eval/instance eval inside an object" spec.
|
|
539
|
+
// cfp->iseq->body->type != ISEQ_TYPE_EVAL) {
|
|
540
|
+
// buff[i] = (VALUE)cme;
|
|
541
|
+
// }
|
|
542
|
+
// else {
|
|
543
|
+
stack_buffer[i].as.ruby_frame.iseq = (VALUE)cfp->iseq;
|
|
544
|
+
stack_buffer[i].as.ruby_frame.caching_pc = (void *) cfp->pc;
|
|
545
|
+
// }
|
|
546
|
+
|
|
547
|
+
// The topmost frame may not have an updated PC because the JIT
|
|
548
|
+
// may not have set one. The JIT compiler will update the PC
|
|
549
|
+
// before entering a new function (so that `caller` will work),
|
|
550
|
+
// so only the topmost frame could possibly have an out of date PC
|
|
551
|
+
#ifndef NO_JIT_RETURN
|
|
552
|
+
if (cfp == top && cfp->jit_return) {
|
|
553
|
+
stack_buffer[i].as.ruby_frame.line = 0;
|
|
554
|
+
} else {
|
|
555
|
+
stack_buffer[i].as.ruby_frame.line = calc_lineno(cfp->iseq, cfp->pc);
|
|
556
|
+
}
|
|
557
|
+
#else // Ruby < 3.1
|
|
558
|
+
stack_buffer[i].as.ruby_frame.line = calc_lineno(cfp->iseq, cfp->pc);
|
|
559
|
+
#endif
|
|
560
|
+
|
|
561
|
+
stack_buffer[i].is_ruby_frame = true;
|
|
562
|
+
i++;
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
cme = rb_vm_frame_method_entry(cfp);
|
|
566
|
+
if (cme && cme->def->type == VM_METHOD_TYPE_CFUNC) {
|
|
567
|
+
if (start > 0) {
|
|
568
|
+
start--;
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
stack_buffer[i].same_frame =
|
|
573
|
+
!stack_buffer[i].is_ruby_frame &&
|
|
574
|
+
stack_buffer[i].as.native_frame.caching_cme == (VALUE) cme;
|
|
575
|
+
|
|
576
|
+
if (stack_buffer[i].same_frame) { // Nothing to do, buffer already contains this frame
|
|
577
|
+
i++;
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
stack_buffer[i].as.native_frame.caching_cme = (VALUE)cme;
|
|
582
|
+
stack_buffer[i].as.native_frame.method_id = cme->def->original_id;
|
|
583
|
+
stack_buffer[i].as.native_frame.function = cme->def->body.cfunc.func;
|
|
584
|
+
stack_buffer[i].is_ruby_frame = false;
|
|
585
|
+
i++;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return i;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// Support code for older Rubies that cannot use the MJIT header
|
|
594
|
+
#ifndef RUBY_MJIT_HEADER
|
|
595
|
+
|
|
596
|
+
#define MJIT_STATIC // No-op on older Rubies
|
|
597
|
+
|
|
598
|
+
// Taken from upstream include/ruby/backward/2/bool.h at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
|
599
|
+
// Copyright (C) Ruby developers <ruby-core@ruby-lang.org>
|
|
600
|
+
// to support our custom rb_profile_frames (see above)
|
|
601
|
+
// Modifications: None
|
|
602
|
+
#ifndef FALSE
|
|
603
|
+
# define FALSE false
|
|
604
|
+
#elif FALSE
|
|
605
|
+
# error FALSE must be false
|
|
606
|
+
#endif
|
|
607
|
+
|
|
608
|
+
#ifndef TRUE
|
|
609
|
+
# define TRUE true
|
|
610
|
+
#elif ! TRUE
|
|
611
|
+
# error TRUE must be true
|
|
612
|
+
#endif
|
|
613
|
+
|
|
614
|
+
// Taken from upstream vm_insnhelper.c at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
|
615
|
+
// Copyright (C) 2007 Koichi Sasada
|
|
616
|
+
// to support our custom rb_profile_frames (see above)
|
|
617
|
+
// Modifications:
|
|
618
|
+
// * Removed debug checks (they were ifdef'd out anyway)
|
|
619
|
+
static rb_callable_method_entry_t *
|
|
620
|
+
check_method_entry(VALUE obj, int can_be_svar)
|
|
621
|
+
{
|
|
622
|
+
if (obj == Qfalse) return NULL;
|
|
623
|
+
|
|
624
|
+
switch (imemo_type(obj)) {
|
|
625
|
+
case imemo_ment:
|
|
626
|
+
return (rb_callable_method_entry_t *)obj;
|
|
627
|
+
case imemo_cref:
|
|
628
|
+
return NULL;
|
|
629
|
+
case imemo_svar:
|
|
630
|
+
if (can_be_svar) {
|
|
631
|
+
return check_method_entry(((struct vm_svar *)obj)->cref_or_me, FALSE);
|
|
632
|
+
}
|
|
633
|
+
// fallthrough
|
|
634
|
+
default:
|
|
635
|
+
return NULL;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// Taken from upstream vm_insnhelper.c at commit 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (March 2022, Ruby 3.2 trunk)
|
|
640
|
+
// Copyright (C) 2007 Koichi Sasada
|
|
641
|
+
// to support our custom rb_profile_frames (see above)
|
|
642
|
+
//
|
|
643
|
+
// While older Rubies may have this function, the symbol is not exported which leads to dynamic loader issues, e.g.
|
|
644
|
+
// `dyld: lazy symbol binding failed: Symbol not found: _rb_vm_frame_method_entry`.
|
|
645
|
+
//
|
|
646
|
+
// Modifications: None
|
|
647
|
+
MJIT_STATIC const rb_callable_method_entry_t *
|
|
648
|
+
rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
|
|
649
|
+
{
|
|
650
|
+
const VALUE *ep = cfp->ep;
|
|
651
|
+
rb_callable_method_entry_t *me;
|
|
652
|
+
|
|
653
|
+
while (!VM_ENV_LOCAL_P(ep)) {
|
|
654
|
+
if ((me = check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], FALSE)) != NULL) return me;
|
|
655
|
+
ep = VM_ENV_PREV_EP(ep);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
return check_method_entry(ep[VM_ENV_DATA_INDEX_ME_CREF], TRUE);
|
|
659
|
+
}
|
|
660
|
+
#endif // RUBY_MJIT_HEADER
|
|
661
|
+
|
|
662
|
+
#ifndef NO_RACTORS
|
|
663
|
+
// This API and definition are exported as a public symbol by the VM BUT the function header is not defined in any public header, so we
|
|
664
|
+
// repeat it here to be able to use in our code.
|
|
665
|
+
#ifndef USE_RACTOR_INTERNAL_APIS_DIRECTLY
|
|
666
|
+
// Disable fast path for detecting multiple Ractors. Unfortunately this symbol is no longer visible on modern Ruby
|
|
667
|
+
// versions, so we need to do a bit more work.
|
|
668
|
+
struct rb_ractor_struct *ruby_single_main_ractor = NULL;
|
|
669
|
+
|
|
670
|
+
// Alternative implementation of rb_ractor_main_p_ that avoids relying on non-public symbols
|
|
671
|
+
bool rb_ractor_main_p_(void) {
|
|
672
|
+
// We need to get the main ractor in a bit of a roundabout way, since Ruby >= 3.3 hid `GET_VM()`
|
|
673
|
+
return ddtrace_get_ractor() == thread_struct_from_object(rb_thread_current())->vm->ractor.main_ractor;
|
|
674
|
+
}
|
|
675
|
+
#else
|
|
676
|
+
// Directly access Ruby internal fast path for detecting multiple Ractors.
|
|
677
|
+
extern struct rb_ractor_struct *ruby_single_main_ractor;
|
|
678
|
+
|
|
679
|
+
// Ruby 3.0 to 3.2 directly expose this symbol, we just need to tell the compiler it exists.
|
|
680
|
+
bool rb_ractor_main_p_(void);
|
|
681
|
+
#endif
|
|
682
|
+
|
|
683
|
+
// Taken from upstream ractor_core.h at commit d9cf0388599a3234b9f3c06ddd006cd59a58ab8b (November 2022, Ruby 3.2 trunk)
|
|
684
|
+
// to allow us to ensure that we're always operating on the main ractor (if Ruby has ractors)
|
|
685
|
+
// Modifications:
|
|
686
|
+
// * None
|
|
687
|
+
bool ddtrace_rb_ractor_main_p(void)
|
|
688
|
+
{
|
|
689
|
+
if (ruby_single_main_ractor) {
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
return rb_ractor_main_p_();
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
#else
|
|
697
|
+
// Simplify callers on older Rubies, instead of having them probe if the VM supports Ractors we just tell them that yes
|
|
698
|
+
// they're always on the main Ractor
|
|
699
|
+
bool ddtrace_rb_ractor_main_p(void) { return true; }
|
|
700
|
+
#endif // NO_RACTORS
|
|
701
|
+
|
|
702
|
+
// This is a tweaked and inlined version of
|
|
703
|
+
// threadptr_invoke_proc_location + rb_proc_location + iseq_location .
|
|
704
|
+
//
|
|
705
|
+
// It's useful to have here because not all of the methods above are accessible to extensions + to avoid the
|
|
706
|
+
// array allocation that iseq_location did to contain its return value.
|
|
707
|
+
static const rb_iseq_t *maybe_thread_invoke_proc_iseq(VALUE thread_value) {
|
|
708
|
+
rb_thread_t *thread = thread_struct_from_object(thread_value);
|
|
709
|
+
|
|
710
|
+
#ifndef NO_THREAD_INVOKE_ARG // Ruby 2.6+
|
|
711
|
+
if (thread->invoke_type != thread_invoke_type_proc) return NULL;
|
|
712
|
+
|
|
713
|
+
VALUE proc = thread->invoke_arg.proc.proc;
|
|
714
|
+
#else
|
|
715
|
+
if (thread->first_func || !thread->first_proc) return NULL;
|
|
716
|
+
|
|
717
|
+
VALUE proc = thread->first_proc;
|
|
718
|
+
#endif
|
|
719
|
+
|
|
720
|
+
const rb_iseq_t *iseq = rb_proc_get_iseq(proc, 0);
|
|
721
|
+
if (iseq == NULL) return NULL;
|
|
722
|
+
|
|
723
|
+
rb_iseq_check(iseq);
|
|
724
|
+
return iseq;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
VALUE invoke_location_for(VALUE thread, int *line_location) {
|
|
728
|
+
const rb_iseq_t *iseq = maybe_thread_invoke_proc_iseq(thread);
|
|
729
|
+
|
|
730
|
+
if (iseq == NULL) return Qnil;
|
|
731
|
+
|
|
732
|
+
*line_location = NUM2INT(rb_iseq_first_lineno(iseq));
|
|
733
|
+
return rb_iseq_path(iseq);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
void self_test_mn_enabled(void) {
|
|
737
|
+
#ifdef NO_MN_THREADS_AVAILABLE
|
|
738
|
+
return;
|
|
739
|
+
#else
|
|
740
|
+
if (ddtrace_get_ractor()->threads.sched.enable_mn_threads == true) {
|
|
741
|
+
rb_raise(rb_eRuntimeError, "Ruby VM is running with RUBY_MN_THREADS=1. This is not yet supported");
|
|
742
|
+
}
|
|
743
|
+
#endif
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Taken from upstream imemo.h at commit 6ebcf25de2859b5b6402b7e8b181066c32d0e0bf (November 2023, master branch)
|
|
747
|
+
// (See the Ruby project copyright and license above)
|
|
748
|
+
// to enable calling rb_imemo_name
|
|
749
|
+
//
|
|
750
|
+
// Modifications:
|
|
751
|
+
// * Added IMEMO_MASK define
|
|
752
|
+
// * Changed return type to int to avoid having to define `enum imemo_type`
|
|
753
|
+
static inline int ddtrace_imemo_type(VALUE imemo) {
|
|
754
|
+
// This mask is the same between Ruby 2.5 and 3.3-preview3. Furthermore, the intention of this method is to be used
|
|
755
|
+
// to call `rb_imemo_name` which correctly handles invalid numbers so even if the mask changes in the future, at most
|
|
756
|
+
// we'll get incorrect results (and never a VM crash)
|
|
757
|
+
#define IMEMO_MASK 0x0f
|
|
758
|
+
return (RBASIC(imemo)->flags >> FL_USHIFT) & IMEMO_MASK;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// Safety: This function assumes the object passed in is of the imemo type. But in the worst case, you'll just get
|
|
762
|
+
// a string that doesn't make any sense.
|
|
763
|
+
#ifndef NO_IMEMO_NAME
|
|
764
|
+
const char *imemo_kind(VALUE imemo) {
|
|
765
|
+
return rb_imemo_name(ddtrace_imemo_type(imemo));
|
|
766
|
+
}
|
|
767
|
+
#else
|
|
768
|
+
const char *imemo_kind(__attribute__((unused)) VALUE imemo) {
|
|
769
|
+
return NULL;
|
|
770
|
+
}
|
|
771
|
+
#endif
|
|
772
|
+
|
|
773
|
+
// This is used to workaround a VM bug. See "handle_sampling_signal" in "collectors_cpu_and_wall_time_worker" for details.
|
|
774
|
+
#ifdef NO_POSTPONED_TRIGGER
|
|
775
|
+
void *objspace_ptr_for_gc_finalize_deferred_workaround(void) {
|
|
776
|
+
return GET_VM()->objspace;
|
|
777
|
+
}
|
|
778
|
+
#endif
|
|
779
|
+
|
|
780
|
+
#ifdef USE_GVL_PROFILING_3_2_WORKAROUNDS // Ruby 3.2
|
|
781
|
+
#include "gvl_profiling_helper.h"
|
|
782
|
+
|
|
783
|
+
gvl_profiling_thread thread_from_thread_object(VALUE thread) {
|
|
784
|
+
return (gvl_profiling_thread) {.thread = thread_struct_from_object(thread)};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Hack: In Ruby 3.3+ we attach gvl profiling state to Ruby threads using the
|
|
788
|
+
// rb_internal_thread_specific_* APIs. These APIs did not exist on Ruby 3.2. On Ruby 3.2 we instead store the
|
|
789
|
+
// needed data inside the `rb_thread_t` structure, specifically in `stat_insn_usage` as a Ruby FIXNUM.
|
|
790
|
+
//
|
|
791
|
+
// Why `stat_insn_usage`? We needed some per-thread storage, and while looking at the Ruby VM sources I noticed
|
|
792
|
+
// that `stat_insn_usage` has been in `rb_thread_t` for a long time, but is not used anywhere in the VM
|
|
793
|
+
// code. There's a comment attached to it "/* statistics data for profiler */" but other than marking this
|
|
794
|
+
// field for GC, I could not find any place in the VM commit history or on GitHub where this has ever been used.
|
|
795
|
+
//
|
|
796
|
+
// Thus, since this hack is only for 3.2, which presumably will never see this field either removed or used
|
|
797
|
+
// during its remaining maintenance release period we... kinda take it for our own usage. It's ugly, I know...
|
|
798
|
+
intptr_t gvl_profiling_state_get(gvl_profiling_thread thread) {
|
|
799
|
+
if (thread.thread == NULL) return 0;
|
|
800
|
+
|
|
801
|
+
VALUE current_value = ((rb_thread_t *)thread.thread)->stat_insn_usage;
|
|
802
|
+
intptr_t result = current_value == Qnil ? 0 : FIX2LONG(current_value);
|
|
803
|
+
return result;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
void gvl_profiling_state_set(gvl_profiling_thread thread, intptr_t value) {
|
|
807
|
+
if (thread.thread == NULL) return;
|
|
808
|
+
((rb_thread_t *)thread.thread)->stat_insn_usage = LONG2FIX(value);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// Because Ruby 3.2 does not give us the current thread when calling the RUBY_INTERNAL_THREAD_EVENT_READY and
|
|
812
|
+
// RUBY_INTERNAL_THREAD_EVENT_RESUMED APIs, we need to figure out this info ourselves.
|
|
813
|
+
//
|
|
814
|
+
// Specifically, this method was created to be called from a RUBY_INTERNAL_THREAD_EVENT_RESUMED callback --
|
|
815
|
+
// when it's triggered, we know the thread the code gets executed on is holding the GVL, so we use this
|
|
816
|
+
// opportunity to initialize our thread-local value.
|
|
817
|
+
gvl_profiling_thread gvl_profiling_state_maybe_initialize(void) {
|
|
818
|
+
gvl_profiling_thread current_thread = gvl_waiting_tls;
|
|
819
|
+
|
|
820
|
+
if (current_thread.thread == NULL) {
|
|
821
|
+
// threads.sched.running is the thread currently holding the GVL, which when this gets executed is the
|
|
822
|
+
// current thread!
|
|
823
|
+
current_thread = (gvl_profiling_thread) {.thread = (void *) rb_current_ractor()->threads.sched.running};
|
|
824
|
+
gvl_waiting_tls = current_thread;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
return current_thread;
|
|
828
|
+
}
|
|
829
|
+
#endif
|
|
830
|
+
|
|
831
|
+
// Is the VM smack in the middle of raising an exception?
|
|
832
|
+
bool is_raised_flag_set(VALUE thread) { return thread_struct_from_object(thread)->ec->raised_flag > 0; }
|
|
833
|
+
|
|
834
|
+
#ifndef NO_CURRENT_FIBER_FOR
|
|
835
|
+
// The following three declarations are all
|
|
836
|
+
// taken from upstream cont.c at commit d97884a58be32e829fd03a80cd521f4733d65c79 (February 2025, master branch)
|
|
837
|
+
// (See the Ruby project copyright and license above)
|
|
838
|
+
// to enable building `current_fiber_for`.
|
|
839
|
+
//
|
|
840
|
+
// We needed to copy them because they aren't otherwise exposed in any VM APIs or headers.
|
|
841
|
+
// @ivoanjo: I manually checked the Ruby 3.1, 3.2, 3.3 and 3.4 branches + master, and the parts we care about in these
|
|
842
|
+
// structures have not changed in many years (in fact, last change I spotted was for 2.7).
|
|
843
|
+
enum context_type {
|
|
844
|
+
CONTINUATION_CONTEXT = 0,
|
|
845
|
+
FIBER_CONTEXT = 1
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
typedef struct rb_context_struct { // This declaration is incomplete -- only contains up to `self` which is the part we care about
|
|
849
|
+
enum context_type type;
|
|
850
|
+
int argc;
|
|
851
|
+
int kw_splat;
|
|
852
|
+
VALUE self;
|
|
853
|
+
} rb_context_t;
|
|
854
|
+
|
|
855
|
+
struct rb_fiber_struct { // This declaration is incomplete -- only contains the first entry which is the part we care about
|
|
856
|
+
rb_context_t cont;
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
VALUE current_fiber_for(VALUE thread) {
|
|
860
|
+
VALUE self = thread_struct_from_object(thread)->ec->fiber_ptr->cont.self;
|
|
861
|
+
return self == 0 ? Qnil : self;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
void self_test_current_fiber_for(void) {
|
|
865
|
+
VALUE expected_current_fiber = current_fiber_for(rb_thread_current());
|
|
866
|
+
VALUE actual_current_fiber = rb_fiber_current();
|
|
867
|
+
|
|
868
|
+
if (expected_current_fiber == Qnil) {
|
|
869
|
+
// On purpose above we tried reading before calling `rb_fiber_current()` so the fiber may have not existed yet.
|
|
870
|
+
// But now it should be there.
|
|
871
|
+
expected_current_fiber = current_fiber_for(rb_thread_current());
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
if (expected_current_fiber != actual_current_fiber) rb_raise(rb_eRuntimeError, "current_fiber_for() self-test failed");
|
|
875
|
+
}
|
|
876
|
+
#else
|
|
877
|
+
NORETURN(VALUE current_fiber_for(DDTRACE_UNUSED VALUE thread));
|
|
878
|
+
|
|
879
|
+
VALUE current_fiber_for(DDTRACE_UNUSED VALUE thread) { rb_raise(rb_eRuntimeError, "Not implemented for Ruby < 3.1"); }
|
|
880
|
+
void self_test_current_fiber_for(void) { } // Nothing to do
|
|
881
|
+
#endif
|