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,1402 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
#include "collectors_thread_context.h"
|
4
|
+
#include "clock_id.h"
|
5
|
+
#include "collectors_stack.h"
|
6
|
+
#include "collectors_gc_profiling_helper.h"
|
7
|
+
#include "helpers.h"
|
8
|
+
#include "libdatadog_helpers.h"
|
9
|
+
#include "private_vm_api_access.h"
|
10
|
+
#include "stack_recorder.h"
|
11
|
+
#include "time_helpers.h"
|
12
|
+
|
13
|
+
// Used to trigger sampling of threads, based on external "events", such as:
|
14
|
+
// * periodic timer for cpu-time and wall-time
|
15
|
+
// * VM garbage collection events
|
16
|
+
// * VM object allocation events
|
17
|
+
//
|
18
|
+
// This file implements the native bits of the Datadog::Profiling::Collectors::ThreadContext class
|
19
|
+
//
|
20
|
+
// Triggering of this component (e.g. watching for the above "events") is implemented by Collectors::CpuAndWallTimeWorker.
|
21
|
+
|
22
|
+
// ---
|
23
|
+
// ## Tracking of cpu-time and wall-time spent during garbage collection
|
24
|
+
//
|
25
|
+
// This feature works by having a special state that a thread can be in: doing garbage collection. This state is
|
26
|
+
// tracked inside the thread's `per_thread_context.gc_tracking` data, and three functions, listed below. The functions
|
27
|
+
// will get called by the `Collectors::CpuAndWallTimeWorker` at very specific times in the VM lifetime.
|
28
|
+
//
|
29
|
+
// * `thread_context_collector_on_gc_start`: Called at the very beginning of the garbage collection process.
|
30
|
+
// The internal VM `during_gc` flag is set to `true`, but Ruby has not done any work yet.
|
31
|
+
// * `thread_context_collector_on_gc_finish`: Called at the very end of the garbage collection process.
|
32
|
+
// The internal VM `during_gc` flag is still set to `true`, but all the work has been done.
|
33
|
+
// * `thread_context_collector_sample_after_gc`: Called shortly after the garbage collection process.
|
34
|
+
// The internal VM `during_gc` flag is set to `false`.
|
35
|
+
//
|
36
|
+
// Inside this component, here's what happens inside those three functions:
|
37
|
+
//
|
38
|
+
// When `thread_context_collector_on_gc_start` gets called, the current cpu and wall-time get recorded to the thread
|
39
|
+
// context: `cpu_time_at_gc_start_ns` and `wall_time_at_gc_start_ns`.
|
40
|
+
//
|
41
|
+
// While `cpu_time_at_gc_start_ns` is set, regular samples (if any) do not account for cpu-time any time that passes
|
42
|
+
// after this timestamp. The idea is that this cpu-time will be blamed separately on GC, and not on the user thread.
|
43
|
+
// Wall-time accounting is not affected by this (e.g. we still record 60 seconds every 60 seconds).
|
44
|
+
//
|
45
|
+
// (Regular samples can still account for the cpu-time between the previous sample and the start of GC.)
|
46
|
+
//
|
47
|
+
// When `thread_context_collector_on_gc_finish` gets called, the cpu-time and wall-time spent during GC gets recorded
|
48
|
+
// into the global gc_tracking structure, and further samples are not affected. (The `cpu_time_at_previous_sample_ns`
|
49
|
+
// of the thread that did GC also gets adjusted to avoid double-accounting.)
|
50
|
+
//
|
51
|
+
// Finally, when `thread_context_collector_sample_after_gc` gets called, a sample gets recorded with a stack having
|
52
|
+
// a single placeholder `Garbage Collection` frame. This sample gets
|
53
|
+
// assigned the cpu-time and wall-time that was recorded between calls to `on_gc_start` and `on_gc_finish`, as well
|
54
|
+
// as metadata for the last GC.
|
55
|
+
//
|
56
|
+
// Note that the Ruby GC does not usually do all of the GC work in one go. Instead, it breaks it up into smaller steps
|
57
|
+
// so that the application can keep doing user work in between GC steps.
|
58
|
+
// The `on_gc_start` / `on_gc_finish` will trigger each time the VM executes these smaller steps, and on a benchmark
|
59
|
+
// that executes `Object.new` in a loop, I measured more than 50k of this steps per second (!!).
|
60
|
+
// Creating these many events for every GC step is a lot of overhead, so instead `on_gc_finish` coalesces time
|
61
|
+
// spent in GC and only flushes it at most every 10 ms/every complete GC collection. This reduces the amount of
|
62
|
+
// individual GC events we need to record. We use the latest GC metadata for this event, reflecting the last GC that
|
63
|
+
// happened in the coalesced period.
|
64
|
+
//
|
65
|
+
// In an earlier attempt at implementing this functionality (https://github.com/DataDog/dd-trace-rb/pull/2308), we
|
66
|
+
// discovered that we needed to factor the sampling work away from `thread_context_collector_on_gc_finish` and into a
|
67
|
+
// separate `thread_context_collector_sample_after_gc` because (as documented in more detail below),
|
68
|
+
// `sample_after_gc` could trigger memory allocation in rare occasions (usually exceptions), which is actually not
|
69
|
+
// allowed to happen during Ruby's garbage collection start/finish hooks.
|
70
|
+
// ---
|
71
|
+
|
72
|
+
#define THREAD_ID_LIMIT_CHARS 44 // Why 44? "#{2**64} (#{2**64})".size + 1 for \0
|
73
|
+
#define THREAD_INVOKE_LOCATION_LIMIT_CHARS 512
|
74
|
+
#define IS_WALL_TIME true
|
75
|
+
#define IS_NOT_WALL_TIME false
|
76
|
+
#define MISSING_TRACER_CONTEXT_KEY 0
|
77
|
+
#define TIME_BETWEEN_GC_EVENTS_NS MILLIS_AS_NS(10)
|
78
|
+
|
79
|
+
static ID at_active_span_id; // id of :@active_span in Ruby
|
80
|
+
static ID at_active_trace_id; // id of :@active_trace in Ruby
|
81
|
+
static ID at_id_id; // id of :@id in Ruby
|
82
|
+
static ID at_resource_id; // id of :@resource in Ruby
|
83
|
+
static ID at_root_span_id; // id of :@root_span in Ruby
|
84
|
+
static ID at_type_id; // id of :@type in Ruby
|
85
|
+
static ID at_otel_values_id; // id of :@otel_values in Ruby
|
86
|
+
static ID at_parent_span_id_id; // id of :@parent_span_id in Ruby
|
87
|
+
static ID at_datadog_trace_id; // id of :@datadog_trace in Ruby
|
88
|
+
|
89
|
+
// Contains state for a single ThreadContext instance
|
90
|
+
struct thread_context_collector_state {
|
91
|
+
// Note: Places in this file that usually need to be changed when this struct is changed are tagged with
|
92
|
+
// "Update this when modifying state struct"
|
93
|
+
|
94
|
+
// Required by Datadog::Profiling::Collectors::Stack as a scratch buffer during sampling
|
95
|
+
sampling_buffer *sampling_buffer;
|
96
|
+
// Hashmap <Thread Object, struct per_thread_context>
|
97
|
+
st_table *hash_map_per_thread_context;
|
98
|
+
// Datadog::Profiling::StackRecorder instance
|
99
|
+
VALUE recorder_instance;
|
100
|
+
// If the tracer is available and enabled, this will be the fiber-local symbol for accessing its running context,
|
101
|
+
// to enable code hotspots and endpoint aggregation.
|
102
|
+
// When not available, this is set to MISSING_TRACER_CONTEXT_KEY.
|
103
|
+
ID tracer_context_key;
|
104
|
+
// Track how many regular samples we've taken. Does not include garbage collection samples.
|
105
|
+
// Currently **outside** of stats struct because we also use it to decide when to clean the contexts, and thus this
|
106
|
+
// is not (just) a stat.
|
107
|
+
unsigned int sample_count;
|
108
|
+
// Reusable array to get list of threads
|
109
|
+
VALUE thread_list_buffer;
|
110
|
+
// Used to omit endpoint names (retrieved from tracer) from collected data
|
111
|
+
bool endpoint_collection_enabled;
|
112
|
+
// Used to omit timestamps / timeline events from collected data
|
113
|
+
bool timeline_enabled;
|
114
|
+
// Used to omit class information from collected allocation data
|
115
|
+
bool allocation_type_enabled;
|
116
|
+
// Used when calling monotonic_to_system_epoch_ns
|
117
|
+
monotonic_to_system_epoch_state time_converter_state;
|
118
|
+
// Used to identify the main thread, to give it a fallback name
|
119
|
+
VALUE main_thread;
|
120
|
+
// Used when extracting trace identifiers from otel spans. Lazily initialized.
|
121
|
+
VALUE otel_current_span_key;
|
122
|
+
|
123
|
+
struct stats {
|
124
|
+
// Track how many garbage collection samples we've taken.
|
125
|
+
unsigned int gc_samples;
|
126
|
+
// See thread_context_collector_on_gc_start for details
|
127
|
+
unsigned int gc_samples_missed_due_to_missing_context;
|
128
|
+
} stats;
|
129
|
+
|
130
|
+
struct {
|
131
|
+
unsigned long accumulated_cpu_time_ns;
|
132
|
+
unsigned long accumulated_wall_time_ns;
|
133
|
+
|
134
|
+
long wall_time_at_previous_gc_ns; // Will be INVALID_TIME unless there's accumulated time above
|
135
|
+
long wall_time_at_last_flushed_gc_event_ns; // Starts at 0 and then will always be valid
|
136
|
+
} gc_tracking;
|
137
|
+
};
|
138
|
+
|
139
|
+
// Tracks per-thread state
|
140
|
+
struct per_thread_context {
|
141
|
+
char thread_id[THREAD_ID_LIMIT_CHARS];
|
142
|
+
ddog_CharSlice thread_id_char_slice;
|
143
|
+
char thread_invoke_location[THREAD_INVOKE_LOCATION_LIMIT_CHARS];
|
144
|
+
ddog_CharSlice thread_invoke_location_char_slice;
|
145
|
+
thread_cpu_time_id thread_cpu_time_id;
|
146
|
+
long cpu_time_at_previous_sample_ns; // Can be INVALID_TIME until initialized or if getting it fails for another reason
|
147
|
+
long wall_time_at_previous_sample_ns; // Can be INVALID_TIME until initialized
|
148
|
+
|
149
|
+
struct {
|
150
|
+
// Both of these fields are set by on_gc_start and kept until on_gc_finish is called.
|
151
|
+
// Outside of this window, they will be INVALID_TIME.
|
152
|
+
long cpu_time_at_start_ns;
|
153
|
+
long wall_time_at_start_ns;
|
154
|
+
} gc_tracking;
|
155
|
+
};
|
156
|
+
|
157
|
+
// Used to correlate profiles with traces
|
158
|
+
struct trace_identifiers {
|
159
|
+
bool valid;
|
160
|
+
uint64_t local_root_span_id;
|
161
|
+
uint64_t span_id;
|
162
|
+
VALUE trace_endpoint;
|
163
|
+
};
|
164
|
+
|
165
|
+
static void thread_context_collector_typed_data_mark(void *state_ptr);
|
166
|
+
static void thread_context_collector_typed_data_free(void *state_ptr);
|
167
|
+
static int hash_map_per_thread_context_mark(st_data_t key_thread, st_data_t _value, st_data_t _argument);
|
168
|
+
static int hash_map_per_thread_context_free_values(st_data_t _thread, st_data_t value_per_thread_context, st_data_t _argument);
|
169
|
+
static VALUE _native_new(VALUE klass);
|
170
|
+
static VALUE _native_initialize(
|
171
|
+
VALUE self,
|
172
|
+
VALUE collector_instance,
|
173
|
+
VALUE recorder_instance,
|
174
|
+
VALUE max_frames,
|
175
|
+
VALUE tracer_context_key,
|
176
|
+
VALUE endpoint_collection_enabled,
|
177
|
+
VALUE timeline_enabled,
|
178
|
+
VALUE allocation_type_enabled
|
179
|
+
);
|
180
|
+
static VALUE _native_sample(VALUE self, VALUE collector_instance, VALUE profiler_overhead_stack_thread);
|
181
|
+
static VALUE _native_on_gc_start(VALUE self, VALUE collector_instance);
|
182
|
+
static VALUE _native_on_gc_finish(VALUE self, VALUE collector_instance);
|
183
|
+
static VALUE _native_sample_after_gc(DDTRACE_UNUSED VALUE self, VALUE collector_instance);
|
184
|
+
void update_metrics_and_sample(
|
185
|
+
struct thread_context_collector_state *state,
|
186
|
+
VALUE thread_being_sampled,
|
187
|
+
VALUE profiler_overhead_stack_thread,
|
188
|
+
struct per_thread_context *thread_context,
|
189
|
+
long current_cpu_time_ns,
|
190
|
+
long current_monotonic_wall_time_ns
|
191
|
+
);
|
192
|
+
static void trigger_sample_for_thread(
|
193
|
+
struct thread_context_collector_state *state,
|
194
|
+
VALUE thread,
|
195
|
+
VALUE stack_from_thread,
|
196
|
+
struct per_thread_context *thread_context,
|
197
|
+
sample_values values,
|
198
|
+
long current_monotonic_wall_time_ns,
|
199
|
+
ddog_CharSlice *ruby_vm_type,
|
200
|
+
ddog_CharSlice *class_name
|
201
|
+
);
|
202
|
+
static VALUE _native_thread_list(VALUE self);
|
203
|
+
static struct per_thread_context *get_or_create_context_for(VALUE thread, struct thread_context_collector_state *state);
|
204
|
+
static struct per_thread_context *get_context_for(VALUE thread, struct thread_context_collector_state *state);
|
205
|
+
static void initialize_context(VALUE thread, struct per_thread_context *thread_context, struct thread_context_collector_state *state);
|
206
|
+
static VALUE _native_inspect(VALUE self, VALUE collector_instance);
|
207
|
+
static VALUE per_thread_context_st_table_as_ruby_hash(struct thread_context_collector_state *state);
|
208
|
+
static int per_thread_context_as_ruby_hash(st_data_t key_thread, st_data_t value_context, st_data_t result_hash);
|
209
|
+
static VALUE stats_as_ruby_hash(struct thread_context_collector_state *state);
|
210
|
+
static VALUE gc_tracking_as_ruby_hash(struct thread_context_collector_state *state);
|
211
|
+
static void remove_context_for_dead_threads(struct thread_context_collector_state *state);
|
212
|
+
static int remove_if_dead_thread(st_data_t key_thread, st_data_t value_context, st_data_t _argument);
|
213
|
+
static VALUE _native_per_thread_context(VALUE self, VALUE collector_instance);
|
214
|
+
static long update_time_since_previous_sample(long *time_at_previous_sample_ns, long current_time_ns, long gc_start_time_ns, bool is_wall_time);
|
215
|
+
static long cpu_time_now_ns(struct per_thread_context *thread_context);
|
216
|
+
static long thread_id_for(VALUE thread);
|
217
|
+
static VALUE _native_stats(VALUE self, VALUE collector_instance);
|
218
|
+
static VALUE _native_gc_tracking(VALUE self, VALUE collector_instance);
|
219
|
+
static void trace_identifiers_for(struct thread_context_collector_state *state, VALUE thread, struct trace_identifiers *trace_identifiers_result);
|
220
|
+
static bool should_collect_resource(VALUE root_span);
|
221
|
+
static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE collector_instance);
|
222
|
+
static VALUE thread_list(struct thread_context_collector_state *state);
|
223
|
+
static VALUE _native_sample_allocation(DDTRACE_UNUSED VALUE self, VALUE collector_instance, VALUE sample_weight, VALUE new_object);
|
224
|
+
static VALUE _native_new_empty_thread(VALUE self);
|
225
|
+
static ddog_CharSlice ruby_value_type_to_class_name(enum ruby_value_type type);
|
226
|
+
static void ddtrace_otel_trace_identifiers_for(
|
227
|
+
struct thread_context_collector_state *state,
|
228
|
+
VALUE *active_trace,
|
229
|
+
VALUE *root_span,
|
230
|
+
VALUE *numeric_span_id,
|
231
|
+
VALUE active_span,
|
232
|
+
VALUE otel_values
|
233
|
+
);
|
234
|
+
|
235
|
+
void collectors_thread_context_init(VALUE profiling_module) {
|
236
|
+
VALUE collectors_module = rb_define_module_under(profiling_module, "Collectors");
|
237
|
+
VALUE collectors_thread_context_class = rb_define_class_under(collectors_module, "ThreadContext", rb_cObject);
|
238
|
+
// Hosts methods used for testing the native code using RSpec
|
239
|
+
VALUE testing_module = rb_define_module_under(collectors_thread_context_class, "Testing");
|
240
|
+
|
241
|
+
// Instances of the ThreadContext class are "TypedData" objects.
|
242
|
+
// "TypedData" objects are special objects in the Ruby VM that can wrap C structs.
|
243
|
+
// In this case, it wraps the thread_context_collector_state.
|
244
|
+
//
|
245
|
+
// Because Ruby doesn't know how to initialize native-level structs, we MUST override the allocation function for objects
|
246
|
+
// of this class so that we can manage this part. Not overriding or disabling the allocation function is a common
|
247
|
+
// gotcha for "TypedData" objects that can very easily lead to VM crashes, see for instance
|
248
|
+
// https://bugs.ruby-lang.org/issues/18007 for a discussion around this.
|
249
|
+
rb_define_alloc_func(collectors_thread_context_class, _native_new);
|
250
|
+
|
251
|
+
rb_define_singleton_method(collectors_thread_context_class, "_native_initialize", _native_initialize, 7);
|
252
|
+
rb_define_singleton_method(collectors_thread_context_class, "_native_inspect", _native_inspect, 1);
|
253
|
+
rb_define_singleton_method(collectors_thread_context_class, "_native_reset_after_fork", _native_reset_after_fork, 1);
|
254
|
+
rb_define_singleton_method(testing_module, "_native_sample", _native_sample, 2);
|
255
|
+
rb_define_singleton_method(testing_module, "_native_sample_allocation", _native_sample_allocation, 3);
|
256
|
+
rb_define_singleton_method(testing_module, "_native_on_gc_start", _native_on_gc_start, 1);
|
257
|
+
rb_define_singleton_method(testing_module, "_native_on_gc_finish", _native_on_gc_finish, 1);
|
258
|
+
rb_define_singleton_method(testing_module, "_native_sample_after_gc", _native_sample_after_gc, 1);
|
259
|
+
rb_define_singleton_method(testing_module, "_native_thread_list", _native_thread_list, 0);
|
260
|
+
rb_define_singleton_method(testing_module, "_native_per_thread_context", _native_per_thread_context, 1);
|
261
|
+
rb_define_singleton_method(testing_module, "_native_stats", _native_stats, 1);
|
262
|
+
rb_define_singleton_method(testing_module, "_native_gc_tracking", _native_gc_tracking, 1);
|
263
|
+
rb_define_singleton_method(testing_module, "_native_new_empty_thread", _native_new_empty_thread, 0);
|
264
|
+
|
265
|
+
at_active_span_id = rb_intern_const("@active_span");
|
266
|
+
at_active_trace_id = rb_intern_const("@active_trace");
|
267
|
+
at_id_id = rb_intern_const("@id");
|
268
|
+
at_resource_id = rb_intern_const("@resource");
|
269
|
+
at_root_span_id = rb_intern_const("@root_span");
|
270
|
+
at_type_id = rb_intern_const("@type");
|
271
|
+
at_otel_values_id = rb_intern_const("@otel_values");
|
272
|
+
at_parent_span_id_id = rb_intern_const("@parent_span_id");
|
273
|
+
at_datadog_trace_id = rb_intern_const("@datadog_trace");
|
274
|
+
|
275
|
+
gc_profiling_init();
|
276
|
+
}
|
277
|
+
|
278
|
+
// This structure is used to define a Ruby object that stores a pointer to a struct thread_context_collector_state
|
279
|
+
// See also https://github.com/ruby/ruby/blob/master/doc/extension.rdoc for how this works
|
280
|
+
static const rb_data_type_t thread_context_collector_typed_data = {
|
281
|
+
.wrap_struct_name = "Datadog::Profiling::Collectors::ThreadContext",
|
282
|
+
.function = {
|
283
|
+
.dmark = thread_context_collector_typed_data_mark,
|
284
|
+
.dfree = thread_context_collector_typed_data_free,
|
285
|
+
.dsize = NULL, // We don't track profile memory usage (although it'd be cool if we did!)
|
286
|
+
//.dcompact = NULL, // FIXME: Add support for compaction
|
287
|
+
},
|
288
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
289
|
+
};
|
290
|
+
|
291
|
+
// This function is called by the Ruby GC to give us a chance to mark any Ruby objects that we're holding on to,
|
292
|
+
// so that they don't get garbage collected
|
293
|
+
static void thread_context_collector_typed_data_mark(void *state_ptr) {
|
294
|
+
struct thread_context_collector_state *state = (struct thread_context_collector_state *) state_ptr;
|
295
|
+
|
296
|
+
// Update this when modifying state struct
|
297
|
+
rb_gc_mark(state->recorder_instance);
|
298
|
+
st_foreach(state->hash_map_per_thread_context, hash_map_per_thread_context_mark, 0 /* unused */);
|
299
|
+
rb_gc_mark(state->thread_list_buffer);
|
300
|
+
rb_gc_mark(state->main_thread);
|
301
|
+
rb_gc_mark(state->otel_current_span_key);
|
302
|
+
}
|
303
|
+
|
304
|
+
static void thread_context_collector_typed_data_free(void *state_ptr) {
|
305
|
+
struct thread_context_collector_state *state = (struct thread_context_collector_state *) state_ptr;
|
306
|
+
|
307
|
+
// Update this when modifying state struct
|
308
|
+
|
309
|
+
// Important: Remember that we're only guaranteed to see here what's been set in _native_new, aka
|
310
|
+
// pointers that have been set NULL there may still be NULL here.
|
311
|
+
if (state->sampling_buffer != NULL) sampling_buffer_free(state->sampling_buffer);
|
312
|
+
|
313
|
+
// Free each entry in the map
|
314
|
+
st_foreach(state->hash_map_per_thread_context, hash_map_per_thread_context_free_values, 0 /* unused */);
|
315
|
+
// ...and then the map
|
316
|
+
st_free_table(state->hash_map_per_thread_context);
|
317
|
+
|
318
|
+
ruby_xfree(state);
|
319
|
+
}
|
320
|
+
|
321
|
+
// Mark Ruby thread references we keep as keys in hash_map_per_thread_context
|
322
|
+
static int hash_map_per_thread_context_mark(st_data_t key_thread, DDTRACE_UNUSED st_data_t _value, DDTRACE_UNUSED st_data_t _argument) {
|
323
|
+
VALUE thread = (VALUE) key_thread;
|
324
|
+
rb_gc_mark(thread);
|
325
|
+
return ST_CONTINUE;
|
326
|
+
}
|
327
|
+
|
328
|
+
// Used to clear each of the per_thread_contexts inside the hash_map_per_thread_context
|
329
|
+
static int hash_map_per_thread_context_free_values(DDTRACE_UNUSED st_data_t _thread, st_data_t value_per_thread_context, DDTRACE_UNUSED st_data_t _argument) {
|
330
|
+
struct per_thread_context *per_thread_context = (struct per_thread_context*) value_per_thread_context;
|
331
|
+
ruby_xfree(per_thread_context);
|
332
|
+
return ST_CONTINUE;
|
333
|
+
}
|
334
|
+
|
335
|
+
static VALUE _native_new(VALUE klass) {
|
336
|
+
struct thread_context_collector_state *state = ruby_xcalloc(1, sizeof(struct thread_context_collector_state));
|
337
|
+
|
338
|
+
// Note: Any exceptions raised from this note until the TypedData_Wrap_Struct call will lead to the state memory
|
339
|
+
// being leaked.
|
340
|
+
|
341
|
+
// Update this when modifying state struct
|
342
|
+
state->sampling_buffer = NULL;
|
343
|
+
state->hash_map_per_thread_context =
|
344
|
+
// "numtable" is an awful name, but TL;DR it's what should be used when keys are `VALUE`s.
|
345
|
+
st_init_numtable();
|
346
|
+
state->recorder_instance = Qnil;
|
347
|
+
state->tracer_context_key = MISSING_TRACER_CONTEXT_KEY;
|
348
|
+
state->thread_list_buffer = rb_ary_new();
|
349
|
+
state->endpoint_collection_enabled = true;
|
350
|
+
state->timeline_enabled = true;
|
351
|
+
state->allocation_type_enabled = true;
|
352
|
+
state->time_converter_state = (monotonic_to_system_epoch_state) MONOTONIC_TO_SYSTEM_EPOCH_INITIALIZER;
|
353
|
+
state->main_thread = rb_thread_main();
|
354
|
+
state->otel_current_span_key = Qnil;
|
355
|
+
state->gc_tracking.wall_time_at_previous_gc_ns = INVALID_TIME;
|
356
|
+
state->gc_tracking.wall_time_at_last_flushed_gc_event_ns = 0;
|
357
|
+
|
358
|
+
return TypedData_Wrap_Struct(klass, &thread_context_collector_typed_data, state);
|
359
|
+
}
|
360
|
+
|
361
|
+
static VALUE _native_initialize(
|
362
|
+
DDTRACE_UNUSED VALUE _self,
|
363
|
+
VALUE collector_instance,
|
364
|
+
VALUE recorder_instance,
|
365
|
+
VALUE max_frames,
|
366
|
+
VALUE tracer_context_key,
|
367
|
+
VALUE endpoint_collection_enabled,
|
368
|
+
VALUE timeline_enabled,
|
369
|
+
VALUE allocation_type_enabled
|
370
|
+
) {
|
371
|
+
ENFORCE_BOOLEAN(endpoint_collection_enabled);
|
372
|
+
ENFORCE_BOOLEAN(timeline_enabled);
|
373
|
+
ENFORCE_BOOLEAN(allocation_type_enabled);
|
374
|
+
|
375
|
+
struct thread_context_collector_state *state;
|
376
|
+
TypedData_Get_Struct(collector_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
377
|
+
|
378
|
+
int max_frames_requested = NUM2INT(max_frames);
|
379
|
+
if (max_frames_requested < 0) rb_raise(rb_eArgError, "Invalid max_frames: value must not be negative");
|
380
|
+
|
381
|
+
// Update this when modifying state struct
|
382
|
+
state->sampling_buffer = sampling_buffer_new(max_frames_requested);
|
383
|
+
// hash_map_per_thread_context is already initialized, nothing to do here
|
384
|
+
state->recorder_instance = enforce_recorder_instance(recorder_instance);
|
385
|
+
state->endpoint_collection_enabled = (endpoint_collection_enabled == Qtrue);
|
386
|
+
state->timeline_enabled = (timeline_enabled == Qtrue);
|
387
|
+
state->allocation_type_enabled = (allocation_type_enabled == Qtrue);
|
388
|
+
|
389
|
+
if (RTEST(tracer_context_key)) {
|
390
|
+
ENFORCE_TYPE(tracer_context_key, T_SYMBOL);
|
391
|
+
// Note about rb_to_id and dynamic symbols: calling `rb_to_id` prevents symbols from ever being garbage collected.
|
392
|
+
// In this case, we can't really escape this because as of this writing, ruby master still calls `rb_to_id` inside
|
393
|
+
// the implementation of Thread#[]= so any symbol that gets used as a key there will already be prevented from GC.
|
394
|
+
state->tracer_context_key = rb_to_id(tracer_context_key);
|
395
|
+
}
|
396
|
+
|
397
|
+
return Qtrue;
|
398
|
+
}
|
399
|
+
|
400
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
401
|
+
// It SHOULD NOT be used for other purposes.
|
402
|
+
static VALUE _native_sample(DDTRACE_UNUSED VALUE _self, VALUE collector_instance, VALUE profiler_overhead_stack_thread) {
|
403
|
+
if (!is_thread_alive(profiler_overhead_stack_thread)) rb_raise(rb_eArgError, "Unexpected: profiler_overhead_stack_thread is not alive");
|
404
|
+
|
405
|
+
thread_context_collector_sample(collector_instance, monotonic_wall_time_now_ns(RAISE_ON_FAILURE), profiler_overhead_stack_thread);
|
406
|
+
return Qtrue;
|
407
|
+
}
|
408
|
+
|
409
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
410
|
+
// It SHOULD NOT be used for other purposes.
|
411
|
+
static VALUE _native_on_gc_start(DDTRACE_UNUSED VALUE self, VALUE collector_instance) {
|
412
|
+
thread_context_collector_on_gc_start(collector_instance);
|
413
|
+
return Qtrue;
|
414
|
+
}
|
415
|
+
|
416
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
417
|
+
// It SHOULD NOT be used for other purposes.
|
418
|
+
static VALUE _native_on_gc_finish(DDTRACE_UNUSED VALUE self, VALUE collector_instance) {
|
419
|
+
thread_context_collector_on_gc_finish(collector_instance);
|
420
|
+
return Qtrue;
|
421
|
+
}
|
422
|
+
|
423
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
424
|
+
// It SHOULD NOT be used for other purposes.
|
425
|
+
static VALUE _native_sample_after_gc(DDTRACE_UNUSED VALUE self, VALUE collector_instance) {
|
426
|
+
thread_context_collector_sample_after_gc(collector_instance);
|
427
|
+
return Qtrue;
|
428
|
+
}
|
429
|
+
|
430
|
+
// This function gets called from the Collectors::CpuAndWallTimeWorker to trigger the actual sampling.
|
431
|
+
//
|
432
|
+
// Assumption 1: This function is called in a thread that is holding the Global VM Lock. Caller is responsible for enforcing this.
|
433
|
+
// Assumption 2: This function is allowed to raise exceptions. Caller is responsible for handling them, if needed.
|
434
|
+
// Assumption 3: This function IS NOT called from a signal handler. This function is not async-signal-safe.
|
435
|
+
// Assumption 4: This function IS NOT called in a reentrant way.
|
436
|
+
// Assumption 5: This function is called from the main Ractor (if Ruby has support for Ractors).
|
437
|
+
//
|
438
|
+
// The `profiler_overhead_stack_thread` is used to attribute the profiler overhead to a stack borrowed from a different thread
|
439
|
+
// (belonging to ddtrace), so that the overhead is visible in the profile rather than blamed on user code.
|
440
|
+
void thread_context_collector_sample(VALUE self_instance, long current_monotonic_wall_time_ns, VALUE profiler_overhead_stack_thread) {
|
441
|
+
struct thread_context_collector_state *state;
|
442
|
+
TypedData_Get_Struct(self_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
443
|
+
|
444
|
+
VALUE current_thread = rb_thread_current();
|
445
|
+
struct per_thread_context *current_thread_context = get_or_create_context_for(current_thread, state);
|
446
|
+
long cpu_time_at_sample_start_for_current_thread = cpu_time_now_ns(current_thread_context);
|
447
|
+
|
448
|
+
VALUE threads = thread_list(state);
|
449
|
+
|
450
|
+
const long thread_count = RARRAY_LEN(threads);
|
451
|
+
for (long i = 0; i < thread_count; i++) {
|
452
|
+
VALUE thread = RARRAY_AREF(threads, i);
|
453
|
+
struct per_thread_context *thread_context = get_or_create_context_for(thread, state);
|
454
|
+
|
455
|
+
// We account for cpu-time for the current thread in a different way -- we use the cpu-time at sampling start, to avoid
|
456
|
+
// blaming the time the profiler took on whatever's running on the thread right now
|
457
|
+
long current_cpu_time_ns = thread != current_thread ? cpu_time_now_ns(thread_context) : cpu_time_at_sample_start_for_current_thread;
|
458
|
+
|
459
|
+
update_metrics_and_sample(
|
460
|
+
state,
|
461
|
+
/* thread_being_sampled: */ thread,
|
462
|
+
/* stack_from_thread: */ thread,
|
463
|
+
thread_context,
|
464
|
+
current_cpu_time_ns,
|
465
|
+
current_monotonic_wall_time_ns
|
466
|
+
);
|
467
|
+
}
|
468
|
+
|
469
|
+
state->sample_count++;
|
470
|
+
|
471
|
+
// TODO: This seems somewhat overkill and inefficient to do often; right now we just do it every few samples
|
472
|
+
// but there's probably a better way to do this if we actually track when threads finish
|
473
|
+
if (state->sample_count % 100 == 0) remove_context_for_dead_threads(state);
|
474
|
+
|
475
|
+
update_metrics_and_sample(
|
476
|
+
state,
|
477
|
+
/* thread_being_sampled: */ current_thread,
|
478
|
+
/* stack_from_thread: */ profiler_overhead_stack_thread,
|
479
|
+
current_thread_context,
|
480
|
+
cpu_time_now_ns(current_thread_context),
|
481
|
+
monotonic_wall_time_now_ns(RAISE_ON_FAILURE)
|
482
|
+
);
|
483
|
+
}
|
484
|
+
|
485
|
+
void update_metrics_and_sample(
|
486
|
+
struct thread_context_collector_state *state,
|
487
|
+
VALUE thread_being_sampled,
|
488
|
+
VALUE stack_from_thread, // This can be different when attributing profiler overhead using a different stack
|
489
|
+
struct per_thread_context *thread_context,
|
490
|
+
long current_cpu_time_ns,
|
491
|
+
long current_monotonic_wall_time_ns
|
492
|
+
) {
|
493
|
+
long cpu_time_elapsed_ns = update_time_since_previous_sample(
|
494
|
+
&thread_context->cpu_time_at_previous_sample_ns,
|
495
|
+
current_cpu_time_ns,
|
496
|
+
thread_context->gc_tracking.cpu_time_at_start_ns,
|
497
|
+
IS_NOT_WALL_TIME
|
498
|
+
);
|
499
|
+
long wall_time_elapsed_ns = update_time_since_previous_sample(
|
500
|
+
&thread_context->wall_time_at_previous_sample_ns,
|
501
|
+
current_monotonic_wall_time_ns,
|
502
|
+
// We explicitly pass in `INVALID_TIME` as an argument for `gc_start_time_ns` here because we don't want wall-time
|
503
|
+
// accounting to change during GC.
|
504
|
+
// E.g. if 60 seconds pass in the real world, 60 seconds of wall-time are recorded, regardless of the thread doing
|
505
|
+
// GC or not.
|
506
|
+
INVALID_TIME,
|
507
|
+
IS_WALL_TIME
|
508
|
+
);
|
509
|
+
|
510
|
+
trigger_sample_for_thread(
|
511
|
+
state,
|
512
|
+
thread_being_sampled,
|
513
|
+
stack_from_thread,
|
514
|
+
thread_context,
|
515
|
+
(sample_values) {.cpu_time_ns = cpu_time_elapsed_ns, .cpu_or_wall_samples = 1, .wall_time_ns = wall_time_elapsed_ns},
|
516
|
+
current_monotonic_wall_time_ns,
|
517
|
+
NULL,
|
518
|
+
NULL
|
519
|
+
);
|
520
|
+
}
|
521
|
+
|
522
|
+
// This function gets called when Ruby is about to start running the Garbage Collector on the current thread.
|
523
|
+
// It updates the per_thread_context of the current thread to include the current cpu/wall times, to be used to later
|
524
|
+
// create an event including the cpu/wall time spent in garbage collector work.
|
525
|
+
//
|
526
|
+
// Safety: This function gets called while Ruby is doing garbage collection. While Ruby is doing garbage collection,
|
527
|
+
// *NO ALLOCATION* is allowed. This function, and any it calls must never trigger memory or object allocation.
|
528
|
+
// This includes exceptions and use of ruby_xcalloc (because xcalloc can trigger GC)!
|
529
|
+
//
|
530
|
+
// Assumption 1: This function is called in a thread that is holding the Global VM Lock. Caller is responsible for enforcing this.
|
531
|
+
// Assumption 2: This function is called from the main Ractor (if Ruby has support for Ractors).
|
532
|
+
void thread_context_collector_on_gc_start(VALUE self_instance) {
|
533
|
+
struct thread_context_collector_state *state;
|
534
|
+
if (!rb_typeddata_is_kind_of(self_instance, &thread_context_collector_typed_data)) return;
|
535
|
+
// This should never fail the the above check passes
|
536
|
+
TypedData_Get_Struct(self_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
537
|
+
|
538
|
+
struct per_thread_context *thread_context = get_context_for(rb_thread_current(), state);
|
539
|
+
|
540
|
+
// If there was no previously-existing context for this thread, we won't allocate one (see safety). For now we just drop
|
541
|
+
// the GC sample, under the assumption that "a thread that is so new that we never sampled it even once before it triggers
|
542
|
+
// GC" is a rare enough case that we can just ignore it.
|
543
|
+
// We can always improve this later if we find that this happens often (and we have the counter to help us figure that out)!
|
544
|
+
if (thread_context == NULL) {
|
545
|
+
state->stats.gc_samples_missed_due_to_missing_context++;
|
546
|
+
return;
|
547
|
+
}
|
548
|
+
|
549
|
+
// Here we record the wall-time first and in on_gc_finish we record it second to try to avoid having wall-time be slightly < cpu-time
|
550
|
+
thread_context->gc_tracking.wall_time_at_start_ns = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
|
551
|
+
thread_context->gc_tracking.cpu_time_at_start_ns = cpu_time_now_ns(thread_context);
|
552
|
+
}
|
553
|
+
|
554
|
+
// This function gets called when Ruby has finished running the Garbage Collector on the current thread.
|
555
|
+
// It records the cpu/wall-time observed during GC, which will be used to later
|
556
|
+
// create an event including the cpu/wall time spent from the start of garbage collector work until now.
|
557
|
+
//
|
558
|
+
// Safety: This function gets called while Ruby is doing garbage collection. While Ruby is doing garbage collection,
|
559
|
+
// *NO ALLOCATION* is allowed. This function, and any it calls must never trigger memory or object allocation.
|
560
|
+
// This includes exceptions and use of ruby_xcalloc (because xcalloc can trigger GC)!
|
561
|
+
//
|
562
|
+
// Assumption 1: This function is called in a thread that is holding the Global VM Lock. Caller is responsible for enforcing this.
|
563
|
+
// Assumption 2: This function is called from the main Ractor (if Ruby has support for Ractors).
|
564
|
+
bool thread_context_collector_on_gc_finish(VALUE self_instance) {
|
565
|
+
struct thread_context_collector_state *state;
|
566
|
+
if (!rb_typeddata_is_kind_of(self_instance, &thread_context_collector_typed_data)) return false;
|
567
|
+
// This should never fail the the above check passes
|
568
|
+
TypedData_Get_Struct(self_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
569
|
+
|
570
|
+
struct per_thread_context *thread_context = get_context_for(rb_thread_current(), state);
|
571
|
+
|
572
|
+
// If there was no previously-existing context for this thread, we won't allocate one (see safety). We keep a metric for
|
573
|
+
// how often this happens -- see on_gc_start.
|
574
|
+
if (thread_context == NULL) return false;
|
575
|
+
|
576
|
+
long cpu_time_at_start_ns = thread_context->gc_tracking.cpu_time_at_start_ns;
|
577
|
+
long wall_time_at_start_ns = thread_context->gc_tracking.wall_time_at_start_ns;
|
578
|
+
|
579
|
+
if (cpu_time_at_start_ns == INVALID_TIME && wall_time_at_start_ns == INVALID_TIME) {
|
580
|
+
// If this happened, it means that on_gc_start was either never called for the thread OR it was called but no thread
|
581
|
+
// context existed at the time. The former can be the result of a bug, but since we can't distinguish them, we just
|
582
|
+
// do nothing.
|
583
|
+
return false;
|
584
|
+
}
|
585
|
+
|
586
|
+
// Mark thread as no longer in GC
|
587
|
+
thread_context->gc_tracking.cpu_time_at_start_ns = INVALID_TIME;
|
588
|
+
thread_context->gc_tracking.wall_time_at_start_ns = INVALID_TIME;
|
589
|
+
|
590
|
+
// Here we record the wall-time second and in on_gc_start we record it first to try to avoid having wall-time be slightly < cpu-time
|
591
|
+
long cpu_time_at_finish_ns = cpu_time_now_ns(thread_context);
|
592
|
+
long wall_time_at_finish_ns = monotonic_wall_time_now_ns(DO_NOT_RAISE_ON_FAILURE);
|
593
|
+
|
594
|
+
// If our end timestamp is not OK, we bail out
|
595
|
+
if (wall_time_at_finish_ns == 0) return false;
|
596
|
+
|
597
|
+
long gc_cpu_time_elapsed_ns = cpu_time_at_finish_ns - cpu_time_at_start_ns;
|
598
|
+
long gc_wall_time_elapsed_ns = wall_time_at_finish_ns - wall_time_at_start_ns;
|
599
|
+
|
600
|
+
// Wall-time can go backwards if the system clock gets changed (and we observed spurious jumps back on macOS as well)
|
601
|
+
// so let's ensure we don't get negative values for time deltas.
|
602
|
+
gc_cpu_time_elapsed_ns = long_max_of(gc_cpu_time_elapsed_ns, 0);
|
603
|
+
gc_wall_time_elapsed_ns = long_max_of(gc_wall_time_elapsed_ns, 0);
|
604
|
+
|
605
|
+
if (state->gc_tracking.wall_time_at_previous_gc_ns == INVALID_TIME) {
|
606
|
+
state->gc_tracking.accumulated_cpu_time_ns = 0;
|
607
|
+
state->gc_tracking.accumulated_wall_time_ns = 0;
|
608
|
+
}
|
609
|
+
|
610
|
+
state->gc_tracking.accumulated_cpu_time_ns += gc_cpu_time_elapsed_ns;
|
611
|
+
state->gc_tracking.accumulated_wall_time_ns += gc_wall_time_elapsed_ns;
|
612
|
+
state->gc_tracking.wall_time_at_previous_gc_ns = wall_time_at_finish_ns;
|
613
|
+
|
614
|
+
// Update cpu-time accounting so it doesn't include the cpu-time spent in GC during the next sample
|
615
|
+
// We don't update the wall-time because we don't subtract the wall-time spent in GC (see call to
|
616
|
+
// `update_time_since_previous_sample` for wall-time in `update_metrics_and_sample`).
|
617
|
+
if (thread_context->cpu_time_at_previous_sample_ns != INVALID_TIME) {
|
618
|
+
thread_context->cpu_time_at_previous_sample_ns += gc_cpu_time_elapsed_ns;
|
619
|
+
}
|
620
|
+
|
621
|
+
// Let the caller know if it should schedule a flush or not. Returning true every time would cause a lot of overhead
|
622
|
+
// on the application (see GC tracking introduction at the top of the file), so instead we try to accumulate a few
|
623
|
+
// samples first.
|
624
|
+
bool over_flush_time_treshold =
|
625
|
+
(wall_time_at_finish_ns - state->gc_tracking.wall_time_at_last_flushed_gc_event_ns) >= TIME_BETWEEN_GC_EVENTS_NS;
|
626
|
+
|
627
|
+
if (over_flush_time_treshold) {
|
628
|
+
return true;
|
629
|
+
} else {
|
630
|
+
return gc_profiling_has_major_gc_finished();
|
631
|
+
}
|
632
|
+
}
|
633
|
+
|
634
|
+
// This function gets called after one or more GC work steps (calls to on_gc_start/on_gc_finish).
|
635
|
+
// It creates a new sample including the cpu and wall-time spent by the garbage collector work, and resets any
|
636
|
+
// GC-related tracking.
|
637
|
+
//
|
638
|
+
// Assumption 1: This function is called in a thread that is holding the Global VM Lock. Caller is responsible for enforcing this.
|
639
|
+
// Assumption 2: This function is allowed to raise exceptions. Caller is responsible for handling them, if needed.
|
640
|
+
// Assumption 3: Unlike `on_gc_start` and `on_gc_finish`, this method is allowed to allocate memory as needed.
|
641
|
+
// Assumption 4: This function is called from the main Ractor (if Ruby has support for Ractors).
|
642
|
+
VALUE thread_context_collector_sample_after_gc(VALUE self_instance) {
|
643
|
+
struct thread_context_collector_state *state;
|
644
|
+
TypedData_Get_Struct(self_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
645
|
+
|
646
|
+
if (state->gc_tracking.wall_time_at_previous_gc_ns == INVALID_TIME) {
|
647
|
+
rb_raise(rb_eRuntimeError, "BUG: Unexpected call to sample_after_gc without valid GC information available");
|
648
|
+
}
|
649
|
+
|
650
|
+
int max_labels_needed_for_gc = 7; // Magic number gets validated inside gc_profiling_set_metadata
|
651
|
+
ddog_prof_Label labels[max_labels_needed_for_gc];
|
652
|
+
uint8_t label_pos = gc_profiling_set_metadata(labels, max_labels_needed_for_gc);
|
653
|
+
|
654
|
+
ddog_prof_Slice_Label slice_labels = {.ptr = labels, .len = label_pos};
|
655
|
+
|
656
|
+
// The end_timestamp_ns is treated specially by libdatadog and that's why it's not added as a ddog_prof_Label
|
657
|
+
int64_t end_timestamp_ns = 0;
|
658
|
+
|
659
|
+
if (state->timeline_enabled) {
|
660
|
+
end_timestamp_ns = monotonic_to_system_epoch_ns(&state->time_converter_state, state->gc_tracking.wall_time_at_previous_gc_ns);
|
661
|
+
}
|
662
|
+
|
663
|
+
record_placeholder_stack(
|
664
|
+
state->sampling_buffer,
|
665
|
+
state->recorder_instance,
|
666
|
+
(sample_values) {
|
667
|
+
// This event gets both a regular cpu/wall-time duration, as a normal cpu/wall-time sample would, as well as a
|
668
|
+
// timeline duration.
|
669
|
+
// This is done to enable two use-cases:
|
670
|
+
// * regular cpu/wall-time makes this event show up as a regular stack in the flamegraph
|
671
|
+
// * the timeline duration is used when the event shows up in the timeline
|
672
|
+
.cpu_time_ns = state->gc_tracking.accumulated_cpu_time_ns,
|
673
|
+
.cpu_or_wall_samples = 1,
|
674
|
+
.wall_time_ns = state->gc_tracking.accumulated_wall_time_ns,
|
675
|
+
.timeline_wall_time_ns = state->gc_tracking.accumulated_wall_time_ns,
|
676
|
+
},
|
677
|
+
(sample_labels) {.labels = slice_labels, .state_label = NULL, .end_timestamp_ns = end_timestamp_ns},
|
678
|
+
DDOG_CHARSLICE_C("Garbage Collection")
|
679
|
+
);
|
680
|
+
|
681
|
+
state->gc_tracking.wall_time_at_last_flushed_gc_event_ns = state->gc_tracking.wall_time_at_previous_gc_ns;
|
682
|
+
state->gc_tracking.wall_time_at_previous_gc_ns = INVALID_TIME;
|
683
|
+
|
684
|
+
state->stats.gc_samples++;
|
685
|
+
|
686
|
+
// Return a VALUE to make it easier to call this function from Ruby APIs that expect a return value (such as rb_rescue2)
|
687
|
+
return Qnil;
|
688
|
+
}
|
689
|
+
|
690
|
+
static void trigger_sample_for_thread(
|
691
|
+
struct thread_context_collector_state *state,
|
692
|
+
VALUE thread,
|
693
|
+
VALUE stack_from_thread, // This can be different when attributing profiler overhead using a different stack
|
694
|
+
struct per_thread_context *thread_context,
|
695
|
+
sample_values values,
|
696
|
+
long current_monotonic_wall_time_ns,
|
697
|
+
// These two labels are only used for allocation profiling; @ivoanjo: may want to refactor this at some point?
|
698
|
+
ddog_CharSlice *ruby_vm_type,
|
699
|
+
ddog_CharSlice *class_name
|
700
|
+
) {
|
701
|
+
int max_label_count =
|
702
|
+
1 + // thread id
|
703
|
+
1 + // thread name
|
704
|
+
1 + // profiler overhead
|
705
|
+
2 + // ruby vm type and allocation class
|
706
|
+
1 + // state (only set for cpu/wall-time samples)
|
707
|
+
2; // local root span id and span id
|
708
|
+
ddog_prof_Label labels[max_label_count];
|
709
|
+
int label_pos = 0;
|
710
|
+
|
711
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
712
|
+
.key = DDOG_CHARSLICE_C("thread id"),
|
713
|
+
.str = thread_context->thread_id_char_slice
|
714
|
+
};
|
715
|
+
|
716
|
+
VALUE thread_name = thread_name_for(thread);
|
717
|
+
if (thread_name != Qnil) {
|
718
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
719
|
+
.key = DDOG_CHARSLICE_C("thread name"),
|
720
|
+
.str = char_slice_from_ruby_string(thread_name)
|
721
|
+
};
|
722
|
+
} else if (thread == state->main_thread) { // Threads are often not named, but we can have a nice fallback for this special thread
|
723
|
+
ddog_CharSlice main_thread_name = DDOG_CHARSLICE_C("main");
|
724
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
725
|
+
.key = DDOG_CHARSLICE_C("thread name"),
|
726
|
+
.str = main_thread_name
|
727
|
+
};
|
728
|
+
} else {
|
729
|
+
// For other threads without name, we use the "invoke location" (first file:line of the block used to start the thread), if any.
|
730
|
+
// This is what Ruby shows in `Thread#to_s`.
|
731
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
732
|
+
.key = DDOG_CHARSLICE_C("thread name"),
|
733
|
+
.str = thread_context->thread_invoke_location_char_slice // This is an empty string if no invoke location was available
|
734
|
+
};
|
735
|
+
}
|
736
|
+
|
737
|
+
struct trace_identifiers trace_identifiers_result = {.valid = false, .trace_endpoint = Qnil};
|
738
|
+
trace_identifiers_for(state, thread, &trace_identifiers_result);
|
739
|
+
|
740
|
+
if (trace_identifiers_result.valid) {
|
741
|
+
labels[label_pos++] = (ddog_prof_Label) {.key = DDOG_CHARSLICE_C("local root span id"), .num = trace_identifiers_result.local_root_span_id};
|
742
|
+
labels[label_pos++] = (ddog_prof_Label) {.key = DDOG_CHARSLICE_C("span id"), .num = trace_identifiers_result.span_id};
|
743
|
+
|
744
|
+
if (trace_identifiers_result.trace_endpoint != Qnil) {
|
745
|
+
// The endpoint gets recorded in a different way because it is mutable in the tracer and can change during a
|
746
|
+
// trace.
|
747
|
+
//
|
748
|
+
// Instead of each sample for the same local_root_span_id getting a potentially-different endpoint,
|
749
|
+
// `record_endpoint` (via libdatadog) keeps a list of local_root_span_id values and their most-recently-seen
|
750
|
+
// endpoint values, and at serialization time the most-recently-seen endpoint is applied to all relevant samples.
|
751
|
+
//
|
752
|
+
// This is why the endpoint is not directly added in this function to the labels array, although it will later
|
753
|
+
// show up in the array in the output pprof.
|
754
|
+
record_endpoint(
|
755
|
+
state->recorder_instance,
|
756
|
+
trace_identifiers_result.local_root_span_id,
|
757
|
+
char_slice_from_ruby_string(trace_identifiers_result.trace_endpoint)
|
758
|
+
);
|
759
|
+
}
|
760
|
+
}
|
761
|
+
|
762
|
+
if (thread != stack_from_thread) {
|
763
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
764
|
+
.key = DDOG_CHARSLICE_C("profiler overhead"),
|
765
|
+
.num = 1
|
766
|
+
};
|
767
|
+
}
|
768
|
+
|
769
|
+
if (ruby_vm_type != NULL) {
|
770
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
771
|
+
.key = DDOG_CHARSLICE_C("ruby vm type"),
|
772
|
+
.str = *ruby_vm_type
|
773
|
+
};
|
774
|
+
}
|
775
|
+
|
776
|
+
if (class_name != NULL) {
|
777
|
+
labels[label_pos++] = (ddog_prof_Label) {
|
778
|
+
.key = DDOG_CHARSLICE_C("allocation class"),
|
779
|
+
.str = *class_name
|
780
|
+
};
|
781
|
+
}
|
782
|
+
|
783
|
+
// This label is handled specially:
|
784
|
+
// 1. It's only set for cpu/wall-time samples
|
785
|
+
// 2. We set it here to its default state of "unknown", but the `Collectors::Stack` may choose to override it with
|
786
|
+
// something more interesting.
|
787
|
+
ddog_prof_Label *state_label = NULL;
|
788
|
+
if (values.cpu_or_wall_samples > 0) {
|
789
|
+
state_label = &labels[label_pos++];
|
790
|
+
*state_label = (ddog_prof_Label) {
|
791
|
+
.key = DDOG_CHARSLICE_C("state"),
|
792
|
+
.str = DDOG_CHARSLICE_C("unknown"),
|
793
|
+
.num = 0, // This shouldn't be needed but the tracer-2.7 docker image ships a buggy gcc that complains about this
|
794
|
+
};
|
795
|
+
}
|
796
|
+
|
797
|
+
// The number of times `label_pos++` shows up in this function needs to match `max_label_count`. To avoid "oops I
|
798
|
+
// forgot to update max_label_count" in the future, we've also added this validation.
|
799
|
+
// @ivoanjo: I wonder if C compilers are smart enough to statically prove this check never triggers unless someone
|
800
|
+
// changes the code erroneously and remove it entirely?
|
801
|
+
if (label_pos > max_label_count) {
|
802
|
+
rb_raise(rb_eRuntimeError, "BUG: Unexpected label_pos (%d) > max_label_count (%d)", label_pos, max_label_count);
|
803
|
+
}
|
804
|
+
|
805
|
+
ddog_prof_Slice_Label slice_labels = {.ptr = labels, .len = label_pos};
|
806
|
+
|
807
|
+
// The end_timestamp_ns is treated specially by libdatadog and that's why it's not added as a ddog_prof_Label
|
808
|
+
int64_t end_timestamp_ns = 0;
|
809
|
+
if (state->timeline_enabled && current_monotonic_wall_time_ns != INVALID_TIME) {
|
810
|
+
end_timestamp_ns = monotonic_to_system_epoch_ns(&state->time_converter_state, current_monotonic_wall_time_ns);
|
811
|
+
}
|
812
|
+
|
813
|
+
sample_thread(
|
814
|
+
stack_from_thread,
|
815
|
+
state->sampling_buffer,
|
816
|
+
state->recorder_instance,
|
817
|
+
values,
|
818
|
+
(sample_labels) {.labels = slice_labels, .state_label = state_label, .end_timestamp_ns = end_timestamp_ns}
|
819
|
+
);
|
820
|
+
}
|
821
|
+
|
822
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
823
|
+
// It SHOULD NOT be used for other purposes.
|
824
|
+
static VALUE _native_thread_list(DDTRACE_UNUSED VALUE _self) {
|
825
|
+
VALUE result = rb_ary_new();
|
826
|
+
ddtrace_thread_list(result);
|
827
|
+
return result;
|
828
|
+
}
|
829
|
+
|
830
|
+
static struct per_thread_context *get_or_create_context_for(VALUE thread, struct thread_context_collector_state *state) {
|
831
|
+
struct per_thread_context* thread_context = NULL;
|
832
|
+
st_data_t value_context = 0;
|
833
|
+
|
834
|
+
if (st_lookup(state->hash_map_per_thread_context, (st_data_t) thread, &value_context)) {
|
835
|
+
thread_context = (struct per_thread_context*) value_context;
|
836
|
+
} else {
|
837
|
+
thread_context = ruby_xcalloc(1, sizeof(struct per_thread_context));
|
838
|
+
initialize_context(thread, thread_context, state);
|
839
|
+
st_insert(state->hash_map_per_thread_context, (st_data_t) thread, (st_data_t) thread_context);
|
840
|
+
}
|
841
|
+
|
842
|
+
return thread_context;
|
843
|
+
}
|
844
|
+
|
845
|
+
static struct per_thread_context *get_context_for(VALUE thread, struct thread_context_collector_state *state) {
|
846
|
+
struct per_thread_context* thread_context = NULL;
|
847
|
+
st_data_t value_context = 0;
|
848
|
+
|
849
|
+
if (st_lookup(state->hash_map_per_thread_context, (st_data_t) thread, &value_context)) {
|
850
|
+
thread_context = (struct per_thread_context*) value_context;
|
851
|
+
}
|
852
|
+
|
853
|
+
return thread_context;
|
854
|
+
}
|
855
|
+
|
856
|
+
#define LOGGING_GEM_PATH "/lib/logging/diagnostic_context.rb"
|
857
|
+
|
858
|
+
// The `logging` gem monkey patches thread creation, which makes the `invoke_location_for` useless, since every thread
|
859
|
+
// will point to the `logging` gem. When that happens, we avoid using the invoke location.
|
860
|
+
//
|
861
|
+
// TODO: This approach is a bit brittle, since it matches on the specific gem path, and only works for the `logging`
|
862
|
+
// gem.
|
863
|
+
// In the future we should probably explore a more generic fix (e.g. using Thread.method(:new).source_location or
|
864
|
+
// something like that to detect redefinition of the `Thread` methods). One difficulty of doing it is that we need
|
865
|
+
// to either run Ruby code during sampling (not great), or otherwise use some of the VM private APIs to detect this.
|
866
|
+
//
|
867
|
+
static bool is_logging_gem_monkey_patch(VALUE invoke_file_location) {
|
868
|
+
int logging_gem_path_len = strlen(LOGGING_GEM_PATH);
|
869
|
+
char *invoke_file = StringValueCStr(invoke_file_location);
|
870
|
+
int invoke_file_len = strlen(invoke_file);
|
871
|
+
|
872
|
+
if (invoke_file_len < logging_gem_path_len) return false;
|
873
|
+
|
874
|
+
return strncmp(invoke_file + invoke_file_len - logging_gem_path_len, LOGGING_GEM_PATH, logging_gem_path_len) == 0;
|
875
|
+
}
|
876
|
+
|
877
|
+
static void initialize_context(VALUE thread, struct per_thread_context *thread_context, struct thread_context_collector_state *state) {
|
878
|
+
snprintf(thread_context->thread_id, THREAD_ID_LIMIT_CHARS, "%"PRIu64" (%lu)", native_thread_id_for(thread), (unsigned long) thread_id_for(thread));
|
879
|
+
thread_context->thread_id_char_slice = (ddog_CharSlice) {.ptr = thread_context->thread_id, .len = strlen(thread_context->thread_id)};
|
880
|
+
|
881
|
+
int invoke_line_location;
|
882
|
+
VALUE invoke_file_location = invoke_location_for(thread, &invoke_line_location);
|
883
|
+
if (invoke_file_location != Qnil) {
|
884
|
+
if (!is_logging_gem_monkey_patch(invoke_file_location)) {
|
885
|
+
snprintf(
|
886
|
+
thread_context->thread_invoke_location,
|
887
|
+
THREAD_INVOKE_LOCATION_LIMIT_CHARS,
|
888
|
+
"%s:%d",
|
889
|
+
StringValueCStr(invoke_file_location),
|
890
|
+
invoke_line_location
|
891
|
+
);
|
892
|
+
} else {
|
893
|
+
snprintf(thread_context->thread_invoke_location, THREAD_INVOKE_LOCATION_LIMIT_CHARS, "%s", "(Unnamed thread)");
|
894
|
+
}
|
895
|
+
} else if (thread != state->main_thread) {
|
896
|
+
// If the first function of a thread is native code, there won't be an invoke location, so we use this fallback.
|
897
|
+
// NOTE: In the future, I wonder if we could take the pointer to the native function, and try to see if there's a native
|
898
|
+
// symbol attached to it.
|
899
|
+
snprintf(thread_context->thread_invoke_location, THREAD_INVOKE_LOCATION_LIMIT_CHARS, "%s", "(Unnamed thread from native code)");
|
900
|
+
}
|
901
|
+
|
902
|
+
thread_context->thread_invoke_location_char_slice = (ddog_CharSlice) {
|
903
|
+
.ptr = thread_context->thread_invoke_location,
|
904
|
+
.len = strlen(thread_context->thread_invoke_location)
|
905
|
+
};
|
906
|
+
|
907
|
+
thread_context->thread_cpu_time_id = thread_cpu_time_id_for(thread);
|
908
|
+
|
909
|
+
// These will get initialized during actual sampling
|
910
|
+
thread_context->cpu_time_at_previous_sample_ns = INVALID_TIME;
|
911
|
+
thread_context->wall_time_at_previous_sample_ns = INVALID_TIME;
|
912
|
+
|
913
|
+
// These will only be used during a GC operation
|
914
|
+
thread_context->gc_tracking.cpu_time_at_start_ns = INVALID_TIME;
|
915
|
+
thread_context->gc_tracking.wall_time_at_start_ns = INVALID_TIME;
|
916
|
+
}
|
917
|
+
|
918
|
+
static VALUE _native_inspect(DDTRACE_UNUSED VALUE _self, VALUE collector_instance) {
|
919
|
+
struct thread_context_collector_state *state;
|
920
|
+
TypedData_Get_Struct(collector_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
921
|
+
|
922
|
+
VALUE result = rb_str_new2(" (native state)");
|
923
|
+
|
924
|
+
// Update this when modifying state struct
|
925
|
+
rb_str_concat(result, rb_sprintf(" hash_map_per_thread_context=%"PRIsVALUE, per_thread_context_st_table_as_ruby_hash(state)));
|
926
|
+
rb_str_concat(result, rb_sprintf(" recorder_instance=%"PRIsVALUE, state->recorder_instance));
|
927
|
+
VALUE tracer_context_key = state->tracer_context_key == MISSING_TRACER_CONTEXT_KEY ? Qnil : ID2SYM(state->tracer_context_key);
|
928
|
+
rb_str_concat(result, rb_sprintf(" tracer_context_key=%+"PRIsVALUE, tracer_context_key));
|
929
|
+
rb_str_concat(result, rb_sprintf(" sample_count=%u", state->sample_count));
|
930
|
+
rb_str_concat(result, rb_sprintf(" stats=%"PRIsVALUE, stats_as_ruby_hash(state)));
|
931
|
+
rb_str_concat(result, rb_sprintf(" endpoint_collection_enabled=%"PRIsVALUE, state->endpoint_collection_enabled ? Qtrue : Qfalse));
|
932
|
+
rb_str_concat(result, rb_sprintf(" timeline_enabled=%"PRIsVALUE, state->timeline_enabled ? Qtrue : Qfalse));
|
933
|
+
rb_str_concat(result, rb_sprintf(" allocation_type_enabled=%"PRIsVALUE, state->allocation_type_enabled ? Qtrue : Qfalse));
|
934
|
+
rb_str_concat(result, rb_sprintf(
|
935
|
+
" time_converter_state={.system_epoch_ns_reference=%ld, .delta_to_epoch_ns=%ld}",
|
936
|
+
state->time_converter_state.system_epoch_ns_reference,
|
937
|
+
state->time_converter_state.delta_to_epoch_ns
|
938
|
+
));
|
939
|
+
rb_str_concat(result, rb_sprintf(" main_thread=%"PRIsVALUE, state->main_thread));
|
940
|
+
rb_str_concat(result, rb_sprintf(" gc_tracking=%"PRIsVALUE, gc_tracking_as_ruby_hash(state)));
|
941
|
+
rb_str_concat(result, rb_sprintf(" otel_current_span_key=%"PRIsVALUE, state->otel_current_span_key));
|
942
|
+
|
943
|
+
return result;
|
944
|
+
}
|
945
|
+
|
946
|
+
static VALUE per_thread_context_st_table_as_ruby_hash(struct thread_context_collector_state *state) {
|
947
|
+
VALUE result = rb_hash_new();
|
948
|
+
st_foreach(state->hash_map_per_thread_context, per_thread_context_as_ruby_hash, result);
|
949
|
+
return result;
|
950
|
+
}
|
951
|
+
|
952
|
+
static int per_thread_context_as_ruby_hash(st_data_t key_thread, st_data_t value_context, st_data_t result_hash) {
|
953
|
+
VALUE thread = (VALUE) key_thread;
|
954
|
+
struct per_thread_context *thread_context = (struct per_thread_context*) value_context;
|
955
|
+
VALUE result = (VALUE) result_hash;
|
956
|
+
VALUE context_as_hash = rb_hash_new();
|
957
|
+
rb_hash_aset(result, thread, context_as_hash);
|
958
|
+
|
959
|
+
VALUE arguments[] = {
|
960
|
+
ID2SYM(rb_intern("thread_id")), /* => */ rb_str_new2(thread_context->thread_id),
|
961
|
+
ID2SYM(rb_intern("thread_invoke_location")), /* => */ rb_str_new2(thread_context->thread_invoke_location),
|
962
|
+
ID2SYM(rb_intern("thread_cpu_time_id_valid?")), /* => */ thread_context->thread_cpu_time_id.valid ? Qtrue : Qfalse,
|
963
|
+
ID2SYM(rb_intern("thread_cpu_time_id")), /* => */ CLOCKID2NUM(thread_context->thread_cpu_time_id.clock_id),
|
964
|
+
ID2SYM(rb_intern("cpu_time_at_previous_sample_ns")), /* => */ LONG2NUM(thread_context->cpu_time_at_previous_sample_ns),
|
965
|
+
ID2SYM(rb_intern("wall_time_at_previous_sample_ns")), /* => */ LONG2NUM(thread_context->wall_time_at_previous_sample_ns),
|
966
|
+
|
967
|
+
ID2SYM(rb_intern("gc_tracking.cpu_time_at_start_ns")), /* => */ LONG2NUM(thread_context->gc_tracking.cpu_time_at_start_ns),
|
968
|
+
ID2SYM(rb_intern("gc_tracking.wall_time_at_start_ns")), /* => */ LONG2NUM(thread_context->gc_tracking.wall_time_at_start_ns),
|
969
|
+
};
|
970
|
+
for (long unsigned int i = 0; i < VALUE_COUNT(arguments); i += 2) rb_hash_aset(context_as_hash, arguments[i], arguments[i+1]);
|
971
|
+
|
972
|
+
return ST_CONTINUE;
|
973
|
+
}
|
974
|
+
|
975
|
+
static VALUE stats_as_ruby_hash(struct thread_context_collector_state *state) {
|
976
|
+
// Update this when modifying state struct (stats inner struct)
|
977
|
+
VALUE stats_as_hash = rb_hash_new();
|
978
|
+
VALUE arguments[] = {
|
979
|
+
ID2SYM(rb_intern("gc_samples")), /* => */ UINT2NUM(state->stats.gc_samples),
|
980
|
+
ID2SYM(rb_intern("gc_samples_missed_due_to_missing_context")), /* => */ UINT2NUM(state->stats.gc_samples_missed_due_to_missing_context),
|
981
|
+
};
|
982
|
+
for (long unsigned int i = 0; i < VALUE_COUNT(arguments); i += 2) rb_hash_aset(stats_as_hash, arguments[i], arguments[i+1]);
|
983
|
+
return stats_as_hash;
|
984
|
+
}
|
985
|
+
|
986
|
+
static VALUE gc_tracking_as_ruby_hash(struct thread_context_collector_state *state) {
|
987
|
+
// Update this when modifying state struct (gc_tracking inner struct)
|
988
|
+
VALUE result = rb_hash_new();
|
989
|
+
VALUE arguments[] = {
|
990
|
+
ID2SYM(rb_intern("accumulated_cpu_time_ns")), /* => */ ULONG2NUM(state->gc_tracking.accumulated_cpu_time_ns),
|
991
|
+
ID2SYM(rb_intern("accumulated_wall_time_ns")), /* => */ ULONG2NUM(state->gc_tracking.accumulated_wall_time_ns),
|
992
|
+
ID2SYM(rb_intern("wall_time_at_previous_gc_ns")), /* => */ LONG2NUM(state->gc_tracking.wall_time_at_previous_gc_ns),
|
993
|
+
ID2SYM(rb_intern("wall_time_at_last_flushed_gc_event_ns")), /* => */ LONG2NUM(state->gc_tracking.wall_time_at_last_flushed_gc_event_ns),
|
994
|
+
};
|
995
|
+
for (long unsigned int i = 0; i < VALUE_COUNT(arguments); i += 2) rb_hash_aset(result, arguments[i], arguments[i+1]);
|
996
|
+
return result;
|
997
|
+
}
|
998
|
+
|
999
|
+
static void remove_context_for_dead_threads(struct thread_context_collector_state *state) {
|
1000
|
+
st_foreach(state->hash_map_per_thread_context, remove_if_dead_thread, 0 /* unused */);
|
1001
|
+
}
|
1002
|
+
|
1003
|
+
static int remove_if_dead_thread(st_data_t key_thread, st_data_t value_context, DDTRACE_UNUSED st_data_t _argument) {
|
1004
|
+
VALUE thread = (VALUE) key_thread;
|
1005
|
+
struct per_thread_context* thread_context = (struct per_thread_context*) value_context;
|
1006
|
+
|
1007
|
+
if (is_thread_alive(thread)) return ST_CONTINUE;
|
1008
|
+
|
1009
|
+
ruby_xfree(thread_context);
|
1010
|
+
return ST_DELETE;
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
1014
|
+
// It SHOULD NOT be used for other purposes.
|
1015
|
+
//
|
1016
|
+
// Returns the whole contents of the per_thread_context structs being tracked.
|
1017
|
+
static VALUE _native_per_thread_context(DDTRACE_UNUSED VALUE _self, VALUE collector_instance) {
|
1018
|
+
struct thread_context_collector_state *state;
|
1019
|
+
TypedData_Get_Struct(collector_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
1020
|
+
|
1021
|
+
return per_thread_context_st_table_as_ruby_hash(state);
|
1022
|
+
}
|
1023
|
+
|
1024
|
+
static long update_time_since_previous_sample(long *time_at_previous_sample_ns, long current_time_ns, long gc_start_time_ns, bool is_wall_time) {
|
1025
|
+
// If we didn't have a time for the previous sample, we use the current one
|
1026
|
+
if (*time_at_previous_sample_ns == INVALID_TIME) *time_at_previous_sample_ns = current_time_ns;
|
1027
|
+
|
1028
|
+
bool is_thread_doing_gc = gc_start_time_ns != INVALID_TIME;
|
1029
|
+
long elapsed_time_ns = -1;
|
1030
|
+
|
1031
|
+
if (is_thread_doing_gc) {
|
1032
|
+
bool previous_sample_was_during_gc = gc_start_time_ns <= *time_at_previous_sample_ns;
|
1033
|
+
|
1034
|
+
if (previous_sample_was_during_gc) {
|
1035
|
+
elapsed_time_ns = 0; // No time to account for -- any time since the last sample is going to get assigned to GC separately
|
1036
|
+
} else {
|
1037
|
+
elapsed_time_ns = gc_start_time_ns - *time_at_previous_sample_ns; // Capture time between previous sample and start of GC only
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
// Remaining time (from gc_start_time to current_time_ns) will be accounted for inside `sample_after_gc`
|
1041
|
+
*time_at_previous_sample_ns = gc_start_time_ns;
|
1042
|
+
} else {
|
1043
|
+
elapsed_time_ns = current_time_ns - *time_at_previous_sample_ns; // Capture all time since previous sample
|
1044
|
+
*time_at_previous_sample_ns = current_time_ns;
|
1045
|
+
}
|
1046
|
+
|
1047
|
+
if (elapsed_time_ns < 0) {
|
1048
|
+
if (is_wall_time) {
|
1049
|
+
// Wall-time can actually go backwards (e.g. when the system clock gets set) so we can't assume time going backwards
|
1050
|
+
// was a bug.
|
1051
|
+
// @ivoanjo: I've also observed time going backwards spuriously on macOS, see discussion on
|
1052
|
+
// https://github.com/DataDog/dd-trace-rb/pull/2336.
|
1053
|
+
elapsed_time_ns = 0;
|
1054
|
+
} else {
|
1055
|
+
// We don't expect non-wall time to go backwards, so let's flag this as a bug
|
1056
|
+
rb_raise(rb_eRuntimeError, "BUG: Unexpected negative elapsed_time_ns between samples");
|
1057
|
+
}
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
return elapsed_time_ns;
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
// Safety: This function is assumed never to raise exceptions by callers
|
1064
|
+
static long cpu_time_now_ns(struct per_thread_context *thread_context) {
|
1065
|
+
thread_cpu_time cpu_time = thread_cpu_time_for(thread_context->thread_cpu_time_id);
|
1066
|
+
|
1067
|
+
if (!cpu_time.valid) {
|
1068
|
+
// Invalidate previous state of the counter (if any), it's no longer accurate. We need to get two good reads
|
1069
|
+
// in a row to have an accurate delta.
|
1070
|
+
thread_context->cpu_time_at_previous_sample_ns = INVALID_TIME;
|
1071
|
+
return 0;
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
return cpu_time.result_ns;
|
1075
|
+
}
|
1076
|
+
|
1077
|
+
static long thread_id_for(VALUE thread) {
|
1078
|
+
VALUE object_id = rb_obj_id(thread);
|
1079
|
+
|
1080
|
+
// The API docs for Ruby state that `rb_obj_id` COULD be a BIGNUM and that if you want to be really sure you don't
|
1081
|
+
// get a BIGNUM, then you should use `rb_memory_id`. But `rb_memory_id` is less interesting because it's less visible
|
1082
|
+
// at the user level than the result of calling `#object_id`.
|
1083
|
+
//
|
1084
|
+
// It also seems uncommon to me that we'd ever get a BIGNUM; on old Ruby versions (pre-GC compaction), the object id
|
1085
|
+
// was the pointer to the object, so that's not going to be a BIGNUM; on modern Ruby versions, Ruby keeps
|
1086
|
+
// a counter, and only increments it for objects for which `#object_id`/`rb_obj_id` is called (e.g. most objects
|
1087
|
+
// won't actually have an object id allocated).
|
1088
|
+
//
|
1089
|
+
// So, for now, let's simplify: we only support FIXNUMs, and we won't break if we get a BIGNUM; we just won't
|
1090
|
+
// record the thread_id (but samples will still be collected).
|
1091
|
+
return FIXNUM_P(object_id) ? FIX2LONG(object_id) : -1;
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
VALUE enforce_thread_context_collector_instance(VALUE object) {
|
1095
|
+
Check_TypedStruct(object, &thread_context_collector_typed_data);
|
1096
|
+
return object;
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
1100
|
+
// It SHOULD NOT be used for other purposes.
|
1101
|
+
static VALUE _native_stats(DDTRACE_UNUSED VALUE _self, VALUE collector_instance) {
|
1102
|
+
struct thread_context_collector_state *state;
|
1103
|
+
TypedData_Get_Struct(collector_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
1104
|
+
|
1105
|
+
return stats_as_ruby_hash(state);
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
1109
|
+
// It SHOULD NOT be used for other purposes.
|
1110
|
+
static VALUE _native_gc_tracking(DDTRACE_UNUSED VALUE _self, VALUE collector_instance) {
|
1111
|
+
struct thread_context_collector_state *state;
|
1112
|
+
TypedData_Get_Struct(collector_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
1113
|
+
|
1114
|
+
return gc_tracking_as_ruby_hash(state);
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
// Assumption 1: This function is called in a thread that is holding the Global VM Lock. Caller is responsible for enforcing this.
|
1118
|
+
static void trace_identifiers_for(struct thread_context_collector_state *state, VALUE thread, struct trace_identifiers *trace_identifiers_result) {
|
1119
|
+
if (state->tracer_context_key == MISSING_TRACER_CONTEXT_KEY) return;
|
1120
|
+
|
1121
|
+
VALUE current_context = rb_thread_local_aref(thread, state->tracer_context_key);
|
1122
|
+
if (current_context == Qnil) return;
|
1123
|
+
|
1124
|
+
VALUE active_trace = rb_ivar_get(current_context, at_active_trace_id /* @active_trace */);
|
1125
|
+
if (active_trace == Qnil) return;
|
1126
|
+
|
1127
|
+
VALUE root_span = rb_ivar_get(active_trace, at_root_span_id /* @root_span */);
|
1128
|
+
VALUE active_span = rb_ivar_get(active_trace, at_active_span_id /* @active_span */);
|
1129
|
+
// Note: On Ruby 3.x `rb_attr_get` is exactly the same as `rb_ivar_get`. For Ruby 2.x, the difference is that
|
1130
|
+
// `rb_ivar_get` can trigger "warning: instance variable @otel_values not initialized" if warnings are enabled and
|
1131
|
+
// opentelemetry is not in use, whereas `rb_attr_get` does the lookup without generating the warning.
|
1132
|
+
VALUE otel_values = rb_attr_get(active_trace, at_otel_values_id /* @otel_values */);
|
1133
|
+
|
1134
|
+
VALUE numeric_span_id = Qnil;
|
1135
|
+
|
1136
|
+
if (otel_values != Qnil) ddtrace_otel_trace_identifiers_for(state, &active_trace, &root_span, &numeric_span_id, active_span, otel_values);
|
1137
|
+
|
1138
|
+
if (root_span == Qnil || (active_span == Qnil && numeric_span_id == Qnil)) return;
|
1139
|
+
|
1140
|
+
VALUE numeric_local_root_span_id = rb_ivar_get(root_span, at_id_id /* @id */);
|
1141
|
+
if (active_span != Qnil && numeric_span_id == Qnil) numeric_span_id = rb_ivar_get(active_span, at_id_id /* @id */);
|
1142
|
+
if (numeric_local_root_span_id == Qnil || numeric_span_id == Qnil) return;
|
1143
|
+
|
1144
|
+
trace_identifiers_result->local_root_span_id = NUM2ULL(numeric_local_root_span_id);
|
1145
|
+
trace_identifiers_result->span_id = NUM2ULL(numeric_span_id);
|
1146
|
+
|
1147
|
+
trace_identifiers_result->valid = true;
|
1148
|
+
|
1149
|
+
if (!state->endpoint_collection_enabled || !should_collect_resource(root_span)) return;
|
1150
|
+
|
1151
|
+
VALUE trace_resource = rb_ivar_get(active_trace, at_resource_id /* @resource */);
|
1152
|
+
if (RB_TYPE_P(trace_resource, T_STRING)) {
|
1153
|
+
trace_identifiers_result->trace_endpoint = trace_resource;
|
1154
|
+
} else if (trace_resource == Qnil) {
|
1155
|
+
// Fall back to resource from span, if any
|
1156
|
+
trace_identifiers_result->trace_endpoint = rb_ivar_get(root_span, at_resource_id /* @resource */);
|
1157
|
+
}
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
// We opt-in to collecting the resource for spans of types:
|
1161
|
+
// * 'web', for web requests
|
1162
|
+
// * 'proxy', used by the rack integration with request_queuing: true (e.g. also represents a web request)
|
1163
|
+
// * 'worker', used for sidekiq and similar background job processors
|
1164
|
+
//
|
1165
|
+
// Over time, this list may be expanded.
|
1166
|
+
// Resources MUST NOT include personal identifiable information (PII); this should not be the case with
|
1167
|
+
// ddtrace integrations, but worth mentioning just in case :)
|
1168
|
+
static bool should_collect_resource(VALUE root_span) {
|
1169
|
+
VALUE root_span_type = rb_ivar_get(root_span, at_type_id /* @type */);
|
1170
|
+
if (root_span_type == Qnil) return false;
|
1171
|
+
ENFORCE_TYPE(root_span_type, T_STRING);
|
1172
|
+
|
1173
|
+
int root_span_type_length = RSTRING_LEN(root_span_type);
|
1174
|
+
const char *root_span_type_value = StringValuePtr(root_span_type);
|
1175
|
+
|
1176
|
+
bool is_web_request =
|
1177
|
+
(root_span_type_length == strlen("web") && (memcmp("web", root_span_type_value, strlen("web")) == 0)) ||
|
1178
|
+
(root_span_type_length == strlen("proxy") && (memcmp("proxy", root_span_type_value, strlen("proxy")) == 0));
|
1179
|
+
|
1180
|
+
if (is_web_request) return true;
|
1181
|
+
|
1182
|
+
bool is_worker_request =
|
1183
|
+
(root_span_type_length == strlen("worker") && (memcmp("worker", root_span_type_value, strlen("worker")) == 0));
|
1184
|
+
|
1185
|
+
return is_worker_request;
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
// After the Ruby VM forks, this method gets called in the child process to clean up any leftover state from the parent.
|
1189
|
+
//
|
1190
|
+
// Assumption: This method gets called BEFORE restarting profiling -- e.g. there are no components attempting to
|
1191
|
+
// trigger samples at the same time.
|
1192
|
+
static VALUE _native_reset_after_fork(DDTRACE_UNUSED VALUE self, VALUE collector_instance) {
|
1193
|
+
struct thread_context_collector_state *state;
|
1194
|
+
TypedData_Get_Struct(collector_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
1195
|
+
|
1196
|
+
st_clear(state->hash_map_per_thread_context);
|
1197
|
+
|
1198
|
+
state->stats = (struct stats) {}; // Resets all stats back to zero
|
1199
|
+
|
1200
|
+
rb_funcall(state->recorder_instance, rb_intern("reset_after_fork"), 0);
|
1201
|
+
|
1202
|
+
return Qtrue;
|
1203
|
+
}
|
1204
|
+
|
1205
|
+
static VALUE thread_list(struct thread_context_collector_state *state) {
|
1206
|
+
VALUE result = state->thread_list_buffer;
|
1207
|
+
rb_ary_clear(result);
|
1208
|
+
ddtrace_thread_list(result);
|
1209
|
+
return result;
|
1210
|
+
}
|
1211
|
+
|
1212
|
+
void thread_context_collector_sample_allocation(VALUE self_instance, unsigned int sample_weight, VALUE new_object) {
|
1213
|
+
struct thread_context_collector_state *state;
|
1214
|
+
TypedData_Get_Struct(self_instance, struct thread_context_collector_state, &thread_context_collector_typed_data, state);
|
1215
|
+
|
1216
|
+
VALUE current_thread = rb_thread_current();
|
1217
|
+
|
1218
|
+
enum ruby_value_type type = rb_type(new_object);
|
1219
|
+
|
1220
|
+
// Tag samples with the VM internal types
|
1221
|
+
ddog_CharSlice ruby_vm_type = ruby_value_type_to_char_slice(type);
|
1222
|
+
|
1223
|
+
// Since this is stack allocated, be careful about moving it
|
1224
|
+
ddog_CharSlice class_name;
|
1225
|
+
ddog_CharSlice *optional_class_name = NULL;
|
1226
|
+
char imemo_type[100];
|
1227
|
+
|
1228
|
+
if (state->allocation_type_enabled) {
|
1229
|
+
optional_class_name = &class_name;
|
1230
|
+
|
1231
|
+
if (
|
1232
|
+
type == RUBY_T_OBJECT ||
|
1233
|
+
type == RUBY_T_CLASS ||
|
1234
|
+
type == RUBY_T_MODULE ||
|
1235
|
+
type == RUBY_T_FLOAT ||
|
1236
|
+
type == RUBY_T_STRING ||
|
1237
|
+
type == RUBY_T_REGEXP ||
|
1238
|
+
type == RUBY_T_ARRAY ||
|
1239
|
+
type == RUBY_T_HASH ||
|
1240
|
+
type == RUBY_T_STRUCT ||
|
1241
|
+
type == RUBY_T_BIGNUM ||
|
1242
|
+
type == RUBY_T_FILE ||
|
1243
|
+
type == RUBY_T_DATA ||
|
1244
|
+
type == RUBY_T_MATCH ||
|
1245
|
+
type == RUBY_T_COMPLEX ||
|
1246
|
+
type == RUBY_T_RATIONAL ||
|
1247
|
+
type == RUBY_T_NIL ||
|
1248
|
+
type == RUBY_T_TRUE ||
|
1249
|
+
type == RUBY_T_FALSE ||
|
1250
|
+
type == RUBY_T_SYMBOL ||
|
1251
|
+
type == RUBY_T_FIXNUM
|
1252
|
+
) {
|
1253
|
+
VALUE klass = rb_class_of(new_object);
|
1254
|
+
|
1255
|
+
// Ruby sometimes plays a bit fast and loose with some of its internal objects, e.g.
|
1256
|
+
// `rb_str_tmp_frozen_acquire` allocates a string with no class (klass=0).
|
1257
|
+
// Thus, we need to make sure there's actually a class before getting its name.
|
1258
|
+
|
1259
|
+
if (klass != 0) {
|
1260
|
+
const char *name = rb_obj_classname(new_object);
|
1261
|
+
size_t name_length = name != NULL ? strlen(name) : 0;
|
1262
|
+
|
1263
|
+
if (name_length > 0) {
|
1264
|
+
class_name = (ddog_CharSlice) {.ptr = name, .len = name_length};
|
1265
|
+
} else {
|
1266
|
+
// @ivoanjo: I'm not sure this can ever happen, but just-in-case
|
1267
|
+
class_name = ruby_value_type_to_class_name(type);
|
1268
|
+
}
|
1269
|
+
} else {
|
1270
|
+
// Fallback for objects with no class
|
1271
|
+
class_name = ruby_value_type_to_class_name(type);
|
1272
|
+
}
|
1273
|
+
} else if (type == RUBY_T_IMEMO) {
|
1274
|
+
const char *imemo_string = imemo_kind(new_object);
|
1275
|
+
if (imemo_string != NULL) {
|
1276
|
+
snprintf(imemo_type, 100, "(VM Internal, T_IMEMO, %s)", imemo_string);
|
1277
|
+
class_name = (ddog_CharSlice) {.ptr = imemo_type, .len = strlen(imemo_type)};
|
1278
|
+
} else { // Ruby < 3
|
1279
|
+
class_name = DDOG_CHARSLICE_C("(VM Internal, T_IMEMO)");
|
1280
|
+
}
|
1281
|
+
} else {
|
1282
|
+
class_name = ruby_vm_type; // For other weird internal things we just use the VM type
|
1283
|
+
}
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
track_object(state->recorder_instance, new_object, sample_weight, optional_class_name);
|
1287
|
+
|
1288
|
+
trigger_sample_for_thread(
|
1289
|
+
state,
|
1290
|
+
/* thread: */ current_thread,
|
1291
|
+
/* stack_from_thread: */ current_thread,
|
1292
|
+
get_or_create_context_for(current_thread, state),
|
1293
|
+
(sample_values) {.alloc_samples = sample_weight},
|
1294
|
+
INVALID_TIME, // For now we're not collecting timestamps for allocation events, as per profiling team internal discussions
|
1295
|
+
&ruby_vm_type,
|
1296
|
+
optional_class_name
|
1297
|
+
);
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
1301
|
+
// It SHOULD NOT be used for other purposes.
|
1302
|
+
static VALUE _native_sample_allocation(DDTRACE_UNUSED VALUE self, VALUE collector_instance, VALUE sample_weight, VALUE new_object) {
|
1303
|
+
thread_context_collector_sample_allocation(collector_instance, NUM2UINT(sample_weight), new_object);
|
1304
|
+
return Qtrue;
|
1305
|
+
}
|
1306
|
+
|
1307
|
+
static VALUE new_empty_thread_inner(DDTRACE_UNUSED void *arg) { return Qnil; }
|
1308
|
+
|
1309
|
+
// This method exists only to enable testing Datadog::Profiling::Collectors::ThreadContext behavior using RSpec.
|
1310
|
+
// It SHOULD NOT be used for other purposes.
|
1311
|
+
// (It creates an empty native thread, so we can test our native thread naming fallback)
|
1312
|
+
static VALUE _native_new_empty_thread(DDTRACE_UNUSED VALUE self) {
|
1313
|
+
return rb_thread_create(new_empty_thread_inner, NULL);
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
static ddog_CharSlice ruby_value_type_to_class_name(enum ruby_value_type type) {
|
1317
|
+
switch (type) {
|
1318
|
+
case(RUBY_T_OBJECT ): return DDOG_CHARSLICE_C("Object");
|
1319
|
+
case(RUBY_T_CLASS ): return DDOG_CHARSLICE_C("Class");
|
1320
|
+
case(RUBY_T_MODULE ): return DDOG_CHARSLICE_C("Module");
|
1321
|
+
case(RUBY_T_FLOAT ): return DDOG_CHARSLICE_C("Float");
|
1322
|
+
case(RUBY_T_STRING ): return DDOG_CHARSLICE_C("String");
|
1323
|
+
case(RUBY_T_REGEXP ): return DDOG_CHARSLICE_C("Regexp");
|
1324
|
+
case(RUBY_T_ARRAY ): return DDOG_CHARSLICE_C("Array");
|
1325
|
+
case(RUBY_T_HASH ): return DDOG_CHARSLICE_C("Hash");
|
1326
|
+
case(RUBY_T_STRUCT ): return DDOG_CHARSLICE_C("Struct");
|
1327
|
+
case(RUBY_T_BIGNUM ): return DDOG_CHARSLICE_C("Integer");
|
1328
|
+
case(RUBY_T_FILE ): return DDOG_CHARSLICE_C("File");
|
1329
|
+
case(RUBY_T_DATA ): return DDOG_CHARSLICE_C("(VM Internal, T_DATA)");
|
1330
|
+
case(RUBY_T_MATCH ): return DDOG_CHARSLICE_C("MatchData");
|
1331
|
+
case(RUBY_T_COMPLEX ): return DDOG_CHARSLICE_C("Complex");
|
1332
|
+
case(RUBY_T_RATIONAL): return DDOG_CHARSLICE_C("Rational");
|
1333
|
+
case(RUBY_T_NIL ): return DDOG_CHARSLICE_C("NilClass");
|
1334
|
+
case(RUBY_T_TRUE ): return DDOG_CHARSLICE_C("TrueClass");
|
1335
|
+
case(RUBY_T_FALSE ): return DDOG_CHARSLICE_C("FalseClass");
|
1336
|
+
case(RUBY_T_SYMBOL ): return DDOG_CHARSLICE_C("Symbol");
|
1337
|
+
case(RUBY_T_FIXNUM ): return DDOG_CHARSLICE_C("Integer");
|
1338
|
+
default: return DDOG_CHARSLICE_C("(VM Internal, Missing class)");
|
1339
|
+
}
|
1340
|
+
}
|
1341
|
+
|
1342
|
+
static VALUE get_otel_current_span_key(struct thread_context_collector_state *state) {
|
1343
|
+
if (state->otel_current_span_key == Qnil) {
|
1344
|
+
VALUE datadog_module = rb_const_get(rb_cObject, rb_intern("Datadog"));
|
1345
|
+
VALUE opentelemetry_module = rb_const_get(datadog_module, rb_intern("OpenTelemetry"));
|
1346
|
+
VALUE api_module = rb_const_get(opentelemetry_module, rb_intern("API"));
|
1347
|
+
VALUE context_module = rb_const_get(api_module, rb_intern_const("Context"));
|
1348
|
+
VALUE current_span_key = rb_const_get(context_module, rb_intern_const("CURRENT_SPAN_KEY"));
|
1349
|
+
|
1350
|
+
if (current_span_key == Qnil) {
|
1351
|
+
rb_raise(rb_eRuntimeError, "Unexpected: Missing Datadog::OpenTelemetry::API::Context::CURRENT_SPAN_KEY");
|
1352
|
+
}
|
1353
|
+
|
1354
|
+
state->otel_current_span_key = current_span_key;
|
1355
|
+
}
|
1356
|
+
|
1357
|
+
return state->otel_current_span_key;
|
1358
|
+
}
|
1359
|
+
|
1360
|
+
// This method gets used when ddtrace is being used indirectly via the otel APIs. Information gets stored slightly
|
1361
|
+
// differently, and this codepath handles it.
|
1362
|
+
static void ddtrace_otel_trace_identifiers_for(
|
1363
|
+
struct thread_context_collector_state *state,
|
1364
|
+
VALUE *active_trace,
|
1365
|
+
VALUE *root_span,
|
1366
|
+
VALUE *numeric_span_id,
|
1367
|
+
VALUE active_span,
|
1368
|
+
VALUE otel_values
|
1369
|
+
) {
|
1370
|
+
VALUE resolved_numeric_span_id =
|
1371
|
+
active_span == Qnil ?
|
1372
|
+
// For traces started from otel spans, the span id will be empty, and the @parent_span_id has the right value
|
1373
|
+
rb_ivar_get(*active_trace, at_parent_span_id_id /* @parent_span_id */) :
|
1374
|
+
// Regular span created by ddtrace
|
1375
|
+
rb_ivar_get(active_span, at_id_id /* @id */);
|
1376
|
+
|
1377
|
+
if (resolved_numeric_span_id == Qnil) return;
|
1378
|
+
|
1379
|
+
VALUE otel_current_span_key = get_otel_current_span_key(state);
|
1380
|
+
VALUE current_trace = *active_trace;
|
1381
|
+
|
1382
|
+
// ddtrace uses a different structure when spans are created from otel, where each otel span will have a unique ddtrace
|
1383
|
+
// trace and span representing it. Each ddtrace trace is then connected to the previous otel span, forming a linked
|
1384
|
+
// list. The local root span is going to be the trace/span we find at the end of this linked list.
|
1385
|
+
while (otel_values != Qnil) {
|
1386
|
+
VALUE otel_span = rb_hash_lookup(otel_values, otel_current_span_key);
|
1387
|
+
if (otel_span == Qnil) break;
|
1388
|
+
VALUE next_trace = rb_ivar_get(otel_span, at_datadog_trace_id);
|
1389
|
+
if (next_trace == Qnil) break;
|
1390
|
+
|
1391
|
+
current_trace = next_trace;
|
1392
|
+
otel_values = rb_ivar_get(current_trace, at_otel_values_id /* @otel_values */);
|
1393
|
+
}
|
1394
|
+
|
1395
|
+
// We found the last trace in the linked list. This contains the local root span
|
1396
|
+
VALUE resolved_root_span = rb_ivar_get(current_trace, at_root_span_id /* @root_span */);
|
1397
|
+
if (resolved_root_span == Qnil) return;
|
1398
|
+
|
1399
|
+
*root_span = resolved_root_span;
|
1400
|
+
*active_trace = current_trace;
|
1401
|
+
*numeric_span_id = resolved_numeric_span_id;
|
1402
|
+
}
|