ddtrace 0.34.1 → 1.23.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3321 -277
- data/LICENSE-3rdparty.csv +8 -0
- data/README.md +17 -9
- data/bin/ddprofrb +15 -0
- data/bin/ddtracerb +17 -0
- data/ext/datadog_profiling_loader/datadog_profiling_loader.c +134 -0
- data/ext/datadog_profiling_loader/extconf.rb +72 -0
- data/ext/datadog_profiling_native_extension/NativeExtensionDesign.md +156 -0
- data/ext/datadog_profiling_native_extension/clock_id.h +22 -0
- data/ext/datadog_profiling_native_extension/clock_id_from_pthread.c +56 -0
- data/ext/datadog_profiling_native_extension/clock_id_noop.c +22 -0
- data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +1161 -0
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c +422 -0
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.h +101 -0
- data/ext/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 +244 -0
- data/ext/datadog_profiling_native_extension/collectors_idle_sampling_helper.h +3 -0
- data/ext/datadog_profiling_native_extension/collectors_stack.c +372 -0
- data/ext/datadog_profiling_native_extension/collectors_stack.h +27 -0
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +1402 -0
- data/ext/datadog_profiling_native_extension/collectors_thread_context.h +15 -0
- data/ext/datadog_profiling_native_extension/extconf.rb +302 -0
- data/ext/datadog_profiling_native_extension/heap_recorder.c +1047 -0
- data/ext/datadog_profiling_native_extension/heap_recorder.h +166 -0
- data/ext/datadog_profiling_native_extension/helpers.h +23 -0
- data/ext/datadog_profiling_native_extension/http_transport.c +375 -0
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.c +62 -0
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.h +42 -0
- data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +319 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +892 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +61 -0
- data/ext/datadog_profiling_native_extension/profiling.c +267 -0
- data/ext/datadog_profiling_native_extension/ruby_helpers.c +267 -0
- data/ext/datadog_profiling_native_extension/ruby_helpers.h +122 -0
- data/ext/datadog_profiling_native_extension/setup_signal_handler.c +115 -0
- data/ext/datadog_profiling_native_extension/setup_signal_handler.h +11 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +1040 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.h +27 -0
- data/ext/datadog_profiling_native_extension/time_helpers.c +53 -0
- data/ext/datadog_profiling_native_extension/time_helpers.h +26 -0
- data/lib/datadog/appsec/assets/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 +7 -0
- data/lib/datadog/appsec/assets/waf_rules/processors.json +92 -0
- data/lib/datadog/appsec/assets/waf_rules/recommended.json +7703 -0
- data/lib/datadog/appsec/assets/waf_rules/scanners.json +114 -0
- data/lib/datadog/appsec/assets/waf_rules/strict.json +1635 -0
- data/lib/datadog/appsec/assets.rb +44 -0
- data/lib/datadog/appsec/autoload.rb +11 -0
- data/lib/datadog/appsec/component.rb +94 -0
- data/lib/datadog/appsec/configuration/settings.rb +202 -0
- data/lib/datadog/appsec/configuration.rb +11 -0
- data/lib/datadog/appsec/contrib/auto_instrument.rb +25 -0
- data/lib/datadog/appsec/contrib/devise/event.rb +57 -0
- data/lib/datadog/appsec/contrib/devise/ext.rb +13 -0
- data/lib/datadog/appsec/contrib/devise/integration.rb +42 -0
- data/lib/datadog/appsec/contrib/devise/patcher/authenticatable_patch.rb +76 -0
- data/lib/datadog/appsec/contrib/devise/patcher/registration_controller_patch.rb +54 -0
- data/lib/datadog/appsec/contrib/devise/patcher.rb +45 -0
- data/lib/datadog/appsec/contrib/devise/resource.rb +35 -0
- data/lib/datadog/appsec/contrib/devise/tracking.rb +57 -0
- data/lib/datadog/appsec/contrib/integration.rb +37 -0
- data/lib/datadog/appsec/contrib/patcher.rb +12 -0
- data/lib/datadog/appsec/contrib/rack/ext.rb +13 -0
- data/lib/datadog/appsec/contrib/rack/gateway/request.rb +104 -0
- data/lib/datadog/appsec/contrib/rack/gateway/response.rb +30 -0
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +160 -0
- data/lib/datadog/appsec/contrib/rack/integration.rb +42 -0
- data/lib/datadog/appsec/contrib/rack/patcher.rb +34 -0
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +81 -0
- data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +60 -0
- data/lib/datadog/appsec/contrib/rack/reactive/response.rb +66 -0
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +44 -0
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +224 -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 +69 -0
- data/lib/datadog/appsec/contrib/rails/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/rails/patcher.rb +165 -0
- data/lib/datadog/appsec/contrib/rails/reactive/action.rb +66 -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/sinatra/ext.rb +14 -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 +115 -0
- data/lib/datadog/appsec/contrib/sinatra/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +166 -0
- data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +61 -0
- data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +20 -0
- data/lib/datadog/appsec/event.rb +169 -0
- data/lib/datadog/appsec/ext.rb +10 -0
- data/lib/datadog/appsec/extensions.rb +15 -0
- data/lib/datadog/appsec/instrumentation/gateway/argument.rb +22 -0
- data/lib/datadog/appsec/instrumentation/gateway.rb +64 -0
- data/lib/datadog/appsec/instrumentation.rb +9 -0
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +67 -0
- data/lib/datadog/appsec/monitor/reactive/set_user.rb +58 -0
- data/lib/datadog/appsec/monitor.rb +11 -0
- data/lib/datadog/appsec/processor/actions.rb +49 -0
- data/lib/datadog/appsec/processor/rule_loader.rb +123 -0
- data/lib/datadog/appsec/processor/rule_merger.rb +152 -0
- data/lib/datadog/appsec/processor.rb +171 -0
- data/lib/datadog/appsec/rate_limiter.rb +58 -0
- data/lib/datadog/appsec/reactive/address_hash.rb +22 -0
- data/lib/datadog/appsec/reactive/engine.rb +47 -0
- data/lib/datadog/appsec/reactive/operation.rb +68 -0
- data/lib/datadog/appsec/reactive/subscriber.rb +19 -0
- data/lib/datadog/appsec/remote.rb +129 -0
- data/lib/datadog/appsec/response.rb +151 -0
- data/lib/datadog/appsec/sample_rate.rb +21 -0
- data/lib/datadog/appsec/scope.rb +61 -0
- data/lib/datadog/appsec/utils/http/media_range.rb +199 -0
- data/lib/datadog/appsec/utils/http/media_type.rb +85 -0
- data/lib/datadog/appsec/utils/http.rb +11 -0
- data/lib/datadog/appsec/utils.rb +9 -0
- data/lib/datadog/appsec.rb +60 -0
- data/lib/datadog/auto_instrument.rb +3 -0
- data/lib/datadog/core/backport.rb +51 -0
- data/lib/datadog/core/buffer/cruby.rb +55 -0
- data/lib/datadog/core/buffer/random.rb +134 -0
- data/lib/datadog/core/buffer/thread_safe.rb +58 -0
- data/lib/datadog/core/chunker.rb +35 -0
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +405 -0
- data/lib/datadog/core/configuration/base.rb +89 -0
- data/lib/datadog/core/configuration/components.rb +174 -0
- data/lib/datadog/core/configuration/ext.rb +47 -0
- data/lib/datadog/core/configuration/option.rb +319 -0
- data/lib/datadog/core/configuration/option_definition.rb +176 -0
- data/lib/datadog/core/configuration/options.rb +128 -0
- data/lib/datadog/core/configuration/settings.rb +848 -0
- data/lib/datadog/core/configuration.rb +309 -0
- data/lib/datadog/core/diagnostics/environment_logger.rb +183 -0
- data/lib/datadog/core/diagnostics/health.rb +19 -0
- data/lib/datadog/core/encoding.rb +72 -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 +46 -0
- data/lib/datadog/core/environment/gc.rb +20 -0
- data/lib/datadog/core/environment/git.rb +25 -0
- data/lib/datadog/core/environment/identity.rb +84 -0
- data/lib/datadog/core/environment/platform.rb +44 -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 +58 -0
- data/lib/datadog/core/error.rb +100 -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 +44 -0
- data/lib/datadog/core/logging/ext.rb +13 -0
- data/lib/datadog/core/metrics/client.rb +197 -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 +42 -0
- data/lib/datadog/core/metrics/metric.rb +14 -0
- data/lib/datadog/core/metrics/options.rb +48 -0
- data/lib/datadog/core/pin.rb +73 -0
- data/lib/datadog/core/remote/client/capabilities.rb +62 -0
- data/lib/datadog/core/remote/client.rb +232 -0
- data/lib/datadog/core/remote/component.rb +162 -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 +294 -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 +27 -0
- data/lib/datadog/core/remote/transport/config.rb +60 -0
- data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
- data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
- data/lib/datadog/core/remote/transport/http/api.rb +58 -0
- data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
- data/lib/datadog/core/remote/transport/http/client.rb +48 -0
- data/lib/datadog/core/remote/transport/http/config.rb +280 -0
- data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
- data/lib/datadog/core/remote/transport/http.rb +179 -0
- data/lib/datadog/core/remote/transport/negotiation.rb +62 -0
- data/lib/datadog/core/remote/worker.rb +102 -0
- data/lib/datadog/core/remote.rb +24 -0
- data/lib/datadog/core/runtime/ext.rb +38 -0
- data/lib/datadog/core/runtime/metrics.rb +183 -0
- data/lib/datadog/core/telemetry/client.rb +95 -0
- data/lib/datadog/core/telemetry/emitter.rb +44 -0
- data/lib/datadog/core/telemetry/event.rb +273 -0
- data/lib/datadog/core/telemetry/ext.rb +16 -0
- data/lib/datadog/core/telemetry/heartbeat.rb +33 -0
- data/lib/datadog/core/telemetry/http/adapters/net.rb +111 -0
- data/lib/datadog/core/telemetry/http/env.rb +20 -0
- data/lib/datadog/core/telemetry/http/ext.rb +25 -0
- data/lib/datadog/core/telemetry/http/response.rb +68 -0
- data/lib/datadog/core/telemetry/http/transport.rb +61 -0
- data/lib/datadog/core/telemetry/request.rb +59 -0
- data/lib/datadog/core/transport/ext.rb +49 -0
- data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
- data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
- data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
- data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
- data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
- data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
- data/lib/datadog/core/transport/http/api/map.rb +18 -0
- data/lib/datadog/core/transport/http/env.rb +62 -0
- data/lib/datadog/core/transport/http/response.rb +60 -0
- data/lib/datadog/core/transport/parcel.rb +22 -0
- data/lib/datadog/core/transport/request.rb +17 -0
- data/lib/datadog/core/transport/response.rb +64 -0
- data/lib/datadog/core/utils/compression.rb +36 -0
- data/lib/datadog/core/utils/duration.rb +52 -0
- data/lib/datadog/core/utils/forking.rb +61 -0
- data/lib/datadog/core/utils/hash.rb +79 -0
- data/lib/datadog/core/utils/network.rb +140 -0
- data/lib/datadog/core/utils/only_once.rb +42 -0
- data/lib/datadog/core/utils/safe_dup.rb +50 -0
- data/lib/datadog/core/utils/sequence.rb +26 -0
- data/lib/datadog/core/utils/time.rb +52 -0
- data/lib/datadog/core/utils/url.rb +25 -0
- data/lib/datadog/core/utils.rb +92 -0
- data/lib/datadog/core/vendor/ipaddr.rb +78 -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 +183 -0
- data/lib/datadog/core/workers/interval_loop.rb +123 -0
- data/lib/datadog/core/workers/polling.rb +57 -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 +45 -0
- data/lib/datadog/kit/appsec/events.rb +169 -0
- data/lib/datadog/kit/enable_core_dumps.rb +49 -0
- data/lib/datadog/kit/identity.rb +104 -0
- data/lib/datadog/kit.rb +11 -0
- data/lib/datadog/opentelemetry/api/context.rb +193 -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 +92 -0
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +134 -0
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +167 -0
- data/lib/datadog/opentelemetry/trace.rb +58 -0
- data/lib/datadog/opentelemetry.rb +51 -0
- data/lib/datadog/opentracer/binary_propagator.rb +26 -0
- data/lib/datadog/opentracer/carrier.rb +9 -0
- data/lib/datadog/opentracer/distributed_headers.rb +54 -0
- data/lib/datadog/opentracer/global_tracer.rb +17 -0
- data/lib/datadog/opentracer/propagator.rb +26 -0
- data/lib/datadog/opentracer/rack_propagator.rb +71 -0
- data/lib/datadog/opentracer/scope.rb +18 -0
- data/lib/datadog/opentracer/scope_manager.rb +9 -0
- data/lib/datadog/opentracer/span.rb +99 -0
- data/lib/datadog/opentracer/span_context.rb +19 -0
- data/lib/datadog/opentracer/span_context_factory.rb +27 -0
- data/lib/datadog/opentracer/text_map_propagator.rb +87 -0
- data/lib/datadog/opentracer/thread_local_scope.rb +34 -0
- data/lib/datadog/opentracer/thread_local_scope_manager.rb +64 -0
- data/lib/datadog/opentracer/tracer.rb +212 -0
- data/lib/datadog/opentracer.rb +33 -0
- data/lib/datadog/profiling/collectors/code_provenance.rb +119 -0
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +137 -0
- data/lib/datadog/profiling/collectors/dynamic_sampling_rate.rb +14 -0
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +68 -0
- data/lib/datadog/profiling/collectors/info.rb +101 -0
- data/lib/datadog/profiling/collectors/stack.rb +13 -0
- data/lib/datadog/profiling/collectors/thread_context.rb +61 -0
- data/lib/datadog/profiling/component.rb +426 -0
- data/lib/datadog/profiling/exporter.rb +104 -0
- data/lib/datadog/profiling/ext/forking.rb +96 -0
- data/lib/datadog/profiling/ext.rb +35 -0
- data/lib/datadog/profiling/flush.rb +43 -0
- data/lib/datadog/profiling/http_transport.rb +147 -0
- data/lib/datadog/profiling/load_native_extension.rb +39 -0
- data/lib/datadog/profiling/native_extension.rb +20 -0
- data/lib/datadog/profiling/preload.rb +5 -0
- data/lib/datadog/profiling/profiler.rb +62 -0
- data/lib/datadog/profiling/scheduler.rb +135 -0
- data/lib/datadog/profiling/stack_recorder.rb +71 -0
- data/lib/datadog/profiling/tag_builder.rb +58 -0
- data/lib/datadog/profiling/tasks/exec.rb +48 -0
- data/lib/datadog/profiling/tasks/help.rb +16 -0
- data/lib/datadog/profiling/tasks/setup.rb +58 -0
- data/lib/datadog/profiling.rb +161 -0
- data/lib/datadog/tracing/analytics.rb +25 -0
- data/lib/datadog/tracing/buffer.rb +127 -0
- data/lib/datadog/tracing/client_ip.rb +61 -0
- data/lib/datadog/tracing/component.rb +235 -0
- data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
- data/lib/datadog/tracing/configuration/dynamic/option.rb +71 -0
- data/lib/datadog/tracing/configuration/dynamic.rb +64 -0
- data/lib/datadog/tracing/configuration/ext.rb +108 -0
- data/lib/datadog/tracing/configuration/http.rb +74 -0
- data/lib/datadog/tracing/configuration/settings.rb +502 -0
- data/lib/datadog/tracing/context.rb +68 -0
- data/lib/datadog/tracing/context_provider.rb +80 -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 +56 -0
- data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +61 -0
- data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +57 -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 +88 -0
- data/lib/datadog/tracing/contrib/action_cable/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/action_cable/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/action_mailer/configuration/settings.rb +40 -0
- data/lib/datadog/tracing/contrib/action_mailer/event.rb +52 -0
- data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +58 -0
- data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +45 -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 +48 -0
- data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +136 -0
- data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +50 -0
- data/lib/datadog/tracing/contrib/action_pack/ext.rb +23 -0
- data/lib/datadog/tracing/contrib/action_pack/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/action_pack/patcher.rb +27 -0
- data/lib/datadog/tracing/contrib/action_pack/utils.rb +38 -0
- data/lib/datadog/tracing/contrib/action_view/configuration/settings.rb +38 -0
- data/lib/datadog/tracing/contrib/action_view/event.rb +35 -0
- data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +52 -0
- data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +55 -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/instrumentation/partial_renderer.rb +76 -0
- data/lib/datadog/tracing/contrib/action_view/instrumentation/template_renderer.rb +89 -0
- data/lib/datadog/tracing/contrib/action_view/integration.rb +55 -0
- data/lib/datadog/tracing/contrib/action_view/patcher.rb +45 -0
- data/lib/datadog/tracing/contrib/action_view/utils.rb +34 -0
- data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +44 -0
- data/lib/datadog/tracing/contrib/active_job/event.rb +58 -0
- data/lib/datadog/tracing/contrib/active_job/events/discard.rb +48 -0
- data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +47 -0
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +47 -0
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +49 -0
- data/lib/datadog/tracing/contrib/active_job/events/perform.rb +47 -0
- data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +48 -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 +48 -0
- data/lib/datadog/tracing/contrib/active_job/log_injection.rb +24 -0
- data/lib/datadog/tracing/contrib/active_job/patcher.rb +36 -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 +43 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +45 -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 +43 -0
- data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +32 -0
- data/lib/datadog/tracing/contrib/active_record/configuration/makara_resolver.rb +34 -0
- data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +150 -0
- data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +47 -0
- data/lib/datadog/tracing/contrib/active_record/event.rb +30 -0
- data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +56 -0
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +75 -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 +54 -0
- data/lib/datadog/tracing/contrib/active_record/patcher.rb +27 -0
- data/lib/datadog/tracing/contrib/active_record/utils.rb +126 -0
- data/lib/datadog/tracing/contrib/active_record/vendor/MIT-LICENSE +20 -0
- data/lib/datadog/tracing/contrib/active_record/vendor/connection_specification.rb +305 -0
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +186 -0
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +76 -0
- data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +47 -0
- data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +46 -0
- data/lib/datadog/tracing/contrib/active_support/ext.rb +32 -0
- data/lib/datadog/tracing/contrib/active_support/integration.rb +49 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +71 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +71 -0
- data/lib/datadog/tracing/contrib/active_support/notifications/subscription.rb +162 -0
- data/lib/datadog/tracing/contrib/active_support/patcher.rb +27 -0
- data/lib/datadog/tracing/contrib/analytics.rb +28 -0
- data/lib/datadog/tracing/contrib/auto_instrument.rb +53 -0
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +52 -0
- data/lib/datadog/tracing/contrib/aws/ext.rb +50 -0
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +119 -0
- data/lib/datadog/tracing/contrib/aws/integration.rb +45 -0
- data/lib/datadog/tracing/contrib/aws/parsed_context.rb +62 -0
- data/lib/datadog/tracing/contrib/aws/patcher.rb +57 -0
- data/lib/datadog/tracing/contrib/aws/service/base.rb +16 -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 +137 -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 +42 -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 +85 -0
- data/lib/datadog/tracing/contrib/configuration/resolvers/pattern_resolver.rb +43 -0
- data/lib/datadog/tracing/contrib/configuration/settings.rb +39 -0
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +57 -0
- data/lib/datadog/tracing/contrib/dalli/ext.rb +40 -0
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +73 -0
- data/lib/datadog/tracing/contrib/dalli/integration.rb +50 -0
- data/lib/datadog/tracing/contrib/dalli/patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/dalli/quantize.rb +24 -0
- data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +45 -0
- data/lib/datadog/tracing/contrib/delayed_job/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/delayed_job/integration.rb +41 -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 +53 -0
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +34 -0
- data/lib/datadog/tracing/contrib/elasticsearch/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +160 -0
- data/lib/datadog/tracing/contrib/elasticsearch/quantize.rb +85 -0
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +55 -0
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +221 -0
- data/lib/datadog/tracing/contrib/ethon/ext.rb +32 -0
- data/lib/datadog/tracing/contrib/ethon/integration.rb +46 -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 +57 -0
- data/lib/datadog/tracing/contrib/excon/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/excon/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/excon/middleware.rb +192 -0
- data/lib/datadog/tracing/contrib/excon/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/ext.rb +55 -0
- data/lib/datadog/tracing/contrib/extensions.rb +233 -0
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +68 -0
- data/lib/datadog/tracing/contrib/faraday/connection.rb +22 -0
- data/lib/datadog/tracing/contrib/faraday/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/faraday/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +110 -0
- data/lib/datadog/tracing/contrib/faraday/patcher.rb +54 -0
- data/lib/datadog/tracing/contrib/faraday/rack_builder.rb +22 -0
- data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +45 -0
- data/lib/datadog/tracing/contrib/grape/endpoint.rb +248 -0
- data/lib/datadog/tracing/contrib/grape/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/grape/instrumentation.rb +35 -0
- data/lib/datadog/tracing/contrib/grape/integration.rb +42 -0
- data/lib/datadog/tracing/contrib/grape/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +39 -0
- data/lib/datadog/tracing/contrib/graphql/ext.rb +20 -0
- data/lib/datadog/tracing/contrib/graphql/integration.rb +42 -0
- data/lib/datadog/tracing/contrib/graphql/patcher.rb +88 -0
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +79 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +119 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +107 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +101 -0
- data/lib/datadog/tracing/contrib/grpc/distributed/fetcher.rb +26 -0
- data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +42 -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 +48 -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/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 +42 -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 +44 -0
- data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +40 -0
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +75 -0
- data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +38 -0
- data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +37 -0
- data/lib/datadog/tracing/contrib/http/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +158 -0
- data/lib/datadog/tracing/contrib/http/integration.rb +49 -0
- data/lib/datadog/tracing/contrib/http/patcher.rb +30 -0
- data/lib/datadog/tracing/contrib/http_annotation_helper.rb +17 -0
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +75 -0
- data/lib/datadog/tracing/contrib/httpclient/ext.rb +30 -0
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +135 -0
- data/lib/datadog/tracing/contrib/httpclient/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/httpclient/patcher.rb +40 -0
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +75 -0
- data/lib/datadog/tracing/contrib/httprb/ext.rb +29 -0
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +145 -0
- data/lib/datadog/tracing/contrib/httprb/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/httprb/patcher.rb +40 -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 +40 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +47 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +45 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +45 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/join_group.rb +35 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/leave_group.rb +35 -0
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/sync_group.rb +35 -0
- data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +39 -0
- data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +42 -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/integration.rb +42 -0
- data/lib/datadog/tracing/contrib/kafka/patcher.rb +29 -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 +48 -0
- data/lib/datadog/tracing/contrib/lograge/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +55 -0
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +38 -0
- data/lib/datadog/tracing/contrib/mongodb/instrumentation.rb +47 -0
- data/lib/datadog/tracing/contrib/mongodb/integration.rb +46 -0
- data/lib/datadog/tracing/contrib/mongodb/parsers.rb +47 -0
- data/lib/datadog/tracing/contrib/mongodb/patcher.rb +34 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +139 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +63 -0
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +28 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +95 -0
- data/lib/datadog/tracing/contrib/mysql2/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/mysql2/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +53 -0
- data/lib/datadog/tracing/contrib/opensearch/ext.rb +38 -0
- data/lib/datadog/tracing/contrib/opensearch/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +135 -0
- data/lib/datadog/tracing/contrib/opensearch/quantize.rb +81 -0
- data/lib/datadog/tracing/contrib/patchable.rb +109 -0
- data/lib/datadog/tracing/contrib/patcher.rb +83 -0
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +64 -0
- data/lib/datadog/tracing/contrib/pg/ext.rb +35 -0
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +211 -0
- data/lib/datadog/tracing/contrib/pg/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/pg/patcher.rb +31 -0
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +51 -0
- data/lib/datadog/tracing/contrib/presto/ext.rb +38 -0
- data/lib/datadog/tracing/contrib/presto/instrumentation.rb +136 -0
- data/lib/datadog/tracing/contrib/presto/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/presto/patcher.rb +35 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb +41 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +33 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +28 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +53 -0
- data/lib/datadog/tracing/contrib/qless/configuration/settings.rb +45 -0
- data/lib/datadog/tracing/contrib/qless/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/qless/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/qless/patcher.rb +36 -0
- data/lib/datadog/tracing/contrib/qless/qless_job.rb +75 -0
- data/lib/datadog/tracing/contrib/qless/tracer_cleaner.rb +30 -0
- data/lib/datadog/tracing/contrib/que/configuration/settings.rb +57 -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 +46 -0
- data/lib/datadog/tracing/contrib/racecar/event.rb +81 -0
- data/lib/datadog/tracing/contrib/racecar/events/batch.rb +36 -0
- data/lib/datadog/tracing/contrib/racecar/events/consume.rb +33 -0
- data/lib/datadog/tracing/contrib/racecar/events/message.rb +36 -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 +42 -0
- data/lib/datadog/tracing/contrib/racecar/patcher.rb +29 -0
- data/lib/datadog/tracing/contrib/rack/configuration/settings.rb +54 -0
- data/lib/datadog/tracing/contrib/rack/ext.rb +31 -0
- data/lib/datadog/tracing/contrib/rack/header_collection.rb +38 -0
- data/lib/datadog/tracing/contrib/rack/header_tagging.rb +63 -0
- data/lib/datadog/tracing/contrib/rack/integration.rb +48 -0
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +315 -0
- data/lib/datadog/tracing/contrib/rack/patcher.rb +117 -0
- data/lib/datadog/tracing/contrib/rack/request_queue.rb +46 -0
- data/lib/datadog/tracing/contrib/rails/auto_instrument_railtie.rb +8 -0
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +84 -0
- data/lib/datadog/tracing/contrib/rails/ext.rb +20 -0
- data/lib/datadog/tracing/contrib/rails/framework.rb +148 -0
- data/lib/datadog/tracing/contrib/rails/integration.rb +47 -0
- data/lib/datadog/tracing/contrib/rails/log_injection.rb +27 -0
- data/lib/datadog/tracing/contrib/rails/middlewares.rb +46 -0
- data/lib/datadog/tracing/contrib/rails/patcher.rb +87 -0
- data/lib/datadog/tracing/contrib/rails/railtie.rb +17 -0
- data/lib/datadog/tracing/contrib/rails/utils.rb +28 -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 +101 -0
- data/lib/datadog/tracing/contrib/rake/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/rake/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/redis/configuration/resolver.rb +47 -0
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +57 -0
- data/lib/datadog/tracing/contrib/redis/ext.rb +35 -0
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +51 -0
- data/lib/datadog/tracing/contrib/redis/integration.rb +78 -0
- data/lib/datadog/tracing/contrib/redis/patcher.rb +90 -0
- data/lib/datadog/tracing/contrib/redis/quantize.rb +80 -0
- data/lib/datadog/tracing/contrib/redis/tags.rb +68 -0
- data/lib/datadog/tracing/contrib/redis/trace_middleware.rb +83 -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 +44 -0
- data/lib/datadog/tracing/contrib/resque/ext.rb +22 -0
- data/lib/datadog/tracing/contrib/resque/integration.rb +46 -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 +28 -0
- data/lib/datadog/tracing/contrib/rest_client/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/rest_client/patcher.rb +28 -0
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +129 -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 +76 -0
- data/lib/datadog/tracing/contrib/roda/integration.rb +45 -0
- data/lib/datadog/tracing/contrib/roda/patcher.rb +30 -0
- data/lib/datadog/tracing/contrib/semantic_logger/configuration/settings.rb +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 +50 -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 +60 -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 +41 -0
- data/lib/datadog/tracing/contrib/sequel/patcher.rb +37 -0
- data/lib/datadog/tracing/contrib/sequel/utils.rb +88 -0
- data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +45 -0
- data/lib/datadog/tracing/contrib/shoryuken/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/shoryuken/integration.rb +42 -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 +66 -0
- data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +53 -0
- data/lib/datadog/tracing/contrib/sidekiq/distributed/propagation.rb +38 -0
- data/lib/datadog/tracing/contrib/sidekiq/ext.rb +45 -0
- data/lib/datadog/tracing/contrib/sidekiq/integration.rb +59 -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 +118 -0
- data/lib/datadog/tracing/contrib/sidekiq/utils.rb +44 -0
- data/lib/datadog/tracing/contrib/sinatra/configuration/settings.rb +44 -0
- data/lib/datadog/tracing/contrib/sinatra/env.rb +36 -0
- data/lib/datadog/tracing/contrib/sinatra/ext.rb +37 -0
- data/lib/datadog/tracing/contrib/sinatra/framework.rb +114 -0
- data/lib/datadog/tracing/contrib/sinatra/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/sinatra/patcher.rb +75 -0
- data/lib/datadog/tracing/contrib/sinatra/tracer.rb +84 -0
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +116 -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 +92 -0
- data/lib/datadog/tracing/contrib/status_code_matcher.rb +72 -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 +67 -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 +102 -0
- data/lib/datadog/tracing/contrib/sucker_punch/integration.rb +41 -0
- data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +35 -0
- data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +58 -0
- data/lib/datadog/tracing/contrib/trilogy/ext.rb +27 -0
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +94 -0
- data/lib/datadog/tracing/contrib/trilogy/integration.rb +43 -0
- data/lib/datadog/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 +109 -0
- data/lib/datadog/tracing/contrib/utils/quantization/http.rb +177 -0
- data/lib/datadog/tracing/contrib.rb +82 -0
- data/lib/datadog/tracing/correlation.rb +128 -0
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +165 -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 +72 -0
- data/lib/datadog/tracing/distributed/b3_single.rb +68 -0
- data/lib/datadog/tracing/distributed/datadog.rb +199 -0
- data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +84 -0
- data/lib/datadog/tracing/distributed/fetcher.rb +21 -0
- data/lib/datadog/tracing/distributed/headers/ext.rb +34 -0
- data/lib/datadog/tracing/distributed/helpers.rb +65 -0
- data/lib/datadog/tracing/distributed/none.rb +18 -0
- data/lib/datadog/tracing/distributed/propagation.rb +127 -0
- data/lib/datadog/tracing/distributed/trace_context.rb +415 -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 +24 -0
- data/lib/datadog/tracing/metadata/ext.rb +191 -0
- data/lib/datadog/tracing/metadata/tagging.rb +129 -0
- data/lib/datadog/tracing/metadata.rb +20 -0
- data/lib/datadog/tracing/pipeline/span_filter.rb +46 -0
- data/lib/datadog/tracing/pipeline/span_processor.rb +39 -0
- data/lib/datadog/tracing/pipeline.rb +61 -0
- data/lib/datadog/tracing/propagation/http.rb +14 -0
- data/lib/datadog/tracing/remote.rb +78 -0
- data/lib/datadog/tracing/runtime/metrics.rb +17 -0
- data/lib/datadog/tracing/sampling/all_sampler.rb +25 -0
- data/lib/datadog/tracing/sampling/ext.rb +56 -0
- data/lib/datadog/tracing/sampling/matcher.rb +88 -0
- data/lib/datadog/tracing/sampling/priority_sampler.rb +165 -0
- data/lib/datadog/tracing/sampling/rate_by_key_sampler.rb +94 -0
- data/lib/datadog/tracing/sampling/rate_by_service_sampler.rb +62 -0
- data/lib/datadog/tracing/sampling/rate_limiter.rb +186 -0
- data/lib/datadog/tracing/sampling/rate_sampler.rb +68 -0
- data/lib/datadog/tracing/sampling/rule.rb +77 -0
- data/lib/datadog/tracing/sampling/rule_sampler.rb +159 -0
- data/lib/datadog/tracing/sampling/sampler.rb +42 -0
- data/lib/datadog/tracing/sampling/span/ext.rb +25 -0
- data/lib/datadog/tracing/sampling/span/matcher.rb +89 -0
- data/lib/datadog/tracing/sampling/span/rule.rb +82 -0
- data/lib/datadog/tracing/sampling/span/rule_parser.rb +104 -0
- data/lib/datadog/tracing/sampling/span/sampler.rb +77 -0
- data/lib/datadog/tracing/span.rb +214 -0
- data/lib/datadog/tracing/span_operation.rb +505 -0
- data/lib/datadog/tracing/sync_writer.rb +67 -0
- data/lib/datadog/tracing/trace_digest.rb +177 -0
- data/lib/datadog/tracing/trace_operation.rb +485 -0
- data/lib/datadog/tracing/trace_segment.rb +220 -0
- data/lib/datadog/tracing/tracer.rb +541 -0
- data/lib/datadog/tracing/transport/http/api/instance.rb +37 -0
- data/lib/datadog/tracing/transport/http/api/spec.rb +19 -0
- data/lib/datadog/tracing/transport/http/api.rb +43 -0
- data/lib/datadog/tracing/transport/http/builder.rb +162 -0
- data/lib/datadog/tracing/transport/http/client.rb +57 -0
- data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
- data/lib/datadog/tracing/transport/http/traces.rb +152 -0
- data/lib/datadog/tracing/transport/http.rb +125 -0
- data/lib/datadog/tracing/transport/io/client.rb +89 -0
- data/lib/datadog/tracing/transport/io/response.rb +27 -0
- data/lib/datadog/tracing/transport/io/traces.rb +101 -0
- data/lib/datadog/tracing/transport/io.rb +30 -0
- data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
- data/lib/datadog/tracing/transport/statistics.rb +77 -0
- data/lib/datadog/tracing/transport/trace_formatter.rb +240 -0
- data/lib/datadog/tracing/transport/traces.rb +224 -0
- data/lib/datadog/tracing/utils.rb +83 -0
- data/lib/datadog/tracing/workers/trace_writer.rb +194 -0
- data/lib/datadog/tracing/workers.rb +123 -0
- data/lib/datadog/tracing/writer.rb +186 -0
- data/lib/datadog/tracing.rb +148 -0
- data/lib/ddtrace/auto_instrument.rb +16 -0
- data/lib/ddtrace/auto_instrument_base.rb +8 -0
- data/lib/ddtrace/profiling/preload.rb +2 -0
- data/lib/ddtrace/transport/ext.rb +47 -0
- data/lib/ddtrace/version.rb +19 -5
- data/lib/ddtrace.rb +9 -72
- metadata +808 -632
- data/.circleci/config.yml +0 -441
- data/.circleci/images/primary/Dockerfile-2.0.0 +0 -73
- data/.circleci/images/primary/Dockerfile-2.1.10 +0 -73
- data/.circleci/images/primary/Dockerfile-2.2.10 +0 -73
- data/.circleci/images/primary/Dockerfile-2.3.8 +0 -75
- data/.circleci/images/primary/Dockerfile-2.4.6 +0 -73
- data/.circleci/images/primary/Dockerfile-2.5.6 +0 -73
- data/.circleci/images/primary/Dockerfile-2.6.4 +0 -73
- data/.circleci/images/primary/Dockerfile-2.7.0 +0 -73
- data/.dockerignore +0 -1
- data/.env +0 -26
- data/.github/CODEOWNERS +0 -1
- data/.gitignore +0 -59
- data/.rspec +0 -1
- data/.rubocop.yml +0 -81
- data/.yardopts +0 -5
- data/Appraisals +0 -944
- data/CONTRIBUTING.md +0 -85
- data/Gemfile +0 -7
- data/Rakefile +0 -722
- data/benchmarks/postgres_database.yml +0 -9
- data/benchmarks/sidekiq_test.rb +0 -154
- data/ddtrace.gemspec +0 -64
- data/docker-compose.yml +0 -335
- data/docs/DevelopmentGuide.md +0 -195
- data/docs/GettingStarted.md +0 -2142
- data/lib/ddtrace/analytics.rb +0 -36
- data/lib/ddtrace/augmentation/method_wrapper.rb +0 -20
- data/lib/ddtrace/augmentation/method_wrapping.rb +0 -38
- data/lib/ddtrace/augmentation/shim.rb +0 -102
- data/lib/ddtrace/augmentation.rb +0 -13
- data/lib/ddtrace/buffer.rb +0 -119
- data/lib/ddtrace/configuration/base.rb +0 -84
- data/lib/ddtrace/configuration/dependency_resolver.rb +0 -24
- data/lib/ddtrace/configuration/option.rb +0 -64
- data/lib/ddtrace/configuration/option_definition.rb +0 -123
- data/lib/ddtrace/configuration/option_definition_set.rb +0 -18
- data/lib/ddtrace/configuration/option_set.rb +0 -6
- data/lib/ddtrace/configuration/options.rb +0 -112
- data/lib/ddtrace/configuration/pin_setup.rb +0 -30
- data/lib/ddtrace/configuration/settings.rb +0 -187
- data/lib/ddtrace/configuration.rb +0 -30
- data/lib/ddtrace/context.rb +0 -305
- data/lib/ddtrace/context_flush.rb +0 -69
- data/lib/ddtrace/context_provider.rb +0 -50
- data/lib/ddtrace/contrib/action_cable/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/action_cable/event.rb +0 -65
- data/lib/ddtrace/contrib/action_cable/events/broadcast.rb +0 -49
- data/lib/ddtrace/contrib/action_cable/events/perform_action.rb +0 -55
- data/lib/ddtrace/contrib/action_cable/events/transmit.rb +0 -50
- data/lib/ddtrace/contrib/action_cable/events.rb +0 -33
- data/lib/ddtrace/contrib/action_cable/ext.rb +0 -23
- data/lib/ddtrace/contrib/action_cable/instrumentation.rb +0 -31
- data/lib/ddtrace/contrib/action_cable/integration.rb +0 -38
- data/lib/ddtrace/contrib/action_cable/patcher.rb +0 -27
- data/lib/ddtrace/contrib/action_pack/action_controller/instrumentation.rb +0 -148
- data/lib/ddtrace/contrib/action_pack/action_controller/patcher.rb +0 -25
- data/lib/ddtrace/contrib/action_pack/configuration/settings.rb +0 -27
- data/lib/ddtrace/contrib/action_pack/ext.rb +0 -16
- data/lib/ddtrace/contrib/action_pack/integration.rb +0 -38
- data/lib/ddtrace/contrib/action_pack/patcher.rb +0 -23
- data/lib/ddtrace/contrib/action_pack/utils.rb +0 -36
- data/lib/ddtrace/contrib/action_view/configuration/settings.rb +0 -26
- data/lib/ddtrace/contrib/action_view/event.rb +0 -39
- data/lib/ddtrace/contrib/action_view/events/render_partial.rb +0 -45
- data/lib/ddtrace/contrib/action_view/events/render_template.rb +0 -48
- data/lib/ddtrace/contrib/action_view/events.rb +0 -30
- data/lib/ddtrace/contrib/action_view/ext.rb +0 -17
- data/lib/ddtrace/contrib/action_view/instrumentation/partial_renderer.rb +0 -74
- data/lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb +0 -167
- data/lib/ddtrace/contrib/action_view/integration.rb +0 -45
- data/lib/ddtrace/contrib/action_view/patcher.rb +0 -47
- data/lib/ddtrace/contrib/action_view/utils.rb +0 -32
- data/lib/ddtrace/contrib/active_model_serializers/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/active_model_serializers/event.rb +0 -68
- data/lib/ddtrace/contrib/active_model_serializers/events/render.rb +0 -32
- data/lib/ddtrace/contrib/active_model_serializers/events/serialize.rb +0 -35
- data/lib/ddtrace/contrib/active_model_serializers/events.rb +0 -30
- data/lib/ddtrace/contrib/active_model_serializers/ext.rb +0 -17
- data/lib/ddtrace/contrib/active_model_serializers/integration.rb +0 -40
- data/lib/ddtrace/contrib/active_model_serializers/patcher.rb +0 -29
- data/lib/ddtrace/contrib/active_record/configuration/resolver.rb +0 -45
- data/lib/ddtrace/contrib/active_record/configuration/settings.rb +0 -30
- data/lib/ddtrace/contrib/active_record/event.rb +0 -30
- data/lib/ddtrace/contrib/active_record/events/instantiation.rb +0 -60
- data/lib/ddtrace/contrib/active_record/events/sql.rb +0 -64
- data/lib/ddtrace/contrib/active_record/events.rb +0 -30
- data/lib/ddtrace/contrib/active_record/ext.rb +0 -21
- data/lib/ddtrace/contrib/active_record/integration.rb +0 -46
- data/lib/ddtrace/contrib/active_record/patcher.rb +0 -23
- data/lib/ddtrace/contrib/active_record/utils.rb +0 -76
- data/lib/ddtrace/contrib/active_support/cache/instrumentation.rb +0 -157
- data/lib/ddtrace/contrib/active_support/cache/patcher.rb +0 -48
- data/lib/ddtrace/contrib/active_support/cache/redis.rb +0 -47
- data/lib/ddtrace/contrib/active_support/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/active_support/ext.rb +0 -21
- data/lib/ddtrace/contrib/active_support/integration.rb +0 -40
- data/lib/ddtrace/contrib/active_support/notifications/event.rb +0 -62
- data/lib/ddtrace/contrib/active_support/notifications/subscriber.rb +0 -66
- data/lib/ddtrace/contrib/active_support/notifications/subscription.rb +0 -159
- data/lib/ddtrace/contrib/active_support/patcher.rb +0 -23
- data/lib/ddtrace/contrib/analytics.rb +0 -24
- data/lib/ddtrace/contrib/aws/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/aws/ext.rb +0 -20
- data/lib/ddtrace/contrib/aws/instrumentation.rb +0 -56
- data/lib/ddtrace/contrib/aws/integration.rb +0 -42
- data/lib/ddtrace/contrib/aws/parsed_context.rb +0 -56
- data/lib/ddtrace/contrib/aws/patcher.rb +0 -49
- data/lib/ddtrace/contrib/aws/services.rb +0 -115
- data/lib/ddtrace/contrib/concurrent_ruby/configuration/settings.rb +0 -15
- data/lib/ddtrace/contrib/concurrent_ruby/context_composite_executor_service.rb +0 -35
- data/lib/ddtrace/contrib/concurrent_ruby/ext.rb +0 -11
- data/lib/ddtrace/contrib/concurrent_ruby/future_patch.rb +0 -23
- data/lib/ddtrace/contrib/concurrent_ruby/integration.rb +0 -38
- data/lib/ddtrace/contrib/concurrent_ruby/patcher.rb +0 -28
- data/lib/ddtrace/contrib/configurable.rb +0 -76
- data/lib/ddtrace/contrib/configuration/resolver.rb +0 -16
- data/lib/ddtrace/contrib/configuration/resolvers/pattern_resolver.rb +0 -39
- data/lib/ddtrace/contrib/configuration/settings.rb +0 -35
- data/lib/ddtrace/contrib/dalli/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/dalli/ext.rb +0 -17
- data/lib/ddtrace/contrib/dalli/instrumentation.rb +0 -50
- data/lib/ddtrace/contrib/dalli/integration.rb +0 -38
- data/lib/ddtrace/contrib/dalli/patcher.rb +0 -67
- data/lib/ddtrace/contrib/dalli/quantize.rb +0 -22
- data/lib/ddtrace/contrib/delayed_job/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/delayed_job/ext.rb +0 -18
- data/lib/ddtrace/contrib/delayed_job/integration.rb +0 -38
- data/lib/ddtrace/contrib/delayed_job/patcher.rb +0 -28
- data/lib/ddtrace/contrib/delayed_job/plugin.rb +0 -61
- data/lib/ddtrace/contrib/elasticsearch/configuration/settings.rb +0 -26
- data/lib/ddtrace/contrib/elasticsearch/ext.rb +0 -19
- data/lib/ddtrace/contrib/elasticsearch/integration.rb +0 -39
- data/lib/ddtrace/contrib/elasticsearch/patcher.rb +0 -118
- data/lib/ddtrace/contrib/elasticsearch/quantize.rb +0 -80
- data/lib/ddtrace/contrib/ethon/configuration/settings.rb +0 -27
- data/lib/ddtrace/contrib/ethon/easy_patch.rb +0 -148
- data/lib/ddtrace/contrib/ethon/ext.rb +0 -15
- data/lib/ddtrace/contrib/ethon/integration.rb +0 -43
- data/lib/ddtrace/contrib/ethon/multi_patch.rb +0 -80
- data/lib/ddtrace/contrib/ethon/patcher.rb +0 -25
- data/lib/ddtrace/contrib/excon/configuration/settings.rb +0 -28
- data/lib/ddtrace/contrib/excon/ext.rb +0 -14
- data/lib/ddtrace/contrib/excon/integration.rb +0 -43
- data/lib/ddtrace/contrib/excon/middleware.rb +0 -157
- data/lib/ddtrace/contrib/excon/patcher.rb +0 -27
- data/lib/ddtrace/contrib/extensions.rb +0 -59
- data/lib/ddtrace/contrib/faraday/configuration/settings.rb +0 -33
- data/lib/ddtrace/contrib/faraday/connection.rb +0 -18
- data/lib/ddtrace/contrib/faraday/ext.rb +0 -14
- data/lib/ddtrace/contrib/faraday/integration.rb +0 -43
- data/lib/ddtrace/contrib/faraday/middleware.rb +0 -81
- data/lib/ddtrace/contrib/faraday/patcher.rb +0 -81
- data/lib/ddtrace/contrib/faraday/rack_builder.rb +0 -18
- data/lib/ddtrace/contrib/grape/configuration/settings.rb +0 -27
- data/lib/ddtrace/contrib/grape/endpoint.rb +0 -208
- data/lib/ddtrace/contrib/grape/ext.rb +0 -19
- data/lib/ddtrace/contrib/grape/instrumentation.rb +0 -33
- data/lib/ddtrace/contrib/grape/integration.rb +0 -39
- data/lib/ddtrace/contrib/grape/patcher.rb +0 -73
- data/lib/ddtrace/contrib/graphql/configuration/settings.rb +0 -27
- data/lib/ddtrace/contrib/graphql/ext.rb +0 -13
- data/lib/ddtrace/contrib/graphql/integration.rb +0 -39
- data/lib/ddtrace/contrib/graphql/patcher.rb +0 -57
- data/lib/ddtrace/contrib/grpc/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/grpc/datadog_interceptor/client.rb +0 -56
- data/lib/ddtrace/contrib/grpc/datadog_interceptor/server.rb +0 -76
- data/lib/ddtrace/contrib/grpc/datadog_interceptor.rb +0 -74
- data/lib/ddtrace/contrib/grpc/ext.rb +0 -15
- data/lib/ddtrace/contrib/grpc/integration.rb +0 -38
- data/lib/ddtrace/contrib/grpc/intercept_with_datadog.rb +0 -49
- data/lib/ddtrace/contrib/grpc/patcher.rb +0 -72
- data/lib/ddtrace/contrib/http/circuit_breaker.rb +0 -63
- data/lib/ddtrace/contrib/http/configuration/settings.rb +0 -27
- data/lib/ddtrace/contrib/http/ext.rb +0 -14
- data/lib/ddtrace/contrib/http/instrumentation.rb +0 -170
- data/lib/ddtrace/contrib/http/integration.rb +0 -45
- data/lib/ddtrace/contrib/http/patcher.rb +0 -26
- data/lib/ddtrace/contrib/http_annotation_helper.rb +0 -10
- data/lib/ddtrace/contrib/integration.rb +0 -16
- data/lib/ddtrace/contrib/mongodb/configuration/settings.rb +0 -28
- data/lib/ddtrace/contrib/mongodb/ext.rb +0 -20
- data/lib/ddtrace/contrib/mongodb/instrumentation.rb +0 -68
- data/lib/ddtrace/contrib/mongodb/integration.rb +0 -38
- data/lib/ddtrace/contrib/mongodb/parsers.rb +0 -68
- data/lib/ddtrace/contrib/mongodb/patcher.rb +0 -31
- data/lib/ddtrace/contrib/mongodb/subscribers.rb +0 -108
- data/lib/ddtrace/contrib/mysql2/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/mysql2/ext.rb +0 -15
- data/lib/ddtrace/contrib/mysql2/instrumentation.rb +0 -60
- data/lib/ddtrace/contrib/mysql2/integration.rb +0 -38
- data/lib/ddtrace/contrib/mysql2/patcher.rb +0 -27
- data/lib/ddtrace/contrib/patchable.rb +0 -59
- data/lib/ddtrace/contrib/patcher.rb +0 -56
- data/lib/ddtrace/contrib/presto/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/presto/ext.rb +0 -25
- data/lib/ddtrace/contrib/presto/instrumentation.rb +0 -107
- data/lib/ddtrace/contrib/presto/integration.rb +0 -38
- data/lib/ddtrace/contrib/presto/patcher.rb +0 -30
- data/lib/ddtrace/contrib/racecar/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/racecar/event.rb +0 -71
- data/lib/ddtrace/contrib/racecar/events/batch.rb +0 -27
- data/lib/ddtrace/contrib/racecar/events/message.rb +0 -27
- data/lib/ddtrace/contrib/racecar/events.rb +0 -30
- data/lib/ddtrace/contrib/racecar/ext.rb +0 -21
- data/lib/ddtrace/contrib/racecar/integration.rb +0 -39
- data/lib/ddtrace/contrib/racecar/patcher.rb +0 -26
- data/lib/ddtrace/contrib/rack/configuration/settings.rb +0 -41
- data/lib/ddtrace/contrib/rack/ext.rb +0 -18
- data/lib/ddtrace/contrib/rack/integration.rb +0 -38
- data/lib/ddtrace/contrib/rack/middlewares.rb +0 -287
- data/lib/ddtrace/contrib/rack/patcher.rb +0 -107
- data/lib/ddtrace/contrib/rack/request_queue.rb +0 -39
- data/lib/ddtrace/contrib/rails/configuration/settings.rb +0 -81
- data/lib/ddtrace/contrib/rails/ext.rb +0 -13
- data/lib/ddtrace/contrib/rails/framework.rb +0 -125
- data/lib/ddtrace/contrib/rails/integration.rb +0 -44
- data/lib/ddtrace/contrib/rails/middlewares.rb +0 -38
- data/lib/ddtrace/contrib/rails/patcher.rb +0 -74
- data/lib/ddtrace/contrib/rails/railtie.rb +0 -17
- data/lib/ddtrace/contrib/rails/utils.rb +0 -20
- data/lib/ddtrace/contrib/rake/configuration/settings.rb +0 -27
- data/lib/ddtrace/contrib/rake/ext.rb +0 -18
- data/lib/ddtrace/contrib/rake/instrumentation.rb +0 -88
- data/lib/ddtrace/contrib/rake/integration.rb +0 -38
- data/lib/ddtrace/contrib/rake/patcher.rb +0 -30
- data/lib/ddtrace/contrib/redis/configuration/resolver.rb +0 -36
- data/lib/ddtrace/contrib/redis/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/redis/ext.rb +0 -18
- data/lib/ddtrace/contrib/redis/integration.rb +0 -42
- data/lib/ddtrace/contrib/redis/patcher.rb +0 -97
- data/lib/ddtrace/contrib/redis/quantize.rb +0 -47
- data/lib/ddtrace/contrib/redis/tags.rb +0 -38
- data/lib/ddtrace/contrib/redis/vendor/resolver.rb +0 -159
- data/lib/ddtrace/contrib/registerable.rb +0 -33
- data/lib/ddtrace/contrib/registry.rb +0 -42
- data/lib/ddtrace/contrib/resque/configuration/settings.rb +0 -26
- data/lib/ddtrace/contrib/resque/ext.rb +0 -14
- data/lib/ddtrace/contrib/resque/integration.rb +0 -47
- data/lib/ddtrace/contrib/resque/patcher.rb +0 -29
- data/lib/ddtrace/contrib/resque/resque_job.rb +0 -80
- data/lib/ddtrace/contrib/rest_client/configuration/settings.rb +0 -26
- data/lib/ddtrace/contrib/rest_client/ext.rb +0 -14
- data/lib/ddtrace/contrib/rest_client/integration.rb +0 -38
- data/lib/ddtrace/contrib/rest_client/patcher.rb +0 -23
- data/lib/ddtrace/contrib/rest_client/request_patch.rb +0 -89
- data/lib/ddtrace/contrib/sequel/configuration/settings.rb +0 -23
- data/lib/ddtrace/contrib/sequel/database.rb +0 -61
- data/lib/ddtrace/contrib/sequel/dataset.rb +0 -62
- data/lib/ddtrace/contrib/sequel/ext.rb +0 -15
- data/lib/ddtrace/contrib/sequel/integration.rb +0 -38
- data/lib/ddtrace/contrib/sequel/patcher.rb +0 -33
- data/lib/ddtrace/contrib/sequel/utils.rb +0 -46
- data/lib/ddtrace/contrib/shoryuken/configuration/settings.rb +0 -24
- data/lib/ddtrace/contrib/shoryuken/ext.rb +0 -18
- data/lib/ddtrace/contrib/shoryuken/integration.rb +0 -39
- data/lib/ddtrace/contrib/shoryuken/patcher.rb +0 -24
- data/lib/ddtrace/contrib/shoryuken/tracer.rb +0 -49
- data/lib/ddtrace/contrib/sidekiq/client_tracer.rb +0 -43
- data/lib/ddtrace/contrib/sidekiq/configuration/settings.rb +0 -31
- data/lib/ddtrace/contrib/sidekiq/ext.rb +0 -23
- data/lib/ddtrace/contrib/sidekiq/integration.rb +0 -38
- data/lib/ddtrace/contrib/sidekiq/patcher.rb +0 -34
- data/lib/ddtrace/contrib/sidekiq/server_tracer.rb +0 -66
- data/lib/ddtrace/contrib/sidekiq/tracing.rb +0 -45
- data/lib/ddtrace/contrib/sinatra/configuration/settings.rb +0 -34
- data/lib/ddtrace/contrib/sinatra/env.rb +0 -38
- data/lib/ddtrace/contrib/sinatra/ext.rb +0 -18
- data/lib/ddtrace/contrib/sinatra/headers.rb +0 -31
- data/lib/ddtrace/contrib/sinatra/integration.rb +0 -38
- data/lib/ddtrace/contrib/sinatra/patcher.rb +0 -27
- data/lib/ddtrace/contrib/sinatra/tracer.rb +0 -87
- data/lib/ddtrace/contrib/sinatra/tracer_middleware.rb +0 -75
- data/lib/ddtrace/contrib/sucker_punch/configuration/settings.rb +0 -25
- data/lib/ddtrace/contrib/sucker_punch/exception_handler.rb +0 -26
- data/lib/ddtrace/contrib/sucker_punch/ext.rb +0 -18
- data/lib/ddtrace/contrib/sucker_punch/instrumentation.rb +0 -84
- data/lib/ddtrace/contrib/sucker_punch/integration.rb +0 -38
- data/lib/ddtrace/contrib/sucker_punch/patcher.rb +0 -42
- data/lib/ddtrace/correlation.rb +0 -35
- data/lib/ddtrace/diagnostics/health.rb +0 -37
- data/lib/ddtrace/distributed_tracing/headers/b3.rb +0 -44
- data/lib/ddtrace/distributed_tracing/headers/b3_single.rb +0 -56
- data/lib/ddtrace/distributed_tracing/headers/datadog.rb +0 -42
- data/lib/ddtrace/distributed_tracing/headers/headers.rb +0 -70
- data/lib/ddtrace/distributed_tracing/headers/helpers.rb +0 -45
- data/lib/ddtrace/encoding.rb +0 -95
- data/lib/ddtrace/environment.rb +0 -27
- data/lib/ddtrace/error.rb +0 -27
- data/lib/ddtrace/event.rb +0 -52
- data/lib/ddtrace/ext/analytics.rb +0 -12
- data/lib/ddtrace/ext/app_types.rb +0 -11
- data/lib/ddtrace/ext/correlation.rb +0 -10
- data/lib/ddtrace/ext/diagnostics.rb +0 -31
- data/lib/ddtrace/ext/distributed.rb +0 -33
- data/lib/ddtrace/ext/environment.rb +0 -13
- data/lib/ddtrace/ext/errors.rb +0 -10
- data/lib/ddtrace/ext/forced_tracing.rb +0 -25
- data/lib/ddtrace/ext/http.rb +0 -46
- data/lib/ddtrace/ext/manual_tracing.rb +0 -9
- data/lib/ddtrace/ext/metrics.rb +0 -15
- data/lib/ddtrace/ext/net.rb +0 -10
- data/lib/ddtrace/ext/priority.rb +0 -16
- data/lib/ddtrace/ext/runtime.rb +0 -26
- data/lib/ddtrace/ext/sampling.rb +0 -16
- data/lib/ddtrace/ext/sql.rb +0 -8
- data/lib/ddtrace/ext/transport.rb +0 -17
- data/lib/ddtrace/forced_tracing.rb +0 -36
- data/lib/ddtrace/logger.rb +0 -81
- data/lib/ddtrace/metrics.rb +0 -222
- data/lib/ddtrace/monkey.rb +0 -58
- data/lib/ddtrace/opentelemetry/extensions.rb +0 -13
- data/lib/ddtrace/opentelemetry/span.rb +0 -33
- data/lib/ddtrace/opentracer/binary_propagator.rb +0 -24
- data/lib/ddtrace/opentracer/carrier.rb +0 -6
- data/lib/ddtrace/opentracer/distributed_headers.rb +0 -52
- data/lib/ddtrace/opentracer/global_tracer.rb +0 -15
- data/lib/ddtrace/opentracer/propagator.rb +0 -22
- data/lib/ddtrace/opentracer/rack_propagator.rb +0 -60
- data/lib/ddtrace/opentracer/scope.rb +0 -15
- data/lib/ddtrace/opentracer/scope_manager.rb +0 -6
- data/lib/ddtrace/opentracer/span.rb +0 -98
- data/lib/ddtrace/opentracer/span_context.rb +0 -14
- data/lib/ddtrace/opentracer/span_context_factory.rb +0 -23
- data/lib/ddtrace/opentracer/text_map_propagator.rb +0 -75
- data/lib/ddtrace/opentracer/thread_local_scope.rb +0 -30
- data/lib/ddtrace/opentracer/thread_local_scope_manager.rb +0 -40
- data/lib/ddtrace/opentracer/tracer.rb +0 -208
- data/lib/ddtrace/opentracer.rb +0 -40
- data/lib/ddtrace/patcher.rb +0 -47
- data/lib/ddtrace/pin.rb +0 -114
- data/lib/ddtrace/pipeline/span_filter.rb +0 -38
- data/lib/ddtrace/pipeline/span_processor.rb +0 -20
- data/lib/ddtrace/pipeline.rb +0 -46
- data/lib/ddtrace/propagation/grpc_propagator.rb +0 -61
- data/lib/ddtrace/propagation/http_propagator.rb +0 -75
- data/lib/ddtrace/quantization/hash.rb +0 -103
- data/lib/ddtrace/quantization/http.rb +0 -86
- data/lib/ddtrace/runtime/cgroup.rb +0 -44
- data/lib/ddtrace/runtime/class_count.rb +0 -17
- data/lib/ddtrace/runtime/container.rb +0 -73
- data/lib/ddtrace/runtime/gc.rb +0 -16
- data/lib/ddtrace/runtime/identity.rb +0 -41
- data/lib/ddtrace/runtime/metrics.rb +0 -93
- data/lib/ddtrace/runtime/object_space.rb +0 -19
- data/lib/ddtrace/runtime/socket.rb +0 -14
- data/lib/ddtrace/runtime/thread_count.rb +0 -16
- data/lib/ddtrace/sampler.rb +0 -290
- data/lib/ddtrace/sampling/matcher.rb +0 -57
- data/lib/ddtrace/sampling/rate_limiter.rb +0 -127
- data/lib/ddtrace/sampling/rule.rb +0 -61
- data/lib/ddtrace/sampling/rule_sampler.rb +0 -125
- data/lib/ddtrace/sampling.rb +0 -2
- data/lib/ddtrace/span.rb +0 -297
- data/lib/ddtrace/sync_writer.rb +0 -72
- data/lib/ddtrace/tracer.rb +0 -437
- data/lib/ddtrace/transport/http/adapters/net.rb +0 -112
- data/lib/ddtrace/transport/http/adapters/registry.rb +0 -24
- data/lib/ddtrace/transport/http/adapters/test.rb +0 -77
- data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -64
- data/lib/ddtrace/transport/http/api/endpoint.rb +0 -27
- data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -22
- data/lib/ddtrace/transport/http/api/instance.rb +0 -29
- data/lib/ddtrace/transport/http/api/map.rb +0 -14
- data/lib/ddtrace/transport/http/api/spec.rb +0 -15
- data/lib/ddtrace/transport/http/api.rb +0 -46
- data/lib/ddtrace/transport/http/builder.rb +0 -165
- data/lib/ddtrace/transport/http/client.rb +0 -107
- data/lib/ddtrace/transport/http/env.rb +0 -48
- data/lib/ddtrace/transport/http/response.rb +0 -26
- data/lib/ddtrace/transport/http/statistics.rb +0 -30
- data/lib/ddtrace/transport/http/traces.rb +0 -140
- data/lib/ddtrace/transport/http.rb +0 -91
- data/lib/ddtrace/transport/io/client.rb +0 -76
- data/lib/ddtrace/transport/io/response.rb +0 -23
- data/lib/ddtrace/transport/io/traces.rb +0 -44
- data/lib/ddtrace/transport/io.rb +0 -26
- data/lib/ddtrace/transport/parcel.rb +0 -17
- data/lib/ddtrace/transport/request.rb +0 -13
- data/lib/ddtrace/transport/response.rb +0 -49
- data/lib/ddtrace/transport/statistics.rb +0 -72
- data/lib/ddtrace/transport/traces.rb +0 -33
- data/lib/ddtrace/utils/database.rb +0 -25
- data/lib/ddtrace/utils/time.rb +0 -14
- data/lib/ddtrace/utils.rb +0 -65
- data/lib/ddtrace/vendor/active_record/connection_specification.rb +0 -301
- data/lib/ddtrace/worker.rb +0 -20
- data/lib/ddtrace/workers/async.rb +0 -165
- data/lib/ddtrace/workers/loop.rb +0 -105
- data/lib/ddtrace/workers/polling.rb +0 -48
- data/lib/ddtrace/workers/queue.rb +0 -39
- data/lib/ddtrace/workers.rb +0 -125
- data/lib/ddtrace/writer.rb +0 -161
- data/tasks/release_gem.rake +0 -28
@@ -0,0 +1,1161 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <ruby/thread.h>
|
3
|
+
#include <ruby/thread_native.h>
|
4
|
+
#include <ruby/debug.h>
|
5
|
+
#include <stdbool.h>
|
6
|
+
#include <stdatomic.h>
|
7
|
+
#include <signal.h>
|
8
|
+
#include <errno.h>
|
9
|
+
|
10
|
+
#include "helpers.h"
|
11
|
+
#include "ruby_helpers.h"
|
12
|
+
#include "collectors_thread_context.h"
|
13
|
+
#include "collectors_dynamic_sampling_rate.h"
|
14
|
+
#include "collectors_idle_sampling_helper.h"
|
15
|
+
#include "collectors_discrete_dynamic_sampler.h"
|
16
|
+
#include "private_vm_api_access.h"
|
17
|
+
#include "setup_signal_handler.h"
|
18
|
+
#include "time_helpers.h"
|
19
|
+
|
20
|
+
#define ERR_CLOCK_FAIL "failed to get clock time"
|
21
|
+
|
22
|
+
// Maximum allowed value for an allocation weight. Attempts to use higher values will result in clamping.
|
23
|
+
unsigned int MAX_ALLOC_WEIGHT = 65535;
|
24
|
+
|
25
|
+
// Used to trigger the execution of Collectors::ThreadState, which implements all of the sampling logic
|
26
|
+
// itself; this class only implements the "when to do it" part.
|
27
|
+
//
|
28
|
+
// This file implements the native bits of the Datadog::Profiling::Collectors::CpuAndWallTimeWorker class
|
29
|
+
|
30
|
+
// ---
|
31
|
+
// Here be dragons: This component is quite fiddly and probably one of the more complex in the profiler as it deals with
|
32
|
+
// multiple threads, signal handlers, global state, etc.
|
33
|
+
//
|
34
|
+
// ## Design notes for this class:
|
35
|
+
//
|
36
|
+
// ### Constraints
|
37
|
+
//
|
38
|
+
// Currently, sampling Ruby threads requires calling Ruby VM APIs that are only safe to call while holding on to the
|
39
|
+
// global VM lock (and are not async-signal safe -- cannot be called from a signal handler).
|
40
|
+
//
|
41
|
+
// @ivoanjo: As a note, I don't think we should think of this constraint as set in stone. Since can reach into the Ruby
|
42
|
+
// internals, we may be able to figure out a way of overcoming it. But it's definitely going to be hard so for now
|
43
|
+
// we're considering it as a given.
|
44
|
+
//
|
45
|
+
// ### Flow for triggering CPU/Wall-time samples
|
46
|
+
//
|
47
|
+
// The flow for triggering samples is as follows:
|
48
|
+
//
|
49
|
+
// 1. Inside the `run_sampling_trigger_loop` function (running in the `CpuAndWallTimeWorker` background thread),
|
50
|
+
// a `SIGPROF` signal gets sent to the current process.
|
51
|
+
//
|
52
|
+
// 2. The `handle_sampling_signal` signal handler function gets called to handle the `SIGPROF` signal.
|
53
|
+
//
|
54
|
+
// Which thread the signal handler function gets called on by the operating system is quite important. We need to perform
|
55
|
+
// an operation -- calling the `rb_postponed_job_register_one` API -- that can only be called from the thread that
|
56
|
+
// is holding on to the global VM lock. So this is the thread we're "hoping" our signal lands on.
|
57
|
+
//
|
58
|
+
// The signal never lands on the `CpuAndWallTimeWorker` background thread because we explicitly block it off from that
|
59
|
+
// thread in `block_sigprof_signal_handler_from_running_in_current_thread`.
|
60
|
+
//
|
61
|
+
// If the signal lands on a thread that is not holding onto the global VM lock, we can't proceed to the next step,
|
62
|
+
// and we need to restart the sampling flow from step 1. (There's still quite a few improvements we can make here,
|
63
|
+
// but this is the current state of the implementation).
|
64
|
+
//
|
65
|
+
// 3. Inside `handle_sampling_signal`, if it's getting executed by the Ruby thread that is holding the global VM lock,
|
66
|
+
// we can call `rb_postponed_job_register_one` to ask the Ruby VM to call our `sample_from_postponed_job` function
|
67
|
+
// "as soon as it can".
|
68
|
+
//
|
69
|
+
// 4. The Ruby VM calls our `sample_from_postponed_job` from a thread holding the global VM lock. A sample is recorded by
|
70
|
+
// calling `thread_context_collector_sample`.
|
71
|
+
//
|
72
|
+
// ### TracePoints and Forking
|
73
|
+
//
|
74
|
+
// When the Ruby VM forks, the CPU/Wall-time profiling stops naturally because it's triggered by a background thread
|
75
|
+
// that doesn't get automatically restarted by the VM on the child process. (The profiler does trigger its restart at
|
76
|
+
// some point -- see `Profiling::Tasks::Setup` for details).
|
77
|
+
//
|
78
|
+
// But this doesn't apply to any `TracePoint`s this class may use, which will continue to be active. Thus, we need to
|
79
|
+
// always remember consider this case of -- the worker thread may not be alive but the `TracePoint`s can continue to
|
80
|
+
// trigger samples.
|
81
|
+
//
|
82
|
+
// ---
|
83
|
+
|
84
|
+
#ifndef NO_POSTPONED_TRIGGER
|
85
|
+
// Used to call the rb_postponed_job_trigger from Ruby 3.3+. These get initialized in
|
86
|
+
// `collectors_cpu_and_wall_time_worker_init` below and always get reused after that.
|
87
|
+
static rb_postponed_job_handle_t sample_from_postponed_job_handle;
|
88
|
+
static rb_postponed_job_handle_t after_gc_from_postponed_job_handle;
|
89
|
+
#endif
|
90
|
+
|
91
|
+
// Contains state for a single CpuAndWallTimeWorker instance
|
92
|
+
struct cpu_and_wall_time_worker_state {
|
93
|
+
// These are immutable after initialization
|
94
|
+
|
95
|
+
bool gc_profiling_enabled;
|
96
|
+
bool no_signals_workaround_enabled;
|
97
|
+
bool dynamic_sampling_rate_enabled;
|
98
|
+
bool allocation_profiling_enabled;
|
99
|
+
bool skip_idle_samples_for_testing;
|
100
|
+
VALUE self_instance;
|
101
|
+
VALUE thread_context_collector_instance;
|
102
|
+
VALUE idle_sampling_helper_instance;
|
103
|
+
VALUE owner_thread;
|
104
|
+
dynamic_sampling_rate_state cpu_dynamic_sampling_rate;
|
105
|
+
discrete_dynamic_sampler allocation_sampler;
|
106
|
+
VALUE gc_tracepoint; // Used to get gc start/finish information
|
107
|
+
VALUE object_allocation_tracepoint; // Used to get allocation counts and allocation profiling
|
108
|
+
|
109
|
+
// These are mutable and used to signal things between the worker thread and other threads
|
110
|
+
|
111
|
+
atomic_bool should_run;
|
112
|
+
// When something goes wrong during sampling, we record the Ruby exception here, so that it can be "re-raised" on
|
113
|
+
// the CpuAndWallTimeWorker thread
|
114
|
+
VALUE failure_exception;
|
115
|
+
// Used by `_native_stop` to flag the worker thread to start (see comment on `_native_sampling_loop`)
|
116
|
+
VALUE stop_thread;
|
117
|
+
|
118
|
+
// Others
|
119
|
+
|
120
|
+
// Used to detect/avoid nested sampling, e.g. when the object_allocation_tracepoint gets triggered by a memory allocation
|
121
|
+
// that happens during another sample.
|
122
|
+
bool during_sample;
|
123
|
+
|
124
|
+
struct stats {
|
125
|
+
// # Generic stats
|
126
|
+
// How many times we tried to trigger a sample
|
127
|
+
unsigned int trigger_sample_attempts;
|
128
|
+
// How many times we tried to simulate signal delivery
|
129
|
+
unsigned int trigger_simulated_signal_delivery_attempts;
|
130
|
+
// How many times we actually simulated signal delivery
|
131
|
+
unsigned int simulated_signal_delivery;
|
132
|
+
// How many times we actually called rb_postponed_job_register_one from a signal handler
|
133
|
+
unsigned int signal_handler_enqueued_sample;
|
134
|
+
// How many times the signal handler was called from the wrong thread
|
135
|
+
unsigned int signal_handler_wrong_thread;
|
136
|
+
// How many times we actually tried to interrupt a thread for sampling
|
137
|
+
unsigned int interrupt_thread_attempts;
|
138
|
+
|
139
|
+
// # Stats for the results of calling rb_postponed_job_register_one
|
140
|
+
// The same function was already waiting to be executed
|
141
|
+
unsigned int postponed_job_skipped_already_existed;
|
142
|
+
// The function was added to the queue successfully
|
143
|
+
unsigned int postponed_job_success;
|
144
|
+
// The queue was full
|
145
|
+
unsigned int postponed_job_full;
|
146
|
+
// The function returned an unknown result code
|
147
|
+
unsigned int postponed_job_unknown_result;
|
148
|
+
|
149
|
+
// # CPU/Walltime sampling stats
|
150
|
+
// How many times we actually CPU/wall sampled
|
151
|
+
unsigned int cpu_sampled;
|
152
|
+
// How many times we skipped a CPU/wall sample because of the dynamic sampling rate mechanism
|
153
|
+
unsigned int cpu_skipped;
|
154
|
+
// Min/max/total wall-time spent on CPU/wall sampling
|
155
|
+
uint64_t cpu_sampling_time_ns_min;
|
156
|
+
uint64_t cpu_sampling_time_ns_max;
|
157
|
+
uint64_t cpu_sampling_time_ns_total;
|
158
|
+
|
159
|
+
// # Allocation sampling stats
|
160
|
+
// How many times we actually allocation sampled
|
161
|
+
uint64_t allocation_sampled;
|
162
|
+
// How many times we skipped an allocation sample because of the dynamic sampling rate mechanism
|
163
|
+
uint64_t allocation_skipped;
|
164
|
+
// Min/max/total wall-time spent on allocation sampling
|
165
|
+
uint64_t allocation_sampling_time_ns_min;
|
166
|
+
uint64_t allocation_sampling_time_ns_max;
|
167
|
+
uint64_t allocation_sampling_time_ns_total;
|
168
|
+
// How many times we saw allocations being done inside a sample
|
169
|
+
unsigned int allocations_during_sample;
|
170
|
+
} stats;
|
171
|
+
};
|
172
|
+
|
173
|
+
static VALUE _native_new(VALUE klass);
|
174
|
+
static VALUE _native_initialize(
|
175
|
+
DDTRACE_UNUSED VALUE _self,
|
176
|
+
VALUE self_instance,
|
177
|
+
VALUE thread_context_collector_instance,
|
178
|
+
VALUE gc_profiling_enabled,
|
179
|
+
VALUE idle_sampling_helper_instance,
|
180
|
+
VALUE no_signals_workaround_enabled,
|
181
|
+
VALUE dynamic_sampling_rate_enabled,
|
182
|
+
VALUE dynamic_sampling_rate_overhead_target_percentage,
|
183
|
+
VALUE allocation_profiling_enabled,
|
184
|
+
VALUE skip_idle_samples_for_testing
|
185
|
+
);
|
186
|
+
static void cpu_and_wall_time_worker_typed_data_mark(void *state_ptr);
|
187
|
+
static VALUE _native_sampling_loop(VALUE self, VALUE instance);
|
188
|
+
static VALUE _native_stop(DDTRACE_UNUSED VALUE _self, VALUE self_instance, VALUE worker_thread);
|
189
|
+
static VALUE stop(VALUE self_instance, VALUE optional_exception);
|
190
|
+
static void stop_state(struct cpu_and_wall_time_worker_state *state, VALUE optional_exception);
|
191
|
+
static void handle_sampling_signal(DDTRACE_UNUSED int _signal, DDTRACE_UNUSED siginfo_t *_info, DDTRACE_UNUSED void *_ucontext);
|
192
|
+
static void *run_sampling_trigger_loop(void *state_ptr);
|
193
|
+
static void interrupt_sampling_trigger_loop(void *state_ptr);
|
194
|
+
static void sample_from_postponed_job(DDTRACE_UNUSED void *_unused);
|
195
|
+
static VALUE rescued_sample_from_postponed_job(VALUE self_instance);
|
196
|
+
static VALUE handle_sampling_failure(VALUE self_instance, VALUE exception);
|
197
|
+
static VALUE _native_current_sigprof_signal_handler(DDTRACE_UNUSED VALUE self);
|
198
|
+
static VALUE release_gvl_and_run_sampling_trigger_loop(VALUE instance);
|
199
|
+
static VALUE _native_is_running(DDTRACE_UNUSED VALUE self, VALUE instance);
|
200
|
+
static void testing_signal_handler(DDTRACE_UNUSED int _signal, DDTRACE_UNUSED siginfo_t *_info, DDTRACE_UNUSED void *_ucontext);
|
201
|
+
static VALUE _native_install_testing_signal_handler(DDTRACE_UNUSED VALUE self);
|
202
|
+
static VALUE _native_remove_testing_signal_handler(DDTRACE_UNUSED VALUE self);
|
203
|
+
static VALUE _native_trigger_sample(DDTRACE_UNUSED VALUE self);
|
204
|
+
static VALUE _native_gc_tracepoint(DDTRACE_UNUSED VALUE self, VALUE instance);
|
205
|
+
static void on_gc_event(VALUE tracepoint_data, DDTRACE_UNUSED void *unused);
|
206
|
+
static void after_gc_from_postponed_job(DDTRACE_UNUSED void *_unused);
|
207
|
+
static VALUE safely_call(VALUE (*function_to_call_safely)(VALUE), VALUE function_to_call_safely_arg, VALUE instance);
|
208
|
+
static VALUE _native_simulate_handle_sampling_signal(DDTRACE_UNUSED VALUE self);
|
209
|
+
static VALUE _native_simulate_sample_from_postponed_job(DDTRACE_UNUSED VALUE self);
|
210
|
+
static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE instance);
|
211
|
+
static VALUE _native_is_sigprof_blocked_in_current_thread(DDTRACE_UNUSED VALUE self);
|
212
|
+
static VALUE _native_stats(DDTRACE_UNUSED VALUE self, VALUE instance);
|
213
|
+
static VALUE _native_stats_reset_not_thread_safe(DDTRACE_UNUSED VALUE self, VALUE instance);
|
214
|
+
void *simulate_sampling_signal_delivery(DDTRACE_UNUSED void *_unused);
|
215
|
+
static void grab_gvl_and_sample(void);
|
216
|
+
static void reset_stats_not_thread_safe(struct cpu_and_wall_time_worker_state *state);
|
217
|
+
static void sleep_for(uint64_t time_ns);
|
218
|
+
static VALUE _native_allocation_count(DDTRACE_UNUSED VALUE self);
|
219
|
+
static void on_newobj_event(VALUE tracepoint_data, DDTRACE_UNUSED void *unused);
|
220
|
+
static void disable_tracepoints(struct cpu_and_wall_time_worker_state *state);
|
221
|
+
static VALUE _native_with_blocked_sigprof(DDTRACE_UNUSED VALUE self);
|
222
|
+
static VALUE rescued_sample_allocation(VALUE tracepoint_data);
|
223
|
+
static void delayed_error(struct cpu_and_wall_time_worker_state *state, const char *error);
|
224
|
+
static VALUE _native_delayed_error(DDTRACE_UNUSED VALUE self, VALUE instance, VALUE error_msg);
|
225
|
+
|
226
|
+
// Note on sampler global state safety:
|
227
|
+
//
|
228
|
+
// Both `active_sampler_instance` and `active_sampler_instance_state` are **GLOBAL** state. Be careful when accessing
|
229
|
+
// or modifying them.
|
230
|
+
// In particular, it's important to only mutate them while holding the global VM lock, to ensure correctness.
|
231
|
+
//
|
232
|
+
// This global state is needed because a bunch of functions on this file need to access it from situations
|
233
|
+
// (e.g. signal handler) where it's impossible or just awkward to pass it as an argument.
|
234
|
+
static VALUE active_sampler_instance = Qnil;
|
235
|
+
static struct cpu_and_wall_time_worker_state *active_sampler_instance_state = NULL;
|
236
|
+
|
237
|
+
// See handle_sampling_signal for details on what this does
|
238
|
+
#ifdef NO_POSTPONED_TRIGGER
|
239
|
+
static void *gc_finalize_deferred_workaround;
|
240
|
+
#endif
|
241
|
+
|
242
|
+
// Used to implement CpuAndWallTimeWorker._native_allocation_count . To be able to use cheap thread-local variables
|
243
|
+
// (here with `__thread`, see https://gcc.gnu.org/onlinedocs/gcc/Thread-Local.html), this needs to be global.
|
244
|
+
//
|
245
|
+
// Carryover of state between profiler instances can happen and is not considered to be a problem -- see expectations for this
|
246
|
+
// API documented in profiling.rb .
|
247
|
+
__thread uint64_t allocation_count = 0;
|
248
|
+
|
249
|
+
void collectors_cpu_and_wall_time_worker_init(VALUE profiling_module) {
|
250
|
+
rb_global_variable(&active_sampler_instance);
|
251
|
+
|
252
|
+
#ifndef NO_POSTPONED_TRIGGER
|
253
|
+
int unused_flags = 0;
|
254
|
+
sample_from_postponed_job_handle = rb_postponed_job_preregister(unused_flags, sample_from_postponed_job, NULL);
|
255
|
+
after_gc_from_postponed_job_handle = rb_postponed_job_preregister(unused_flags, after_gc_from_postponed_job, NULL);
|
256
|
+
|
257
|
+
if (sample_from_postponed_job_handle == POSTPONED_JOB_HANDLE_INVALID || after_gc_from_postponed_job_handle == POSTPONED_JOB_HANDLE_INVALID) {
|
258
|
+
rb_raise(rb_eRuntimeError, "Failed to register profiler postponed jobs (got POSTPONED_JOB_HANDLE_INVALID)");
|
259
|
+
}
|
260
|
+
#else
|
261
|
+
gc_finalize_deferred_workaround = objspace_ptr_for_gc_finalize_deferred_workaround();
|
262
|
+
#endif
|
263
|
+
|
264
|
+
VALUE collectors_module = rb_define_module_under(profiling_module, "Collectors");
|
265
|
+
VALUE collectors_cpu_and_wall_time_worker_class = rb_define_class_under(collectors_module, "CpuAndWallTimeWorker", rb_cObject);
|
266
|
+
// Hosts methods used for testing the native code using RSpec
|
267
|
+
VALUE testing_module = rb_define_module_under(collectors_cpu_and_wall_time_worker_class, "Testing");
|
268
|
+
|
269
|
+
// Instances of the CpuAndWallTimeWorker class are "TypedData" objects.
|
270
|
+
// "TypedData" objects are special objects in the Ruby VM that can wrap C structs.
|
271
|
+
// In this case, it wraps the cpu_and_wall_time_worker_state.
|
272
|
+
//
|
273
|
+
// Because Ruby doesn't know how to initialize native-level structs, we MUST override the allocation function for objects
|
274
|
+
// of this class so that we can manage this part. Not overriding or disabling the allocation function is a common
|
275
|
+
// gotcha for "TypedData" objects that can very easily lead to VM crashes, see for instance
|
276
|
+
// https://bugs.ruby-lang.org/issues/18007 for a discussion around this.
|
277
|
+
rb_define_alloc_func(collectors_cpu_and_wall_time_worker_class, _native_new);
|
278
|
+
|
279
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_initialize", _native_initialize, 9);
|
280
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_sampling_loop", _native_sampling_loop, 1);
|
281
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_stop", _native_stop, 2);
|
282
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_reset_after_fork", _native_reset_after_fork, 1);
|
283
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_stats", _native_stats, 1);
|
284
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_stats_reset_not_thread_safe", _native_stats_reset_not_thread_safe, 1);
|
285
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_allocation_count", _native_allocation_count, 0);
|
286
|
+
rb_define_singleton_method(collectors_cpu_and_wall_time_worker_class, "_native_is_running?", _native_is_running, 1);
|
287
|
+
rb_define_singleton_method(testing_module, "_native_current_sigprof_signal_handler", _native_current_sigprof_signal_handler, 0);
|
288
|
+
// TODO: Remove `_native_is_running` from `testing_module` once `prof-correctness` has been updated to not need it
|
289
|
+
rb_define_singleton_method(testing_module, "_native_is_running?", _native_is_running, 1);
|
290
|
+
rb_define_singleton_method(testing_module, "_native_install_testing_signal_handler", _native_install_testing_signal_handler, 0);
|
291
|
+
rb_define_singleton_method(testing_module, "_native_remove_testing_signal_handler", _native_remove_testing_signal_handler, 0);
|
292
|
+
rb_define_singleton_method(testing_module, "_native_trigger_sample", _native_trigger_sample, 0);
|
293
|
+
rb_define_singleton_method(testing_module, "_native_gc_tracepoint", _native_gc_tracepoint, 1);
|
294
|
+
rb_define_singleton_method(testing_module, "_native_simulate_handle_sampling_signal", _native_simulate_handle_sampling_signal, 0);
|
295
|
+
rb_define_singleton_method(testing_module, "_native_simulate_sample_from_postponed_job", _native_simulate_sample_from_postponed_job, 0);
|
296
|
+
rb_define_singleton_method(testing_module, "_native_is_sigprof_blocked_in_current_thread", _native_is_sigprof_blocked_in_current_thread, 0);
|
297
|
+
rb_define_singleton_method(testing_module, "_native_with_blocked_sigprof", _native_with_blocked_sigprof, 0);
|
298
|
+
rb_define_singleton_method(testing_module, "_native_delayed_error", _native_delayed_error, 2);
|
299
|
+
}
|
300
|
+
|
301
|
+
// This structure is used to define a Ruby object that stores a pointer to a struct cpu_and_wall_time_worker_state
|
302
|
+
// See also https://github.com/ruby/ruby/blob/master/doc/extension.rdoc for how this works
|
303
|
+
static const rb_data_type_t cpu_and_wall_time_worker_typed_data = {
|
304
|
+
.wrap_struct_name = "Datadog::Profiling::Collectors::CpuAndWallTimeWorker",
|
305
|
+
.function = {
|
306
|
+
.dmark = cpu_and_wall_time_worker_typed_data_mark,
|
307
|
+
.dfree = RUBY_DEFAULT_FREE,
|
308
|
+
.dsize = NULL, // We don't track memory usage (although it'd be cool if we did!)
|
309
|
+
//.dcompact = NULL, // FIXME: Add support for compaction
|
310
|
+
},
|
311
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
312
|
+
};
|
313
|
+
|
314
|
+
static VALUE _native_new(VALUE klass) {
|
315
|
+
struct cpu_and_wall_time_worker_state *state = ruby_xcalloc(1, sizeof(struct cpu_and_wall_time_worker_state));
|
316
|
+
|
317
|
+
// Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory
|
318
|
+
// being leaked.
|
319
|
+
|
320
|
+
state->gc_profiling_enabled = false;
|
321
|
+
state->no_signals_workaround_enabled = false;
|
322
|
+
state->dynamic_sampling_rate_enabled = true;
|
323
|
+
state->allocation_profiling_enabled = false;
|
324
|
+
state->skip_idle_samples_for_testing = false;
|
325
|
+
state->thread_context_collector_instance = Qnil;
|
326
|
+
state->idle_sampling_helper_instance = Qnil;
|
327
|
+
state->owner_thread = Qnil;
|
328
|
+
dynamic_sampling_rate_init(&state->cpu_dynamic_sampling_rate);
|
329
|
+
state->gc_tracepoint = Qnil;
|
330
|
+
state->object_allocation_tracepoint = Qnil;
|
331
|
+
|
332
|
+
atomic_init(&state->should_run, false);
|
333
|
+
state->failure_exception = Qnil;
|
334
|
+
state->stop_thread = Qnil;
|
335
|
+
|
336
|
+
state->during_sample = false;
|
337
|
+
|
338
|
+
reset_stats_not_thread_safe(state);
|
339
|
+
|
340
|
+
long now = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
|
341
|
+
if (now == 0) {
|
342
|
+
ruby_xfree(state);
|
343
|
+
rb_raise(rb_eRuntimeError, ERR_CLOCK_FAIL);
|
344
|
+
}
|
345
|
+
|
346
|
+
discrete_dynamic_sampler_init(&state->allocation_sampler, "allocation", now);
|
347
|
+
|
348
|
+
return state->self_instance = TypedData_Wrap_Struct(klass, &cpu_and_wall_time_worker_typed_data, state);
|
349
|
+
}
|
350
|
+
|
351
|
+
static VALUE _native_initialize(
|
352
|
+
DDTRACE_UNUSED VALUE _self,
|
353
|
+
VALUE self_instance,
|
354
|
+
VALUE thread_context_collector_instance,
|
355
|
+
VALUE gc_profiling_enabled,
|
356
|
+
VALUE idle_sampling_helper_instance,
|
357
|
+
VALUE no_signals_workaround_enabled,
|
358
|
+
VALUE dynamic_sampling_rate_enabled,
|
359
|
+
VALUE dynamic_sampling_rate_overhead_target_percentage,
|
360
|
+
VALUE allocation_profiling_enabled,
|
361
|
+
VALUE skip_idle_samples_for_testing
|
362
|
+
) {
|
363
|
+
ENFORCE_BOOLEAN(gc_profiling_enabled);
|
364
|
+
ENFORCE_BOOLEAN(no_signals_workaround_enabled);
|
365
|
+
ENFORCE_BOOLEAN(dynamic_sampling_rate_enabled);
|
366
|
+
ENFORCE_TYPE(dynamic_sampling_rate_overhead_target_percentage, T_FLOAT);
|
367
|
+
ENFORCE_BOOLEAN(allocation_profiling_enabled);
|
368
|
+
ENFORCE_BOOLEAN(skip_idle_samples_for_testing)
|
369
|
+
|
370
|
+
struct cpu_and_wall_time_worker_state *state;
|
371
|
+
TypedData_Get_Struct(self_instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
372
|
+
|
373
|
+
state->gc_profiling_enabled = (gc_profiling_enabled == Qtrue);
|
374
|
+
state->no_signals_workaround_enabled = (no_signals_workaround_enabled == Qtrue);
|
375
|
+
state->dynamic_sampling_rate_enabled = (dynamic_sampling_rate_enabled == Qtrue);
|
376
|
+
state->allocation_profiling_enabled = (allocation_profiling_enabled == Qtrue);
|
377
|
+
state->skip_idle_samples_for_testing = (skip_idle_samples_for_testing == Qtrue);
|
378
|
+
|
379
|
+
double total_overhead_target_percentage = NUM2DBL(dynamic_sampling_rate_overhead_target_percentage);
|
380
|
+
if (!state->allocation_profiling_enabled) {
|
381
|
+
dynamic_sampling_rate_set_overhead_target_percentage(&state->cpu_dynamic_sampling_rate, total_overhead_target_percentage);
|
382
|
+
} else {
|
383
|
+
// TODO: May be nice to offer customization here? Distribute available "overhead" margin with a bias towards one or the other
|
384
|
+
// sampler.
|
385
|
+
dynamic_sampling_rate_set_overhead_target_percentage(&state->cpu_dynamic_sampling_rate, total_overhead_target_percentage / 2);
|
386
|
+
long now = monotonic_wall_time_now_ns(RAISE_ON_FAILURE);
|
387
|
+
discrete_dynamic_sampler_set_overhead_target_percentage(&state->allocation_sampler, total_overhead_target_percentage / 2, now);
|
388
|
+
}
|
389
|
+
|
390
|
+
state->thread_context_collector_instance = enforce_thread_context_collector_instance(thread_context_collector_instance);
|
391
|
+
state->idle_sampling_helper_instance = idle_sampling_helper_instance;
|
392
|
+
state->gc_tracepoint = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_GC_ENTER | RUBY_INTERNAL_EVENT_GC_EXIT, on_gc_event, NULL /* unused */);
|
393
|
+
state->object_allocation_tracepoint = rb_tracepoint_new(Qnil, RUBY_INTERNAL_EVENT_NEWOBJ, on_newobj_event, NULL /* unused */);
|
394
|
+
|
395
|
+
return Qtrue;
|
396
|
+
}
|
397
|
+
|
398
|
+
// Since our state contains references to Ruby objects, we need to tell the Ruby GC about them
|
399
|
+
static void cpu_and_wall_time_worker_typed_data_mark(void *state_ptr) {
|
400
|
+
struct cpu_and_wall_time_worker_state *state = (struct cpu_and_wall_time_worker_state *) state_ptr;
|
401
|
+
|
402
|
+
rb_gc_mark(state->thread_context_collector_instance);
|
403
|
+
rb_gc_mark(state->idle_sampling_helper_instance);
|
404
|
+
rb_gc_mark(state->owner_thread);
|
405
|
+
rb_gc_mark(state->failure_exception);
|
406
|
+
rb_gc_mark(state->stop_thread);
|
407
|
+
rb_gc_mark(state->gc_tracepoint);
|
408
|
+
rb_gc_mark(state->object_allocation_tracepoint);
|
409
|
+
}
|
410
|
+
|
411
|
+
// Called in a background thread created in CpuAndWallTimeWorker#start
|
412
|
+
static VALUE _native_sampling_loop(DDTRACE_UNUSED VALUE _self, VALUE instance) {
|
413
|
+
struct cpu_and_wall_time_worker_state *state;
|
414
|
+
TypedData_Get_Struct(instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
415
|
+
|
416
|
+
// If we already got a delayed exception registered even before starting, raise before starting
|
417
|
+
if (state->failure_exception != Qnil) {
|
418
|
+
disable_tracepoints(state);
|
419
|
+
rb_exc_raise(state->failure_exception);
|
420
|
+
}
|
421
|
+
|
422
|
+
struct cpu_and_wall_time_worker_state *old_state = active_sampler_instance_state;
|
423
|
+
if (old_state != NULL) {
|
424
|
+
if (is_thread_alive(old_state->owner_thread)) {
|
425
|
+
rb_raise(
|
426
|
+
rb_eRuntimeError,
|
427
|
+
"Could not start CpuAndWallTimeWorker: There's already another instance of CpuAndWallTimeWorker active in a different thread"
|
428
|
+
);
|
429
|
+
} else {
|
430
|
+
// The previously active thread seems to have died without cleaning up after itself.
|
431
|
+
// In this case, we can still go ahead and start the profiler BUT we make sure to disable any existing tracepoint
|
432
|
+
// first as:
|
433
|
+
// a) If this is a new instance of the CpuAndWallTimeWorker, we don't want the tracepoint from the old instance
|
434
|
+
// being kept around
|
435
|
+
// b) If this is the same instance of the CpuAndWallTimeWorker if we call enable on a tracepoint that is already
|
436
|
+
// enabled, it will start firing more than once, see https://bugs.ruby-lang.org/issues/19114 for details.
|
437
|
+
disable_tracepoints(old_state);
|
438
|
+
}
|
439
|
+
}
|
440
|
+
|
441
|
+
// We use `stop_thread` to distinguish when `_native_stop` was called before we actually had a chance to start. In this
|
442
|
+
// situation we stop immediately and never even start the sampling trigger loop.
|
443
|
+
if (state->stop_thread == rb_thread_current()) return Qnil;
|
444
|
+
|
445
|
+
// Reset the dynamic sampling rate state, if any (reminder: the monotonic clock reference may change after a fork)
|
446
|
+
dynamic_sampling_rate_reset(&state->cpu_dynamic_sampling_rate);
|
447
|
+
long now = monotonic_wall_time_now_ns(RAISE_ON_FAILURE);
|
448
|
+
discrete_dynamic_sampler_reset(&state->allocation_sampler, now);
|
449
|
+
|
450
|
+
// This write to a global is thread-safe BECAUSE we're still holding on to the global VM lock at this point
|
451
|
+
active_sampler_instance_state = state;
|
452
|
+
active_sampler_instance = instance;
|
453
|
+
state->owner_thread = rb_thread_current();
|
454
|
+
|
455
|
+
atomic_store(&state->should_run, true);
|
456
|
+
|
457
|
+
block_sigprof_signal_handler_from_running_in_current_thread(); // We want to interrupt the thread with the global VM lock, never this one
|
458
|
+
|
459
|
+
// Release GVL, get to the actual work!
|
460
|
+
int exception_state;
|
461
|
+
rb_protect(release_gvl_and_run_sampling_trigger_loop, instance, &exception_state);
|
462
|
+
|
463
|
+
// The sample trigger loop finished (either cleanly or with an error); let's clean up
|
464
|
+
|
465
|
+
disable_tracepoints(state);
|
466
|
+
|
467
|
+
active_sampler_instance_state = NULL;
|
468
|
+
active_sampler_instance = Qnil;
|
469
|
+
state->owner_thread = Qnil;
|
470
|
+
|
471
|
+
// If this `Thread` is about to die, why is this important? It's because Ruby caches native threads for a period after
|
472
|
+
// the `Thread` dies, and reuses them if a new Ruby `Thread` gets created. This means that while conceptually the
|
473
|
+
// worker background `Thread` is about to die, the low-level native OS thread can be reused for something else in the Ruby app.
|
474
|
+
// Then, the reused thread would "inherit" the SIGPROF blocking, which is... really unexpected.
|
475
|
+
// This actually caused a flaky test -- the `native_extension_spec.rb` creates a `Thread` and tries to specifically
|
476
|
+
// send SIGPROF signals to it, and oops it could fail if it got the reused native thread from the worker which still
|
477
|
+
// had SIGPROF delivery blocked. :hide_the_pain_harold:
|
478
|
+
unblock_sigprof_signal_handler_from_running_in_current_thread();
|
479
|
+
|
480
|
+
// Why replace and not use remove the signal handler? We do this because when a process receives a SIGPROF without
|
481
|
+
// having an explicit signal handler set up, the process will instantly terminate with a confusing
|
482
|
+
// "Profiling timer expired" message left behind. (This message doesn't come from us -- it's the default message for
|
483
|
+
// an unhandled SIGPROF. Pretty confusing UNIX/POSIX behavior...)
|
484
|
+
//
|
485
|
+
// Unfortunately, because signal delivery is asynchronous, there's no way to guarantee that there are no pending
|
486
|
+
// profiler-sent signals by the time we get here and want to clean up.
|
487
|
+
// @ivoanjo: I suspect this will never happen, but the cost of getting it wrong is really high (VM terminates) so this
|
488
|
+
// is a just-in-case situation.
|
489
|
+
//
|
490
|
+
// Note 2: This can raise exceptions as well, so make sure that all cleanups are done by the time we get here.
|
491
|
+
replace_sigprof_signal_handler_with_empty_handler(handle_sampling_signal);
|
492
|
+
|
493
|
+
// Ensure that instance is not garbage collected while the native sampling loop is running; this is probably not needed, but just in case
|
494
|
+
RB_GC_GUARD(instance);
|
495
|
+
|
496
|
+
if (exception_state) rb_jump_tag(exception_state); // Re-raise any exception that happened
|
497
|
+
|
498
|
+
return Qnil;
|
499
|
+
}
|
500
|
+
|
501
|
+
static VALUE _native_stop(DDTRACE_UNUSED VALUE _self, VALUE self_instance, VALUE worker_thread) {
|
502
|
+
struct cpu_and_wall_time_worker_state *state;
|
503
|
+
TypedData_Get_Struct(self_instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
504
|
+
|
505
|
+
state->stop_thread = worker_thread;
|
506
|
+
|
507
|
+
return stop(self_instance, /* optional_exception: */ Qnil);
|
508
|
+
}
|
509
|
+
|
510
|
+
static void stop_state(struct cpu_and_wall_time_worker_state *state, VALUE optional_exception) {
|
511
|
+
atomic_store(&state->should_run, false);
|
512
|
+
state->failure_exception = optional_exception;
|
513
|
+
|
514
|
+
// Disable the tracepoints as soon as possible, so the VM doesn't keep on calling them
|
515
|
+
disable_tracepoints(state);
|
516
|
+
}
|
517
|
+
|
518
|
+
static VALUE stop(VALUE self_instance, VALUE optional_exception) {
|
519
|
+
struct cpu_and_wall_time_worker_state *state;
|
520
|
+
TypedData_Get_Struct(self_instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
521
|
+
|
522
|
+
stop_state(state, optional_exception);
|
523
|
+
|
524
|
+
return Qtrue;
|
525
|
+
}
|
526
|
+
|
527
|
+
// NOTE: Remember that this will run in the thread and within the scope of user code, including user C code.
|
528
|
+
// We need to be careful not to change any state that may be observed OR to restore it if we do. For instance, if anything
|
529
|
+
// we do here can set `errno`, then we must be careful to restore the old `errno` after the fact.
|
530
|
+
static void handle_sampling_signal(DDTRACE_UNUSED int _signal, DDTRACE_UNUSED siginfo_t *_info, DDTRACE_UNUSED void *_ucontext) {
|
531
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
532
|
+
|
533
|
+
// This can potentially happen if the CpuAndWallTimeWorker was stopped while the signal delivery was happening; nothing to do
|
534
|
+
if (state == NULL) return;
|
535
|
+
|
536
|
+
if (
|
537
|
+
!ruby_native_thread_p() || // Not a Ruby thread
|
538
|
+
!is_current_thread_holding_the_gvl() || // Not safe to enqueue a sample from this thread
|
539
|
+
!ddtrace_rb_ractor_main_p() // We're not on the main Ractor; we currently don't support profiling non-main Ractors
|
540
|
+
) {
|
541
|
+
state->stats.signal_handler_wrong_thread++;
|
542
|
+
return;
|
543
|
+
}
|
544
|
+
|
545
|
+
// We implicitly assume there can be no concurrent nor nested calls to handle_sampling_signal because
|
546
|
+
// a) we get triggered using SIGPROF, and the docs state a second SIGPROF will not interrupt an existing one
|
547
|
+
// b) we validate we are in the thread that has the global VM lock; if a different thread gets a signal, it will return early
|
548
|
+
// because it will not have the global VM lock
|
549
|
+
|
550
|
+
// Note: rb_postponed_job_register_one ensures that if there's a previous sample_from_postponed_job queued for execution
|
551
|
+
// then we will not queue a second one. It does this by doing a linear scan on the existing jobs; in the future we
|
552
|
+
// may want to implement that check ourselves.
|
553
|
+
|
554
|
+
state->stats.signal_handler_enqueued_sample++;
|
555
|
+
|
556
|
+
// Note: If we ever want to get rid of rb_postponed_job_register_one, remember not to clobber Ruby exceptions, as
|
557
|
+
// this function does this helpful job for us now -- https://github.com/ruby/ruby/commit/a98e343d39c4d7bf1e2190b076720f32d9f298b3.
|
558
|
+
#ifndef NO_POSTPONED_TRIGGER // Ruby 3.3+
|
559
|
+
rb_postponed_job_trigger(sample_from_postponed_job_handle);
|
560
|
+
state->stats.postponed_job_success++; // Always succeeds
|
561
|
+
#else
|
562
|
+
|
563
|
+
// This is a workaround for https://bugs.ruby-lang.org/issues/19991 (for Ruby < 3.3)
|
564
|
+
//
|
565
|
+
// TL;DR the `rb_postponed_job_register_one` API is not atomic (which is why it got replaced by `rb_postponed_job_trigger`)
|
566
|
+
// and in rare cases can cause VM crashes.
|
567
|
+
//
|
568
|
+
// Specifically, if we're interrupting `rb_postponed_job_flush` (the function that processes postponed jobs), the way
|
569
|
+
// that this function reads the jobs is not atomic, and can cause our call to
|
570
|
+
// `rb_postponed_job_register(function, arg)` to clobber an existing job that is getting dequeued.
|
571
|
+
// Clobbering an existing job is somewhat annoying, but the worst part is that it can happen that we clobber only
|
572
|
+
// the existing job's arguments.
|
573
|
+
// As surveyed in https://github.com/ruby/ruby/pull/8949#issuecomment-1821441370 clobbering the arguments turns out
|
574
|
+
// to not matter in many cases as usually `rb_postponed_job_register` calls in the VM and ecosystem ignore the argument.
|
575
|
+
//
|
576
|
+
// https://bugs.ruby-lang.org/issues/19991 is the exception: inside Ruby's `gc.c`, when dealing with object
|
577
|
+
// finalizers, Ruby calls `gc_finalize_deferred_register` which internally calls
|
578
|
+
// `rb_postponed_job_register_one(gc_finalize_deferred, objspace)`.
|
579
|
+
// Clobbering this call means that `gc_finalize_deferred` would get called with `NULL`, causing a segmentation fault.
|
580
|
+
//
|
581
|
+
// Note that this is quite rare: our signal needs to land at exactly the point where the VM has read the function
|
582
|
+
// to execute, but has yet to read the arguments. @ivoanjo: I could only reproduce it by manually changing the VM
|
583
|
+
// code to simulate this happening.
|
584
|
+
//
|
585
|
+
// Thus, our workaround is simple: we pass in objspace as our argument, just in case the clobbering happens.
|
586
|
+
// In the happy path, we never use this argument so it makes no difference. In the buggy path, we avoid crashing the VM.
|
587
|
+
int result = rb_postponed_job_register(0, sample_from_postponed_job, gc_finalize_deferred_workaround /* instead of NULL */);
|
588
|
+
|
589
|
+
// Officially, the result of rb_postponed_job_register_one is documented as being opaque, but in practice it does not
|
590
|
+
// seem to have changed between Ruby 2.3 and 3.2, and so we track it as a debugging mechanism
|
591
|
+
switch (result) {
|
592
|
+
case 0:
|
593
|
+
state->stats.postponed_job_full++; break;
|
594
|
+
case 1:
|
595
|
+
state->stats.postponed_job_success++; break;
|
596
|
+
case 2:
|
597
|
+
state->stats.postponed_job_skipped_already_existed++; break;
|
598
|
+
default:
|
599
|
+
state->stats.postponed_job_unknown_result++;
|
600
|
+
}
|
601
|
+
#endif
|
602
|
+
}
|
603
|
+
|
604
|
+
// The actual sampling trigger loop always runs **without** the global vm lock.
|
605
|
+
static void *run_sampling_trigger_loop(void *state_ptr) {
|
606
|
+
struct cpu_and_wall_time_worker_state *state = (struct cpu_and_wall_time_worker_state *) state_ptr;
|
607
|
+
|
608
|
+
uint64_t minimum_time_between_signals = MILLIS_AS_NS(10);
|
609
|
+
|
610
|
+
while (atomic_load(&state->should_run)) {
|
611
|
+
state->stats.trigger_sample_attempts++;
|
612
|
+
|
613
|
+
if (state->no_signals_workaround_enabled) {
|
614
|
+
// In the no_signals_workaround_enabled mode, the profiler never sends SIGPROF signals.
|
615
|
+
//
|
616
|
+
// This is a fallback for a few incompatibilities and limitations -- see the code that decides when to enable
|
617
|
+
// `no_signals_workaround_enabled` in `Profiling::Component` for details.
|
618
|
+
//
|
619
|
+
// Thus, we instead pretty please ask Ruby to let us run. This means profiling data can be biased by when the Ruby
|
620
|
+
// scheduler chooses to schedule us.
|
621
|
+
state->stats.trigger_simulated_signal_delivery_attempts++;
|
622
|
+
grab_gvl_and_sample(); // Note: Can raise exceptions
|
623
|
+
} else {
|
624
|
+
current_gvl_owner owner = gvl_owner();
|
625
|
+
if (owner.valid) {
|
626
|
+
// Note that reading the GVL owner and sending them a signal is a race -- the Ruby VM keeps on executing while
|
627
|
+
// we're doing this, so we may still not signal the correct thread from time to time, but our signal handler
|
628
|
+
// includes a check to see if it got called in the right thread
|
629
|
+
state->stats.interrupt_thread_attempts++;
|
630
|
+
pthread_kill(owner.owner, SIGPROF);
|
631
|
+
} else {
|
632
|
+
if (state->skip_idle_samples_for_testing) {
|
633
|
+
// This was added to make sure our tests don't accidentally pass due to idle samples. Specifically, if we
|
634
|
+
// comment out the thread interruption code inside `if (owner.valid)` above, our tests should not pass!
|
635
|
+
} else {
|
636
|
+
// If no thread owns the Global VM Lock, the application is probably idle at the moment. We still want to sample
|
637
|
+
// so we "ask a friend" (the IdleSamplingHelper component) to grab the GVL and simulate getting a SIGPROF.
|
638
|
+
//
|
639
|
+
// In a previous version of the code, we called `grab_gvl_and_sample` directly BUT this was problematic because
|
640
|
+
// Ruby may concurrently get busy and so the CpuAndWallTimeWorker would be blocked in line to acquire the GVL
|
641
|
+
// for an uncontrolled amount of time. (This can still happen to the IdleSamplingHelper, but the
|
642
|
+
// CpuAndWallTimeWorker will still be free to interrupt the Ruby VM and keep sampling for the entire blocking period).
|
643
|
+
state->stats.trigger_simulated_signal_delivery_attempts++;
|
644
|
+
idle_sampling_helper_request_action(state->idle_sampling_helper_instance, grab_gvl_and_sample);
|
645
|
+
}
|
646
|
+
}
|
647
|
+
}
|
648
|
+
|
649
|
+
sleep_for(minimum_time_between_signals);
|
650
|
+
|
651
|
+
// The dynamic sampling rate module keeps track of how long samples are taking, and in here we extend our sleep time
|
652
|
+
// to take that into account.
|
653
|
+
// Note that we deliberately should NOT combine this sleep_for with the one above because the result of
|
654
|
+
// `dynamic_sampling_rate_get_sleep` may have changed while the above sleep was ongoing.
|
655
|
+
uint64_t extra_sleep =
|
656
|
+
dynamic_sampling_rate_get_sleep(&state->cpu_dynamic_sampling_rate, monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE));
|
657
|
+
if (state->dynamic_sampling_rate_enabled && extra_sleep > 0) sleep_for(extra_sleep);
|
658
|
+
}
|
659
|
+
|
660
|
+
return NULL; // Unused
|
661
|
+
}
|
662
|
+
|
663
|
+
// This is called by the Ruby VM when it wants to shut down the background thread
|
664
|
+
static void interrupt_sampling_trigger_loop(void *state_ptr) {
|
665
|
+
struct cpu_and_wall_time_worker_state *state = (struct cpu_and_wall_time_worker_state *) state_ptr;
|
666
|
+
|
667
|
+
atomic_store(&state->should_run, false);
|
668
|
+
}
|
669
|
+
|
670
|
+
static void sample_from_postponed_job(DDTRACE_UNUSED void *_unused) {
|
671
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
672
|
+
|
673
|
+
// This can potentially happen if the CpuAndWallTimeWorker was stopped while the postponed job was waiting to be executed; nothing to do
|
674
|
+
if (state == NULL) return;
|
675
|
+
|
676
|
+
// @ivoanjo: I'm not sure this can ever happen because `handle_sampling_signal` only enqueues this callback if
|
677
|
+
// it's running on the main Ractor, but just in case...
|
678
|
+
if (!ddtrace_rb_ractor_main_p()) {
|
679
|
+
return; // We're not on the main Ractor; we currently don't support profiling non-main Ractors
|
680
|
+
}
|
681
|
+
|
682
|
+
state->during_sample = true;
|
683
|
+
|
684
|
+
// Rescue against any exceptions that happen during sampling
|
685
|
+
safely_call(rescued_sample_from_postponed_job, state->self_instance, state->self_instance);
|
686
|
+
|
687
|
+
state->during_sample = false;
|
688
|
+
}
|
689
|
+
|
690
|
+
static VALUE rescued_sample_from_postponed_job(VALUE self_instance) {
|
691
|
+
struct cpu_and_wall_time_worker_state *state;
|
692
|
+
TypedData_Get_Struct(self_instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
693
|
+
|
694
|
+
long wall_time_ns_before_sample = monotonic_wall_time_now_ns(RAISE_ON_FAILURE);
|
695
|
+
|
696
|
+
if (state->dynamic_sampling_rate_enabled && !dynamic_sampling_rate_should_sample(&state->cpu_dynamic_sampling_rate, wall_time_ns_before_sample)) {
|
697
|
+
state->stats.cpu_skipped++;
|
698
|
+
return Qnil;
|
699
|
+
}
|
700
|
+
|
701
|
+
state->stats.cpu_sampled++;
|
702
|
+
|
703
|
+
VALUE profiler_overhead_stack_thread = state->owner_thread; // Used to attribute profiler overhead to a different stack
|
704
|
+
thread_context_collector_sample(state->thread_context_collector_instance, wall_time_ns_before_sample, profiler_overhead_stack_thread);
|
705
|
+
|
706
|
+
long wall_time_ns_after_sample = monotonic_wall_time_now_ns(RAISE_ON_FAILURE);
|
707
|
+
long delta_ns = wall_time_ns_after_sample - wall_time_ns_before_sample;
|
708
|
+
|
709
|
+
// Guard against wall-time going backwards, see https://github.com/DataDog/dd-trace-rb/pull/2336 for discussion.
|
710
|
+
uint64_t sampling_time_ns = delta_ns < 0 ? 0 : delta_ns;
|
711
|
+
|
712
|
+
state->stats.cpu_sampling_time_ns_min = uint64_min_of(sampling_time_ns, state->stats.cpu_sampling_time_ns_min);
|
713
|
+
state->stats.cpu_sampling_time_ns_max = uint64_max_of(sampling_time_ns, state->stats.cpu_sampling_time_ns_max);
|
714
|
+
state->stats.cpu_sampling_time_ns_total += sampling_time_ns;
|
715
|
+
|
716
|
+
dynamic_sampling_rate_after_sample(&state->cpu_dynamic_sampling_rate, wall_time_ns_after_sample, sampling_time_ns);
|
717
|
+
|
718
|
+
// Return a dummy VALUE because we're called from rb_rescue2 which requires it
|
719
|
+
return Qnil;
|
720
|
+
}
|
721
|
+
|
722
|
+
static VALUE handle_sampling_failure(VALUE self_instance, VALUE exception) {
|
723
|
+
stop(self_instance, exception);
|
724
|
+
return Qnil;
|
725
|
+
}
|
726
|
+
|
727
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
728
|
+
// It SHOULD NOT be used for other purposes.
|
729
|
+
static VALUE _native_current_sigprof_signal_handler(DDTRACE_UNUSED VALUE self) {
|
730
|
+
struct sigaction existing_signal_handler_config = {.sa_sigaction = NULL};
|
731
|
+
if (sigaction(SIGPROF, NULL, &existing_signal_handler_config) != 0) {
|
732
|
+
rb_sys_fail("Failed to probe existing handler");
|
733
|
+
}
|
734
|
+
|
735
|
+
if (existing_signal_handler_config.sa_sigaction == handle_sampling_signal) {
|
736
|
+
return ID2SYM(rb_intern("profiling"));
|
737
|
+
} else if (existing_signal_handler_config.sa_sigaction == empty_signal_handler) {
|
738
|
+
return ID2SYM(rb_intern("empty"));
|
739
|
+
} else if (existing_signal_handler_config.sa_sigaction != NULL) {
|
740
|
+
return ID2SYM(rb_intern("other"));
|
741
|
+
} else {
|
742
|
+
return Qnil;
|
743
|
+
}
|
744
|
+
}
|
745
|
+
|
746
|
+
static VALUE release_gvl_and_run_sampling_trigger_loop(VALUE instance) {
|
747
|
+
struct cpu_and_wall_time_worker_state *state;
|
748
|
+
TypedData_Get_Struct(instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
749
|
+
|
750
|
+
// Final preparations: Setup signal handler and enable tracepoints. We run these here and not in `_native_sampling_loop`
|
751
|
+
// because they may raise exceptions.
|
752
|
+
install_sigprof_signal_handler(handle_sampling_signal, "handle_sampling_signal");
|
753
|
+
if (state->gc_profiling_enabled) rb_tracepoint_enable(state->gc_tracepoint);
|
754
|
+
if (state->allocation_profiling_enabled) rb_tracepoint_enable(state->object_allocation_tracepoint);
|
755
|
+
|
756
|
+
// Flag the profiler as running before we release the GVL, in case anyone's waiting to know about it
|
757
|
+
rb_funcall(instance, rb_intern("signal_running"), 0);
|
758
|
+
|
759
|
+
rb_thread_call_without_gvl(run_sampling_trigger_loop, state, interrupt_sampling_trigger_loop, state);
|
760
|
+
|
761
|
+
// If we stopped sampling due to an exception, re-raise it (now in the worker thread)
|
762
|
+
if (state->failure_exception != Qnil) rb_exc_raise(state->failure_exception);
|
763
|
+
|
764
|
+
return Qnil;
|
765
|
+
}
|
766
|
+
|
767
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
768
|
+
// It SHOULD NOT be used for other purposes.
|
769
|
+
static VALUE _native_is_running(DDTRACE_UNUSED VALUE self, VALUE instance) {
|
770
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
771
|
+
|
772
|
+
return (state != NULL && is_thread_alive(state->owner_thread) && state->self_instance == instance) ? Qtrue : Qfalse;
|
773
|
+
}
|
774
|
+
|
775
|
+
static void testing_signal_handler(DDTRACE_UNUSED int _signal, DDTRACE_UNUSED siginfo_t *_info, DDTRACE_UNUSED void *_ucontext) {
|
776
|
+
/* Does nothing on purpose */
|
777
|
+
}
|
778
|
+
|
779
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
780
|
+
// It SHOULD NOT be used for other purposes.
|
781
|
+
static VALUE _native_install_testing_signal_handler(DDTRACE_UNUSED VALUE self) {
|
782
|
+
install_sigprof_signal_handler(testing_signal_handler, "testing_signal_handler");
|
783
|
+
return Qtrue;
|
784
|
+
}
|
785
|
+
|
786
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
787
|
+
// It SHOULD NOT be used for other purposes.
|
788
|
+
static VALUE _native_remove_testing_signal_handler(DDTRACE_UNUSED VALUE self) {
|
789
|
+
remove_sigprof_signal_handler();
|
790
|
+
return Qtrue;
|
791
|
+
}
|
792
|
+
|
793
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
794
|
+
// It SHOULD NOT be used for other purposes.
|
795
|
+
static VALUE _native_trigger_sample(DDTRACE_UNUSED VALUE self) {
|
796
|
+
sample_from_postponed_job(NULL);
|
797
|
+
return Qtrue;
|
798
|
+
}
|
799
|
+
|
800
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
801
|
+
// It SHOULD NOT be used for other purposes.
|
802
|
+
static VALUE _native_gc_tracepoint(DDTRACE_UNUSED VALUE self, VALUE instance) {
|
803
|
+
struct cpu_and_wall_time_worker_state *state;
|
804
|
+
TypedData_Get_Struct(instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
805
|
+
|
806
|
+
return state->gc_tracepoint;
|
807
|
+
}
|
808
|
+
|
809
|
+
// Implements tracking of cpu-time and wall-time spent doing GC. This function is called by Ruby from the `gc_tracepoint`
|
810
|
+
// when the RUBY_INTERNAL_EVENT_GC_ENTER and RUBY_INTERNAL_EVENT_GC_EXIT events are triggered.
|
811
|
+
//
|
812
|
+
// See the comments on
|
813
|
+
// * thread_context_collector_on_gc_start
|
814
|
+
// * thread_context_collector_on_gc_finish
|
815
|
+
// * thread_context_collector_sample_after_gc
|
816
|
+
//
|
817
|
+
// For the expected times in which to call them, and their assumptions.
|
818
|
+
//
|
819
|
+
// Safety: This function gets called while Ruby is doing garbage collection. While Ruby is doing garbage collection,
|
820
|
+
// *NO ALLOCATION* is allowed. This function, and any it calls must never trigger memory or object allocation.
|
821
|
+
// This includes exceptions and use of ruby_xcalloc (because xcalloc can trigger GC)!
|
822
|
+
static void on_gc_event(VALUE tracepoint_data, DDTRACE_UNUSED void *unused) {
|
823
|
+
if (!ddtrace_rb_ractor_main_p()) {
|
824
|
+
return; // We're not on the main Ractor; we currently don't support profiling non-main Ractors
|
825
|
+
}
|
826
|
+
|
827
|
+
int event = rb_tracearg_event_flag(rb_tracearg_from_tracepoint(tracepoint_data));
|
828
|
+
if (event != RUBY_INTERNAL_EVENT_GC_ENTER && event != RUBY_INTERNAL_EVENT_GC_EXIT) return; // Unknown event
|
829
|
+
|
830
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
831
|
+
|
832
|
+
// This should not happen in a normal situation because the tracepoint is always enabled after the instance is set
|
833
|
+
// and disabled before it is cleared, but just in case...
|
834
|
+
if (state == NULL) return;
|
835
|
+
|
836
|
+
if (event == RUBY_INTERNAL_EVENT_GC_ENTER) {
|
837
|
+
thread_context_collector_on_gc_start(state->thread_context_collector_instance);
|
838
|
+
} else if (event == RUBY_INTERNAL_EVENT_GC_EXIT) {
|
839
|
+
bool should_flush = thread_context_collector_on_gc_finish(state->thread_context_collector_instance);
|
840
|
+
|
841
|
+
// We use rb_postponed_job_register_one to ask Ruby to run thread_context_collector_sample_after_gc when the
|
842
|
+
// thread collector flags it's time to flush.
|
843
|
+
if (should_flush) {
|
844
|
+
#ifndef NO_POSTPONED_TRIGGER // Ruby 3.3+
|
845
|
+
rb_postponed_job_trigger(after_gc_from_postponed_job_handle);
|
846
|
+
#else
|
847
|
+
rb_postponed_job_register_one(0, after_gc_from_postponed_job, NULL);
|
848
|
+
#endif
|
849
|
+
}
|
850
|
+
}
|
851
|
+
}
|
852
|
+
|
853
|
+
static void after_gc_from_postponed_job(DDTRACE_UNUSED void *_unused) {
|
854
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
855
|
+
|
856
|
+
// This can potentially happen if the CpuAndWallTimeWorker was stopped while the postponed job was waiting to be executed; nothing to do
|
857
|
+
if (state == NULL) return;
|
858
|
+
|
859
|
+
// @ivoanjo: I'm not sure this can ever happen because `on_gc_event` only enqueues this callback if
|
860
|
+
// it's running on the main Ractor, but just in case...
|
861
|
+
if (!ddtrace_rb_ractor_main_p()) {
|
862
|
+
return; // We're not on the main Ractor; we currently don't support profiling non-main Ractors
|
863
|
+
}
|
864
|
+
|
865
|
+
state->during_sample = true;
|
866
|
+
|
867
|
+
// Trigger sampling using the Collectors::ThreadState; rescue against any exceptions that happen during sampling
|
868
|
+
safely_call(thread_context_collector_sample_after_gc, state->thread_context_collector_instance, state->self_instance);
|
869
|
+
|
870
|
+
state->during_sample = false;
|
871
|
+
}
|
872
|
+
|
873
|
+
// Equivalent to Ruby begin/rescue call, where we call a C function and jump to the exception handler if an
|
874
|
+
// exception gets raised within
|
875
|
+
static VALUE safely_call(VALUE (*function_to_call_safely)(VALUE), VALUE function_to_call_safely_arg, VALUE instance) {
|
876
|
+
VALUE exception_handler_function_arg = instance;
|
877
|
+
return rb_rescue2(
|
878
|
+
function_to_call_safely,
|
879
|
+
function_to_call_safely_arg,
|
880
|
+
handle_sampling_failure,
|
881
|
+
exception_handler_function_arg,
|
882
|
+
rb_eException, // rb_eException is the base class of all Ruby exceptions
|
883
|
+
0 // Required by API to be the last argument
|
884
|
+
);
|
885
|
+
}
|
886
|
+
|
887
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
888
|
+
// It SHOULD NOT be used for other purposes.
|
889
|
+
static VALUE _native_simulate_handle_sampling_signal(DDTRACE_UNUSED VALUE self) {
|
890
|
+
handle_sampling_signal(0, NULL, NULL);
|
891
|
+
return Qtrue;
|
892
|
+
}
|
893
|
+
|
894
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::CpuAndWallTimeWorker behavior using RSpec.
|
895
|
+
// It SHOULD NOT be used for other purposes.
|
896
|
+
static VALUE _native_simulate_sample_from_postponed_job(DDTRACE_UNUSED VALUE self) {
|
897
|
+
sample_from_postponed_job(NULL);
|
898
|
+
return Qtrue;
|
899
|
+
}
|
900
|
+
|
901
|
+
// After the Ruby VM forks, this method gets called in the child process to clean up any leftover state from the parent.
|
902
|
+
//
|
903
|
+
// Assumption: This method gets called BEFORE restarting profiling. Note that profiling-related tracepoints may still
|
904
|
+
// be active, so we make sure to disable them before calling into anything else, so that there are no components
|
905
|
+
// attempting to trigger samples at the same time as the reset is done.
|
906
|
+
//
|
907
|
+
// In the future, if we add more other components with tracepoints, we will need to coordinate stopping all such
|
908
|
+
// tracepoints before doing the other cleaning steps.
|
909
|
+
static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE instance) {
|
910
|
+
struct cpu_and_wall_time_worker_state *state;
|
911
|
+
TypedData_Get_Struct(instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
912
|
+
|
913
|
+
// Disable all tracepoints, so that there are no more attempts to mutate the profile
|
914
|
+
disable_tracepoints(state);
|
915
|
+
|
916
|
+
reset_stats_not_thread_safe(state);
|
917
|
+
|
918
|
+
// Remove all state from the `Collectors::ThreadState` and connected downstream components
|
919
|
+
rb_funcall(state->thread_context_collector_instance, rb_intern("reset_after_fork"), 0);
|
920
|
+
|
921
|
+
return Qtrue;
|
922
|
+
}
|
923
|
+
|
924
|
+
static VALUE _native_is_sigprof_blocked_in_current_thread(DDTRACE_UNUSED VALUE self) {
|
925
|
+
return is_sigprof_blocked_in_current_thread();
|
926
|
+
}
|
927
|
+
|
928
|
+
static VALUE _native_stats(DDTRACE_UNUSED VALUE self, VALUE instance) {
|
929
|
+
struct cpu_and_wall_time_worker_state *state;
|
930
|
+
TypedData_Get_Struct(instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
931
|
+
|
932
|
+
unsigned long total_cpu_samples_attempted = state->stats.cpu_sampled + state->stats.cpu_skipped;
|
933
|
+
VALUE effective_cpu_sample_rate =
|
934
|
+
total_cpu_samples_attempted == 0 ? Qnil : DBL2NUM(((double) state->stats.cpu_sampled) / total_cpu_samples_attempted);
|
935
|
+
unsigned long total_allocation_samples_attempted = state->stats.allocation_sampled + state->stats.allocation_skipped;
|
936
|
+
VALUE effective_allocation_sample_rate =
|
937
|
+
total_allocation_samples_attempted == 0 ? Qnil : DBL2NUM(((double) state->stats.allocation_sampled) / total_allocation_samples_attempted);
|
938
|
+
|
939
|
+
VALUE allocation_sampler_snapshot = state->allocation_profiling_enabled && state->dynamic_sampling_rate_enabled ?
|
940
|
+
discrete_dynamic_sampler_state_snapshot(&state->allocation_sampler) : Qnil;
|
941
|
+
|
942
|
+
VALUE stats_as_hash = rb_hash_new();
|
943
|
+
VALUE arguments[] = {
|
944
|
+
ID2SYM(rb_intern("trigger_sample_attempts")), /* => */ UINT2NUM(state->stats.trigger_sample_attempts),
|
945
|
+
ID2SYM(rb_intern("trigger_simulated_signal_delivery_attempts")), /* => */ UINT2NUM(state->stats.trigger_simulated_signal_delivery_attempts),
|
946
|
+
ID2SYM(rb_intern("simulated_signal_delivery")), /* => */ UINT2NUM(state->stats.simulated_signal_delivery),
|
947
|
+
ID2SYM(rb_intern("signal_handler_enqueued_sample")), /* => */ UINT2NUM(state->stats.signal_handler_enqueued_sample),
|
948
|
+
ID2SYM(rb_intern("signal_handler_wrong_thread")), /* => */ UINT2NUM(state->stats.signal_handler_wrong_thread),
|
949
|
+
ID2SYM(rb_intern("postponed_job_skipped_already_existed")), /* => */ UINT2NUM(state->stats.postponed_job_skipped_already_existed),
|
950
|
+
ID2SYM(rb_intern("postponed_job_success")), /* => */ UINT2NUM(state->stats.postponed_job_success),
|
951
|
+
ID2SYM(rb_intern("postponed_job_full")), /* => */ UINT2NUM(state->stats.postponed_job_full),
|
952
|
+
ID2SYM(rb_intern("postponed_job_unknown_result")), /* => */ UINT2NUM(state->stats.postponed_job_unknown_result),
|
953
|
+
ID2SYM(rb_intern("interrupt_thread_attempts")), /* => */ UINT2NUM(state->stats.interrupt_thread_attempts),
|
954
|
+
|
955
|
+
// CPU Stats
|
956
|
+
ID2SYM(rb_intern("cpu_sampled")), /* => */ UINT2NUM(state->stats.cpu_sampled),
|
957
|
+
ID2SYM(rb_intern("cpu_skipped")), /* => */ UINT2NUM(state->stats.cpu_skipped),
|
958
|
+
ID2SYM(rb_intern("cpu_effective_sample_rate")), /* => */ effective_cpu_sample_rate,
|
959
|
+
ID2SYM(rb_intern("cpu_sampling_time_ns_min")), /* => */ RUBY_NUM_OR_NIL(state->stats.cpu_sampling_time_ns_min, != UINT64_MAX, ULL2NUM),
|
960
|
+
ID2SYM(rb_intern("cpu_sampling_time_ns_max")), /* => */ RUBY_NUM_OR_NIL(state->stats.cpu_sampling_time_ns_max, > 0, ULL2NUM),
|
961
|
+
ID2SYM(rb_intern("cpu_sampling_time_ns_total")), /* => */ RUBY_NUM_OR_NIL(state->stats.cpu_sampling_time_ns_total, > 0, ULL2NUM),
|
962
|
+
ID2SYM(rb_intern("cpu_sampling_time_ns_avg")), /* => */ RUBY_AVG_OR_NIL(state->stats.cpu_sampling_time_ns_total, state->stats.cpu_sampled),
|
963
|
+
|
964
|
+
// Allocation stats
|
965
|
+
ID2SYM(rb_intern("allocation_sampled")), /* => */ state->allocation_profiling_enabled ? ULONG2NUM(state->stats.allocation_sampled) : Qnil,
|
966
|
+
ID2SYM(rb_intern("allocation_skipped")), /* => */ state->allocation_profiling_enabled ? ULONG2NUM(state->stats.allocation_skipped) : Qnil,
|
967
|
+
ID2SYM(rb_intern("allocation_effective_sample_rate")), /* => */ effective_allocation_sample_rate,
|
968
|
+
ID2SYM(rb_intern("allocation_sampling_time_ns_min")), /* => */ RUBY_NUM_OR_NIL(state->stats.allocation_sampling_time_ns_min, != UINT64_MAX, ULL2NUM),
|
969
|
+
ID2SYM(rb_intern("allocation_sampling_time_ns_max")), /* => */ RUBY_NUM_OR_NIL(state->stats.allocation_sampling_time_ns_max, > 0, ULL2NUM),
|
970
|
+
ID2SYM(rb_intern("allocation_sampling_time_ns_total")), /* => */ RUBY_NUM_OR_NIL(state->stats.allocation_sampling_time_ns_total, > 0, ULL2NUM),
|
971
|
+
ID2SYM(rb_intern("allocation_sampling_time_ns_avg")), /* => */ RUBY_AVG_OR_NIL(state->stats.allocation_sampling_time_ns_total, state->stats.allocation_sampled),
|
972
|
+
ID2SYM(rb_intern("allocation_sampler_snapshot")), /* => */ allocation_sampler_snapshot,
|
973
|
+
ID2SYM(rb_intern("allocations_during_sample")), /* => */ state->allocation_profiling_enabled ? UINT2NUM(state->stats.allocations_during_sample) : Qnil,
|
974
|
+
};
|
975
|
+
for (long unsigned int i = 0; i < VALUE_COUNT(arguments); i += 2) rb_hash_aset(stats_as_hash, arguments[i], arguments[i+1]);
|
976
|
+
return stats_as_hash;
|
977
|
+
}
|
978
|
+
|
979
|
+
static VALUE _native_stats_reset_not_thread_safe(DDTRACE_UNUSED VALUE self, VALUE instance) {
|
980
|
+
struct cpu_and_wall_time_worker_state *state;
|
981
|
+
TypedData_Get_Struct(instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
982
|
+
reset_stats_not_thread_safe(state);
|
983
|
+
return Qnil;
|
984
|
+
}
|
985
|
+
|
986
|
+
void *simulate_sampling_signal_delivery(DDTRACE_UNUSED void *_unused) {
|
987
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
988
|
+
|
989
|
+
// This can potentially happen if the CpuAndWallTimeWorker was stopped while the IdleSamplingHelper was trying to execute this action
|
990
|
+
if (state == NULL) return NULL;
|
991
|
+
|
992
|
+
state->stats.simulated_signal_delivery++;
|
993
|
+
|
994
|
+
// @ivoanjo: We could instead directly call sample_from_postponed_job, but I chose to go through the signal handler
|
995
|
+
// so that the simulated case is as close to the original one as well (including any metrics increases, etc).
|
996
|
+
handle_sampling_signal(0, NULL, NULL);
|
997
|
+
|
998
|
+
return NULL; // Unused
|
999
|
+
}
|
1000
|
+
|
1001
|
+
static void grab_gvl_and_sample(void) { rb_thread_call_with_gvl(simulate_sampling_signal_delivery, NULL); }
|
1002
|
+
|
1003
|
+
static void reset_stats_not_thread_safe(struct cpu_and_wall_time_worker_state *state) {
|
1004
|
+
// NOTE: This is not really thread safe so ongoing sampling operations that are concurrent with a reset can have their stats:
|
1005
|
+
// * Lost (writes after stats retrieval but before reset).
|
1006
|
+
// * Included in the previous stats window (writes before stats retrieval and reset).
|
1007
|
+
// * Included in the following stats window (writes after stats retrieval and reset).
|
1008
|
+
// Given the expected infrequency of resetting (~once per 60s profile) and the auxiliary/non-critical nature of these stats
|
1009
|
+
// this momentary loss of accuracy is deemed acceptable to keep overhead to a minimum.
|
1010
|
+
state->stats = (struct stats) {
|
1011
|
+
.cpu_sampling_time_ns_min = UINT64_MAX, // Since we always take the min between existing and latest sample
|
1012
|
+
.allocation_sampling_time_ns_min = UINT64_MAX, // Since we always take the min between existing and latest sample
|
1013
|
+
};
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
static void sleep_for(uint64_t time_ns) {
|
1017
|
+
// As a simplification, we currently only support setting .tv_nsec
|
1018
|
+
if (time_ns >= SECONDS_AS_NS(1)) {
|
1019
|
+
grab_gvl_and_raise(rb_eArgError, "sleep_for can only sleep for less than 1 second, time_ns: %"PRIu64, time_ns);
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
struct timespec time_to_sleep = {.tv_nsec = time_ns};
|
1023
|
+
|
1024
|
+
while (nanosleep(&time_to_sleep, &time_to_sleep) != 0) {
|
1025
|
+
if (errno == EINTR) {
|
1026
|
+
// We were interrupted. nanosleep updates "time_to_sleep" to contain only the remaining time, so we just let the
|
1027
|
+
// loop keep going.
|
1028
|
+
} else {
|
1029
|
+
ENFORCE_SUCCESS_NO_GVL(errno);
|
1030
|
+
}
|
1031
|
+
}
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
static VALUE _native_allocation_count(DDTRACE_UNUSED VALUE self) {
|
1035
|
+
bool are_allocations_being_tracked = active_sampler_instance_state != NULL && active_sampler_instance_state->allocation_profiling_enabled;
|
1036
|
+
|
1037
|
+
return are_allocations_being_tracked ? ULL2NUM(allocation_count) : Qnil;
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
// Implements memory-related profiling events. This function is called by Ruby via the `object_allocation_tracepoint`
|
1041
|
+
// when the RUBY_INTERNAL_EVENT_NEWOBJ event is triggered.
|
1042
|
+
static void on_newobj_event(VALUE tracepoint_data, DDTRACE_UNUSED void *unused) {
|
1043
|
+
// Update thread-local allocation count
|
1044
|
+
if (RB_UNLIKELY(allocation_count == UINT64_MAX)) {
|
1045
|
+
allocation_count = 0;
|
1046
|
+
} else {
|
1047
|
+
allocation_count++;
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
1051
|
+
|
1052
|
+
// This should not happen in a normal situation because the tracepoint is always enabled after the instance is set
|
1053
|
+
// and disabled before it is cleared, but just in case...
|
1054
|
+
if (state == NULL) return;
|
1055
|
+
|
1056
|
+
// In a few cases, we may actually be allocating an object as part of profiler sampling. We don't want to recursively
|
1057
|
+
// sample, so we just return early
|
1058
|
+
if (state->during_sample) {
|
1059
|
+
state->stats.allocations_during_sample++;
|
1060
|
+
return;
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
if (state->dynamic_sampling_rate_enabled) {
|
1064
|
+
long now = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
|
1065
|
+
if (now == 0) {
|
1066
|
+
delayed_error(state, ERR_CLOCK_FAIL);
|
1067
|
+
return;
|
1068
|
+
}
|
1069
|
+
if (!discrete_dynamic_sampler_should_sample(&state->allocation_sampler, now)) {
|
1070
|
+
state->stats.allocation_skipped++;
|
1071
|
+
return;
|
1072
|
+
}
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
// @ivoanjo: Strictly speaking, this is not needed because Ruby should not call the same tracepoint while a previous
|
1076
|
+
// invocation is still pending, (e.g. it wouldn't call `on_newobj_event` while it's already running), but I decided
|
1077
|
+
// to keep this here for consistency -- every call to the thread context (other than the special gc calls which are
|
1078
|
+
// defined as not being able to allocate) sets this.
|
1079
|
+
state->during_sample = true;
|
1080
|
+
|
1081
|
+
// Rescue against any exceptions that happen during sampling
|
1082
|
+
safely_call(rescued_sample_allocation, tracepoint_data, state->self_instance);
|
1083
|
+
|
1084
|
+
if (state->dynamic_sampling_rate_enabled) {
|
1085
|
+
long now = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
|
1086
|
+
if (now == 0) {
|
1087
|
+
delayed_error(state, ERR_CLOCK_FAIL);
|
1088
|
+
// NOTE: Not short-circuiting here to make sure cleanup happens
|
1089
|
+
}
|
1090
|
+
uint64_t sampling_time_ns = discrete_dynamic_sampler_after_sample(&state->allocation_sampler, now);
|
1091
|
+
// NOTE: To keep things lean when dynamic sampling rate is disabled we skip clock interactions which is
|
1092
|
+
// why we're fine with having this inside this conditional.
|
1093
|
+
state->stats.allocation_sampling_time_ns_min = uint64_min_of(sampling_time_ns, state->stats.allocation_sampling_time_ns_min);
|
1094
|
+
state->stats.allocation_sampling_time_ns_max = uint64_max_of(sampling_time_ns, state->stats.allocation_sampling_time_ns_max);
|
1095
|
+
state->stats.allocation_sampling_time_ns_total += sampling_time_ns;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
state->stats.allocation_sampled++;
|
1099
|
+
|
1100
|
+
state->during_sample = false;
|
1101
|
+
}
|
1102
|
+
|
1103
|
+
static void disable_tracepoints(struct cpu_and_wall_time_worker_state *state) {
|
1104
|
+
if (state->gc_tracepoint != Qnil) {
|
1105
|
+
rb_tracepoint_disable(state->gc_tracepoint);
|
1106
|
+
}
|
1107
|
+
if (state->object_allocation_tracepoint != Qnil) {
|
1108
|
+
rb_tracepoint_disable(state->object_allocation_tracepoint);
|
1109
|
+
}
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
static VALUE _native_with_blocked_sigprof(DDTRACE_UNUSED VALUE self) {
|
1113
|
+
block_sigprof_signal_handler_from_running_in_current_thread();
|
1114
|
+
int exception_state;
|
1115
|
+
VALUE result = rb_protect(rb_yield, Qundef, &exception_state);
|
1116
|
+
unblock_sigprof_signal_handler_from_running_in_current_thread();
|
1117
|
+
|
1118
|
+
if (exception_state) {
|
1119
|
+
rb_jump_tag(exception_state);
|
1120
|
+
} else {
|
1121
|
+
return result;
|
1122
|
+
}
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
static VALUE rescued_sample_allocation(VALUE tracepoint_data) {
|
1126
|
+
struct cpu_and_wall_time_worker_state *state = active_sampler_instance_state; // Read from global variable, see "sampler global state safety" note above
|
1127
|
+
|
1128
|
+
// This should not happen in a normal situation because on_newobj_event already checked for this, but just in case...
|
1129
|
+
if (state == NULL) return Qnil;
|
1130
|
+
|
1131
|
+
rb_trace_arg_t *data = rb_tracearg_from_tracepoint(tracepoint_data);
|
1132
|
+
VALUE new_object = rb_tracearg_object(data);
|
1133
|
+
|
1134
|
+
unsigned long allocations_since_last_sample = state->dynamic_sampling_rate_enabled ?
|
1135
|
+
// if we're doing dynamic sampling, ask the sampler how many events since last sample
|
1136
|
+
discrete_dynamic_sampler_events_since_last_sample(&state->allocation_sampler) :
|
1137
|
+
// if we aren't, then we're sampling every event
|
1138
|
+
1;
|
1139
|
+
// TODO: Signal in the profile that clamping happened?
|
1140
|
+
unsigned int weight = allocations_since_last_sample > MAX_ALLOC_WEIGHT ? MAX_ALLOC_WEIGHT : (unsigned int) allocations_since_last_sample;
|
1141
|
+
thread_context_collector_sample_allocation(state->thread_context_collector_instance, weight, new_object);
|
1142
|
+
|
1143
|
+
// Return a dummy VALUE because we're called from rb_rescue2 which requires it
|
1144
|
+
return Qnil;
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
static void delayed_error(struct cpu_and_wall_time_worker_state *state, const char *error) {
|
1148
|
+
// If we can't raise an immediate exception at the calling site, use the asynchronous flow through the main worker loop.
|
1149
|
+
stop_state(state, rb_exc_new_cstr(rb_eRuntimeError, error));
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
static VALUE _native_delayed_error(DDTRACE_UNUSED VALUE self, VALUE instance, VALUE error_msg) {
|
1153
|
+
ENFORCE_TYPE(error_msg, T_STRING);
|
1154
|
+
|
1155
|
+
struct cpu_and_wall_time_worker_state *state;
|
1156
|
+
TypedData_Get_Struct(instance, struct cpu_and_wall_time_worker_state, &cpu_and_wall_time_worker_typed_data, state);
|
1157
|
+
|
1158
|
+
delayed_error(state, rb_string_value_cstr(&error_msg));
|
1159
|
+
|
1160
|
+
return Qnil;
|
1161
|
+
}
|