datadog 2.22.0 → 2.24.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 +100 -1
- data/ext/LIBDATADOG_DEVELOPMENT.md +1 -58
- data/ext/datadog_profiling_native_extension/collectors_stack.c +21 -5
- data/ext/datadog_profiling_native_extension/crashtracking_runtime_stacks.c +239 -0
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +1 -1
- data/ext/datadog_profiling_native_extension/extconf.rb +9 -4
- data/ext/datadog_profiling_native_extension/heap_recorder.c +1 -1
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +12 -0
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +4 -0
- data/ext/datadog_profiling_native_extension/profiling.c +2 -0
- data/ext/libdatadog_api/datadog_ruby_common.h +1 -1
- data/ext/libdatadog_api/feature_flags.c +554 -0
- data/ext/libdatadog_api/feature_flags.h +5 -0
- data/ext/libdatadog_api/init.c +2 -0
- data/ext/libdatadog_api/library_config.c +12 -11
- data/ext/libdatadog_extconf_helpers.rb +1 -1
- data/lib/datadog/appsec/api_security/route_extractor.rb +23 -6
- data/lib/datadog/appsec/api_security/sampler.rb +7 -4
- data/lib/datadog/appsec/assets/blocked.html +8 -0
- data/lib/datadog/appsec/assets/blocked.json +1 -1
- data/lib/datadog/appsec/assets/blocked.text +3 -1
- data/lib/datadog/appsec/assets.rb +1 -1
- data/lib/datadog/appsec/context.rb +2 -1
- data/lib/datadog/appsec/remote.rb +5 -9
- data/lib/datadog/appsec/response.rb +18 -4
- data/lib/datadog/appsec/security_engine/result.rb +2 -1
- data/lib/datadog/core/configuration/components.rb +30 -3
- data/lib/datadog/core/configuration/config_helper.rb +2 -2
- data/lib/datadog/core/configuration/deprecations.rb +2 -2
- data/lib/datadog/core/configuration/option_definition.rb +4 -2
- data/lib/datadog/core/configuration/options.rb +8 -5
- data/lib/datadog/core/configuration/settings.rb +28 -3
- data/lib/datadog/core/configuration/supported_configurations.rb +332 -302
- data/lib/datadog/core/ddsketch.rb +0 -2
- data/lib/datadog/core/environment/cgroup.rb +52 -25
- data/lib/datadog/core/environment/container.rb +140 -46
- data/lib/datadog/core/environment/ext.rb +7 -0
- data/lib/datadog/core/environment/process.rb +87 -0
- data/lib/datadog/core/feature_flags.rb +61 -0
- data/lib/datadog/core/rate_limiter.rb +9 -1
- data/lib/datadog/core/remote/client/capabilities.rb +7 -0
- data/lib/datadog/core/remote/client.rb +14 -6
- data/lib/datadog/core/remote/component.rb +6 -4
- data/lib/datadog/core/remote/configuration/content.rb +15 -2
- data/lib/datadog/core/remote/configuration/digest.rb +14 -7
- data/lib/datadog/core/remote/configuration/repository.rb +1 -1
- data/lib/datadog/core/remote/configuration/target.rb +13 -6
- data/lib/datadog/core/remote/transport/config.rb +4 -25
- data/lib/datadog/core/remote/transport/http/config.rb +10 -50
- data/lib/datadog/core/remote/transport/http/negotiation.rb +14 -44
- data/lib/datadog/core/remote/transport/http.rb +15 -24
- data/lib/datadog/core/remote/transport/negotiation.rb +8 -33
- data/lib/datadog/core/remote/worker.rb +25 -37
- data/lib/datadog/core/tag_builder.rb +0 -4
- data/lib/datadog/core/tag_normalizer.rb +84 -0
- data/lib/datadog/core/telemetry/component.rb +59 -16
- data/lib/datadog/core/telemetry/event/app_started.rb +86 -49
- data/lib/datadog/core/telemetry/event/synth_app_client_configuration_change.rb +27 -4
- data/lib/datadog/core/telemetry/logger.rb +2 -2
- data/lib/datadog/core/telemetry/logging.rb +2 -8
- data/lib/datadog/core/telemetry/metrics_manager.rb +9 -0
- data/lib/datadog/core/telemetry/request.rb +17 -3
- data/lib/datadog/core/telemetry/transport/http/telemetry.rb +3 -34
- data/lib/datadog/core/telemetry/transport/http.rb +21 -16
- data/lib/datadog/core/telemetry/transport/telemetry.rb +3 -11
- data/lib/datadog/core/telemetry/worker.rb +88 -32
- data/lib/datadog/core/transport/ext.rb +2 -0
- data/lib/datadog/core/transport/http/api/endpoint.rb +9 -4
- data/lib/datadog/core/transport/http/api/instance.rb +4 -21
- data/lib/datadog/core/transport/http/builder.rb +9 -5
- data/lib/datadog/core/transport/http/client.rb +80 -0
- data/lib/datadog/core/transport/http.rb +22 -19
- data/lib/datadog/core/transport/response.rb +9 -0
- data/lib/datadog/core/transport/transport.rb +90 -0
- data/lib/datadog/core/utils/array.rb +29 -0
- data/lib/datadog/{appsec/api_security → core/utils}/lru_cache.rb +10 -21
- data/lib/datadog/core/utils/network.rb +3 -1
- data/lib/datadog/core/utils/only_once_successful.rb +8 -2
- data/lib/datadog/core/utils/time.rb +1 -1
- data/lib/datadog/core/utils.rb +2 -0
- data/lib/datadog/core/workers/async.rb +10 -1
- data/lib/datadog/core/workers/interval_loop.rb +44 -3
- data/lib/datadog/core/workers/polling.rb +2 -0
- data/lib/datadog/core/workers/queue.rb +100 -1
- data/lib/datadog/data_streams/configuration/settings.rb +49 -0
- data/lib/datadog/data_streams/configuration.rb +11 -0
- data/lib/datadog/data_streams/ext.rb +11 -0
- data/lib/datadog/data_streams/extensions.rb +16 -0
- data/lib/datadog/data_streams/pathway_context.rb +169 -0
- data/lib/datadog/data_streams/processor.rb +509 -0
- data/lib/datadog/data_streams/transport/http/stats.rb +52 -0
- data/lib/datadog/data_streams/transport/http.rb +40 -0
- data/lib/datadog/data_streams/transport/stats.rb +46 -0
- data/lib/datadog/data_streams.rb +100 -0
- data/lib/datadog/di/component.rb +0 -16
- data/lib/datadog/di/contrib/active_record.rb +31 -5
- data/lib/datadog/di/el/compiler.rb +8 -4
- data/lib/datadog/di/el/evaluator.rb +1 -1
- data/lib/datadog/di/error.rb +9 -0
- data/lib/datadog/di/instrumenter.rb +93 -34
- data/lib/datadog/di/probe.rb +20 -0
- data/lib/datadog/di/probe_builder.rb +2 -1
- data/lib/datadog/di/probe_manager.rb +47 -33
- data/lib/datadog/di/probe_notification_builder.rb +77 -25
- data/lib/datadog/di/proc_responder.rb +32 -0
- data/lib/datadog/di/remote.rb +89 -84
- data/lib/datadog/di/transport/diagnostics.rb +8 -36
- data/lib/datadog/di/transport/http/diagnostics.rb +1 -33
- data/lib/datadog/di/transport/http/input.rb +1 -33
- data/lib/datadog/di/transport/http.rb +32 -17
- data/lib/datadog/di/transport/input.rb +67 -34
- data/lib/datadog/di.rb +61 -5
- data/lib/datadog/open_feature/component.rb +60 -0
- data/lib/datadog/open_feature/configuration.rb +27 -0
- data/lib/datadog/open_feature/evaluation_engine.rb +70 -0
- data/lib/datadog/open_feature/exposures/batch_builder.rb +32 -0
- data/lib/datadog/open_feature/exposures/buffer.rb +43 -0
- data/lib/datadog/open_feature/exposures/deduplicator.rb +30 -0
- data/lib/datadog/open_feature/exposures/event.rb +60 -0
- data/lib/datadog/open_feature/exposures/reporter.rb +40 -0
- data/lib/datadog/open_feature/exposures/worker.rb +116 -0
- data/lib/datadog/open_feature/ext.rb +14 -0
- data/lib/datadog/open_feature/native_evaluator.rb +38 -0
- data/lib/datadog/open_feature/noop_evaluator.rb +26 -0
- data/lib/datadog/open_feature/provider.rb +141 -0
- data/lib/datadog/open_feature/remote.rb +67 -0
- data/lib/datadog/open_feature/resolution_details.rb +35 -0
- data/lib/datadog/open_feature/transport.rb +70 -0
- data/lib/datadog/open_feature.rb +19 -0
- data/lib/datadog/opentelemetry/api/baggage.rb +1 -1
- data/lib/datadog/opentelemetry/configuration/settings.rb +159 -0
- data/lib/datadog/opentelemetry/metrics.rb +117 -0
- data/lib/datadog/opentelemetry/sdk/configurator.rb +25 -1
- data/lib/datadog/opentelemetry/sdk/metrics_exporter.rb +35 -0
- data/lib/datadog/opentelemetry.rb +3 -0
- data/lib/datadog/profiling/collectors/code_provenance.rb +41 -7
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +1 -1
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
- data/lib/datadog/profiling/collectors/info.rb +2 -1
- data/lib/datadog/profiling/component.rb +12 -11
- data/lib/datadog/profiling/http_transport.rb +4 -1
- data/lib/datadog/profiling/profiler.rb +4 -0
- data/lib/datadog/profiling/tag_builder.rb +36 -3
- data/lib/datadog/profiling.rb +1 -2
- data/lib/datadog/single_step_instrument.rb +1 -1
- data/lib/datadog/tracing/configuration/ext.rb +9 -0
- data/lib/datadog/tracing/configuration/settings.rb +74 -0
- data/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb +4 -4
- data/lib/datadog/tracing/contrib/action_pack/utils.rb +1 -2
- data/lib/datadog/tracing/contrib/active_job/log_injection.rb +21 -7
- data/lib/datadog/tracing/contrib/active_job/patcher.rb +5 -1
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +4 -2
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +4 -1
- data/lib/datadog/tracing/contrib/excon/configuration/settings.rb +11 -3
- data/lib/datadog/tracing/contrib/extensions.rb +10 -2
- data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +11 -7
- data/lib/datadog/tracing/contrib/grape/configuration/settings.rb +7 -3
- data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +22 -17
- data/lib/datadog/tracing/contrib/http/configuration/settings.rb +11 -3
- data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +11 -3
- data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +11 -3
- data/lib/datadog/tracing/contrib/kafka/instrumentation/consumer.rb +66 -0
- data/lib/datadog/tracing/contrib/kafka/instrumentation/producer.rb +66 -0
- data/lib/datadog/tracing/contrib/kafka/patcher.rb +14 -0
- data/lib/datadog/tracing/contrib/karafka/framework.rb +30 -0
- data/lib/datadog/tracing/contrib/karafka/monitor.rb +11 -0
- data/lib/datadog/tracing/contrib/karafka/patcher.rb +35 -4
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +59 -27
- data/lib/datadog/tracing/contrib/rack/route_inference.rb +53 -0
- data/lib/datadog/tracing/contrib/rails/middlewares.rb +2 -2
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +4 -1
- data/lib/datadog/tracing/contrib/roda/instrumentation.rb +3 -1
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +3 -1
- data/lib/datadog/tracing/contrib/status_range_matcher.rb +9 -1
- data/lib/datadog/tracing/contrib/utils/quantization/hash.rb +3 -1
- data/lib/datadog/tracing/contrib/waterdrop/configuration/settings.rb +27 -0
- data/lib/datadog/tracing/contrib/waterdrop/distributed/propagation.rb +48 -0
- data/lib/datadog/tracing/contrib/waterdrop/ext.rb +17 -0
- data/lib/datadog/tracing/contrib/waterdrop/integration.rb +43 -0
- data/lib/datadog/tracing/contrib/waterdrop/middleware.rb +46 -0
- data/lib/datadog/tracing/contrib/waterdrop/patcher.rb +49 -0
- data/lib/datadog/tracing/contrib/waterdrop/producer.rb +50 -0
- data/lib/datadog/tracing/contrib/waterdrop.rb +37 -0
- data/lib/datadog/tracing/contrib.rb +1 -0
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +1 -1
- data/lib/datadog/tracing/metadata/ext.rb +1 -1
- data/lib/datadog/tracing/remote.rb +1 -9
- data/lib/datadog/tracing/span_event.rb +2 -2
- data/lib/datadog/tracing/span_operation.rb +9 -4
- data/lib/datadog/tracing/trace_operation.rb +44 -6
- data/lib/datadog/tracing/tracer.rb +42 -16
- data/lib/datadog/tracing/transport/http/client.rb +12 -26
- data/lib/datadog/tracing/transport/http/traces.rb +2 -50
- data/lib/datadog/tracing/transport/http.rb +15 -9
- data/lib/datadog/tracing/transport/io/client.rb +1 -1
- data/lib/datadog/tracing/transport/trace_formatter.rb +11 -0
- data/lib/datadog/tracing/transport/traces.rb +9 -71
- data/lib/datadog/tracing/workers/trace_writer.rb +5 -0
- data/lib/datadog/tracing/writer.rb +1 -0
- data/lib/datadog/version.rb +2 -2
- data/lib/datadog.rb +2 -0
- metadata +78 -21
- data/lib/datadog/core/remote/transport/http/api.rb +0 -53
- data/lib/datadog/core/remote/transport/http/client.rb +0 -49
- data/lib/datadog/core/telemetry/transport/http/api.rb +0 -43
- data/lib/datadog/core/telemetry/transport/http/client.rb +0 -49
- data/lib/datadog/core/transport/http/api/spec.rb +0 -36
- data/lib/datadog/di/transport/http/api.rb +0 -42
- data/lib/datadog/di/transport/http/client.rb +0 -47
- data/lib/datadog/opentelemetry/api/baggage.rbs +0 -26
- data/lib/datadog/tracing/transport/http/api.rb +0 -44
|
@@ -94,8 +94,8 @@ module Datadog
|
|
|
94
94
|
|
|
95
95
|
# @public_api
|
|
96
96
|
module HTTP
|
|
97
|
-
ERROR_RANGE = (500...600).freeze
|
|
98
97
|
TAG_BASE_URL = 'http.base_url'
|
|
98
|
+
TAG_ENDPOINT = 'http.endpoint'
|
|
99
99
|
TAG_METHOD = 'http.method'
|
|
100
100
|
TAG_STATUS_CODE = 'http.status_code'
|
|
101
101
|
TAG_USER_AGENT = 'http.useragent'
|
|
@@ -7,8 +7,6 @@ module Datadog
|
|
|
7
7
|
module Tracing
|
|
8
8
|
# Remote configuration declaration
|
|
9
9
|
module Remote
|
|
10
|
-
class ReadError < StandardError; end
|
|
11
|
-
|
|
12
10
|
class << self
|
|
13
11
|
PRODUCT = 'APM_TRACING'
|
|
14
12
|
|
|
@@ -71,13 +69,7 @@ module Datadog
|
|
|
71
69
|
private
|
|
72
70
|
|
|
73
71
|
def parse_content(content)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
content.data.rewind
|
|
77
|
-
|
|
78
|
-
raise ReadError, 'EOF reached' if data.nil?
|
|
79
|
-
|
|
80
|
-
JSON.parse(data)
|
|
72
|
+
JSON.parse(content.data)
|
|
81
73
|
end
|
|
82
74
|
end
|
|
83
75
|
end
|
|
@@ -69,8 +69,8 @@ module Datadog
|
|
|
69
69
|
|
|
70
70
|
private
|
|
71
71
|
|
|
72
|
-
MIN_INT64_SIGNED = -2
|
|
73
|
-
MAX_INT64_SIGNED = 2 <<
|
|
72
|
+
MIN_INT64_SIGNED = -2 << 62
|
|
73
|
+
MAX_INT64_SIGNED = (2 << 62) - 1
|
|
74
74
|
|
|
75
75
|
# Checks the attributes hash to ensure it only contains serializable values.
|
|
76
76
|
# Invalid values are removed from the hash.
|
|
@@ -289,7 +289,8 @@ module Datadog
|
|
|
289
289
|
def duration
|
|
290
290
|
return @duration_end - @duration_start if @duration_start && @duration_end
|
|
291
291
|
|
|
292
|
-
|
|
292
|
+
# Steep: https://github.com/soutaro/steep/issues/477
|
|
293
|
+
@end_time - @start_time if @start_time && @end_time # steep:ignore NoMethod
|
|
293
294
|
end
|
|
294
295
|
|
|
295
296
|
def set_error(e)
|
|
@@ -387,7 +388,8 @@ module Datadog
|
|
|
387
388
|
class Events
|
|
388
389
|
include Tracing::Events
|
|
389
390
|
|
|
390
|
-
|
|
391
|
+
# Steep: https://github.com/soutaro/steep/issues/335
|
|
392
|
+
DEFAULT_ON_ERROR = proc { |span_op, error| span_op&.set_error(error) } # steep:ignore IncompatibleAssignment
|
|
391
393
|
|
|
392
394
|
attr_reader \
|
|
393
395
|
:logger,
|
|
@@ -395,7 +397,7 @@ module Datadog
|
|
|
395
397
|
:after_stop,
|
|
396
398
|
:before_start
|
|
397
399
|
|
|
398
|
-
def initialize(logger: Datadog.logger
|
|
400
|
+
def initialize(logger: Datadog.logger)
|
|
399
401
|
@logger = logger
|
|
400
402
|
@after_finish = AfterFinish.new
|
|
401
403
|
@after_stop = AfterStop.new
|
|
@@ -548,7 +550,10 @@ module Datadog
|
|
|
548
550
|
# Used for serialization
|
|
549
551
|
# @return [Integer] in nanoseconds since Epoch
|
|
550
552
|
def start_time_nano
|
|
551
|
-
|
|
553
|
+
return 0 if @start_time.nil?
|
|
554
|
+
|
|
555
|
+
# Steep: https://github.com/soutaro/steep/issues/477
|
|
556
|
+
@start_time.to_i * 1000000000 + @start_time.nsec # steep:ignore NoMethod
|
|
552
557
|
end
|
|
553
558
|
|
|
554
559
|
# Used for serialization
|
|
@@ -55,6 +55,12 @@ module Datadog
|
|
|
55
55
|
:sampled,
|
|
56
56
|
:service
|
|
57
57
|
|
|
58
|
+
# Creates a new TraceOperation.
|
|
59
|
+
#
|
|
60
|
+
# @param auto_finish [Boolean] when true, automatically finishes the trace when the local root span finishes.
|
|
61
|
+
# When false, the trace remains unfinished until {#finish!} is called.
|
|
62
|
+
# This is useful when this {TraceOperation} represents the continuation of a remote {TraceDigest},
|
|
63
|
+
# in which case local root spans in this {TraceOperation} are children of the {TraceDigest}'s last active span.
|
|
58
64
|
def initialize(
|
|
59
65
|
logger: Datadog.logger,
|
|
60
66
|
agent_sample_rate: nil,
|
|
@@ -80,7 +86,8 @@ module Datadog
|
|
|
80
86
|
trace_state_unknown_fields: nil,
|
|
81
87
|
remote_parent: false,
|
|
82
88
|
tracer: nil, # DEV-3.0: deprecated, remove in 3.0
|
|
83
|
-
baggage: nil
|
|
89
|
+
baggage: nil,
|
|
90
|
+
auto_finish: true
|
|
84
91
|
)
|
|
85
92
|
@logger = logger
|
|
86
93
|
|
|
@@ -119,6 +126,7 @@ module Datadog
|
|
|
119
126
|
@events = events || Events.new
|
|
120
127
|
@finished = false
|
|
121
128
|
@spans = []
|
|
129
|
+
@auto_finish = !!auto_finish
|
|
122
130
|
end
|
|
123
131
|
|
|
124
132
|
def full?
|
|
@@ -318,6 +326,29 @@ module Datadog
|
|
|
318
326
|
build_trace(spans, !finished)
|
|
319
327
|
end
|
|
320
328
|
|
|
329
|
+
# When automatic context management is disabled (@auto_finish is false),
|
|
330
|
+
# this method finishes the trace, marking it as completed.
|
|
331
|
+
#
|
|
332
|
+
# The trace will **not** automatically finish when its local root span
|
|
333
|
+
# when @auto_finish is false, thus calling this method is mandatory
|
|
334
|
+
# in such scenario.
|
|
335
|
+
#
|
|
336
|
+
# Unfinished spans are discarded.
|
|
337
|
+
#
|
|
338
|
+
# This method is idempotent and safe to call after the trace is finished.
|
|
339
|
+
# It is also a no-op when @auto_finish is true, to prevent misuse.
|
|
340
|
+
#
|
|
341
|
+
# @!visibility private
|
|
342
|
+
def finish!
|
|
343
|
+
return if @auto_finish || finished?
|
|
344
|
+
|
|
345
|
+
@finished = true
|
|
346
|
+
@active_span = nil
|
|
347
|
+
@active_span_count = 0
|
|
348
|
+
|
|
349
|
+
events.trace_finished.publish(self)
|
|
350
|
+
end
|
|
351
|
+
|
|
321
352
|
# Returns a set of trace headers used for continuing traces.
|
|
322
353
|
# Used for propagation across execution contexts.
|
|
323
354
|
# Data should reflect the active state of the trace.
|
|
@@ -460,7 +491,7 @@ module Datadog
|
|
|
460
491
|
|
|
461
492
|
@active_span = span_op
|
|
462
493
|
|
|
463
|
-
|
|
494
|
+
set_local_root_span!(span_op)
|
|
464
495
|
end
|
|
465
496
|
|
|
466
497
|
def deactivate_span!(span_op)
|
|
@@ -483,6 +514,12 @@ module Datadog
|
|
|
483
514
|
logger.debug { "Error starting span on trace: #{e} Backtrace: #{e.backtrace.first(3)}" }
|
|
484
515
|
end
|
|
485
516
|
|
|
517
|
+
# For traces with automatic context management (auto_finish),
|
|
518
|
+
# when the local root span finishes, the trace also finishes.
|
|
519
|
+
# The trace cannot receive new spans after finished.
|
|
520
|
+
#
|
|
521
|
+
# Without auto_finish, the trace can still receive spans
|
|
522
|
+
# until explicitly finished.
|
|
486
523
|
def finish_span(span, span_op, parent)
|
|
487
524
|
# Save finished span & root span
|
|
488
525
|
@spans << span unless span.nil?
|
|
@@ -490,8 +527,9 @@ module Datadog
|
|
|
490
527
|
# Deactivate the span, re-activate parent.
|
|
491
528
|
deactivate_span!(span_op)
|
|
492
529
|
|
|
493
|
-
#
|
|
494
|
-
|
|
530
|
+
# Finish if the local root span is finished and automatic
|
|
531
|
+
# context management is enabled.
|
|
532
|
+
@finished = true if span_op == root_span && @auto_finish
|
|
495
533
|
|
|
496
534
|
# Update active span count
|
|
497
535
|
@active_span_count -= 1
|
|
@@ -505,8 +543,8 @@ module Datadog
|
|
|
505
543
|
logger.debug { "Error finishing span on trace: #{e} Backtrace: #{e.backtrace.first(3)}" }
|
|
506
544
|
end
|
|
507
545
|
|
|
508
|
-
# Track the root
|
|
509
|
-
def
|
|
546
|
+
# Track the root {SpanOperation} object from the current execution context.
|
|
547
|
+
def set_local_root_span!(span)
|
|
510
548
|
return if span.nil? || root_span
|
|
511
549
|
|
|
512
550
|
@root_span = span
|
|
@@ -129,7 +129,6 @@ module Datadog
|
|
|
129
129
|
# @yield Optional block where new newly created {Datadog::Tracing::SpanOperation} captures the execution.
|
|
130
130
|
# @yieldparam [Datadog::Tracing::SpanOperation] span_op the newly created and active [Datadog::Tracing::SpanOperation]
|
|
131
131
|
# @yieldparam [Datadog::Tracing::TraceOperation] trace_op the active [Datadog::Tracing::TraceOperation]
|
|
132
|
-
# rubocop:disable Metrics/MethodLength
|
|
133
132
|
def trace(
|
|
134
133
|
name,
|
|
135
134
|
continue_from: nil,
|
|
@@ -241,10 +240,21 @@ module Datadog
|
|
|
241
240
|
trace.to_correlation
|
|
242
241
|
end
|
|
243
242
|
|
|
244
|
-
# Setup a new trace to continue from where another
|
|
243
|
+
# Setup a new trace execution context to continue from where another
|
|
245
244
|
# trace left off.
|
|
245
|
+
# This is useful to continue distributed or async traces.
|
|
246
246
|
#
|
|
247
|
-
#
|
|
247
|
+
# The first span created in the restored context is a direct child of the
|
|
248
|
+
# active span from when the {Datadog::Tracing::TraceDigest} was created.
|
|
249
|
+
#
|
|
250
|
+
# When no block is given, the trace context is restored in the current thread.
|
|
251
|
+
# It remains active until the first span created in this restored context is finished.
|
|
252
|
+
# After that, if a new span is created, it start a new, unrelated trace.
|
|
253
|
+
#
|
|
254
|
+
# When a block is given, the trace context is restored inside the block execution.
|
|
255
|
+
# It remains active until the block ends, even when the first span created inside
|
|
256
|
+
# the block finishes. This means that multiple spans can be direct children of the
|
|
257
|
+
# active span from when the {Datadog::Tracing::TraceDigest} was created.
|
|
248
258
|
#
|
|
249
259
|
# @param [Datadog::Tracing::TraceDigest] digest continue from the {Datadog::Tracing::TraceDigest}.
|
|
250
260
|
# @param [Thread] key Thread to retrieve trace from. Defaults to current thread. For internal use only.
|
|
@@ -260,13 +270,32 @@ module Datadog
|
|
|
260
270
|
# Start a new trace from the digest
|
|
261
271
|
context = call_context(key)
|
|
262
272
|
original_trace = active_trace(key)
|
|
263
|
-
trace
|
|
273
|
+
# When we want the trace to be bound to a block, we cannot let
|
|
274
|
+
# it auto finish when the local root span finishes. This would
|
|
275
|
+
# create mutiple traces inside the block. Instead, we'll
|
|
276
|
+
# expliclity finish the trace after the block finishes.
|
|
277
|
+
auto_finish = !block
|
|
278
|
+
|
|
279
|
+
trace = start_trace(continue_from: digest, auto_finish: auto_finish)
|
|
264
280
|
|
|
265
281
|
# If block hasn't been given; we need to manually deactivate
|
|
266
282
|
# this trace. Subscribe to the trace finished event to do this.
|
|
267
283
|
subscribe_trace_deactivation!(context, trace, original_trace) unless block
|
|
268
284
|
|
|
269
|
-
|
|
285
|
+
if block
|
|
286
|
+
# When a block is given, the trace will be active until the block finishes.
|
|
287
|
+
context.activate!(trace) do
|
|
288
|
+
yield
|
|
289
|
+
ensure # We have to flush even when an error occurs
|
|
290
|
+
# On block completion, force the trace to finish and flush its finished spans.
|
|
291
|
+
# Unfinished spans are lost as the {TraceOperation} has ended.
|
|
292
|
+
trace.finish!
|
|
293
|
+
flush_trace(trace)
|
|
294
|
+
end
|
|
295
|
+
else
|
|
296
|
+
# Otherwise, the trace will be bound to the current thread after this point
|
|
297
|
+
context.activate!(trace)
|
|
298
|
+
end
|
|
270
299
|
end
|
|
271
300
|
|
|
272
301
|
# Sample a span, tagging the trace as appropriate.
|
|
@@ -329,7 +358,7 @@ module Datadog
|
|
|
329
358
|
@provider.context(key)
|
|
330
359
|
end
|
|
331
360
|
|
|
332
|
-
def build_trace(digest
|
|
361
|
+
def build_trace(digest, auto_finish)
|
|
333
362
|
# Resolve hostname if configured
|
|
334
363
|
hostname = Core::Environment::Socket.hostname if Datadog.configuration.tracing.report_hostname
|
|
335
364
|
hostname = (hostname && !hostname.empty?) ? hostname : nil
|
|
@@ -353,7 +382,8 @@ module Datadog
|
|
|
353
382
|
trace_state_unknown_fields: digest.trace_state_unknown_fields,
|
|
354
383
|
remote_parent: digest.span_remote,
|
|
355
384
|
tracer: self,
|
|
356
|
-
baggage: digest.baggage
|
|
385
|
+
baggage: digest.baggage,
|
|
386
|
+
auto_finish: auto_finish
|
|
357
387
|
)
|
|
358
388
|
else
|
|
359
389
|
TraceOperation.new(
|
|
@@ -362,13 +392,12 @@ module Datadog
|
|
|
362
392
|
profiling_enabled: profiling_enabled,
|
|
363
393
|
apm_tracing_enabled: apm_tracing_enabled,
|
|
364
394
|
remote_parent: false,
|
|
365
|
-
tracer: self
|
|
395
|
+
tracer: self,
|
|
396
|
+
auto_finish: auto_finish
|
|
366
397
|
)
|
|
367
398
|
end
|
|
368
399
|
end
|
|
369
|
-
# rubocop:enable Metrics/MethodLength
|
|
370
400
|
|
|
371
|
-
# rubocop:disable Metrics/MethodLength
|
|
372
401
|
def bind_trace_events!(trace_op)
|
|
373
402
|
events = trace_op.send(:events)
|
|
374
403
|
|
|
@@ -387,13 +416,12 @@ module Datadog
|
|
|
387
416
|
flush_trace(event_trace_op)
|
|
388
417
|
end
|
|
389
418
|
end
|
|
390
|
-
# rubocop:enable Metrics/MethodLength
|
|
391
419
|
|
|
392
420
|
# Creates a new TraceOperation, with events bounds to this Tracer instance.
|
|
393
421
|
# @return [TraceOperation]
|
|
394
|
-
def start_trace(continue_from: nil)
|
|
422
|
+
def start_trace(continue_from: nil, auto_finish: true)
|
|
395
423
|
# Build a new trace using digest if provided.
|
|
396
|
-
trace = build_trace(continue_from)
|
|
424
|
+
trace = build_trace(continue_from, auto_finish)
|
|
397
425
|
|
|
398
426
|
# Bind trace events: sample trace, set default service, flush spans.
|
|
399
427
|
bind_trace_events!(trace)
|
|
@@ -402,7 +430,6 @@ module Datadog
|
|
|
402
430
|
end
|
|
403
431
|
|
|
404
432
|
# rubocop:disable Lint/UnderscorePrefixedVariableName
|
|
405
|
-
# rubocop:disable Metrics/MethodLength
|
|
406
433
|
def start_span(
|
|
407
434
|
name,
|
|
408
435
|
continue_from: nil,
|
|
@@ -454,9 +481,8 @@ module Datadog
|
|
|
454
481
|
span
|
|
455
482
|
end
|
|
456
483
|
end
|
|
457
|
-
# rubocop:enable Lint/UnderscorePrefixedVariableName
|
|
458
|
-
# rubocop:enable Metrics/MethodLength
|
|
459
484
|
|
|
485
|
+
# rubocop:enable Lint/UnderscorePrefixedVariableName
|
|
460
486
|
def resolve_tags(tags, service)
|
|
461
487
|
merged_tags = if @tags.any? && tags
|
|
462
488
|
# Combine default tags with provided tags,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'statistics'
|
|
4
|
+
require_relative '../../../core/transport/http/client'
|
|
4
5
|
require_relative '../../../core/transport/http/env'
|
|
5
6
|
require_relative '../../../core/transport/http/response'
|
|
6
7
|
|
|
@@ -9,33 +10,24 @@ module Datadog
|
|
|
9
10
|
module Transport
|
|
10
11
|
module HTTP
|
|
11
12
|
# Routes, encodes, and sends tracer data to the trace agent via HTTP.
|
|
12
|
-
class Client
|
|
13
|
+
class Client < Core::Transport::HTTP::Client
|
|
13
14
|
include Datadog::Tracing::Transport::HTTP::Statistics
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
private
|
|
16
17
|
|
|
17
|
-
def
|
|
18
|
-
|
|
19
|
-
@logger = logger
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def send_request(request, &block)
|
|
23
|
-
# Build request into env
|
|
24
|
-
env = build_env(request)
|
|
25
|
-
|
|
26
|
-
# Get responses from API
|
|
27
|
-
response = yield(api, env)
|
|
18
|
+
def on_response(response)
|
|
19
|
+
super
|
|
28
20
|
|
|
29
21
|
# Update statistics
|
|
30
22
|
update_stats_from_response!(response)
|
|
23
|
+
end
|
|
31
24
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
def on_exception(exception)
|
|
26
|
+
# Note: this method does NOT call super - it has replacement
|
|
27
|
+
# logic for how to log the exception.
|
|
28
|
+
|
|
29
|
+
message = build_exception_message(exception)
|
|
37
30
|
|
|
38
|
-
# Log error
|
|
39
31
|
if stats.consecutive_errors > 0
|
|
40
32
|
logger.debug(message)
|
|
41
33
|
else
|
|
@@ -44,13 +36,7 @@ module Datadog
|
|
|
44
36
|
end
|
|
45
37
|
|
|
46
38
|
# Update statistics
|
|
47
|
-
update_stats_from_exception!(
|
|
48
|
-
|
|
49
|
-
Datadog::Core::Transport::InternalErrorResponse.new(e)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def build_env(request)
|
|
53
|
-
Datadog::Core::Transport::HTTP::Env.new(request)
|
|
39
|
+
update_stats_from_exception!(exception)
|
|
54
40
|
end
|
|
55
41
|
end
|
|
56
42
|
end
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
require 'json'
|
|
4
4
|
|
|
5
|
-
require_relative '../traces'
|
|
6
|
-
require_relative 'client'
|
|
7
5
|
require_relative '../../../core/transport/http/response'
|
|
8
6
|
require_relative '../../../core/transport/http/api/endpoint'
|
|
9
|
-
require_relative '../../../core/transport/http/api/spec'
|
|
10
7
|
require_relative '../../../core/transport/http/api/instance'
|
|
8
|
+
require_relative '../traces'
|
|
11
9
|
|
|
12
10
|
module Datadog
|
|
13
11
|
module Tracing
|
|
@@ -27,58 +25,15 @@ module Datadog
|
|
|
27
25
|
end
|
|
28
26
|
end
|
|
29
27
|
|
|
30
|
-
# Extensions for HTTP client
|
|
31
|
-
module Client
|
|
32
|
-
def send_traces_payload(request)
|
|
33
|
-
send_request(request) do |api, env|
|
|
34
|
-
api.send_traces(env)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
28
|
module API
|
|
40
|
-
# HTTP API Spec
|
|
41
|
-
class Spec < Core::Transport::HTTP::API::Spec
|
|
42
|
-
attr_accessor :traces
|
|
43
|
-
|
|
44
|
-
def send_traces(env, &block)
|
|
45
|
-
raise Core::Transport::HTTP::API::Spec::EndpointNotDefinedError.new('traces', self) if traces.nil?
|
|
46
|
-
|
|
47
|
-
traces.call(env, &block)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def encoder
|
|
51
|
-
traces.encoder
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# HTTP API Instance
|
|
56
|
-
class Instance < Core::Transport::HTTP::API::Instance
|
|
57
|
-
def send_traces(env)
|
|
58
|
-
unless spec.is_a?(Traces::API::Spec)
|
|
59
|
-
raise Core::Transport::HTTP::API::Instance::EndpointNotSupportedError.new(
|
|
60
|
-
'traces', self
|
|
61
|
-
)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
spec.send_traces(env) do |request_env|
|
|
65
|
-
call(request_env)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
29
|
# Endpoint for submitting trace data
|
|
71
30
|
class Endpoint < Datadog::Core::Transport::HTTP::API::Endpoint
|
|
72
31
|
HEADER_CONTENT_TYPE = 'Content-Type'
|
|
73
32
|
HEADER_TRACE_COUNT = 'X-Datadog-Trace-Count'
|
|
74
33
|
SERVICE_RATE_KEY = 'rate_by_service'
|
|
75
34
|
|
|
76
|
-
attr_reader \
|
|
77
|
-
:encoder
|
|
78
|
-
|
|
79
35
|
def initialize(path, encoder, options = {})
|
|
80
|
-
super(:post, path)
|
|
81
|
-
@encoder = encoder
|
|
36
|
+
super(:post, path, encoder: encoder)
|
|
82
37
|
@service_rates = options.fetch(:service_rates, false)
|
|
83
38
|
end
|
|
84
39
|
|
|
@@ -111,9 +66,6 @@ module Datadog
|
|
|
111
66
|
end
|
|
112
67
|
end
|
|
113
68
|
end
|
|
114
|
-
|
|
115
|
-
# Add traces behavior to transport components
|
|
116
|
-
HTTP::Client.include(Traces::Client)
|
|
117
69
|
end
|
|
118
70
|
end
|
|
119
71
|
end
|
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative '../../core/encoding'
|
|
3
4
|
require_relative '../../core/environment/container'
|
|
4
5
|
require_relative '../../core/environment/ext'
|
|
5
6
|
require_relative '../../core/transport/ext'
|
|
6
7
|
require_relative '../../core/transport/http'
|
|
7
|
-
require_relative 'http/
|
|
8
|
-
require_relative '../../../datadog/version'
|
|
8
|
+
require_relative 'http/traces'
|
|
9
9
|
|
|
10
10
|
module Datadog
|
|
11
11
|
module Tracing
|
|
12
12
|
module Transport
|
|
13
13
|
# Namespace for HTTP transport components
|
|
14
14
|
module HTTP
|
|
15
|
+
V4 = Traces::API::Endpoint.new(
|
|
16
|
+
'/v0.4/traces',
|
|
17
|
+
Core::Encoding::MsgpackEncoder,
|
|
18
|
+
service_rates: true
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
V3 = Traces::API::Endpoint.new(
|
|
22
|
+
'/v0.3/traces',
|
|
23
|
+
Core::Encoding::MsgpackEncoder,
|
|
24
|
+
)
|
|
25
|
+
|
|
15
26
|
module_function
|
|
16
27
|
|
|
17
28
|
# Builds a new Transport::HTTP::Client with default settings
|
|
@@ -19,20 +30,15 @@ module Datadog
|
|
|
19
30
|
def default(
|
|
20
31
|
agent_settings:,
|
|
21
32
|
logger: Datadog.logger,
|
|
22
|
-
api_version: nil,
|
|
23
33
|
headers: nil
|
|
24
34
|
)
|
|
25
35
|
Core::Transport::HTTP.build(
|
|
26
|
-
api_instance_class: Traces::API::Instance,
|
|
27
36
|
agent_settings: agent_settings,
|
|
28
37
|
logger: logger,
|
|
29
|
-
api_version: api_version,
|
|
30
38
|
headers: headers
|
|
31
39
|
) do |transport|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
transport.api API::V4, apis[API::V4], fallback: API::V3, default: true
|
|
35
|
-
transport.api API::V3, apis[API::V3]
|
|
40
|
+
transport.api 'v0.4', V4, fallback: 'v0.3', default: true
|
|
41
|
+
transport.api 'v0.3', V3
|
|
36
42
|
|
|
37
43
|
# Call block to apply any customization, if provided
|
|
38
44
|
yield(transport) if block_given?
|
|
@@ -42,7 +42,7 @@ module Datadog
|
|
|
42
42
|
response
|
|
43
43
|
rescue => e
|
|
44
44
|
message =
|
|
45
|
-
"Internal error during IO transport request. Cause: #{e.class.name} #{e.message} " \
|
|
45
|
+
"Internal error during IO transport request. Cause: #{e.class.name}: #{e.message} " \
|
|
46
46
|
"Location: #{Array(e.backtrace).first}"
|
|
47
47
|
|
|
48
48
|
# Log error
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative '../../core/environment/identity'
|
|
4
|
+
require_relative '../../core/environment/process'
|
|
4
5
|
require_relative '../../core/environment/socket'
|
|
5
6
|
require_relative '../../core/environment/git'
|
|
6
7
|
require_relative '../../core/git/ext'
|
|
@@ -62,6 +63,7 @@ module Datadog
|
|
|
62
63
|
tag_apm_tracing_disabled!
|
|
63
64
|
|
|
64
65
|
if first_span
|
|
66
|
+
tag_process_tags!
|
|
65
67
|
tag_git_repository_url!
|
|
66
68
|
tag_git_commit_sha!
|
|
67
69
|
end
|
|
@@ -215,6 +217,15 @@ module Datadog
|
|
|
215
217
|
first_span.set_tag(Core::Git::Ext::TAG_COMMIT_SHA, git_commit_sha)
|
|
216
218
|
end
|
|
217
219
|
|
|
220
|
+
def tag_process_tags!
|
|
221
|
+
return unless Datadog.configuration.experimental_propagate_process_tags_enabled
|
|
222
|
+
|
|
223
|
+
first_span.set_tag(
|
|
224
|
+
Core::Environment::Ext::TAG_PROCESS_TAGS,
|
|
225
|
+
Core::Environment::Process.serialized
|
|
226
|
+
)
|
|
227
|
+
end
|
|
228
|
+
|
|
218
229
|
private
|
|
219
230
|
|
|
220
231
|
def partial?
|