datadog 2.47.0 → 2.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +76 -1
- data/LICENSE-3rdparty.csv +1 -0
- data/ext/datadog_profiling_native_extension/collectors_stack.c +142 -102
- data/ext/datadog_profiling_native_extension/collectors_stack.h +13 -3
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +6 -1
- data/ext/datadog_profiling_native_extension/extconf.rb +10 -13
- data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +3 -3
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +79 -34
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +5 -1
- data/ext/datadog_profiling_native_extension/profiling.c +1 -1
- data/ext/libdatadog_api/extconf.rb +11 -7
- data/ext/libdatadog_api/feature_flags.c +137 -0
- data/ext/libdatadog_api/process_discovery.c +3 -3
- data/ext/libdatadog_api/trace_exporter.c +34 -7
- data/ext/libdatadog_extconf_helpers.rb +2 -2
- data/lib/datadog/ai_guard/component.rb +1 -1
- data/lib/datadog/ai_guard/contrib/rack/patcher.rb +3 -5
- data/lib/datadog/ai_guard/contrib/rack/request_middleware.rb +1 -9
- data/lib/datadog/ai_guard/contrib/rails/patcher.rb +8 -10
- data/lib/datadog/ai_guard/contrib/ruby_llm/message_adapter.rb +1 -1
- data/lib/datadog/ai_guard/contrib/ruby_llm/patcher.rb +3 -5
- data/lib/datadog/ai_guard/contrib/ruby_llm/redaction_change_set.rb +3 -3
- data/lib/datadog/ai_guard/evaluation/client.rb +3 -3
- data/lib/datadog/ai_guard/evaluation.rb +2 -2
- data/lib/datadog/ai_guard/http_client.rb +3 -2
- data/lib/datadog/ai_guard/metrics/telemetry.rb +2 -4
- data/lib/datadog/ai_guard/redaction.rb +1 -1
- data/lib/datadog/appsec/actions_handler.rb +5 -7
- data/lib/datadog/appsec/api_security/endpoint_collection/grape_route_serializer.rb +1 -3
- data/lib/datadog/appsec/api_security/endpoint_collection/rails_collector.rb +1 -1
- data/lib/datadog/appsec/api_security/endpoint_collection/rails_route_serializer.rb +1 -3
- data/lib/datadog/appsec/api_security/endpoint_collection/sinatra_route_serializer.rb +1 -3
- data/lib/datadog/appsec/assets/waf_rules/README.md +3 -3
- data/lib/datadog/appsec/assets/waf_rules/recommended.json +5366 -1517
- data/lib/datadog/appsec/assets/waf_rules/strict.json +2 -2
- data/lib/datadog/appsec/assets.rb +8 -10
- data/lib/datadog/appsec/autoload.rb +1 -1
- data/lib/datadog/appsec/component.rb +1 -1
- data/lib/datadog/appsec/compressed_json.rb +1 -1
- data/lib/datadog/appsec/configuration.rb +4 -4
- data/lib/datadog/appsec/context.rb +64 -7
- data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +12 -4
- data/lib/datadog/appsec/contrib/active_record/patcher.rb +33 -28
- data/lib/datadog/appsec/contrib/aws_lambda/gateway/watcher.rb +2 -2
- data/lib/datadog/appsec/contrib/aws_lambda/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/aws_lambda/waf_addresses.rb +10 -12
- data/lib/datadog/appsec/contrib/devise/configuration.rb +3 -5
- data/lib/datadog/appsec/contrib/devise/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/devise/patches/signin_tracking_patch.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/patches/signup_tracking_patch.rb +1 -1
- data/lib/datadog/appsec/contrib/devise/tracking_middleware.rb +1 -1
- data/lib/datadog/appsec/contrib/excon/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/excon/ssrf_detection_middleware.rb +1 -1
- data/lib/datadog/appsec/contrib/faraday/patcher.rb +4 -6
- data/lib/datadog/appsec/contrib/faraday/ssrf_detection_middleware.rb +1 -1
- data/lib/datadog/appsec/contrib/graphql/gateway/multiplex.rb +7 -7
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +1 -1
- data/lib/datadog/appsec/contrib/graphql/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +3 -3
- data/lib/datadog/appsec/contrib/rack/input_peeker.rb +3 -5
- data/lib/datadog/appsec/contrib/rack/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +5 -4
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +11 -12
- data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +2 -2
- data/lib/datadog/appsec/contrib/rails/patcher.rb +21 -18
- data/lib/datadog/appsec/contrib/rails/patches/live_thread_patch.rb +33 -0
- data/lib/datadog/appsec/contrib/rest_client/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/rest_client/request_ssrf_detection_patch.rb +1 -1
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +3 -3
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +5 -7
- data/lib/datadog/appsec/default_header_tags.rb +2 -4
- data/lib/datadog/appsec/metrics/collector.rb +5 -5
- data/lib/datadog/appsec/metrics/exporter.rb +4 -6
- data/lib/datadog/appsec/metrics/telemetry.rb +1 -3
- data/lib/datadog/appsec/metrics/telemetry_exporter.rb +5 -7
- data/lib/datadog/appsec/monitor/gateway/watcher.rb +2 -2
- data/lib/datadog/appsec/processor/rule_loader.rb +1 -1
- data/lib/datadog/appsec/response.rb +1 -1
- data/lib/datadog/appsec/route_normalizer/route_text.rb +1 -3
- data/lib/datadog/appsec/route_normalizer.rb +4 -6
- data/lib/datadog/appsec/security_engine/engine.rb +6 -6
- data/lib/datadog/appsec/security_engine/runner.rb +2 -2
- data/lib/datadog/appsec/trace_keeper.rb +1 -1
- data/lib/datadog/appsec/utils/http/body_reader.rb +3 -5
- data/lib/datadog/appsec/utils/http/url_encoded.rb +2 -4
- data/lib/datadog/appsec.rb +1 -1
- data/lib/datadog/core/borrowing_token_bucket.rb +60 -0
- data/lib/datadog/core/chunker.rb +1 -3
- data/lib/datadog/core/configuration/agent_settings_resolver.rb +14 -13
- data/lib/datadog/core/configuration/agentless_settings_resolver.rb +2 -2
- data/lib/datadog/core/configuration/components.rb +49 -18
- data/lib/datadog/core/configuration/settings.rb +7 -3
- data/lib/datadog/core/configuration/supported_configurations.rb +3 -0
- data/lib/datadog/core/configuration.rb +2 -2
- data/lib/datadog/core/crashtracking/component.rb +1 -1
- data/lib/datadog/core/diagnostics/environment_logger.rb +2 -7
- data/lib/datadog/core/encoding.rb +8 -12
- data/lib/datadog/core/environment/cgroup.rb +5 -7
- data/lib/datadog/core/environment/container.rb +12 -14
- data/lib/datadog/core/environment/ext.rb +1 -6
- data/lib/datadog/core/environment/gc.rb +2 -4
- data/lib/datadog/core/environment/identity.rb +13 -15
- data/lib/datadog/core/environment/platform.rb +10 -12
- data/lib/datadog/core/environment/socket.rb +3 -5
- data/lib/datadog/core/environment/thread_count.rb +2 -4
- data/lib/datadog/core/environment/variable_helpers.rb +2 -6
- data/lib/datadog/core/environment/vm_cache.rb +5 -7
- data/lib/datadog/core/environment/yjit.rb +25 -24
- data/lib/datadog/core/logger.rb +5 -2
- data/lib/datadog/core/metrics/client.rb +13 -21
- data/lib/datadog/core/metrics/helpers.rb +3 -0
- data/lib/datadog/core/metrics/metric.rb +3 -1
- data/lib/datadog/core/process_discovery.rb +1 -1
- data/lib/datadog/core/rate_limiter.rb +9 -31
- data/lib/datadog/core/refillable_bucket.rb +72 -0
- data/lib/datadog/core/remote/client/capabilities.rb +4 -0
- data/lib/datadog/core/remote/client.rb +1 -5
- data/lib/datadog/core/remote/tie/tracing.rb +4 -3
- data/lib/datadog/core/remote/transport/http.rb +4 -6
- data/lib/datadog/core/runtime/metrics.rb +14 -14
- data/lib/datadog/core/semaphore.rb +3 -1
- data/lib/datadog/core/tag_normalizer.rb +0 -2
- data/lib/datadog/core/telemetry/configuration_value.rb +1 -3
- data/lib/datadog/core/telemetry/event/app_started.rb +9 -9
- data/lib/datadog/core/telemetry/logger.rb +1 -1
- data/lib/datadog/core/telemetry/logging.rb +1 -1
- data/lib/datadog/core/telemetry/request.rb +9 -3
- data/lib/datadog/core/telemetry/transport/http.rb +4 -6
- data/lib/datadog/core/telemetry/worker.rb +30 -24
- data/lib/datadog/core/transport/http/adapters/net.rb +1 -1
- data/lib/datadog/core/transport/http/adapters/unix_socket.rb +1 -1
- data/lib/datadog/core/transport/http/builder.rb +1 -1
- data/lib/datadog/core/transport/http.rb +5 -7
- data/lib/datadog/core/utils/at_fork_monkey_patch.rb +4 -4
- data/lib/datadog/core/utils/forking.rb +1 -1
- data/lib/datadog/core/utils/lru_cache.rb +2 -2
- data/lib/datadog/core/utils/network.rb +1 -1
- data/lib/datadog/core/utils/time.rb +2 -2
- data/lib/datadog/core/utils/truncation.rb +1 -3
- data/lib/datadog/core/workers/async.rb +17 -15
- data/lib/datadog/core/workers/runtime_metrics.rb +2 -2
- data/lib/datadog/data_streams/pathway_context.rb +1 -1
- data/lib/datadog/data_streams/processor.rb +48 -27
- data/lib/datadog/data_streams/transport/http.rb +2 -4
- data/lib/datadog/data_streams.rb +16 -0
- data/lib/datadog/di/capture_expression_evaluator.rb +48 -11
- data/lib/datadog/di/component.rb +17 -4
- data/lib/datadog/di/configuration.rb +19 -0
- data/lib/datadog/di/context.rb +50 -0
- data/lib/datadog/di/contrib/active_record.rb +1 -1
- data/lib/datadog/di/contrib.rb +2 -2
- data/lib/datadog/di/correlation_sampler/trace_budget.rb +75 -0
- data/lib/datadog/di/correlation_sampler/trace_budget_ledger/entry.rb +34 -0
- data/lib/datadog/di/correlation_sampler/trace_budget_ledger.rb +104 -0
- data/lib/datadog/di/correlation_sampler.rb +224 -0
- data/lib/datadog/di/el/compiler.rb +4 -4
- data/lib/datadog/di/el/evaluator.rb +247 -43
- data/lib/datadog/di/el/expression.rb +36 -6
- data/lib/datadog/di/error.rb +16 -0
- data/lib/datadog/di/guardrails_telemetry/reason.rb +11 -5
- data/lib/datadog/di/instrumenter.rb +325 -111
- data/lib/datadog/di/probe.rb +13 -2
- data/lib/datadog/di/probe_builder.rb +6 -8
- data/lib/datadog/di/probe_file_loader.rb +2 -2
- data/lib/datadog/di/probe_manager.rb +7 -30
- data/lib/datadog/di/probe_notification_builder.rb +100 -21
- data/lib/datadog/di/probe_notifier_worker.rb +12 -1
- data/lib/datadog/di/serializer.rb +20 -2
- data/lib/datadog/di/snapshot_pruner/node.rb +190 -0
- data/lib/datadog/di/snapshot_pruner/node_queue.rb +104 -0
- data/lib/datadog/di/snapshot_pruner/parser.rb +102 -0
- data/lib/datadog/di/snapshot_pruner.rb +128 -0
- data/lib/datadog/di/transport/input.rb +75 -15
- data/lib/datadog/di/utils.rb +3 -3
- data/lib/datadog/di.rb +56 -0
- data/lib/datadog/error_tracking/component.rb +1 -1
- data/lib/datadog/error_tracking/configuration.rb +1 -1
- data/lib/datadog/error_tracking/filters.rb +6 -8
- data/lib/datadog/kit/appsec/events/v2.rb +6 -6
- data/lib/datadog/kit/appsec/events.rb +1 -1
- data/lib/datadog/kit/enable_core_dumps.rb +1 -1
- data/lib/datadog/kit/identity.rb +1 -1
- data/lib/datadog/open_feature/activation.rb +26 -1
- data/lib/datadog/open_feature/agentless/configuration_source.rb +94 -15
- data/lib/datadog/open_feature/agentless/parser.rb +2 -4
- data/lib/datadog/open_feature/component.rb +46 -4
- data/lib/datadog/open_feature/configuration/agentless_endpoint.rb +6 -0
- data/lib/datadog/open_feature/configuration.rb +17 -4
- data/lib/datadog/open_feature/evaluation_engine.rb +67 -9
- data/lib/datadog/open_feature/exposure_hook.rb +146 -0
- data/lib/datadog/open_feature/exposures/buffer.rb +4 -0
- data/lib/datadog/open_feature/exposures/event.rb +10 -8
- data/lib/datadog/open_feature/exposures/reporter.rb +40 -18
- data/lib/datadog/open_feature/exposures/worker.rb +37 -6
- data/lib/datadog/open_feature/ext.rb +12 -0
- data/lib/datadog/open_feature/flag_evaluation/aggregator.rb +13 -11
- data/lib/datadog/open_feature/flag_evaluation/writer.rb +10 -7
- data/lib/datadog/open_feature/hooks/debug_logging_hook.rb +56 -0
- data/lib/datadog/open_feature/hooks/exposure_logging_hook.rb +58 -0
- data/lib/datadog/open_feature/hooks/flag_eval_evp_hook.rb +4 -2
- data/lib/datadog/open_feature/hooks/flag_eval_metrics_hook.rb +3 -5
- data/lib/datadog/open_feature/hooks/span_enrichment_hook/codec.rb +3 -5
- data/lib/datadog/open_feature/hooks/span_enrichment_hook.rb +2 -2
- data/lib/datadog/open_feature/metrics/flag_eval_metrics.rb +1 -1
- data/lib/datadog/open_feature/native_evaluator.rb +31 -3
- data/lib/datadog/open_feature/noop_evaluator.rb +4 -2
- data/lib/datadog/open_feature/provider.rb +103 -15
- data/lib/datadog/open_feature/remote.rb +8 -1
- data/lib/datadog/open_feature/resolution_details.rb +3 -2
- data/lib/datadog/open_feature/split_features.rb +76 -0
- data/lib/datadog/open_feature/transport.rb +6 -6
- data/lib/datadog/opentelemetry/api/context.rb +3 -3
- data/lib/datadog/opentelemetry/logs.rb +5 -5
- data/lib/datadog/opentelemetry/metrics.rb +3 -3
- data/lib/datadog/opentelemetry/sdk/propagator.rb +8 -5
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +2 -2
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +1 -1
- data/lib/datadog/profiling/collectors/code_provenance.rb +3 -3
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +32 -35
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
- data/lib/datadog/profiling/collectors/thread_context.rb +1 -1
- data/lib/datadog/profiling/component.rb +50 -28
- data/lib/datadog/profiling/exporter.rb +1 -1
- data/lib/datadog/profiling/http_transport.rb +3 -3
- data/lib/datadog/profiling/profiler.rb +8 -2
- data/lib/datadog/profiling/remote.rb +381 -0
- data/lib/datadog/profiling/scheduler.rb +2 -2
- data/lib/datadog/profiling/tag_builder.rb +1 -1
- data/lib/datadog/profiling/worker_state.rb +65 -0
- data/lib/datadog/profiling.rb +1 -0
- data/lib/datadog/symbol_database/extractor.rb +8 -8
- data/lib/datadog/symbol_database/file_hash.rb +1 -3
- data/lib/datadog/symbol_database/uploader.rb +1 -1
- data/lib/datadog/tracing/buffer.rb +3 -3
- data/lib/datadog/tracing/client_ip.rb +1 -1
- data/lib/datadog/tracing/component.rb +22 -24
- data/lib/datadog/tracing/configuration/dynamic/option.rb +2 -2
- data/lib/datadog/tracing/configuration/settings.rb +5 -5
- data/lib/datadog/tracing/context.rb +1 -1
- data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +4 -6
- data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +4 -6
- data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +4 -6
- data/lib/datadog/tracing/contrib/action_cable/events.rb +3 -5
- data/lib/datadog/tracing/contrib/action_cable/instrumentation.rb +2 -2
- data/lib/datadog/tracing/contrib/action_cable/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +5 -7
- data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +4 -6
- data/lib/datadog/tracing/contrib/action_mailer/events.rb +3 -5
- data/lib/datadog/tracing/contrib/action_mailer/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +2 -4
- data/lib/datadog/tracing/contrib/action_pack/action_controller/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/action_pack/action_dispatch/instrumentation.rb +2 -4
- data/lib/datadog/tracing/contrib/action_pack/action_dispatch/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/action_pack/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +3 -5
- data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +3 -5
- data/lib/datadog/tracing/contrib/action_view/events.rb +3 -5
- data/lib/datadog/tracing/contrib/action_view/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/action_view/utils.rb +1 -3
- data/lib/datadog/tracing/contrib/active_job/data_streams.rb +27 -2
- data/lib/datadog/tracing/contrib/active_job/events/discard.rb +3 -5
- data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +3 -5
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +3 -5
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +3 -5
- data/lib/datadog/tracing/contrib/active_job/events/perform.rb +3 -5
- data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +3 -5
- data/lib/datadog/tracing/contrib/active_job/events.rb +3 -5
- data/lib/datadog/tracing/contrib/active_job/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +4 -6
- data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +4 -6
- data/lib/datadog/tracing/contrib/active_model_serializers/events.rb +3 -5
- data/lib/datadog/tracing/contrib/active_model_serializers/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +2 -2
- data/lib/datadog/tracing/contrib/active_record/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +4 -6
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +3 -5
- data/lib/datadog/tracing/contrib/active_record/events.rb +3 -5
- data/lib/datadog/tracing/contrib/active_record/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/active_record/utils.rb +1 -1
- data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +8 -10
- data/lib/datadog/tracing/contrib/active_support/cache/events.rb +3 -5
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +6 -8
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/active_support/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +2 -2
- data/lib/datadog/tracing/contrib/active_support/notifications/subscription.rb +2 -2
- data/lib/datadog/tracing/contrib/active_support/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/analytics.rb +4 -6
- data/lib/datadog/tracing/contrib/aws/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +1 -1
- data/lib/datadog/tracing/contrib/aws/patcher.rb +5 -7
- data/lib/datadog/tracing/contrib/concurrent_ruby/patcher.rb +5 -7
- data/lib/datadog/tracing/contrib/configuration/settings.rb +17 -0
- data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +1 -1
- data/lib/datadog/tracing/contrib/dalli/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/dalli/quantize.rb +1 -3
- data/lib/datadog/tracing/contrib/delayed_job/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +2 -2
- data/lib/datadog/tracing/contrib/elasticsearch/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +6 -8
- data/lib/datadog/tracing/contrib/elasticsearch/quantize.rb +6 -8
- data/lib/datadog/tracing/contrib/ethon/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +8 -8
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +1 -1
- data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/excon/middleware.rb +7 -7
- data/lib/datadog/tracing/contrib/excon/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -5
- data/lib/datadog/tracing/contrib/faraday/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/grape/endpoint.rb +4 -4
- data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/graphql/patcher.rb +5 -7
- data/lib/datadog/tracing/contrib/graphql/trace_patcher.rb +1 -3
- data/lib/datadog/tracing/contrib/graphql/tracing_patcher.rb +1 -3
- data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +3 -3
- data/lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb +1 -3
- data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +2 -2
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +1 -1
- data/lib/datadog/tracing/contrib/grpc/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/grpc.rb +1 -1
- data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +1 -1
- data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/hanami/plugin.rb +1 -1
- data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +1 -1
- data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +1 -1
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +6 -6
- data/lib/datadog/tracing/contrib/http/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/http.rb +1 -1
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +7 -7
- data/lib/datadog/tracing/contrib/httpclient/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -5
- data/lib/datadog/tracing/contrib/httprb/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +4 -6
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +3 -5
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +3 -5
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +3 -5
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/join_group.rb +2 -4
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/leave_group.rb +2 -4
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/sync_group.rb +2 -4
- data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +4 -6
- data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +4 -6
- data/lib/datadog/tracing/contrib/kafka/events.rb +3 -5
- data/lib/datadog/tracing/contrib/kafka/instrumentation/consumer.rb +2 -2
- data/lib/datadog/tracing/contrib/kafka/instrumentation/producer.rb +2 -2
- data/lib/datadog/tracing/contrib/kafka/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/karafka/monitor.rb +1 -1
- data/lib/datadog/tracing/contrib/karafka/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/karafka.rb +1 -1
- data/lib/datadog/tracing/contrib/lograge/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/mongodb/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/mongodb/parsers.rb +6 -8
- data/lib/datadog/tracing/contrib/mongodb/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +1 -1
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +3 -3
- data/lib/datadog/tracing/contrib/mysql2/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/opensearch/configuration/settings.rb +2 -2
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/opensearch/quantize.rb +5 -7
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +4 -4
- data/lib/datadog/tracing/contrib/pg/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/presto/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/presto/instrumentation.rb +4 -4
- data/lib/datadog/tracing/contrib/presto/patcher.rb +1 -3
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
- data/lib/datadog/tracing/contrib/que/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/que/tracer.rb +1 -1
- data/lib/datadog/tracing/contrib/racecar/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/racecar/events/batch.rb +4 -6
- data/lib/datadog/tracing/contrib/racecar/events/consume.rb +3 -5
- data/lib/datadog/tracing/contrib/racecar/events/message.rb +4 -6
- data/lib/datadog/tracing/contrib/racecar/events.rb +3 -5
- data/lib/datadog/tracing/contrib/racecar/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +3 -3
- data/lib/datadog/tracing/contrib/rack/patcher.rb +14 -20
- data/lib/datadog/tracing/contrib/rack/request_queue.rb +1 -3
- data/lib/datadog/tracing/contrib/rack/route_inference.rb +4 -6
- data/lib/datadog/tracing/contrib/rack/trace_proxy_middleware.rb +4 -6
- data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -0
- data/lib/datadog/tracing/contrib/rails/ext.rb +2 -0
- data/lib/datadog/tracing/contrib/rails/framework.rb +12 -14
- data/lib/datadog/tracing/contrib/rails/log_injection.rb +2 -4
- data/lib/datadog/tracing/contrib/rails/patcher.rb +9 -11
- data/lib/datadog/tracing/contrib/rails/runner.rb +4 -4
- data/lib/datadog/tracing/contrib/rake/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/redis/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/redis/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/redis/quantize.rb +8 -10
- data/lib/datadog/tracing/contrib/redis/tags.rb +1 -1
- data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/rest_client/configuration/settings.rb +1 -1
- data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +8 -8
- data/lib/datadog/tracing/contrib/roda/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/semantic_logger/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/sequel/database.rb +1 -1
- data/lib/datadog/tracing/contrib/sequel/dataset.rb +1 -1
- data/lib/datadog/tracing/contrib/sequel/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +1 -1
- data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +2 -2
- data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +7 -9
- data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +2 -2
- data/lib/datadog/tracing/contrib/sidekiq.rb +1 -1
- data/lib/datadog/tracing/contrib/sinatra/env.rb +3 -5
- data/lib/datadog/tracing/contrib/sinatra/patcher.rb +5 -7
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +1 -1
- data/lib/datadog/tracing/contrib/sneakers/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/status_range_env_parser.rb +1 -1
- data/lib/datadog/tracing/contrib/stripe/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/stripe/request.rb +4 -6
- data/lib/datadog/tracing/contrib/sucker_punch/exception_handler.rb +1 -3
- data/lib/datadog/tracing/contrib/sucker_punch/instrumentation.rb +2 -4
- data/lib/datadog/tracing/contrib/sucker_punch/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/support.rb +1 -3
- data/lib/datadog/tracing/contrib/trilogy/configuration/settings.rb +5 -1
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +5 -4
- data/lib/datadog/tracing/contrib/trilogy/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/utils/database.rb +1 -3
- data/lib/datadog/tracing/contrib/utils/quantization/hash_formatter.rb +8 -10
- data/lib/datadog/tracing/contrib/utils/quantization/http.rb +11 -13
- data/lib/datadog/tracing/contrib/waterdrop/middleware.rb +2 -2
- data/lib/datadog/tracing/contrib/waterdrop/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/waterdrop.rb +1 -1
- data/lib/datadog/tracing/correlation.rb +3 -5
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_multi.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_single.rb +1 -1
- data/lib/datadog/tracing/distributed/baggage.rb +3 -3
- data/lib/datadog/tracing/distributed/datadog.rb +3 -3
- data/lib/datadog/tracing/distributed/propagation.rb +9 -9
- data/lib/datadog/tracing/distributed/propagation_policy.rb +1 -3
- data/lib/datadog/tracing/distributed/trace_context.rb +1 -1
- data/lib/datadog/tracing/distributed/trace_state/datadog.rb +5 -5
- data/lib/datadog/tracing/distributed/trace_state/open_telemetry.rb +3 -3
- data/lib/datadog/tracing/metadata/ext.rb +3 -9
- data/lib/datadog/tracing/otel_thread_context.rb +3 -3
- data/lib/datadog/tracing/pipeline.rb +1 -1
- data/lib/datadog/tracing/remote.rb +1 -1
- data/lib/datadog/tracing/sampling/priority_sampler.rb +1 -1
- data/lib/datadog/tracing/sampling/rule.rb +1 -1
- data/lib/datadog/tracing/sampling/rule_sampler.rb +1 -1
- data/lib/datadog/tracing/sampling/span/rule_parser.rb +2 -2
- data/lib/datadog/tracing/span_operation.rb +1 -1
- data/lib/datadog/tracing/trace_digest.rb +1 -1
- data/lib/datadog/tracing/trace_operation.rb +17 -9
- data/lib/datadog/tracing/tracer.rb +15 -7
- data/lib/datadog/tracing/transport/http/telemetry.rb +1 -1
- data/lib/datadog/tracing/transport/http.rb +3 -5
- data/lib/datadog/tracing/transport/io.rb +3 -5
- data/lib/datadog/tracing/transport/native.rb +3 -3
- data/lib/datadog/tracing/transport/statistics.rb +2 -2
- data/lib/datadog/tracing/transport/telemetry.rb +3 -1
- data/lib/datadog/tracing/transport/trace_formatter.rb +12 -12
- data/lib/datadog/tracing/transport/traces.rb +2 -4
- data/lib/datadog/tracing/utils.rb +5 -7
- data/lib/datadog/tracing/workers.rb +1 -1
- data/lib/datadog/version.rb +1 -1
- metadata +23 -6
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../core/rate_limiter"
|
|
4
|
+
require_relative "correlation_sampler/trace_budget"
|
|
5
|
+
require_relative "correlation_sampler/trace_budget_ledger"
|
|
6
|
+
|
|
7
|
+
module Datadog
|
|
8
|
+
module DI
|
|
9
|
+
# Sampling gate that coordinates capturing Live Debugger probe hits within
|
|
10
|
+
# one trace and bounds total snapshot volume with process-wide budgets.
|
|
11
|
+
#
|
|
12
|
+
# @api private
|
|
13
|
+
class CorrelationSampler
|
|
14
|
+
# Sweep floor for the per-trace budget ledger.
|
|
15
|
+
DEFAULT_SWEEP_THRESHOLD = 4096
|
|
16
|
+
|
|
17
|
+
# Snapshots per second, process-wide, that may establish an emitting
|
|
18
|
+
# trace.
|
|
19
|
+
TOP_RATE = 10
|
|
20
|
+
|
|
21
|
+
# Snapshots per second, process-wide, across all emits.
|
|
22
|
+
GLOBAL_RATE = 20
|
|
23
|
+
|
|
24
|
+
# Snapshots one probe may emit within one trace.
|
|
25
|
+
PER_PROBE_BUDGET = 1
|
|
26
|
+
|
|
27
|
+
# Snapshots all probes together may emit within one trace.
|
|
28
|
+
ALL_BUDGET = 20
|
|
29
|
+
|
|
30
|
+
# Initializes an empty per-trace ledger and full process-wide TOP/GLOBAL
|
|
31
|
+
# buckets.
|
|
32
|
+
#
|
|
33
|
+
# @param sweep_threshold [Integer] sweep floor for the per-trace budget
|
|
34
|
+
# ledger
|
|
35
|
+
# @param top_rate [Numeric] TOP rate limit, snapshots/second
|
|
36
|
+
# @param global_rate [Numeric] GLOBAL rate limit, snapshots/second
|
|
37
|
+
# @param per_probe_budget [Integer] per-probe counter start value for
|
|
38
|
+
# each trace's budget
|
|
39
|
+
# @param all_budget [Integer] all-probe counter start value for each
|
|
40
|
+
# trace's budget
|
|
41
|
+
# @raise [ArgumentError] when sweep_threshold is zero, negative, or
|
|
42
|
+
# non-Integer, or when per_probe_budget or all_budget is negative
|
|
43
|
+
# or non-Integer
|
|
44
|
+
# @return [void]
|
|
45
|
+
def initialize(sweep_threshold: DEFAULT_SWEEP_THRESHOLD, top_rate: TOP_RATE,
|
|
46
|
+
global_rate: GLOBAL_RATE, per_probe_budget: PER_PROBE_BUDGET,
|
|
47
|
+
all_budget: ALL_BUDGET)
|
|
48
|
+
TraceBudget.validate_budgets!(per_probe_budget: per_probe_budget, all_budget: all_budget)
|
|
49
|
+
|
|
50
|
+
@per_probe_budget = per_probe_budget
|
|
51
|
+
@all_budget = all_budget
|
|
52
|
+
@sweep_threshold = sweep_threshold
|
|
53
|
+
@top_rate = top_rate
|
|
54
|
+
@global_rate = global_rate
|
|
55
|
+
rebuild_state
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Decides whether this capturing probe hit emits a snapshot, and names
|
|
59
|
+
# the drop decision for a denial.
|
|
60
|
+
#
|
|
61
|
+
# @param probe [Datadog::DI::Probe]
|
|
62
|
+
# @param trace [Datadog::Tracing::TraceOperation, nil]
|
|
63
|
+
# @return [Array(Boolean, Symbol, nil)] the admitted flag, and the drop
|
|
64
|
+
# decision naming the denying limit: +:own_rate_limit+,
|
|
65
|
+
# +:global_budget+, +:top_gate+ or +:trace_budget+, nil when admitted
|
|
66
|
+
def emit_with_reason?(probe, trace)
|
|
67
|
+
lock.synchronize do
|
|
68
|
+
return emit_uncorrelated?(probe) if trace.nil?
|
|
69
|
+
|
|
70
|
+
budget = trace_budgets.fetch(trace)
|
|
71
|
+
if budget
|
|
72
|
+
emit_correlated?(budget, probe)
|
|
73
|
+
else
|
|
74
|
+
emit_first_probe?(probe, trace)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Decides whether this capturing probe hit emits a snapshot.
|
|
80
|
+
#
|
|
81
|
+
# @param probe [Datadog::DI::Probe]
|
|
82
|
+
# @param trace [Datadog::Tracing::TraceOperation, nil]
|
|
83
|
+
# @return [Boolean]
|
|
84
|
+
def emit?(probe, trace)
|
|
85
|
+
admitted, = emit_with_reason?(probe, trace)
|
|
86
|
+
admitted
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Consumes one GLOBAL token for a snapshot payload the coordinated
|
|
90
|
+
# emit path does not gate, such as a condition-evaluation-failure
|
|
91
|
+
# notification with no active trace or from a non-capturing probe.
|
|
92
|
+
# GLOBAL admits the payload only while the balance is
|
|
93
|
+
# positive, matching the uncorrelated emit path, so condition-error
|
|
94
|
+
# payloads and capturing emits share one process-wide snapshot budget.
|
|
95
|
+
#
|
|
96
|
+
# @return [Boolean] true when the process-wide budget admits the payload
|
|
97
|
+
def admit_process_wide_snapshot?
|
|
98
|
+
lock.synchronize do
|
|
99
|
+
global_limiter.try_consume
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Rebuilds the process-scoped state for a freshly forked child. Must
|
|
104
|
+
# run while the child is single-threaded.
|
|
105
|
+
#
|
|
106
|
+
# @return [void]
|
|
107
|
+
def after_fork!
|
|
108
|
+
rebuild_state
|
|
109
|
+
nil
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
# Process-wide mutex guarding trace_budgets and the shared limiters.
|
|
115
|
+
# @return [Thread::Mutex]
|
|
116
|
+
attr_reader :lock
|
|
117
|
+
|
|
118
|
+
# Store of per-trace budgets, keyed by the trace object.
|
|
119
|
+
# @return [TraceBudgetLedger]
|
|
120
|
+
attr_reader :trace_budgets
|
|
121
|
+
|
|
122
|
+
# Process-wide TOP gate.
|
|
123
|
+
# @return [Datadog::Core::TokenBucket]
|
|
124
|
+
attr_reader :top_limiter
|
|
125
|
+
|
|
126
|
+
# Process-wide GLOBAL gate.
|
|
127
|
+
# @return [Datadog::Core::BorrowingTokenBucket]
|
|
128
|
+
attr_reader :global_limiter
|
|
129
|
+
|
|
130
|
+
# Per-probe counter start value this sampler seeds trace budgets with.
|
|
131
|
+
# @return [Integer]
|
|
132
|
+
attr_reader :per_probe_budget
|
|
133
|
+
|
|
134
|
+
# All-probe counter start value this sampler seeds trace budgets with.
|
|
135
|
+
# @return [Integer]
|
|
136
|
+
attr_reader :all_budget
|
|
137
|
+
|
|
138
|
+
# Sweep floor this sampler rebuilds the ledger with.
|
|
139
|
+
# @return [Integer]
|
|
140
|
+
attr_reader :sweep_threshold
|
|
141
|
+
|
|
142
|
+
# TOP rate this sampler rebuilds its TOP bucket with.
|
|
143
|
+
# @return [Numeric]
|
|
144
|
+
attr_reader :top_rate
|
|
145
|
+
|
|
146
|
+
# GLOBAL rate this sampler rebuilds its GLOBAL bucket with.
|
|
147
|
+
# @return [Numeric]
|
|
148
|
+
attr_reader :global_rate
|
|
149
|
+
|
|
150
|
+
# Builds the process-scoped state objects: the mutex, the per-trace
|
|
151
|
+
# budget ledger and the TOP/GLOBAL buckets at the configured rates.
|
|
152
|
+
#
|
|
153
|
+
# @return [void]
|
|
154
|
+
def rebuild_state
|
|
155
|
+
@lock = Mutex.new
|
|
156
|
+
@trace_budgets = TraceBudgetLedger.new(sweep_threshold)
|
|
157
|
+
@top_limiter = Core::TokenBucket.new(top_rate)
|
|
158
|
+
@global_limiter = Core::BorrowingTokenBucket.new(global_rate)
|
|
159
|
+
nil
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Decides a hit with no active trace through the probe's own rate
|
|
163
|
+
# limit and the process-wide GLOBAL budget. Must hold the lock.
|
|
164
|
+
#
|
|
165
|
+
# @param probe [Datadog::DI::Probe]
|
|
166
|
+
# @return [Array(Boolean, Symbol, nil)] the admitted flag and the drop
|
|
167
|
+
# decision, nil when admitted
|
|
168
|
+
def emit_uncorrelated?(probe)
|
|
169
|
+
return [false, :own_rate_limit] unless probe.own_rate_limit_allows?
|
|
170
|
+
return [false, :global_budget] unless global_limiter.try_consume
|
|
171
|
+
|
|
172
|
+
[true, nil]
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# First capturing probe in the trace. Passes the process-wide GLOBAL and
|
|
176
|
+
# TOP gates to emit and seed the trace counters; on either gate's refusal,
|
|
177
|
+
# or when the seeded budget denies the top probe itself, marks the trace
|
|
178
|
+
# starved so every correlated probe in it also drops without re-querying
|
|
179
|
+
# the process-wide gates. The GLOBAL gate consumes its token as part of
|
|
180
|
+
# the check, so a hit the TOP gate refuses still spends one GLOBAL
|
|
181
|
+
# token, and GLOBAL refills once per hit. Must hold the lock.
|
|
182
|
+
#
|
|
183
|
+
# @param probe [Datadog::DI::Probe]
|
|
184
|
+
# @param trace [Datadog::Tracing::TraceOperation]
|
|
185
|
+
# @return [Array(Boolean, Symbol, nil)] the admitted flag and the drop
|
|
186
|
+
# decision, nil when admitted
|
|
187
|
+
def emit_first_probe?(probe, trace)
|
|
188
|
+
unless global_limiter.try_consume && top_limiter.allow?
|
|
189
|
+
store(trace, TraceBudget.new(per_probe_budget: per_probe_budget, all_budget: 0))
|
|
190
|
+
return [false, :top_gate]
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
budget = TraceBudget.new(per_probe_budget: per_probe_budget, all_budget: all_budget)
|
|
194
|
+
store(trace, budget)
|
|
195
|
+
return [false, :trace_budget] unless budget.admit(probe.id)
|
|
196
|
+
|
|
197
|
+
[true, nil]
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# A capturing probe firing inside an established unit. Bounded by the
|
|
201
|
+
# per-probe and all counters; consumes GLOBAL on emit. Must hold the lock.
|
|
202
|
+
#
|
|
203
|
+
# @param budget [TraceBudget]
|
|
204
|
+
# @param probe [Datadog::DI::Probe]
|
|
205
|
+
# @return [Array(Boolean, Symbol, nil)] the admitted flag and the drop
|
|
206
|
+
# decision, nil when admitted
|
|
207
|
+
def emit_correlated?(budget, probe)
|
|
208
|
+
return [false, :trace_budget] unless budget.admit(probe.id)
|
|
209
|
+
|
|
210
|
+
global_limiter.consume
|
|
211
|
+
[true, nil]
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Stores the trace's budget in the ledger. Must hold the lock.
|
|
215
|
+
#
|
|
216
|
+
# @param trace [Datadog::Tracing::TraceOperation]
|
|
217
|
+
# @param budget [TraceBudget]
|
|
218
|
+
# @return [void]
|
|
219
|
+
def store(trace, budget)
|
|
220
|
+
trace_budgets.store(trace, budget)
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
@@ -133,7 +133,7 @@ module Datadog
|
|
|
133
133
|
raise DI::Error::BadVariableName, "Bad variable name: #{target}"
|
|
134
134
|
end
|
|
135
135
|
method_name = (($1 == "@") ? "iref" : "ref")
|
|
136
|
-
"#{method_name}('#{target}')"
|
|
136
|
+
"#{method_name}(context, '#{target}')"
|
|
137
137
|
end
|
|
138
138
|
when *SINGLE_ARG_METHODS
|
|
139
139
|
method_name = op.gsub(/[A-Z]/) { |m| "_#{m.downcase}" }
|
|
@@ -146,10 +146,10 @@ module Datadog
|
|
|
146
146
|
if String === second
|
|
147
147
|
# Match against a literal regular expression (string).
|
|
148
148
|
index = precompile_regexp(second, regexps)
|
|
149
|
-
"matches_compiled(#{compile_partial(first, regexps)}, #{index})"
|
|
149
|
+
"matches_compiled(#{compile_partial(first, regexps)}, #{index}, evaluation_deadline)"
|
|
150
150
|
else
|
|
151
151
|
# Match against a (complex) expression.
|
|
152
|
-
"matches(#{compile_partial(first, regexps)}, (#{compile_partial(second, regexps)}))"
|
|
152
|
+
"matches(#{compile_partial(first, regexps)}, (#{compile_partial(second, regexps)}), evaluation_deadline)"
|
|
153
153
|
end
|
|
154
154
|
when *TWO_ARG_METHODS
|
|
155
155
|
method_name = op.gsub(/[A-Z]/) { |m| "_#{m.downcase}" }
|
|
@@ -185,7 +185,7 @@ module Datadog
|
|
|
185
185
|
unless Array === target && target.length == 2
|
|
186
186
|
raise DI::Error::InvalidExpression, "Improper #{op} syntax"
|
|
187
187
|
end
|
|
188
|
-
"#{op}(#{compile_partial(target.first, regexps)}) { |current_item, current_key, current_value| #{compile_partial(target.last, regexps)} }"
|
|
188
|
+
"#{op}(#{compile_partial(target.first, regexps)}, evaluation_deadline) { |current_item, current_key, current_value| #{compile_partial(target.last, regexps)} }"
|
|
189
189
|
else
|
|
190
190
|
raise DI::Error::InvalidExpression, "Unknown operation: #{op}"
|
|
191
191
|
end
|
|
@@ -12,8 +12,29 @@ module Datadog
|
|
|
12
12
|
# @api private
|
|
13
13
|
class Evaluator
|
|
14
14
|
# Maximum wall-clock time allowed for evaluating a single `matches`
|
|
15
|
-
# operator.
|
|
16
|
-
|
|
15
|
+
# operator. Wall clock, while the evaluation budget is thread CPU
|
|
16
|
+
# time: the regexp engine's `timeout:` keyword and Timeout.timeout
|
|
17
|
+
# offer no CPU-time mode.
|
|
18
|
+
MATCHES_TIMEOUT_SECONDS = 0.05
|
|
19
|
+
|
|
20
|
+
MATCHES_TIMEOUT_MESSAGE = "matches operator timeout"
|
|
21
|
+
|
|
22
|
+
# Number of collection items processed between cooperative
|
|
23
|
+
# evaluation-deadline checks; evaluation aborts within one
|
|
24
|
+
# interval's worth of items past the deadline. A `matches`
|
|
25
|
+
# invocation can spend MATCHES_TIMEOUT_SECONDS of wall time, so
|
|
26
|
+
# #matches and #matches_compiled check the deadline before each
|
|
27
|
+
# match; a predicate that runs `matches` per item therefore
|
|
28
|
+
# adds at most the one match in flight when the deadline
|
|
29
|
+
# passes to the overshoot.
|
|
30
|
+
EVALUATION_DEADLINE_CHECK_INTERVAL = 64
|
|
31
|
+
|
|
32
|
+
# Built-in Array#each and Hash#each, resolved once at load and
|
|
33
|
+
# bound per invocation: the collection operators' iteration then
|
|
34
|
+
# dispatches no customer each override during probe evaluation.
|
|
35
|
+
ARRAY_EACH = Array.instance_method(:each)
|
|
36
|
+
HASH_EACH = Hash.instance_method(:each)
|
|
37
|
+
private_constant :ARRAY_EACH, :HASH_EACH
|
|
17
38
|
|
|
18
39
|
# @param regexps [Array<Regexp>] Regexps precompiled from literal
|
|
19
40
|
# `matches` patterns, looked up by index by #matches_compiled.
|
|
@@ -25,12 +46,110 @@ module Datadog
|
|
|
25
46
|
|
|
26
47
|
attr_reader :regexps
|
|
27
48
|
|
|
28
|
-
|
|
29
|
-
|
|
49
|
+
# Raises DI::Error::EvaluationTimeout when the evaluation deadline
|
|
50
|
+
# has been exceeded, aborting evaluation cooperatively.
|
|
51
|
+
#
|
|
52
|
+
# @param evaluation_deadline [Float] invocation-local evaluation
|
|
53
|
+
# deadline, passed from the compiled #evaluate into the operator
|
|
54
|
+
# calls.
|
|
55
|
+
# @return [void]
|
|
56
|
+
# @raise [DI::Error::EvaluationTimeout] the deadline has been exceeded.
|
|
57
|
+
def raise_if_evaluation_deadline_exceeded(evaluation_deadline)
|
|
58
|
+
if self.class.evaluation_deadline_exceeded?(evaluation_deadline)
|
|
59
|
+
raise DI::Error::EvaluationTimeout
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
private :raise_if_evaluation_deadline_exceeded
|
|
63
|
+
|
|
64
|
+
# Raises DI::Error::EvaluationTimeout when +item_index+ falls on
|
|
65
|
+
# a cooperative check boundary and the evaluation deadline has
|
|
66
|
+
# been exceeded. The thread CPU clock is read only at every
|
|
67
|
+
# EVALUATION_DEADLINE_CHECK_INTERVAL-th item, so an already-exceeded
|
|
68
|
+
# deadline raises at the first boundary at or after it passes.
|
|
69
|
+
#
|
|
70
|
+
# @param item_index [Integer] zero-based index of the collection
|
|
71
|
+
# element being processed.
|
|
72
|
+
# @param evaluation_deadline [Float] invocation-local evaluation
|
|
73
|
+
# deadline, passed from the compiled #evaluate into the operator
|
|
74
|
+
# calls.
|
|
75
|
+
# @return [void]
|
|
76
|
+
# @raise [DI::Error::EvaluationTimeout] a check boundary was reached
|
|
77
|
+
# with the deadline exceeded.
|
|
78
|
+
def raise_if_deadline_check_due_and_exceeded(item_index, evaluation_deadline)
|
|
79
|
+
if (item_index % EVALUATION_DEADLINE_CHECK_INTERVAL).zero?
|
|
80
|
+
raise_if_evaluation_deadline_exceeded(evaluation_deadline)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
private :raise_if_deadline_check_due_and_exceeded
|
|
84
|
+
|
|
85
|
+
# Yields the evaluation values for one collection element — the
|
|
86
|
+
# item alone for an Array element, or the [key, value] pair as
|
|
87
|
+
# @it together with the @key and the @value for a Hash element —
|
|
88
|
+
# iterating through the built-in iteration methods bound per
|
|
89
|
+
# invocation and performing the interval-gated evaluation-deadline
|
|
90
|
+
# check and its counter advance between elements.
|
|
91
|
+
#
|
|
92
|
+
# @param collection [Array, Hash] collection whose elements the
|
|
93
|
+
# block receives.
|
|
94
|
+
# @param evaluation_deadline [Float] invocation-local evaluation deadline.
|
|
95
|
+
# @param operator_name [String] name of the invoking collection
|
|
96
|
+
# operator, reported in the bad-collection-type error.
|
|
97
|
+
# @yield [current_item, current_key, current_value] evaluation
|
|
98
|
+
# values for one element.
|
|
99
|
+
# @return [void]
|
|
100
|
+
# @raise [DI::Error::EvaluationTimeout] the evaluation deadline was
|
|
101
|
+
# exceeded mid-iteration.
|
|
102
|
+
# @raise [DI::Error::ExpressionEvaluationError] +collection+ is
|
|
103
|
+
# not an Array or a Hash.
|
|
104
|
+
def each_collection_item(collection, evaluation_deadline, operator_name)
|
|
105
|
+
case collection
|
|
106
|
+
when Array
|
|
107
|
+
i = 0
|
|
108
|
+
ARRAY_EACH.bind(collection).call do |item|
|
|
109
|
+
raise_if_deadline_check_due_and_exceeded(i, evaluation_deadline)
|
|
110
|
+
i += 1
|
|
111
|
+
yield item, nil, nil
|
|
112
|
+
end
|
|
113
|
+
when Hash
|
|
114
|
+
i = 0
|
|
115
|
+
HASH_EACH.bind(collection).call do |key, value|
|
|
116
|
+
raise_if_deadline_check_due_and_exceeded(i, evaluation_deadline)
|
|
117
|
+
i += 1
|
|
118
|
+
yield [key, value], key, value
|
|
119
|
+
end
|
|
120
|
+
else
|
|
121
|
+
raise DI::Error::ExpressionEvaluationError, "Bad collection type for #{operator_name}: #{collection.class}"
|
|
122
|
+
end
|
|
123
|
+
nil
|
|
124
|
+
end
|
|
125
|
+
private :each_collection_item
|
|
126
|
+
|
|
127
|
+
# Returns whether the thread CPU clock has passed +evaluation_deadline+.
|
|
128
|
+
#
|
|
129
|
+
# @param evaluation_deadline [Float] the deadline to check.
|
|
130
|
+
# @return [Boolean] whether the deadline has been exceeded.
|
|
131
|
+
def self.evaluation_deadline_exceeded?(evaluation_deadline)
|
|
132
|
+
Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID, :float_second) >= evaluation_deadline
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Resolves the value of the local variable or argument +var+ from
|
|
136
|
+
# the evaluation +context+.
|
|
137
|
+
#
|
|
138
|
+
# @param context [Context] context holding the evaluation locals.
|
|
139
|
+
# @param var [Symbol, String] name of the local variable or argument.
|
|
140
|
+
# @return [Object] value of the local variable or argument.
|
|
141
|
+
def ref(context, var)
|
|
142
|
+
context.fetch(var)
|
|
30
143
|
end
|
|
31
144
|
|
|
32
|
-
|
|
33
|
-
|
|
145
|
+
# Resolves the value of the instance variable +var+ from the
|
|
146
|
+
# receiver of the evaluation +context+.
|
|
147
|
+
#
|
|
148
|
+
# @param context [Context] context holding the evaluation receiver.
|
|
149
|
+
# @param var [Symbol, String] name of the instance variable.
|
|
150
|
+
# @return [Object] value of the instance variable.
|
|
151
|
+
def iref(context, var)
|
|
152
|
+
context.fetch_ivar(var)
|
|
34
153
|
end
|
|
35
154
|
|
|
36
155
|
def len(var, var_name)
|
|
@@ -92,10 +211,14 @@ module Datadog
|
|
|
92
211
|
#
|
|
93
212
|
# @param haystack [String] string to match against.
|
|
94
213
|
# @param needle [String] regexp source.
|
|
214
|
+
# @param evaluation_deadline [Float] invocation-local evaluation
|
|
215
|
+
# deadline.
|
|
95
216
|
# @return [Boolean] whether the haystack matches the regexp.
|
|
96
|
-
# @raise [
|
|
97
|
-
#
|
|
98
|
-
|
|
217
|
+
# @raise [DI::Error::EvaluationTimeout] the evaluation deadline was
|
|
218
|
+
# exceeded before the match started, or the match exceeded
|
|
219
|
+
# MATCHES_TIMEOUT_SECONDS.
|
|
220
|
+
def matches(haystack, needle, evaluation_deadline)
|
|
221
|
+
raise_if_evaluation_deadline_exceeded(evaluation_deadline)
|
|
99
222
|
bounded_match?(Evaluator.compile_regexp(needle), haystack)
|
|
100
223
|
end
|
|
101
224
|
|
|
@@ -104,10 +227,14 @@ module Datadog
|
|
|
104
227
|
#
|
|
105
228
|
# @param haystack [String] string to match against.
|
|
106
229
|
# @param index [Integer] position of the precompiled Regexp in +regexps+.
|
|
230
|
+
# @param evaluation_deadline [Float] invocation-local evaluation
|
|
231
|
+
# deadline.
|
|
107
232
|
# @return [Boolean] whether the haystack matches the regexp.
|
|
108
|
-
# @raise [
|
|
109
|
-
#
|
|
110
|
-
|
|
233
|
+
# @raise [DI::Error::EvaluationTimeout] the evaluation deadline was
|
|
234
|
+
# exceeded before the match started, or the match exceeded
|
|
235
|
+
# MATCHES_TIMEOUT_SECONDS.
|
|
236
|
+
def matches_compiled(haystack, index, evaluation_deadline)
|
|
237
|
+
raise_if_evaluation_deadline_exceeded(evaluation_deadline)
|
|
111
238
|
bounded_match?(regexps.fetch(index), haystack)
|
|
112
239
|
end
|
|
113
240
|
|
|
@@ -117,18 +244,32 @@ module Datadog
|
|
|
117
244
|
# @param re [Regexp] regexp to match against.
|
|
118
245
|
# @param haystack [String] string to match against.
|
|
119
246
|
# @return [Boolean] whether the haystack matches the regexp.
|
|
247
|
+
# @raise [DI::Error::EvaluationTimeout] the match exceeded
|
|
248
|
+
# MATCHES_TIMEOUT_SECONDS.
|
|
120
249
|
if Datadog::RubyVersion.is?(">= 3.2")
|
|
121
250
|
def bounded_match?(re, haystack)
|
|
122
251
|
# Uses Regexp#match? rather than =~ so that the
|
|
123
252
|
# thread-local match data ($~, $1, ...) is not mutated as a side
|
|
124
253
|
# effect of DI expression evaluation.
|
|
125
254
|
re.match?(haystack)
|
|
255
|
+
rescue Regexp::TimeoutError
|
|
256
|
+
raise DI::Error::EvaluationTimeout.new(message: MATCHES_TIMEOUT_MESSAGE)
|
|
126
257
|
end
|
|
127
258
|
else
|
|
259
|
+
# Raised by Timeout.timeout in the matching thread. A dedicated
|
|
260
|
+
# class because Timeout.timeout passes a positional message,
|
|
261
|
+
# which EvaluationTimeout does not accept, and because rescuing
|
|
262
|
+
# Timeout::Error would also catch an enclosing customer timeout.
|
|
263
|
+
class MatchTimeoutSignal < StandardError
|
|
264
|
+
end
|
|
265
|
+
private_constant :MatchTimeoutSignal
|
|
266
|
+
|
|
128
267
|
def bounded_match?(re, haystack)
|
|
129
|
-
Timeout.timeout(MATCHES_TIMEOUT_SECONDS) do
|
|
268
|
+
Timeout.timeout(MATCHES_TIMEOUT_SECONDS, MatchTimeoutSignal) do
|
|
130
269
|
re.match?(haystack)
|
|
131
270
|
end
|
|
271
|
+
rescue MatchTimeoutSignal
|
|
272
|
+
raise DI::Error::EvaluationTimeout.new(message: MATCHES_TIMEOUT_MESSAGE)
|
|
132
273
|
end
|
|
133
274
|
end
|
|
134
275
|
private :bounded_match?
|
|
@@ -171,50 +312,113 @@ module Datadog
|
|
|
171
312
|
String === haystack && haystack.end_with?(needle)
|
|
172
313
|
end
|
|
173
314
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
315
|
+
# Returns true when +block+ returns a truthy value for every element
|
|
316
|
+
# of +collection+.
|
|
317
|
+
#
|
|
318
|
+
# @param collection [Array, Hash] collection to test.
|
|
319
|
+
# @param evaluation_deadline [Float] invocation-local evaluation deadline.
|
|
320
|
+
# @return [Boolean] whether the block is satisfied by every element.
|
|
321
|
+
# @raise [DI::Error::EvaluationTimeout] the evaluation deadline was
|
|
322
|
+
# exceeded mid-iteration.
|
|
323
|
+
# @raise [DI::Error::ExpressionEvaluationError] +collection+ is not
|
|
324
|
+
# an Array or a Hash.
|
|
325
|
+
def all(collection, evaluation_deadline, &block)
|
|
326
|
+
result = true
|
|
327
|
+
each_collection_item(collection, evaluation_deadline, "all") do |current_item, current_key, current_value|
|
|
328
|
+
unless block.call(current_item, current_key, current_value)
|
|
329
|
+
result = false
|
|
330
|
+
break
|
|
185
331
|
end
|
|
186
|
-
else
|
|
187
|
-
raise DI::Error::ExpressionEvaluationError, "Bad collection type for all: #{collection.class}"
|
|
188
332
|
end
|
|
333
|
+
result
|
|
189
334
|
end
|
|
190
335
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
336
|
+
# Returns true when +block+ returns a truthy value for any element
|
|
337
|
+
# of +collection+.
|
|
338
|
+
#
|
|
339
|
+
# @param collection [Array, Hash] collection to test.
|
|
340
|
+
# @param evaluation_deadline [Float] invocation-local evaluation deadline.
|
|
341
|
+
# @return [Boolean] whether the block is satisfied by any element.
|
|
342
|
+
# @raise [DI::Error::EvaluationTimeout] the evaluation deadline was
|
|
343
|
+
# exceeded mid-iteration.
|
|
344
|
+
# @raise [DI::Error::ExpressionEvaluationError] +collection+ is not
|
|
345
|
+
# an Array or a Hash.
|
|
346
|
+
def any(collection, evaluation_deadline, &block)
|
|
347
|
+
result = false
|
|
348
|
+
each_collection_item(collection, evaluation_deadline, "any") do |current_item, current_key, current_value|
|
|
349
|
+
if block.call(current_item, current_key, current_value)
|
|
350
|
+
result = true
|
|
351
|
+
break
|
|
196
352
|
end
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
353
|
+
end
|
|
354
|
+
result
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
# Returns the key-value pairs of the Hash +collection+ for which
|
|
358
|
+
# +block+ returns a truthy value.
|
|
359
|
+
#
|
|
360
|
+
# Ruby 3.1 changed Hash#select to reuse the stored key hashes
|
|
361
|
+
# instead of invoking the keys' hash methods and to keep a
|
|
362
|
+
# compare_by_identity hash's distinct-but-eql? keys and identity
|
|
363
|
+
# flag, so this Ruby filters through the built-in Hash#select
|
|
364
|
+
# bound per invocation. Earlier Rubies invoke the keys' hash
|
|
365
|
+
# methods and collapse identity hashes, so they keep the manual
|
|
366
|
+
# iteration through #each_collection_item, preserving the source
|
|
367
|
+
# hash's identity mode in the result.
|
|
368
|
+
if Datadog::RubyVersion.is?(">= 3.1")
|
|
369
|
+
# Built-in Hash#select, resolved once at load and bound per
|
|
370
|
+
# invocation: #filter's Hash iteration then dispatches no
|
|
371
|
+
# customer select override during probe evaluation.
|
|
372
|
+
HASH_SELECT = Hash.instance_method(:select)
|
|
373
|
+
private_constant :HASH_SELECT
|
|
374
|
+
|
|
375
|
+
def filter_hash(collection, evaluation_deadline, &block)
|
|
376
|
+
i = 0
|
|
377
|
+
HASH_SELECT.bind(collection).call do |key, value|
|
|
378
|
+
raise_if_deadline_check_due_and_exceeded(i, evaluation_deadline)
|
|
379
|
+
i += 1
|
|
201
380
|
block.call([key, value], key, value)
|
|
381
|
+
end.to_h
|
|
382
|
+
end
|
|
383
|
+
else
|
|
384
|
+
# Core identity-mode check, resolved once at load and bound per
|
|
385
|
+
# invocation so that #filter dispatches no customer
|
|
386
|
+
# compare_by_identity? override during probe evaluation.
|
|
387
|
+
IDENTITY_MODE_CHECK = Hash.instance_method(:compare_by_identity?)
|
|
388
|
+
private_constant :IDENTITY_MODE_CHECK
|
|
389
|
+
|
|
390
|
+
def filter_hash(collection, evaluation_deadline, &block)
|
|
391
|
+
result = {}
|
|
392
|
+
result.compare_by_identity if IDENTITY_MODE_CHECK.bind(collection).call
|
|
393
|
+
each_collection_item(collection, evaluation_deadline, "filter") do |_current_item, current_key, current_value|
|
|
394
|
+
result[current_key] = current_value if block.call([current_key, current_value], current_key, current_value)
|
|
202
395
|
end
|
|
203
|
-
|
|
204
|
-
raise DI::Error::ExpressionEvaluationError, "Bad collection type for any: #{collection.class}"
|
|
396
|
+
result
|
|
205
397
|
end
|
|
206
398
|
end
|
|
399
|
+
private :filter_hash
|
|
207
400
|
|
|
208
|
-
|
|
401
|
+
# Returns the elements of +collection+ for which +block+ returns a
|
|
402
|
+
# truthy value: the selected items of an Array collection, and a
|
|
403
|
+
# Hash of the selected key-value pairs of a Hash collection.
|
|
404
|
+
#
|
|
405
|
+
# @param collection [Array, Hash] collection to filter.
|
|
406
|
+
# @param evaluation_deadline [Float] invocation-local evaluation deadline.
|
|
407
|
+
# @return [Array, Hash] the selected elements.
|
|
408
|
+
# @raise [DI::Error::EvaluationTimeout] the evaluation deadline was
|
|
409
|
+
# exceeded mid-iteration.
|
|
410
|
+
# @raise [DI::Error::ExpressionEvaluationError] +collection+ is not
|
|
411
|
+
# an Array or a Hash.
|
|
412
|
+
def filter(collection, evaluation_deadline, &block)
|
|
209
413
|
case collection
|
|
210
414
|
when Array
|
|
211
|
-
|
|
212
|
-
|
|
415
|
+
result = []
|
|
416
|
+
each_collection_item(collection, evaluation_deadline, "filter") do |current_item, current_key, current_value|
|
|
417
|
+
result << current_item if block.call(current_item, current_key, current_value)
|
|
213
418
|
end
|
|
419
|
+
result
|
|
214
420
|
when Hash
|
|
215
|
-
collection
|
|
216
|
-
block.call([key, value], key, value)
|
|
217
|
-
end.to_h
|
|
421
|
+
filter_hash(collection, evaluation_deadline, &block)
|
|
218
422
|
else
|
|
219
423
|
raise DI::Error::ExpressionEvaluationError, "Bad collection type for filter: #{collection.class}"
|
|
220
424
|
end
|
|
@@ -27,8 +27,18 @@ module Datadog
|
|
|
27
27
|
cls = Class.new(Evaluator)
|
|
28
28
|
cls.class_exec do
|
|
29
29
|
eval(<<-RUBY, Object.new.send(:binding), __FILE__, __LINE__ + 1) # standard:disable Security/Eval
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
# Evaluates the compiled expression against +context+ within
|
|
31
|
+
# the cooperative evaluation +evaluation_deadline+.
|
|
32
|
+
#
|
|
33
|
+
# @param context [Context] evaluation context (locals, instance
|
|
34
|
+
# variables, and per-invocation special variables).
|
|
35
|
+
# @param evaluation_deadline [Float] invocation-local evaluation
|
|
36
|
+
# deadline, as CLOCK_THREAD_CPUTIME_ID float seconds.
|
|
37
|
+
# @return [Object] the value the expression evaluates to.
|
|
38
|
+
# @raise [DI::Error::ExpressionEvaluationError] the expression
|
|
39
|
+
# failed to evaluate, including the EvaluationTimeout
|
|
40
|
+
# subclass raised when the deadline is exceeded.
|
|
41
|
+
def evaluate(context, evaluation_deadline)
|
|
32
42
|
#{compiled_expr}
|
|
33
43
|
end
|
|
34
44
|
RUBY
|
|
@@ -40,12 +50,32 @@ module Datadog
|
|
|
40
50
|
attr_reader :evaluator
|
|
41
51
|
attr_reader :redaction_identifier
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
# Evaluates the expression against +context+.
|
|
54
|
+
#
|
|
55
|
+
# @param context [Context] evaluation context (locals, instance
|
|
56
|
+
# variables, and per-invocation special variables).
|
|
57
|
+
# @param evaluation_deadline [Float] cooperative evaluation deadline, as
|
|
58
|
+
# CLOCK_THREAD_CPUTIME_ID float seconds.
|
|
59
|
+
# @return [Object] the value the expression evaluates to.
|
|
60
|
+
# @raise [DI::Error::ExpressionEvaluationError] the expression failed
|
|
61
|
+
# to evaluate; DI::Error::EvaluationTimeout, raised when the
|
|
62
|
+
# evaluation deadline is exceeded, is a subclass.
|
|
63
|
+
def evaluate(context, evaluation_deadline:)
|
|
64
|
+
evaluator.evaluate(context, evaluation_deadline)
|
|
45
65
|
end
|
|
46
66
|
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
# Returns whether the expression evaluates to a truthy value
|
|
68
|
+
# against +context+.
|
|
69
|
+
#
|
|
70
|
+
# @param context [Context] evaluation context.
|
|
71
|
+
# @param evaluation_deadline [Float] cooperative evaluation deadline, as
|
|
72
|
+
# CLOCK_THREAD_CPUTIME_ID float seconds.
|
|
73
|
+
# @return [Boolean] whether the expression is satisfied.
|
|
74
|
+
# @raise [DI::Error::ExpressionEvaluationError] the expression failed
|
|
75
|
+
# to evaluate; DI::Error::EvaluationTimeout, raised when the
|
|
76
|
+
# evaluation deadline is exceeded, is a subclass.
|
|
77
|
+
def satisfied?(context, evaluation_deadline:)
|
|
78
|
+
!!evaluate(context, evaluation_deadline: evaluation_deadline)
|
|
49
79
|
end
|
|
50
80
|
end
|
|
51
81
|
end
|