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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative "utils/time"
|
|
4
|
+
require_relative "refillable_bucket"
|
|
5
|
+
require_relative "borrowing_token_bucket"
|
|
4
6
|
|
|
5
7
|
module Datadog
|
|
6
8
|
module Core
|
|
@@ -31,29 +33,26 @@ module Datadog
|
|
|
31
33
|
#
|
|
32
34
|
# @see https://en.wikipedia.org/wiki/Token_bucket Token bucket
|
|
33
35
|
class TokenBucket < RateLimiter
|
|
34
|
-
|
|
36
|
+
include RefillableBucket
|
|
35
37
|
|
|
38
|
+
# Initializes the bucket balance and the conformance-rate statistics
|
|
39
|
+
# windows.
|
|
40
|
+
#
|
|
36
41
|
# @param rate [Numeric] Allowance rate, in units per second
|
|
37
42
|
# if rate is negative, always allow
|
|
38
43
|
# if rate is zero, never allow
|
|
39
44
|
# @param max_tokens [Numeric] Limit of available tokens
|
|
45
|
+
# @raise [ArgumentError] when rate or max_tokens is not a number
|
|
40
46
|
def initialize(rate, max_tokens = rate)
|
|
41
47
|
super()
|
|
42
48
|
|
|
43
|
-
|
|
44
|
-
raise ArgumentError, "max_tokens must be a number: #{max_tokens}" unless max_tokens.is_a?(Numeric)
|
|
45
|
-
|
|
46
|
-
@rate = rate
|
|
47
|
-
@max_tokens = max_tokens
|
|
49
|
+
initialize_bucket(rate, max_tokens)
|
|
48
50
|
|
|
49
|
-
@tokens = max_tokens
|
|
50
51
|
@total_messages = 0
|
|
51
52
|
@conforming_messages = 0
|
|
52
53
|
@prev_conforming_messages = nil
|
|
53
54
|
@prev_total_messages = nil
|
|
54
55
|
@current_window = nil
|
|
55
|
-
|
|
56
|
-
@last_refill = Core::Utils::Time.get_time
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
# Checks if a message of provided +size+
|
|
@@ -102,29 +101,8 @@ module Datadog
|
|
|
102
101
|
@conforming_messages.to_f / @total_messages
|
|
103
102
|
end
|
|
104
103
|
|
|
105
|
-
# @return [Numeric] number of tokens currently available
|
|
106
|
-
def available_tokens
|
|
107
|
-
@tokens
|
|
108
|
-
end
|
|
109
|
-
|
|
110
104
|
private
|
|
111
105
|
|
|
112
|
-
def refill_since_last_message
|
|
113
|
-
now = Core::Utils::Time.get_time
|
|
114
|
-
elapsed = now - @last_refill
|
|
115
|
-
|
|
116
|
-
# Update the number of available tokens, but ensure we do not exceed the max
|
|
117
|
-
# we return the min of tokens + rate*elapsed, or max tokens
|
|
118
|
-
refill_tokens(@rate * elapsed)
|
|
119
|
-
|
|
120
|
-
@last_refill = now
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def refill_tokens(size)
|
|
124
|
-
@tokens += size
|
|
125
|
-
@tokens = @max_tokens if @tokens > @max_tokens
|
|
126
|
-
end
|
|
127
|
-
|
|
128
106
|
def increment_total_count
|
|
129
107
|
@total_messages += 1
|
|
130
108
|
end
|
|
@@ -140,7 +118,7 @@ module Datadog
|
|
|
140
118
|
# negative rate limit disables rate limiting
|
|
141
119
|
return true if @rate < 0
|
|
142
120
|
|
|
143
|
-
|
|
121
|
+
refill
|
|
144
122
|
|
|
145
123
|
# if tokens < 1 we don't allow?
|
|
146
124
|
return false if @tokens < size
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "utils/time"
|
|
4
|
+
|
|
5
|
+
module Datadog
|
|
6
|
+
module Core
|
|
7
|
+
# Token-bucket balance shared by rate limiter classes: the balance
|
|
8
|
+
# refills at +rate+ tokens per second toward +max_tokens+, and including
|
|
9
|
+
# classes define the admission policy on top of it. Including classes
|
|
10
|
+
# call +initialize_bucket+ from their constructors to set up the state.
|
|
11
|
+
module RefillableBucket
|
|
12
|
+
# @return [Numeric] refill rate, in tokens per second
|
|
13
|
+
attr_reader :rate
|
|
14
|
+
|
|
15
|
+
# @return [Numeric] ceiling the balance refills toward
|
|
16
|
+
attr_reader :max_tokens
|
|
17
|
+
|
|
18
|
+
# Monotonic time of the last refill, in seconds, read from the process
|
|
19
|
+
# monotonic clock.
|
|
20
|
+
#
|
|
21
|
+
# @return [Numeric]
|
|
22
|
+
attr_reader :last_refill
|
|
23
|
+
|
|
24
|
+
# @return [Numeric] the token balance as of the last refill; reads
|
|
25
|
+
# between refills return a stale balance
|
|
26
|
+
def available_tokens
|
|
27
|
+
@tokens
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Returns the balance the bucket holds at +now+: the stored balance
|
|
31
|
+
# plus +rate+ tokens for every second since the last refill, capped
|
|
32
|
+
# at +max_tokens+.
|
|
33
|
+
#
|
|
34
|
+
# @param now [Float] monotonic time, in seconds
|
|
35
|
+
# @return [Numeric]
|
|
36
|
+
def balance_at(now)
|
|
37
|
+
accrued = available_tokens + rate * (now - last_refill)
|
|
38
|
+
accrued = max_tokens if accrued > max_tokens
|
|
39
|
+
accrued
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# Sets the shared bucket state: the balance starts at +max_tokens+ and
|
|
45
|
+
# refills at +rate+ tokens per second.
|
|
46
|
+
#
|
|
47
|
+
# @param rate [Numeric] refill rate, in tokens per second
|
|
48
|
+
# @param max_tokens [Numeric] ceiling the balance refills toward
|
|
49
|
+
# @raise [ArgumentError] when rate or max_tokens is not a number
|
|
50
|
+
# @return [void]
|
|
51
|
+
def initialize_bucket(rate, max_tokens)
|
|
52
|
+
raise ArgumentError, "rate must be a number: #{rate}" unless rate.is_a?(Numeric)
|
|
53
|
+
raise ArgumentError, "max_tokens must be a number: #{max_tokens}" unless max_tokens.is_a?(Numeric)
|
|
54
|
+
|
|
55
|
+
@rate = rate
|
|
56
|
+
@max_tokens = max_tokens
|
|
57
|
+
@tokens = max_tokens
|
|
58
|
+
@last_refill = Core::Utils::Time.get_time
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Persists the balance the bucket holds at the current time.
|
|
62
|
+
# @return [void]
|
|
63
|
+
def refill
|
|
64
|
+
now = Core::Utils::Time.get_time
|
|
65
|
+
@tokens = balance_at(now)
|
|
66
|
+
@last_refill = now
|
|
67
|
+
|
|
68
|
+
nil
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -4,6 +4,7 @@ require_relative "../../utils/base64_codec"
|
|
|
4
4
|
require_relative "../../../appsec/remote"
|
|
5
5
|
require_relative "../../../tracing/remote"
|
|
6
6
|
require_relative "../../../di/remote"
|
|
7
|
+
require_relative "../../../profiling/remote"
|
|
7
8
|
require_relative "../../../symbol_database"
|
|
8
9
|
require_relative "../../../symbol_database/remote"
|
|
9
10
|
|
|
@@ -81,6 +82,9 @@ module Datadog
|
|
|
81
82
|
register_products(Datadog::Tracing::Remote.products)
|
|
82
83
|
register_receivers(Datadog::Tracing::Remote.receivers(@telemetry))
|
|
83
84
|
|
|
85
|
+
register_products(Datadog::Profiling::Remote.products)
|
|
86
|
+
register_receivers(Datadog::Profiling::Remote.receivers(@telemetry))
|
|
87
|
+
|
|
84
88
|
if settings.respond_to?(:dynamic_instrumentation) &&
|
|
85
89
|
!Datadog::DI::Remote.explicitly_disabled?(settings) &&
|
|
86
90
|
Datadog::DI.supported_runtime?
|
|
@@ -177,7 +177,7 @@ module Datadog
|
|
|
177
177
|
"ruby.runtime.platform:#{RUBY_PLATFORM}",
|
|
178
178
|
"ruby.runtime.version:#{RUBY_VERSION}",
|
|
179
179
|
"ruby.runtime.engine.name:#{RUBY_ENGINE}",
|
|
180
|
-
"ruby.runtime.engine.version:#{
|
|
180
|
+
"ruby.runtime.engine.version:#{RUBY_ENGINE_VERSION}",
|
|
181
181
|
"ruby.rubygems.platform.local:#{Gem::Platform.local}",
|
|
182
182
|
"ruby.gem.libddwaf.version:#{gem_spec("libddwaf").version}",
|
|
183
183
|
"ruby.gem.libddwaf.platform:#{gem_spec("libddwaf").platform}",
|
|
@@ -240,10 +240,6 @@ module Datadog
|
|
|
240
240
|
@tracer_version ||= Core::Environment::Identity.gem_datadog_version_semver2
|
|
241
241
|
end
|
|
242
242
|
|
|
243
|
-
def ruby_engine_version
|
|
244
|
-
@ruby_engine_version ||= defined?(RUBY_ENGINE_VERSION) ? RUBY_ENGINE_VERSION : RUBY_VERSION
|
|
245
|
-
end
|
|
246
|
-
|
|
247
243
|
def gem_spec(name)
|
|
248
244
|
(@gem_specs ||= {})[name] ||= ::Gem.loaded_specs[name] || GemSpecificationFallback.new(nil, nil)
|
|
249
245
|
end
|
|
@@ -28,11 +28,9 @@ module Datadog
|
|
|
28
28
|
Core::Encoding::JSONEncoder,
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
module_function
|
|
32
|
-
|
|
33
31
|
# Builds a new Transport::HTTP::Client with default settings
|
|
34
32
|
# Pass a block to override any settings.
|
|
35
|
-
def root(
|
|
33
|
+
def self.root(
|
|
36
34
|
agent_settings:,
|
|
37
35
|
logger:,
|
|
38
36
|
headers: nil
|
|
@@ -51,7 +49,7 @@ module Datadog
|
|
|
51
49
|
|
|
52
50
|
# Builds a new Transport::HTTP::Client with default settings
|
|
53
51
|
# Pass a block to override any settings.
|
|
54
|
-
def v7(
|
|
52
|
+
def self.v7(
|
|
55
53
|
agent_settings:,
|
|
56
54
|
logger:,
|
|
57
55
|
headers: nil
|
|
@@ -10,8 +10,6 @@ module Datadog
|
|
|
10
10
|
# Useful for ensuring that tag keys and values are normalized consistently
|
|
11
11
|
# An use case for now is Process Tags which need to be sent across various intakes (profiling, tracing, etc.) consistently
|
|
12
12
|
|
|
13
|
-
module_function
|
|
14
|
-
|
|
15
13
|
INVALID_TAG_CHARACTERS = %r{[^\p{L}0-9_\-:./]}
|
|
16
14
|
LEADING_INVALID_CHARS_NO_DIGITS = %r{\A[^\p{L}:]++}
|
|
17
15
|
LEADING_INVALID_CHARS_WITH_DIGITS = %r{\A[^\p{L}0-9:./]++}
|
|
@@ -20,11 +20,9 @@ module Datadog
|
|
|
20
20
|
Core::Encoding::JSONEncoder,
|
|
21
21
|
)
|
|
22
22
|
|
|
23
|
-
module_function
|
|
24
|
-
|
|
25
23
|
# Builds a new Transport::HTTP::Client with default settings
|
|
26
24
|
# Pass a block to override any settings.
|
|
27
|
-
def agentless_telemetry(
|
|
25
|
+
def self.agentless_telemetry(
|
|
28
26
|
agent_settings:,
|
|
29
27
|
logger:,
|
|
30
28
|
api_key: nil,
|
|
@@ -45,7 +43,7 @@ module Datadog
|
|
|
45
43
|
|
|
46
44
|
# Builds a new Transport::HTTP::Client with default settings
|
|
47
45
|
# Pass a block to override any settings.
|
|
48
|
-
def agent_telemetry(
|
|
46
|
+
def self.agent_telemetry(
|
|
49
47
|
agent_settings:,
|
|
50
48
|
logger:,
|
|
51
49
|
headers: nil
|
|
@@ -52,18 +52,19 @@ module Datadog
|
|
|
52
52
|
# We actually restart the worker after fork, but this is done
|
|
53
53
|
# via the AtForkMonkeyPatch rather than the worker fork policy
|
|
54
54
|
# because we also need to reset state outside of the worker
|
|
55
|
-
# (
|
|
55
|
+
# (the metrics, for example).
|
|
56
56
|
self.fork_policy = Core::Workers::Async::Thread::FORK_POLICY_RESTART
|
|
57
57
|
|
|
58
58
|
@shutdown_timeout = shutdown_timeout
|
|
59
59
|
@buffer_size = buffer_size
|
|
60
|
+
@initial_event = nil
|
|
60
61
|
|
|
61
62
|
initialize_state
|
|
62
63
|
end
|
|
63
64
|
|
|
64
65
|
# To make the method calls clear, the initialization code is in this
|
|
65
66
|
# method called +initialize_state+ which is called from +after_fork+.
|
|
66
|
-
# This way users of this class (
|
|
67
|
+
# This way users of this class (telemetry Component, for example) do not
|
|
67
68
|
# need to invoke +initialize_state+ directly, which can be confusing.
|
|
68
69
|
private def initialize_state
|
|
69
70
|
self.buffer = buffer_klass.new(@buffer_size)
|
|
@@ -86,7 +87,7 @@ module Datadog
|
|
|
86
87
|
@initial_event = initial_event
|
|
87
88
|
|
|
88
89
|
# starts async worker
|
|
89
|
-
# perform
|
|
90
|
+
# perform returns true when it actually starts the thread,
|
|
90
91
|
# false otherwise
|
|
91
92
|
perform
|
|
92
93
|
end
|
|
@@ -139,7 +140,7 @@ module Datadog
|
|
|
139
140
|
if need_initial_event?
|
|
140
141
|
started!
|
|
141
142
|
unless sent_initial_event?
|
|
142
|
-
# We still
|
|
143
|
+
# We still have not succeeded in sending the started event,
|
|
143
144
|
# which will make flush_events do nothing - but the events
|
|
144
145
|
# given to us as the parameter have already been removed
|
|
145
146
|
# from the queue.
|
|
@@ -193,14 +194,17 @@ module Datadog
|
|
|
193
194
|
def started!
|
|
194
195
|
return unless enabled?
|
|
195
196
|
|
|
197
|
+
initial_event = @initial_event
|
|
198
|
+
return unless initial_event
|
|
199
|
+
|
|
196
200
|
initial_event_once.run do
|
|
197
201
|
res = send_event(initial_event)
|
|
198
202
|
|
|
199
203
|
if res.ok?
|
|
200
204
|
logger.debug { "Telemetry initial event (#{initial_event.type}) is successfully sent" }
|
|
201
205
|
|
|
202
|
-
# TODO
|
|
203
|
-
# dependencies and send the new ones.
|
|
206
|
+
# TODO The DependenciesLoaded event can probably also check
|
|
207
|
+
# for new dependencies and send the new ones.
|
|
204
208
|
# System tests demand only one instance of this event per
|
|
205
209
|
# dependency.
|
|
206
210
|
if @dependency_collection && initial_event.app_started?
|
|
@@ -260,10 +264,11 @@ module Datadog
|
|
|
260
264
|
|
|
261
265
|
# Call this method in a forked child to reset the state of this worker.
|
|
262
266
|
#
|
|
263
|
-
# Discard any accumulated events since
|
|
264
|
-
#
|
|
267
|
+
# Discard any accumulated events since the parent will send
|
|
268
|
+
# them.
|
|
265
269
|
# Discard any accumulated metrics.
|
|
266
|
-
#
|
|
270
|
+
# If the worker thread was running in the parent process,
|
|
271
|
+
# restart it.
|
|
267
272
|
#
|
|
268
273
|
# This method cannot be called +after_fork+ because workers define
|
|
269
274
|
# and call +after_fork+ which is supposed to do different things.
|
|
@@ -274,25 +279,26 @@ module Datadog
|
|
|
274
279
|
initialize_state
|
|
275
280
|
# In the child process, we get a new runtime_id.
|
|
276
281
|
# As such we need to send AppStarted event.
|
|
277
|
-
# In the parent process, the event
|
|
282
|
+
# In the parent process, the previous event was possibly the
|
|
278
283
|
# SynthAppClientConfigurationChange instead of AppStarted,
|
|
279
284
|
# and in that case we need to convert it to the "regular"
|
|
280
285
|
# AppStarted event.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
#
|
|
286
|
+
initial_event = @initial_event
|
|
287
|
+
if initial_event.is_a?(Event::SynthAppClientConfigurationChange)
|
|
288
|
+
# Ideally we replace the initial event in
|
|
289
|
+
# +initialize_state+ directly. Unfortunately this event requires
|
|
284
290
|
# the entire component tree to build its payload, which we
|
|
285
|
-
# 1)
|
|
286
|
-
# 2)
|
|
291
|
+
# 1) do not currently have in telemetry and
|
|
292
|
+
# 2) do not want to keep a permanent reference to in any case.
|
|
287
293
|
# Therefore we have this +reset!+ method that changes the
|
|
288
294
|
# event type while keeping the payload.
|
|
289
|
-
|
|
295
|
+
initial_event.reset!
|
|
290
296
|
end
|
|
291
297
|
|
|
292
298
|
if enabled? && !worker.nil?
|
|
293
|
-
#
|
|
294
|
-
# process (which requires telemetry to be enabled).
|
|
295
|
-
#
|
|
299
|
+
# If the background thread was started in the parent
|
|
300
|
+
# process (which requires telemetry to be enabled), start it.
|
|
301
|
+
# Do this after all of the state resets.
|
|
296
302
|
perform
|
|
297
303
|
end
|
|
298
304
|
end
|
|
@@ -329,16 +335,16 @@ module Datadog
|
|
|
329
335
|
end
|
|
330
336
|
|
|
331
337
|
def idle?
|
|
332
|
-
# The
|
|
338
|
+
# The worker itself sends the AppStarted event,
|
|
333
339
|
# from the worker thread. As such the main thread has no way
|
|
334
340
|
# to delay itself until that event is queued and we need some
|
|
335
341
|
# way to wait until that event is sent out to assert on it in
|
|
336
|
-
# the test suite. Check the run once flag which *
|
|
337
|
-
#
|
|
338
|
-
# depth check
|
|
342
|
+
# the test suite. Check the run once flag which *normally*
|
|
343
|
+
# indicates the event was queued (at which point our queue
|
|
344
|
+
# depth check waits until it is sent).
|
|
339
345
|
# This is still a hack because the flag can be overridden
|
|
340
346
|
# either way with or without the event being sent out.
|
|
341
|
-
#
|
|
347
|
+
# If sending the AppStarted event fails, this check
|
|
342
348
|
# will return false and flushing will be blocked until the
|
|
343
349
|
# 15 second timeout.
|
|
344
350
|
# Note that the first wait interval between telemetry event
|
|
@@ -26,12 +26,10 @@ module Datadog
|
|
|
26
26
|
Core::Transport::Ext::UnixSocket::ADAPTER,
|
|
27
27
|
)
|
|
28
28
|
|
|
29
|
-
module_function
|
|
30
|
-
|
|
31
29
|
# Helper function that delegates to Builder.new
|
|
32
30
|
# but is under HTTP namespace so that client code requires this file
|
|
33
31
|
# to get the adapters configured, and not the builder directly.
|
|
34
|
-
def build(
|
|
32
|
+
def self.build(
|
|
35
33
|
agent_settings:,
|
|
36
34
|
logger: Datadog.logger,
|
|
37
35
|
headers: nil,
|
|
@@ -49,7 +47,7 @@ module Datadog
|
|
|
49
47
|
end
|
|
50
48
|
end
|
|
51
49
|
|
|
52
|
-
def default_headers
|
|
50
|
+
def self.default_headers
|
|
53
51
|
{
|
|
54
52
|
Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => "1",
|
|
55
53
|
Core::Transport::Ext::HTTP::HEADER_META_LANG =>
|
|
@@ -65,7 +65,7 @@ module Datadog
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
error = nil
|
|
68
|
+
error = nil #: Exception?
|
|
69
69
|
callbacks.each do |callback|
|
|
70
70
|
next if started && callback.group && !started.key?(callback.group)
|
|
71
71
|
|
|
@@ -170,7 +170,7 @@ module Datadog
|
|
|
170
170
|
# Invoke original block
|
|
171
171
|
yield
|
|
172
172
|
end
|
|
173
|
-
end
|
|
173
|
+
end #: (^() -> void)?
|
|
174
174
|
|
|
175
175
|
begin
|
|
176
176
|
# Run pre-fork callbacks in the parent, just before forking.
|
|
@@ -48,7 +48,7 @@ module Datadog
|
|
|
48
48
|
#
|
|
49
49
|
# This wrapper prevents this by initializing the fork PID when the object is created.
|
|
50
50
|
if RubyVersion.is?(">= 3")
|
|
51
|
-
def initialize(*args, **kwargs, &block)
|
|
51
|
+
def initialize(*args, **kwargs, &block) # steep:ignore DifferentMethodParameterKind
|
|
52
52
|
super
|
|
53
53
|
update_fork_pid!
|
|
54
54
|
end
|
|
@@ -5,8 +5,8 @@ require "forwardable"
|
|
|
5
5
|
module Datadog
|
|
6
6
|
module Core
|
|
7
7
|
module Utils
|
|
8
|
-
# An LRU (Least Recently Used) cache implementation that relies on
|
|
9
|
-
#
|
|
8
|
+
# An LRU (Least Recently Used) cache implementation that relies on
|
|
9
|
+
# `Hash` guaranteeing insertion order.
|
|
10
10
|
#
|
|
11
11
|
# WARNING: This implementation is NOT thread-safe and should be used
|
|
12
12
|
# in a single-threaded context or guarded by Mutex.
|
|
@@ -12,7 +12,7 @@ module Datadog
|
|
|
12
12
|
# If not present we assume these methods have not been monkey-patched and are the original.
|
|
13
13
|
|
|
14
14
|
original_clock_gettime_name = Process.respond_to?(:clock_gettime_without_mock) ? :clock_gettime_without_mock : :clock_gettime
|
|
15
|
-
define_singleton_method(:original_clock_gettime,
|
|
15
|
+
define_singleton_method(:original_clock_gettime, Process.method(original_clock_gettime_name).to_proc)
|
|
16
16
|
|
|
17
17
|
MONOTONIC_CLOCK_ID = RUBY_PLATFORM.include?("darwin") ? Process::CLOCK_MONOTONIC_RAW : Process::CLOCK_MONOTONIC
|
|
18
18
|
|
|
@@ -30,7 +30,7 @@ module Datadog
|
|
|
30
30
|
#
|
|
31
31
|
# @return [Time] current time object
|
|
32
32
|
original_time_now_name = ::Time.respond_to?(:now_without_mock_time) ? :now_without_mock_time : :now
|
|
33
|
-
define_singleton_method(:now,
|
|
33
|
+
define_singleton_method(:now, ::Time.method(original_time_now_name).to_proc)
|
|
34
34
|
|
|
35
35
|
def self.measure(unit = :float_second)
|
|
36
36
|
before = get_time(unit)
|
|
@@ -5,9 +5,7 @@ module Datadog
|
|
|
5
5
|
module Utils
|
|
6
6
|
# Helper methods for truncating data
|
|
7
7
|
module Truncation
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def truncate_in_middle(string, max_prefix_length, max_suffix_length)
|
|
8
|
+
def self.truncate_in_middle(string, max_prefix_length, max_suffix_length)
|
|
11
9
|
max_length = max_prefix_length + 3 + max_suffix_length
|
|
12
10
|
if string.length > max_length
|
|
13
11
|
"#{string[0...max_prefix_length]}...#{string[-max_suffix_length..-1]}"
|
|
@@ -45,21 +45,23 @@ module Datadog
|
|
|
45
45
|
:fork_policy
|
|
46
46
|
|
|
47
47
|
def join(timeout = nil)
|
|
48
|
-
|
|
48
|
+
thread = worker
|
|
49
|
+
return true unless thread&.alive?
|
|
49
50
|
|
|
50
|
-
!
|
|
51
|
+
!thread.join(timeout).nil?
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
def terminate
|
|
54
|
-
|
|
55
|
+
thread = worker
|
|
56
|
+
return false unless thread&.alive?
|
|
55
57
|
|
|
56
58
|
@run_async = false
|
|
57
59
|
Datadog.logger.debug { "Forcibly terminating worker thread for: #{self}" }
|
|
58
|
-
|
|
60
|
+
thread.terminate
|
|
59
61
|
# Wait for the worker thread to end
|
|
60
62
|
begin
|
|
61
63
|
Timeout.timeout(SHUTDOWN_TIMEOUT) do
|
|
62
|
-
|
|
64
|
+
thread.join
|
|
63
65
|
end
|
|
64
66
|
rescue Timeout::Error
|
|
65
67
|
Datadog.logger.debug { "Worker thread did not end after #{SHUTDOWN_TIMEOUT} seconds: #{self}" }
|
|
@@ -78,7 +80,7 @@ module Datadog
|
|
|
78
80
|
end
|
|
79
81
|
|
|
80
82
|
def running?
|
|
81
|
-
|
|
83
|
+
!!worker&.alive?
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
def error?
|
|
@@ -88,11 +90,12 @@ module Datadog
|
|
|
88
90
|
end
|
|
89
91
|
|
|
90
92
|
def completed?
|
|
91
|
-
|
|
93
|
+
worker&.status == false && !error?
|
|
92
94
|
end
|
|
93
95
|
|
|
94
96
|
def failed?
|
|
95
|
-
|
|
97
|
+
thread = worker
|
|
98
|
+
!thread.nil? && thread.status.nil?
|
|
96
99
|
end
|
|
97
100
|
|
|
98
101
|
def forked?
|
|
@@ -144,25 +147,23 @@ module Datadog
|
|
|
144
147
|
stop_fork
|
|
145
148
|
false
|
|
146
149
|
when FORK_POLICY_RESTART
|
|
147
|
-
# restart_after_fork should return true
|
|
148
150
|
restart_after_fork(&block)
|
|
149
151
|
end
|
|
150
152
|
elsif !run_async?
|
|
151
|
-
# start_worker should return true
|
|
152
153
|
start_worker(&block)
|
|
153
154
|
end
|
|
154
155
|
end
|
|
155
156
|
end
|
|
156
157
|
|
|
157
158
|
# Returns true if worker thread is successfully started,
|
|
158
|
-
# which
|
|
159
|
+
# which is always the case.
|
|
159
160
|
def start_worker
|
|
160
161
|
@run_async = true
|
|
161
162
|
@pid = Process.pid
|
|
162
163
|
@error = nil
|
|
163
164
|
Datadog.logger.debug { "Starting thread for: #{self}" }
|
|
164
165
|
|
|
165
|
-
|
|
166
|
+
worker = ::Thread.new do
|
|
166
167
|
yield
|
|
167
168
|
# rubocop:disable Lint/RescueException
|
|
168
169
|
rescue Exception => e
|
|
@@ -174,8 +175,9 @@ module Datadog
|
|
|
174
175
|
|
|
175
176
|
# rubocop:enable Lint/RescueException
|
|
176
177
|
end
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
worker.name = self.class.name
|
|
179
|
+
worker.thread_variable_set(:fork_safe, true)
|
|
180
|
+
@worker = worker
|
|
179
181
|
|
|
180
182
|
true
|
|
181
183
|
end
|
data/lib/datadog/di/component.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "correlation_sampler"
|
|
3
4
|
require_relative "fatal_exceptions"
|
|
4
5
|
|
|
5
6
|
module Datadog
|
|
@@ -98,7 +99,9 @@ module Datadog
|
|
|
98
99
|
settings: settings, serializer: serializer, logger: logger,
|
|
99
100
|
guardrails_telemetry: guardrails_telemetry, telemetry: telemetry,
|
|
100
101
|
)
|
|
101
|
-
@
|
|
102
|
+
@correlation_sampler = CorrelationSampler.new
|
|
103
|
+
@instrumenter = Instrumenter.new(settings, serializer, logger, code_tracker: code_tracker,
|
|
104
|
+
correlation_sampler: correlation_sampler, telemetry: telemetry,
|
|
102
105
|
guardrails_telemetry: guardrails_telemetry,
|
|
103
106
|
capture_expression_evaluator: capture_expression_evaluator)
|
|
104
107
|
@probe_repository = ProbeRepository.new
|
|
@@ -116,7 +119,6 @@ module Datadog
|
|
|
116
119
|
@probe_manager = ProbeManager.new(
|
|
117
120
|
settings, instrumenter, probe_notification_builder, probe_notifier_worker, logger, probe_repository,
|
|
118
121
|
telemetry: telemetry,
|
|
119
|
-
guardrails_telemetry: guardrails_telemetry,
|
|
120
122
|
)
|
|
121
123
|
# @started transitions are serialized by @lifecycle_mutex so that
|
|
122
124
|
# concurrent RC callbacks (which run on the remote-config thread)
|
|
@@ -137,6 +139,8 @@ module Datadog
|
|
|
137
139
|
# @return [CaptureExpressionEvaluator]
|
|
138
140
|
attr_reader :capture_expression_evaluator
|
|
139
141
|
attr_reader :code_tracker
|
|
142
|
+
# @return [Datadog::DI::CorrelationSampler]
|
|
143
|
+
attr_reader :correlation_sampler
|
|
140
144
|
attr_reader :instrumenter
|
|
141
145
|
attr_reader :probe_repository
|
|
142
146
|
attr_reader :probe_notifier_worker
|
|
@@ -203,6 +207,14 @@ module Datadog
|
|
|
203
207
|
@started
|
|
204
208
|
end
|
|
205
209
|
|
|
210
|
+
# Rebuilds the process-scoped coordinated-sampling state after the
|
|
211
|
+
# process forks, so the child starts with fresh budgets.
|
|
212
|
+
#
|
|
213
|
+
# @return [void]
|
|
214
|
+
def after_fork
|
|
215
|
+
correlation_sampler.after_fork!
|
|
216
|
+
end
|
|
217
|
+
|
|
206
218
|
# Whether the component is started while the customer left
|
|
207
219
|
# DD_DYNAMIC_INSTRUMENTATION_ENABLED at its default, the state produced
|
|
208
220
|
# by remote-configuration enablement.
|