datadog 2.48.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 +47 -1
- data/ext/datadog_profiling_native_extension/collectors_stack.c +1 -1
- data/ext/datadog_profiling_native_extension/collectors_stack.h +4 -2
- data/ext/datadog_profiling_native_extension/extconf.rb +3 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +13 -21
- data/ext/libdatadog_api/extconf.rb +2 -0
- data/ext/libdatadog_api/feature_flags.c +137 -0
- data/ext/libdatadog_api/process_discovery.c +3 -3
- data/ext/libdatadog_extconf_helpers.rb +1 -1
- data/lib/datadog/ai_guard/contrib/rack/patcher.rb +3 -5
- data/lib/datadog/ai_guard/contrib/rails/patcher.rb +7 -9
- data/lib/datadog/ai_guard/contrib/ruby_llm/patcher.rb +3 -5
- data/lib/datadog/ai_guard/metrics/telemetry.rb +2 -4
- 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_route_serializer.rb +1 -3
- data/lib/datadog/appsec/api_security/endpoint_collection/sinatra_route_serializer.rb +1 -3
- data/lib/datadog/appsec/assets.rb +8 -10
- data/lib/datadog/appsec/configuration.rb +1 -1
- data/lib/datadog/appsec/context.rb +63 -6
- data/lib/datadog/appsec/contrib/active_record/instrumentation.rb +1 -3
- data/lib/datadog/appsec/contrib/active_record/patcher.rb +21 -24
- data/lib/datadog/appsec/contrib/aws_lambda/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/aws_lambda/waf_addresses.rb +9 -11
- data/lib/datadog/appsec/contrib/devise/configuration.rb +2 -4
- data/lib/datadog/appsec/contrib/devise/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/excon/patcher.rb +3 -5
- data/lib/datadog/appsec/contrib/faraday/patcher.rb +4 -6
- data/lib/datadog/appsec/contrib/graphql/patcher.rb +3 -5
- 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 +6 -7
- data/lib/datadog/appsec/contrib/rails/patcher.rb +19 -16
- 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/sinatra/patcher.rb +4 -6
- data/lib/datadog/appsec/default_header_tags.rb +2 -4
- 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 +2 -4
- data/lib/datadog/appsec/route_normalizer/route_text.rb +1 -3
- data/lib/datadog/appsec/route_normalizer.rb +4 -6
- 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/core/borrowing_token_bucket.rb +60 -0
- data/lib/datadog/core/chunker.rb +1 -3
- data/lib/datadog/core/configuration/components.rb +48 -17
- data/lib/datadog/core/configuration/settings.rb +2 -1
- data/lib/datadog/core/configuration/supported_configurations.rb +2 -0
- data/lib/datadog/core/diagnostics/environment_logger.rb +1 -6
- data/lib/datadog/core/encoding.rb +8 -12
- data/lib/datadog/core/environment/cgroup.rb +3 -5
- data/lib/datadog/core/environment/container.rb +9 -11
- 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 +8 -16
- data/lib/datadog/core/metrics/helpers.rb +3 -0
- data/lib/datadog/core/metrics/metric.rb +3 -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/transport/http.rb +2 -4
- data/lib/datadog/core/tag_normalizer.rb +0 -2
- data/lib/datadog/core/telemetry/configuration_value.rb +1 -3
- data/lib/datadog/core/telemetry/transport/http.rb +2 -4
- data/lib/datadog/core/telemetry/worker.rb +30 -24
- data/lib/datadog/core/transport/http.rb +2 -4
- data/lib/datadog/core/utils/at_fork_monkey_patch.rb +2 -2
- 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 +16 -14
- data/lib/datadog/core/workers/runtime_metrics.rb +1 -1
- data/lib/datadog/data_streams/transport/http.rb +1 -3
- data/lib/datadog/di/component.rb +14 -2
- data/lib/datadog/di/context.rb +50 -0
- 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/guardrails_telemetry/reason.rb +8 -3
- data/lib/datadog/di/instrumenter.rb +294 -109
- 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 +42 -11
- data/lib/datadog/di/probe_notifier_worker.rb +11 -0
- 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 +29 -0
- data/lib/datadog/error_tracking/filters.rb +6 -8
- data/lib/datadog/open_feature/agentless/parser.rb +2 -4
- data/lib/datadog/open_feature/component.rb +24 -2
- data/lib/datadog/open_feature/configuration.rb +13 -0
- data/lib/datadog/open_feature/evaluation_engine.rb +5 -5
- data/lib/datadog/open_feature/exposure_hook.rb +146 -0
- data/lib/datadog/open_feature/exposures/event.rb +10 -8
- data/lib/datadog/open_feature/exposures/reporter.rb +34 -25
- data/lib/datadog/open_feature/ext.rb +12 -0
- data/lib/datadog/open_feature/flag_evaluation/aggregator.rb +10 -8
- data/lib/datadog/open_feature/flag_evaluation/writer.rb +9 -6
- 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/native_evaluator.rb +30 -2
- data/lib/datadog/open_feature/noop_evaluator.rb +3 -1
- data/lib/datadog/open_feature/provider.rb +54 -4
- data/lib/datadog/open_feature/resolution_details.rb +1 -0
- data/lib/datadog/open_feature/split_features.rb +76 -0
- data/lib/datadog/opentelemetry/sdk/propagator.rb +5 -2
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +28 -31
- data/lib/datadog/profiling/component.rb +31 -9
- data/lib/datadog/profiling/profiler.rb +6 -0
- data/lib/datadog/profiling/remote.rb +381 -0
- data/lib/datadog/profiling/worker_state.rb +65 -0
- data/lib/datadog/profiling.rb +1 -0
- data/lib/datadog/symbol_database/file_hash.rb +1 -3
- data/lib/datadog/tracing/component.rb +14 -16
- data/lib/datadog/tracing/configuration/settings.rb +2 -2
- 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/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/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/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_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 +5 -7
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -6
- 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/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/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/elasticsearch/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/elasticsearch/quantize.rb +6 -8
- data/lib/datadog/tracing/contrib/ethon/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/excon/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/faraday/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/grape/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/graphql/patcher.rb +4 -6
- 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_patcher.rb +1 -3
- data/lib/datadog/tracing/contrib/grpc/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/hanami/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/http/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/httpclient/patcher.rb +2 -4
- 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/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/karafka/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/lograge/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/mongodb/parsers.rb +5 -7
- data/lib/datadog/tracing/contrib/mongodb/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/mysql2/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/opensearch/patcher.rb +1 -3
- data/lib/datadog/tracing/contrib/opensearch/quantize.rb +5 -7
- data/lib/datadog/tracing/contrib/pg/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/presto/patcher.rb +1 -3
- data/lib/datadog/tracing/contrib/que/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/racecar/events/batch.rb +3 -5
- data/lib/datadog/tracing/contrib/racecar/events/consume.rb +3 -5
- data/lib/datadog/tracing/contrib/racecar/events/message.rb +3 -5
- 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/patcher.rb +13 -19
- 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 +6 -8
- data/lib/datadog/tracing/contrib/rails/log_injection.rb +1 -3
- data/lib/datadog/tracing/contrib/rails/patcher.rb +9 -11
- data/lib/datadog/tracing/contrib/rake/patcher.rb +3 -5
- data/lib/datadog/tracing/contrib/redis/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/redis/quantize.rb +7 -9
- data/lib/datadog/tracing/contrib/resque/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/rest_client/patcher.rb +2 -4
- 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/patcher.rb +4 -6
- data/lib/datadog/tracing/contrib/shoryuken/patcher.rb +2 -4
- data/lib/datadog/tracing/contrib/sidekiq/patcher.rb +7 -9
- 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/sneakers/patcher.rb +2 -4
- 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 +1 -3
- 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 +4 -0
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +2 -1
- 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/patcher.rb +3 -5
- data/lib/datadog/tracing/correlation.rb +3 -5
- data/lib/datadog/tracing/distributed/propagation.rb +2 -2
- data/lib/datadog/tracing/distributed/propagation_policy.rb +1 -3
- data/lib/datadog/tracing/distributed/trace_state/datadog.rb +5 -5
- data/lib/datadog/tracing/distributed/trace_state/open_telemetry.rb +2 -2
- data/lib/datadog/tracing/metadata/ext.rb +3 -9
- data/lib/datadog/tracing/remote.rb +1 -1
- data/lib/datadog/tracing/trace_operation.rb +11 -3
- data/lib/datadog/tracing/tracer.rb +9 -1
- data/lib/datadog/tracing/transport/http.rb +1 -3
- data/lib/datadog/tracing/transport/io.rb +2 -4
- data/lib/datadog/tracing/transport/traces.rb +1 -3
- data/lib/datadog/tracing/utils.rb +4 -6
- data/lib/datadog/version.rb +1 -1
- metadata +22 -6
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "snapshot_pruner/node"
|
|
4
|
+
require_relative "snapshot_pruner/node_queue"
|
|
5
|
+
require_relative "snapshot_pruner/parser"
|
|
6
|
+
|
|
7
|
+
module Datadog
|
|
8
|
+
module DI
|
|
9
|
+
# Reduces an encoded snapshot below a byte limit by replacing captured
|
|
10
|
+
# value objects with the pruned marker, operating directly on the
|
|
11
|
+
# encoded bytes. The largest, most deeply nested captured values are
|
|
12
|
+
# replaced first.
|
|
13
|
+
#
|
|
14
|
+
# @api private
|
|
15
|
+
class SnapshotPruner
|
|
16
|
+
# Replacement for each pruned object.
|
|
17
|
+
PRUNED_MARKER = '{"pruned":true}'
|
|
18
|
+
|
|
19
|
+
# Shallowest nesting level that is pruned. The snapshot payload nests
|
|
20
|
+
# +debugger+, +snapshot+, +captures+ and the capture sets above the
|
|
21
|
+
# captured values, which start at level 5 (method probe +arguments+
|
|
22
|
+
# and +locals+ members, line probe line objects). Applying the level
|
|
23
|
+
# to promoted parents as well keeps +captures+ and the capture sets.
|
|
24
|
+
MIN_LEVEL = 5
|
|
25
|
+
|
|
26
|
+
# Initializes the pruner.
|
|
27
|
+
#
|
|
28
|
+
# @return [void]
|
|
29
|
+
def initialize
|
|
30
|
+
@parser = Parser.new
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# The parser that builds the object tree of an encoded snapshot.
|
|
34
|
+
# @return [Parser]
|
|
35
|
+
attr_reader :parser
|
|
36
|
+
|
|
37
|
+
# Prunes an encoded snapshot that exceeds +max_size+.
|
|
38
|
+
#
|
|
39
|
+
# @param json [String] the encoded snapshot, a JSON object
|
|
40
|
+
# @param max_size [Integer] the size limit in bytes
|
|
41
|
+
# @return [String] +json+ itself when it is within +max_size+ or has
|
|
42
|
+
# no object that can be pruned; otherwise a copy with the selected
|
|
43
|
+
# objects replaced by PRUNED_MARKER, which exceeds +max_size+ only
|
|
44
|
+
# when pruning every candidate cannot cover the excess
|
|
45
|
+
# @raise [ArgumentError] when the document is malformed
|
|
46
|
+
def prune(json, max_size:)
|
|
47
|
+
excess = json.bytesize - max_size
|
|
48
|
+
return json if excess <= 0
|
|
49
|
+
|
|
50
|
+
root = parser.parse(json)
|
|
51
|
+
selected_nodes = select_nodes(root, excess)
|
|
52
|
+
return json if selected_nodes.empty?
|
|
53
|
+
|
|
54
|
+
rewrite(json, selected_nodes)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
# Selects the objects to replace, highest priority first, until their
|
|
60
|
+
# replacement saves at least +excess+ bytes or no candidate is left.
|
|
61
|
+
#
|
|
62
|
+
# An object no larger than PRUNED_MARKER, such as an empty Hash, is
|
|
63
|
+
# kept, because replacing it would grow the snapshot; it
|
|
64
|
+
# still counts as pruned toward its parent's promotion, so that the
|
|
65
|
+
# parent can be replaced whole.
|
|
66
|
+
#
|
|
67
|
+
# @param root [Node] the root object of the snapshot
|
|
68
|
+
# @param excess [Integer] bytes the snapshot exceeds the limit by
|
|
69
|
+
# @return [Array<Node>] non-overlapping selected objects in document order
|
|
70
|
+
def select_nodes(root, excess)
|
|
71
|
+
queue = NodeQueue.new
|
|
72
|
+
root.each_leaf do |leaf|
|
|
73
|
+
queue.push(leaf) if leaf.level >= MIN_LEVEL
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
selected = {}
|
|
77
|
+
saving = 0
|
|
78
|
+
while (node = queue.pop)
|
|
79
|
+
node_saving = replacement_saving(node)
|
|
80
|
+
if node_saving > 0
|
|
81
|
+
selected[node.start_offset] = node
|
|
82
|
+
saving += node_saving
|
|
83
|
+
break if saving >= excess
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
parent = node.parent
|
|
87
|
+
next unless parent && parent.level >= MIN_LEVEL
|
|
88
|
+
parent.record_pruned_child
|
|
89
|
+
next unless parent.all_children_pruned?
|
|
90
|
+
|
|
91
|
+
parent.promote
|
|
92
|
+
queue.push(parent)
|
|
93
|
+
parent.children.each do |child|
|
|
94
|
+
saving -= replacement_saving(child) if selected.delete(child.start_offset)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
selected.values.sort_by!(&:start_offset)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Returns the bytes saved by replacing an object with PRUNED_MARKER.
|
|
102
|
+
#
|
|
103
|
+
# @param node [Node] the object to replace
|
|
104
|
+
# @return [Integer] the saving, zero or negative for an object no
|
|
105
|
+
# larger than PRUNED_MARKER
|
|
106
|
+
def replacement_saving(node)
|
|
107
|
+
node.size - PRUNED_MARKER.bytesize
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Copies +json+ with each selected object replaced by PRUNED_MARKER.
|
|
111
|
+
#
|
|
112
|
+
# @param json [String] the encoded snapshot
|
|
113
|
+
# @param selected_nodes [Array<Node>] non-overlapping objects in document order
|
|
114
|
+
# @return [String] the pruned snapshot
|
|
115
|
+
def rewrite(json, selected_nodes)
|
|
116
|
+
pruned = String.new(capacity: json.bytesize, encoding: json.encoding)
|
|
117
|
+
offset = 0
|
|
118
|
+
selected_nodes.each do |node|
|
|
119
|
+
kept = json.byteslice(offset, node.start_offset - offset) #: String
|
|
120
|
+
pruned << kept << PRUNED_MARKER
|
|
121
|
+
offset = node.end_offset
|
|
122
|
+
end
|
|
123
|
+
tail = json.byteslice(offset, json.bytesize - offset) #: String
|
|
124
|
+
pruned << tail
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -9,6 +9,7 @@ require_relative "../../core/transport/transport"
|
|
|
9
9
|
require_relative "../error"
|
|
10
10
|
require_relative "../fatal_exceptions"
|
|
11
11
|
require_relative "../guardrails_telemetry"
|
|
12
|
+
require_relative "../snapshot_pruner"
|
|
12
13
|
require_relative "http/input"
|
|
13
14
|
|
|
14
15
|
module Datadog
|
|
@@ -30,6 +31,9 @@ module Datadog
|
|
|
30
31
|
# The guardrails metric emitter.
|
|
31
32
|
# @return [GuardrailsTelemetry]
|
|
32
33
|
attr_reader :guardrails_telemetry
|
|
34
|
+
# The pruner applied to snapshots above MAX_SERIALIZED_SNAPSHOT_SIZE.
|
|
35
|
+
# @return [SnapshotPruner]
|
|
36
|
+
attr_reader :snapshot_pruner
|
|
33
37
|
|
|
34
38
|
# Initializes the transport.
|
|
35
39
|
#
|
|
@@ -43,16 +47,20 @@ module Datadog
|
|
|
43
47
|
super(apis, default_api, logger: logger)
|
|
44
48
|
@telemetry = telemetry
|
|
45
49
|
@guardrails_telemetry = guardrails_telemetry
|
|
50
|
+
@snapshot_pruner = SnapshotPruner.new
|
|
46
51
|
end
|
|
47
52
|
|
|
48
|
-
# The limit on an individual snapshot payload, aka
|
|
49
|
-
# is 1 MB.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
# The backend's limit on an individual snapshot payload, aka
|
|
54
|
+
# "log line", is 1 MB.
|
|
55
|
+
BACKEND_SNAPSHOT_SIZE_LIMIT = 1024 * 1024
|
|
56
|
+
|
|
57
|
+
# The intake adds host tags and +ddtags+ to a snapshot before the
|
|
58
|
+
# backend applies BACKEND_SNAPSHOT_SIZE_LIMIT.
|
|
59
|
+
BACKEND_ENRICHMENT_HEADROOM = 4 * 1024
|
|
60
|
+
|
|
61
|
+
# The largest encoded snapshot that is sent. Larger snapshots are
|
|
62
|
+
# pruned to fit.
|
|
63
|
+
MAX_SERIALIZED_SNAPSHOT_SIZE = BACKEND_SNAPSHOT_SIZE_LIMIT - BACKEND_ENRICHMENT_HEADROOM
|
|
56
64
|
|
|
57
65
|
# The maximum chunk (batch) size that intake permits is 5 MB.
|
|
58
66
|
#
|
|
@@ -72,8 +80,11 @@ module Datadog
|
|
|
72
80
|
# and exception, allowing the caller to disable the affected probe.
|
|
73
81
|
# Successfully serialized snapshots are still sent.
|
|
74
82
|
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
83
|
+
# Snapshots larger than MAX_SERIALIZED_SNAPSHOT_SIZE are pruned:
|
|
84
|
+
# their largest, most deeply nested captured values are replaced
|
|
85
|
+
# with a pruned marker until they fit. Snapshots that pruning
|
|
86
|
+
# cannot fit are dropped. Batches are split into chunks of ~2MB
|
|
87
|
+
# each to avoid large network requests.
|
|
77
88
|
#
|
|
78
89
|
# @param payload [Array<SnapshotEvent>] the snapshot events to send, each paired with its probe's guardrails event type
|
|
79
90
|
# @param tags [Hash] Tags to send with the snapshots
|
|
@@ -86,14 +97,17 @@ module Datadog
|
|
|
86
97
|
# Serialize each snapshot individually to isolate failures
|
|
87
98
|
encoded_snapshots = []
|
|
88
99
|
dropped_events = []
|
|
100
|
+
pruned_events = []
|
|
89
101
|
payload.each do |event|
|
|
90
102
|
encoded = encoder.encode(event.payload)
|
|
91
103
|
if encoded.bytesize > MAX_SERIALIZED_SNAPSHOT_SIZE
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
pruned = prune_snapshot(encoded)
|
|
105
|
+
unless pruned
|
|
106
|
+
dropped_events << [event, encoded.bytesize]
|
|
107
|
+
next
|
|
94
108
|
end
|
|
95
|
-
|
|
96
|
-
|
|
109
|
+
pruned_events << event
|
|
110
|
+
encoded = pruned
|
|
97
111
|
end
|
|
98
112
|
encoded_snapshots << encoded
|
|
99
113
|
rescue Exception => exc # standard:disable Lint/RescueException
|
|
@@ -122,12 +136,19 @@ module Datadog
|
|
|
122
136
|
)
|
|
123
137
|
end
|
|
124
138
|
|
|
139
|
+
pruned_events.each do |event|
|
|
140
|
+
guardrails_telemetry.capture_incomplete(
|
|
141
|
+
reason: GuardrailsTelemetry::Reason::PAYLOAD_TOO_LARGE,
|
|
142
|
+
event_type: event.event_type,
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
|
|
125
146
|
return payload if encoded_snapshots.empty?
|
|
126
147
|
|
|
127
148
|
Datadog::Core::Chunker.chunk_by_size(
|
|
128
149
|
encoded_snapshots, DEFAULT_CHUNK_SIZE,
|
|
129
150
|
).each do |chunk|
|
|
130
|
-
#
|
|
151
|
+
# Snapshots that are too big were pruned or dropped earlier.
|
|
131
152
|
# The limit on chunked payload length here is greater
|
|
132
153
|
# than the limit on snapshot size, therefore no chunks
|
|
133
154
|
# can exceed limits here.
|
|
@@ -147,6 +168,45 @@ module Datadog
|
|
|
147
168
|
payload
|
|
148
169
|
end
|
|
149
170
|
|
|
171
|
+
# Prunes an encoded snapshot to fit MAX_SERIALIZED_SNAPSHOT_SIZE.
|
|
172
|
+
#
|
|
173
|
+
# A pruner failure drops the snapshot and is reported here, so
|
|
174
|
+
# that it does not reach the serialization error callback, which
|
|
175
|
+
# disables the probe.
|
|
176
|
+
#
|
|
177
|
+
# @param encoded [String] the encoded snapshot
|
|
178
|
+
# @return [String, nil] the pruned snapshot, nil when the snapshot
|
|
179
|
+
# is to be dropped because pruning cannot fit it or failed
|
|
180
|
+
def prune_snapshot(encoded)
|
|
181
|
+
pruned = snapshot_pruner.prune(encoded, max_size: MAX_SERIALIZED_SNAPSHOT_SIZE)
|
|
182
|
+
if pruned.bytesize > MAX_SERIALIZED_SNAPSHOT_SIZE
|
|
183
|
+
log_snapshot_drop
|
|
184
|
+
return
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
logger.debug do
|
|
188
|
+
"di: pruned snapshot from #{encoded.bytesize} to #{pruned.bytesize} bytes " \
|
|
189
|
+
"(#{GuardrailsTelemetry::Reason::PAYLOAD_TOO_LARGE})"
|
|
190
|
+
end
|
|
191
|
+
pruned
|
|
192
|
+
rescue Exception => exc # standard:disable Lint/RescueException
|
|
193
|
+
Datadog::DI.reraise_if_fatal(exc)
|
|
194
|
+
logger.debug { "di: snapshot pruning failed: #{exc.class}: #{exc.message} (at #{exc.backtrace&.first})" }
|
|
195
|
+
telemetry&.report(exc, description: "Snapshot pruning failed")
|
|
196
|
+
log_snapshot_drop
|
|
197
|
+
nil
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Logs the drop of a snapshot that exceeds MAX_SERIALIZED_SNAPSHOT_SIZE.
|
|
201
|
+
#
|
|
202
|
+
# @return [void]
|
|
203
|
+
def log_snapshot_drop
|
|
204
|
+
logger.debug do
|
|
205
|
+
"di: dropping too big snapshot (#{GuardrailsTelemetry::Reason::PAYLOAD_TOO_LARGE})"
|
|
206
|
+
end
|
|
207
|
+
nil
|
|
208
|
+
end
|
|
209
|
+
|
|
150
210
|
def send_input_chunk(chunked_payload, serialized_tags)
|
|
151
211
|
parcel = Core::Transport::Parcel.new(chunked_payload, content_type: encoder.content_type)
|
|
152
212
|
request = Request.new(parcel, serialized_tags)
|
data/lib/datadog/di/utils.rb
CHANGED
|
@@ -85,7 +85,7 @@ module Datadog
|
|
|
85
85
|
# Returns +path+ with Windows-style backslash separators translated to
|
|
86
86
|
# forward slashes (DEBUG-5111). Used to normalize probe source paths
|
|
87
87
|
# that originate from IDE tooling running on Windows.
|
|
88
|
-
|
|
88
|
+
def self.normalize_windows_separators(path)
|
|
89
89
|
path.tr("\\", "/")
|
|
90
90
|
end
|
|
91
91
|
|
|
@@ -106,7 +106,7 @@ module Datadog
|
|
|
106
106
|
#
|
|
107
107
|
# If suffix is not an absolute path, the path matches if its suffix is
|
|
108
108
|
# the provided suffix, at a path component boundary.
|
|
109
|
-
|
|
109
|
+
def self.path_matches_suffix?(path, suffix, case_insensitive: false)
|
|
110
110
|
if path.nil?
|
|
111
111
|
raise ArgumentError, "nil path passed"
|
|
112
112
|
end
|
|
@@ -146,7 +146,7 @@ module Datadog
|
|
|
146
146
|
# Matching is attempted case-sensitively first (steps 5-6 in the design
|
|
147
147
|
# comment above) and only falls back to case-insensitive (steps 7-8)
|
|
148
148
|
# when no case-sensitive match is found.
|
|
149
|
-
|
|
149
|
+
def self.path_can_match_spec?(path, spec)
|
|
150
150
|
# Normalize Windows-style backslash separators (DEBUG-5111) so the
|
|
151
151
|
# suffix-shortening loop's "/+" regex can strip leading components.
|
|
152
152
|
spec = normalize_windows_separators(spec)
|
data/lib/datadog/di.rb
CHANGED
|
@@ -134,6 +134,35 @@ module Datadog
|
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
|
|
137
|
+
# Returns the tracer of the built component tree, or nil when tracing
|
|
138
|
+
# is not loaded or the tree is not built. The component lookup skips
|
|
139
|
+
# initialization because initialization would run from the customer's
|
|
140
|
+
# call stack.
|
|
141
|
+
#
|
|
142
|
+
# @return [Datadog::Tracing::Tracer, nil]
|
|
143
|
+
private def built_tracer
|
|
144
|
+
if defined?(Datadog::Tracing)
|
|
145
|
+
components = Datadog.send(:components, allow_initialization: false)
|
|
146
|
+
components&.tracer
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Returns the active APM trace, or nil when tracing is not loaded or
|
|
151
|
+
# no trace is active.
|
|
152
|
+
#
|
|
153
|
+
# @return [Datadog::Tracing::TraceOperation, nil]
|
|
154
|
+
def active_trace
|
|
155
|
+
built_tracer&.active_trace
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Returns the active APM span, or nil when tracing is not loaded or no
|
|
159
|
+
# span is active.
|
|
160
|
+
#
|
|
161
|
+
# @return [Datadog::Tracing::SpanOperation, nil]
|
|
162
|
+
def active_span
|
|
163
|
+
built_tracer&.active_span
|
|
164
|
+
end
|
|
165
|
+
|
|
137
166
|
# Returns iseqs that correspond to loaded files (filtering out eval'd code).
|
|
138
167
|
#
|
|
139
168
|
# There are several types of iseqs returned by +all_iseqs+:
|
|
@@ -11,9 +11,7 @@ module Datadog
|
|
|
11
11
|
#
|
|
12
12
|
# @api private
|
|
13
13
|
module Filters
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def get_gem_name(file_path)
|
|
14
|
+
def self.get_gem_name(file_path)
|
|
17
15
|
regex = %r{gems/([^/]+)-\d}
|
|
18
16
|
regex_match = regex.match(file_path)
|
|
19
17
|
return unless regex_match
|
|
@@ -27,25 +25,25 @@ module Datadog
|
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
27
|
|
|
30
|
-
def user_code?(file_path)
|
|
28
|
+
def self.user_code?(file_path)
|
|
31
29
|
!get_gem_name(file_path)
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
def datadog_code?(file_path)
|
|
32
|
+
def self.datadog_code?(file_path)
|
|
35
33
|
file_path.include?("lib/datadog/")
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
def third_party_code?(file_path)
|
|
36
|
+
def self.third_party_code?(file_path)
|
|
39
37
|
gem_name = get_gem_name(file_path)
|
|
40
38
|
gem_name && gem_name != "datadog"
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
def file_included?(file_path, instrumented_files)
|
|
41
|
+
def self.file_included?(file_path, instrumented_files)
|
|
44
42
|
instrumented_files.include?(file_path)
|
|
45
43
|
end
|
|
46
44
|
|
|
47
45
|
# Generate the proc used in the TracePoint
|
|
48
|
-
def generate_filter(to_instrument_scope, handled_errors_include = nil)
|
|
46
|
+
def self.generate_filter(to_instrument_scope, handled_errors_include = nil)
|
|
49
47
|
case to_instrument_scope
|
|
50
48
|
# If DD_ERROR_TRACKING_HANDLED_ERRORS is set
|
|
51
49
|
when "all"
|
|
@@ -9,9 +9,7 @@ module Datadog
|
|
|
9
9
|
module Parser
|
|
10
10
|
RESOURCE_TYPE = "universal-flag-configuration"
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def parse(body)
|
|
12
|
+
def self.parse(body)
|
|
15
13
|
payload = JSON.parse(body)
|
|
16
14
|
return unless payload.is_a?(Hash)
|
|
17
15
|
|
|
@@ -26,7 +24,7 @@ module Datadog
|
|
|
26
24
|
nil
|
|
27
25
|
end
|
|
28
26
|
|
|
29
|
-
def valid_attributes?(attributes)
|
|
27
|
+
def self.valid_attributes?(attributes)
|
|
30
28
|
return false unless attributes.is_a?(Hash)
|
|
31
29
|
|
|
32
30
|
environment = attributes["environment"]
|
|
@@ -14,6 +14,7 @@ require_relative "hooks/flag_eval_metrics_hook"
|
|
|
14
14
|
require_relative "hooks/flag_eval_evp_hook"
|
|
15
15
|
require_relative "hooks/span_enrichment_hook"
|
|
16
16
|
require_relative "hooks/debug_logging_hook"
|
|
17
|
+
require_relative "hooks/exposure_logging_hook"
|
|
17
18
|
|
|
18
19
|
module Datadog
|
|
19
20
|
module OpenFeature
|
|
@@ -60,14 +61,15 @@ module Datadog
|
|
|
60
61
|
transport = Transport::HTTP.build(agent_settings: agent_settings, logger: logger)
|
|
61
62
|
@worker = Exposures::Worker.new(settings: settings, transport: transport, telemetry: telemetry, logger: logger)
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
@engine = EvaluationEngine.new(reporter, telemetry: telemetry, logger: logger)
|
|
64
|
+
@engine = EvaluationEngine.new(telemetry: telemetry, logger: logger)
|
|
65
65
|
|
|
66
66
|
@telemetry = telemetry
|
|
67
67
|
@logger = logger
|
|
68
68
|
@settings = settings
|
|
69
69
|
@agent_settings = agent_settings
|
|
70
70
|
@on_configuration_change = on_configuration_change
|
|
71
|
+
@exposure_logging_hook_mutex = Mutex.new
|
|
72
|
+
@exposure_logging_hook = create_exposure_logging_hook
|
|
71
73
|
@flag_eval_metrics_hook = create_flag_eval_metrics_hook
|
|
72
74
|
@flag_eval_evp_hook = create_flag_eval_evp_hook
|
|
73
75
|
@span_enrichment_hook = create_span_enrichment_hook
|
|
@@ -106,6 +108,15 @@ module Datadog
|
|
|
106
108
|
@on_configuration_change&.call(event) if event
|
|
107
109
|
end
|
|
108
110
|
|
|
111
|
+
# Retried until the OpenFeature SDK loads, since Remote Configuration can build this component first.
|
|
112
|
+
# Built at most once: each hook owns an exposure cache, and two caches would send repeats.
|
|
113
|
+
def exposure_logging_hook
|
|
114
|
+
hook = @exposure_logging_hook
|
|
115
|
+
return hook if hook
|
|
116
|
+
|
|
117
|
+
@exposure_logging_hook_mutex.synchronize { @exposure_logging_hook ||= create_exposure_logging_hook }
|
|
118
|
+
end
|
|
119
|
+
|
|
109
120
|
# Checked per evaluation so the SDK skips hook dispatch unless debug logging is on. Built lazily
|
|
110
121
|
# because Remote Configuration can build this component before the OpenFeature SDK loads.
|
|
111
122
|
def debug_logging_hook
|
|
@@ -161,6 +172,17 @@ module Datadog
|
|
|
161
172
|
@configuration_mutex.synchronize { @configuration_shutdown }
|
|
162
173
|
end
|
|
163
174
|
|
|
175
|
+
def create_exposure_logging_hook
|
|
176
|
+
return unless Hooks::ExposureLoggingHook.available?
|
|
177
|
+
|
|
178
|
+
reporter = Exposures::Reporter.new(
|
|
179
|
+
@worker,
|
|
180
|
+
logger: @logger,
|
|
181
|
+
datadog_logging_enabled: @settings.feature_flags.exposures_datadog_logging_enabled,
|
|
182
|
+
)
|
|
183
|
+
Hooks::ExposureLoggingHook.new(reporter, telemetry: @telemetry, logger: @logger)
|
|
184
|
+
end
|
|
185
|
+
|
|
164
186
|
def create_flag_eval_metrics_hook
|
|
165
187
|
return unless Hooks::FlagEvalMetricsHook.available?
|
|
166
188
|
|
|
@@ -72,6 +72,12 @@ module Datadog
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
settings :feature_flags do
|
|
75
|
+
option :experimentation_opt_out_mode do |o|
|
|
76
|
+
o.type :string
|
|
77
|
+
o.env "DD_FEATURE_FLAGS_EXPERIMENTATION_OPT_OUT_MODE"
|
|
78
|
+
o.default "disabled"
|
|
79
|
+
end
|
|
80
|
+
|
|
75
81
|
option :enabled do |o|
|
|
76
82
|
o.type :bool
|
|
77
83
|
o.env "DD_FEATURE_FLAGS_ENABLED"
|
|
@@ -84,6 +90,13 @@ module Datadog
|
|
|
84
90
|
o.default false
|
|
85
91
|
end
|
|
86
92
|
|
|
93
|
+
# Sends exposure events to Datadog.
|
|
94
|
+
option :exposures_datadog_logging_enabled do |o|
|
|
95
|
+
o.type :bool
|
|
96
|
+
o.env "DD_FEATURE_FLAGS_EXPOSURES_DATADOG_LOGGING_ENABLED"
|
|
97
|
+
o.default true
|
|
98
|
+
end
|
|
99
|
+
|
|
87
100
|
option :configuration_source do |o|
|
|
88
101
|
o.type :string
|
|
89
102
|
o.env "DD_FEATURE_FLAGS_CONFIGURATION_SOURCE"
|
|
@@ -21,8 +21,7 @@ module Datadog
|
|
|
21
21
|
"(targeting keys, evaluation context attributes, flag values, and default values) that may contain " \
|
|
22
22
|
"personal or sensitive information. Unset DD_TRACE_DEBUG when you no longer need it."
|
|
23
23
|
|
|
24
|
-
def initialize(
|
|
25
|
-
@reporter = reporter
|
|
24
|
+
def initialize(telemetry:, logger:)
|
|
26
25
|
@telemetry = telemetry
|
|
27
26
|
@logger = logger
|
|
28
27
|
@raw_data_warning = Core::Utils::OnlyOnce.new
|
|
@@ -30,7 +29,9 @@ module Datadog
|
|
|
30
29
|
@evaluator = NoopEvaluator.new(nil)
|
|
31
30
|
end
|
|
32
31
|
|
|
33
|
-
def fetch_value(
|
|
32
|
+
def fetch_value(
|
|
33
|
+
flag_key, default_value:, expected_type:, evaluation_context: nil, experimentation_opt_out_mode: :disabled
|
|
34
|
+
)
|
|
34
35
|
# Pre-bound to the safe default so the rescue below can still read it if the
|
|
35
36
|
# evaluator read itself raises.
|
|
36
37
|
observe_full_evaluation_data = false
|
|
@@ -51,13 +52,12 @@ module Datadog
|
|
|
51
52
|
context = evaluation_context&.fields.to_h
|
|
52
53
|
result = evaluator.get_assignment(
|
|
53
54
|
flag_key, default_value: default_value, context: context, expected_type: expected_type,
|
|
55
|
+
experimentation_opt_out_mode: experimentation_opt_out_mode,
|
|
54
56
|
)
|
|
55
57
|
|
|
56
58
|
result = with_observe_full_evaluation_data(result, observe_full_evaluation_data)
|
|
57
59
|
log_resolution(flag_key, expected_type, result)
|
|
58
60
|
|
|
59
|
-
@reporter.report(result, flag_key: flag_key, context: evaluation_context)
|
|
60
|
-
|
|
61
61
|
result
|
|
62
62
|
rescue => e
|
|
63
63
|
@telemetry.report(e, description: "OpenFeature: Failed to fetch flag value")
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open_feature/sdk"
|
|
4
|
+
|
|
5
|
+
require_relative "ext"
|
|
6
|
+
require_relative "split_features"
|
|
7
|
+
require_relative "../core/utils/only_once"
|
|
8
|
+
|
|
9
|
+
module Datadog
|
|
10
|
+
module OpenFeature
|
|
11
|
+
# An OpenFeature hook that hands each completed evaluation to a callback, with the Datadog
|
|
12
|
+
# exposure decision, so an application can record exposures in its own data store.
|
|
13
|
+
#
|
|
14
|
+
# Register it on the OpenFeature API, a client, or an evaluation:
|
|
15
|
+
#
|
|
16
|
+
# hook = Datadog::OpenFeature::ExposureHook.new do |evaluation|
|
|
17
|
+
# next unless evaluation.should_send?
|
|
18
|
+
#
|
|
19
|
+
# exposure_queue << [evaluation.flag_key, evaluation.targeting_key, evaluation.variant, evaluation.features]
|
|
20
|
+
# end
|
|
21
|
+
# OpenFeature::SDK.configure { |config| config.hooks << hook }
|
|
22
|
+
#
|
|
23
|
+
# The callback runs on the evaluation thread for every evaluation of a directly registered
|
|
24
|
+
# Datadog provider, including errors and repeats. It must not block or do I/O. An exception
|
|
25
|
+
# raised by the callback never affects the evaluation: the first one is logged at warn level,
|
|
26
|
+
# later ones at debug level.
|
|
27
|
+
#
|
|
28
|
+
# @public_api
|
|
29
|
+
class ExposureHook
|
|
30
|
+
include ::OpenFeature::SDK::Hooks::Hook if defined?(::OpenFeature::SDK::Hooks::Hook)
|
|
31
|
+
|
|
32
|
+
# A completed evaluation and its Datadog exposure decision.
|
|
33
|
+
#
|
|
34
|
+
# @public_api
|
|
35
|
+
class Evaluation
|
|
36
|
+
attr_reader :evaluation_context, :evaluation_details
|
|
37
|
+
|
|
38
|
+
def initialize(hook_context, evaluation_details)
|
|
39
|
+
@flag_key = hook_context.flag_key
|
|
40
|
+
@evaluation_context = hook_context.evaluation_context
|
|
41
|
+
@evaluation_details = evaluation_details
|
|
42
|
+
metadata = evaluation_details.flag_metadata
|
|
43
|
+
@metadata = metadata.is_a?(Hash) ? metadata : SplitFeatures::EMPTY
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
attr_reader :flag_key
|
|
47
|
+
|
|
48
|
+
def variant
|
|
49
|
+
@evaluation_details.variant
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def allocation_key
|
|
53
|
+
allocation_key = @metadata[Ext::METADATA_ALLOCATION_KEY]
|
|
54
|
+
allocation_key if allocation_key.is_a?(String)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def split_serial_id
|
|
58
|
+
serial_id = @metadata[Ext::METADATA_SPLIT_SERIAL_ID]
|
|
59
|
+
serial_id if serial_id.is_a?(Integer)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def targeting_key
|
|
63
|
+
@evaluation_context&.targeting_key
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# True for a successful evaluation of an allocation that logs exposures, repeats included.
|
|
67
|
+
def exposure?
|
|
68
|
+
@evaluation_details.error_code.nil? &&
|
|
69
|
+
@evaluation_details.reason != Ext::ERROR &&
|
|
70
|
+
!variant.nil? &&
|
|
71
|
+
!allocation_key.nil? &&
|
|
72
|
+
@metadata[Ext::METADATA_DO_LOG] == true
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# True when this subject was already exposed to the same allocation, variant and serial id.
|
|
76
|
+
def cache_hit?
|
|
77
|
+
exposure? && @metadata[Ext::METADATA_EXPOSURE_CACHE_HIT] == true
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# True for a new or changed exposure: the exposures the provider selects for reporting to Datadog while
|
|
81
|
+
# DD_FEATURE_FLAGS_EXPOSURES_DATADOG_LOGGING_ENABLED is on. This does not confirm delivery.
|
|
82
|
+
def should_send?
|
|
83
|
+
exposure? && @metadata[Ext::METADATA_EXPOSURE_CACHE_HIT] == false
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# The selected split's features, such as "holdout.key"; values are String, Float or true/false.
|
|
87
|
+
#
|
|
88
|
+
# @return [Hash{String => String, Float, Boolean}] frozen, empty when the split has none
|
|
89
|
+
def features
|
|
90
|
+
@features ||= SplitFeatures.read(@metadata, Ext::METADATA_FEATURE_PREFIX)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def initialize(callback = nil, &block)
|
|
95
|
+
raise ArgumentError, "pass either a callback or a block, not both" if callback && block
|
|
96
|
+
|
|
97
|
+
callable = callback || block
|
|
98
|
+
raise ArgumentError, "callback must respond to #call" unless callable.respond_to?(:call)
|
|
99
|
+
|
|
100
|
+
@callback = callable
|
|
101
|
+
@failure_warning = Core::Utils::OnlyOnce.new
|
|
102
|
+
@unsupported_provider_warning = Core::Utils::OnlyOnce.new
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def finally(hook_context:, evaluation_details:, **_opts)
|
|
106
|
+
return unless datadog_provider?(hook_context)
|
|
107
|
+
|
|
108
|
+
@callback.call(Evaluation.new(hook_context, evaluation_details))
|
|
109
|
+
rescue StandardError, ScriptError => e
|
|
110
|
+
log_callback_failure(hook_context, e)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
# A composed provider does not run the Datadog provider's hooks, so no exposure decision exists.
|
|
116
|
+
def datadog_provider?(hook_context)
|
|
117
|
+
return true if hook_context.provider_metadata&.name == Ext::PROVIDER_NAME
|
|
118
|
+
|
|
119
|
+
@unsupported_provider_warning.run do
|
|
120
|
+
Datadog.logger.warn(
|
|
121
|
+
"Feature Flags: ExposureHook requires a directly registered Datadog provider; " \
|
|
122
|
+
"callbacks are skipped for other providers",
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
false
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def log_callback_failure(hook_context, error)
|
|
129
|
+
message = "Feature Flags: ExposureHook callback failed for #{hook_context.flag_key.inspect}: #{error.class}"
|
|
130
|
+
warned = false
|
|
131
|
+
@failure_warning.run do
|
|
132
|
+
warned = true
|
|
133
|
+
Datadog.logger.warn("#{message}; later failures are logged at debug level")
|
|
134
|
+
end
|
|
135
|
+
Datadog.logger.debug { "#{message}: #{exception_message(error)}" } unless warned
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Customer exceptions can override #message with code that raises.
|
|
139
|
+
def exception_message(error)
|
|
140
|
+
error.message
|
|
141
|
+
rescue StandardError, ScriptError => e
|
|
142
|
+
"#{e.class} raised while reading the exception message"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|