ddtrace 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -1
- data/ext/ddtrace_profiling_loader/extconf.rb +1 -1
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +66 -6
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +51 -54
- data/ext/ddtrace_profiling_native_extension/collectors_stack.c +11 -13
- data/ext/ddtrace_profiling_native_extension/extconf.rb +1 -1
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +3 -2
- data/ext/ddtrace_profiling_native_extension/setup_signal_handler.c +96 -0
- data/ext/ddtrace_profiling_native_extension/setup_signal_handler.h +7 -0
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +70 -18
- data/ext/ddtrace_profiling_native_extension/stack_recorder.h +1 -0
- data/lib/datadog/appsec/assets/blocked.html +98 -3
- data/lib/datadog/appsec/assets/blocked.json +1 -0
- data/lib/datadog/appsec/assets/blocked.text +5 -0
- data/lib/datadog/appsec/assets/waf_rules/recommended.json +35 -46
- data/lib/datadog/appsec/assets/waf_rules/risky.json +1 -1
- data/lib/datadog/appsec/assets/waf_rules/strict.json +46 -1
- data/lib/datadog/appsec/assets.rb +2 -2
- data/lib/datadog/appsec/configuration/settings.rb +6 -0
- data/lib/datadog/appsec/configuration.rb +4 -0
- data/lib/datadog/appsec/contrib/rack/reactive/request.rb +4 -8
- data/lib/datadog/appsec/contrib/rack/request.rb +17 -0
- data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +2 -2
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +2 -2
- data/lib/datadog/appsec/contrib/rails/patcher.rb +3 -6
- data/lib/datadog/appsec/contrib/sinatra/ext.rb +1 -0
- data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +1 -1
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +11 -8
- data/lib/datadog/appsec/extensions.rb +10 -0
- data/lib/datadog/appsec/processor.rb +18 -0
- data/lib/datadog/appsec/response.rb +54 -0
- data/lib/datadog/core/runtime/ext.rb +1 -1
- data/lib/datadog/opentracer/distributed_headers.rb +5 -7
- data/lib/datadog/opentracer/rack_propagator.rb +0 -3
- data/lib/datadog/opentracer/text_map_propagator.rb +5 -7
- data/lib/datadog/profiling/collectors/cpu_and_wall_time.rb +10 -4
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +4 -0
- data/lib/datadog/profiling/collectors/old_stack.rb +7 -0
- data/lib/datadog/profiling/exporter.rb +5 -0
- data/lib/datadog/profiling/old_recorder.rb +8 -0
- data/lib/datadog/profiling/profiler.rb +7 -0
- data/lib/datadog/profiling/scheduler.rb +4 -7
- data/lib/datadog/profiling/stack_recorder.rb +22 -0
- data/lib/datadog/profiling/tasks/setup.rb +0 -7
- data/lib/datadog/tracing/contrib/delayed_job/plugin.rb +4 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +2 -1
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +6 -12
- data/lib/datadog/tracing/contrib/grpc/distributed/fetcher.rb +27 -0
- data/lib/datadog/tracing/contrib/grpc/distributed/propagation.rb +38 -0
- data/lib/datadog/tracing/contrib/grpc/patcher.rb +0 -2
- data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +32 -0
- data/lib/datadog/tracing/contrib/http/distributed/propagation.rb +33 -0
- data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +1 -0
- data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +1 -0
- data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +1 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +2 -0
- data/lib/datadog/tracing/contrib/que/tracer.rb +2 -0
- data/lib/datadog/tracing/contrib/racecar/events/batch.rb +4 -1
- data/lib/datadog/tracing/contrib/racecar/events/message.rb +4 -1
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +2 -0
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/redis/integration.rb +2 -1
- data/lib/datadog/tracing/contrib/redis/patcher.rb +2 -3
- data/lib/datadog/tracing/contrib/resque/resque_job.rb +2 -0
- data/lib/datadog/tracing/contrib/shoryuken/tracer.rb +2 -0
- data/lib/datadog/tracing/contrib/sidekiq/client_tracer.rb +5 -0
- data/lib/datadog/tracing/contrib/sidekiq/server_tracer.rb +5 -0
- data/lib/datadog/tracing/contrib/sneakers/tracer.rb +2 -0
- data/lib/datadog/tracing/distributed/b3.rb +66 -0
- data/lib/datadog/tracing/distributed/b3_single.rb +66 -0
- data/lib/datadog/tracing/distributed/datadog.rb +153 -0
- data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +1 -0
- data/lib/datadog/tracing/distributed/fetcher.rb +30 -0
- data/lib/datadog/tracing/distributed/headers/ext.rb +18 -16
- data/lib/datadog/tracing/distributed/helpers.rb +7 -6
- data/lib/datadog/tracing/distributed/propagation.rb +127 -0
- data/lib/datadog/tracing/propagation/http.rb +3 -106
- data/lib/datadog/tracing/trace_segment.rb +1 -1
- data/lib/ddtrace/transport/trace_formatter.rb +2 -5
- data/lib/ddtrace/version.rb +1 -1
- metadata +19 -14
- data/lib/datadog/tracing/distributed/headers/b3.rb +0 -55
- data/lib/datadog/tracing/distributed/headers/b3_single.rb +0 -67
- data/lib/datadog/tracing/distributed/headers/datadog.rb +0 -144
- data/lib/datadog/tracing/distributed/headers/parser.rb +0 -37
- data/lib/datadog/tracing/distributed/metadata/b3.rb +0 -55
- data/lib/datadog/tracing/distributed/metadata/b3_single.rb +0 -66
- data/lib/datadog/tracing/distributed/metadata/datadog.rb +0 -73
- data/lib/datadog/tracing/distributed/metadata/parser.rb +0 -34
- data/lib/datadog/tracing/propagation/grpc.rb +0 -98
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddtrace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Datadog, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 0.10.16
|
34
34
|
- - "<="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 0.10.
|
36
|
+
version: 0.10.18
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 0.10.16
|
44
44
|
- - "<="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.10.
|
46
|
+
version: 0.10.18
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: libddwaf
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,11 +114,15 @@ files:
|
|
114
114
|
- ext/ddtrace_profiling_native_extension/profiling.c
|
115
115
|
- ext/ddtrace_profiling_native_extension/ruby_helpers.c
|
116
116
|
- ext/ddtrace_profiling_native_extension/ruby_helpers.h
|
117
|
+
- ext/ddtrace_profiling_native_extension/setup_signal_handler.c
|
118
|
+
- ext/ddtrace_profiling_native_extension/setup_signal_handler.h
|
117
119
|
- ext/ddtrace_profiling_native_extension/stack_recorder.c
|
118
120
|
- ext/ddtrace_profiling_native_extension/stack_recorder.h
|
119
121
|
- lib/datadog/appsec.rb
|
120
122
|
- lib/datadog/appsec/assets.rb
|
121
123
|
- lib/datadog/appsec/assets/blocked.html
|
124
|
+
- lib/datadog/appsec/assets/blocked.json
|
125
|
+
- lib/datadog/appsec/assets/blocked.text
|
122
126
|
- lib/datadog/appsec/assets/waf_rules/README.md
|
123
127
|
- lib/datadog/appsec/assets/waf_rules/recommended.json
|
124
128
|
- lib/datadog/appsec/assets/waf_rules/risky.json
|
@@ -168,6 +172,7 @@ files:
|
|
168
172
|
- lib/datadog/appsec/reactive/engine.rb
|
169
173
|
- lib/datadog/appsec/reactive/operation.rb
|
170
174
|
- lib/datadog/appsec/reactive/subscriber.rb
|
175
|
+
- lib/datadog/appsec/response.rb
|
171
176
|
- lib/datadog/ci.rb
|
172
177
|
- lib/datadog/ci/configuration/components.rb
|
173
178
|
- lib/datadog/ci/configuration/settings.rb
|
@@ -492,6 +497,8 @@ files:
|
|
492
497
|
- lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb
|
493
498
|
- lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb
|
494
499
|
- lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb
|
500
|
+
- lib/datadog/tracing/contrib/grpc/distributed/fetcher.rb
|
501
|
+
- lib/datadog/tracing/contrib/grpc/distributed/propagation.rb
|
495
502
|
- lib/datadog/tracing/contrib/grpc/ext.rb
|
496
503
|
- lib/datadog/tracing/contrib/grpc/integration.rb
|
497
504
|
- lib/datadog/tracing/contrib/grpc/intercept_with_datadog.rb
|
@@ -506,6 +513,8 @@ files:
|
|
506
513
|
- lib/datadog/tracing/contrib/hanami/router_tracing.rb
|
507
514
|
- lib/datadog/tracing/contrib/http/circuit_breaker.rb
|
508
515
|
- lib/datadog/tracing/contrib/http/configuration/settings.rb
|
516
|
+
- lib/datadog/tracing/contrib/http/distributed/fetcher.rb
|
517
|
+
- lib/datadog/tracing/contrib/http/distributed/propagation.rb
|
509
518
|
- lib/datadog/tracing/contrib/http/ext.rb
|
510
519
|
- lib/datadog/tracing/contrib/http/instrumentation.rb
|
511
520
|
- lib/datadog/tracing/contrib/http/integration.rb
|
@@ -689,17 +698,14 @@ files:
|
|
689
698
|
- lib/datadog/tracing/contrib/utils/quantization/hash.rb
|
690
699
|
- lib/datadog/tracing/contrib/utils/quantization/http.rb
|
691
700
|
- lib/datadog/tracing/correlation.rb
|
701
|
+
- lib/datadog/tracing/distributed/b3.rb
|
702
|
+
- lib/datadog/tracing/distributed/b3_single.rb
|
703
|
+
- lib/datadog/tracing/distributed/datadog.rb
|
692
704
|
- lib/datadog/tracing/distributed/datadog_tags_codec.rb
|
693
|
-
- lib/datadog/tracing/distributed/
|
694
|
-
- lib/datadog/tracing/distributed/headers/b3_single.rb
|
695
|
-
- lib/datadog/tracing/distributed/headers/datadog.rb
|
705
|
+
- lib/datadog/tracing/distributed/fetcher.rb
|
696
706
|
- lib/datadog/tracing/distributed/headers/ext.rb
|
697
|
-
- lib/datadog/tracing/distributed/headers/parser.rb
|
698
707
|
- lib/datadog/tracing/distributed/helpers.rb
|
699
|
-
- lib/datadog/tracing/distributed/
|
700
|
-
- lib/datadog/tracing/distributed/metadata/b3_single.rb
|
701
|
-
- lib/datadog/tracing/distributed/metadata/datadog.rb
|
702
|
-
- lib/datadog/tracing/distributed/metadata/parser.rb
|
708
|
+
- lib/datadog/tracing/distributed/propagation.rb
|
703
709
|
- lib/datadog/tracing/event.rb
|
704
710
|
- lib/datadog/tracing/flush.rb
|
705
711
|
- lib/datadog/tracing/metadata.rb
|
@@ -710,7 +716,6 @@ files:
|
|
710
716
|
- lib/datadog/tracing/pipeline.rb
|
711
717
|
- lib/datadog/tracing/pipeline/span_filter.rb
|
712
718
|
- lib/datadog/tracing/pipeline/span_processor.rb
|
713
|
-
- lib/datadog/tracing/propagation/grpc.rb
|
714
719
|
- lib/datadog/tracing/propagation/http.rb
|
715
720
|
- lib/datadog/tracing/runtime/metrics.rb
|
716
721
|
- lib/datadog/tracing/sampling/all_sampler.rb
|
@@ -796,7 +801,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
796
801
|
- !ruby/object:Gem::Version
|
797
802
|
version: 2.0.0
|
798
803
|
requirements: []
|
799
|
-
rubygems_version: 3.
|
804
|
+
rubygems_version: 3.1.6
|
800
805
|
signing_key:
|
801
806
|
specification_version: 4
|
802
807
|
summary: Datadog tracing code for your Ruby applications
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
|
3
|
-
require_relative 'parser'
|
4
|
-
require_relative '../helpers'
|
5
|
-
require_relative 'ext'
|
6
|
-
require_relative '../../trace_digest'
|
7
|
-
|
8
|
-
module Datadog
|
9
|
-
module Tracing
|
10
|
-
module Distributed
|
11
|
-
module Headers
|
12
|
-
# B3 provides helpers to inject or extract headers for B3 style headers
|
13
|
-
module B3
|
14
|
-
include Ext
|
15
|
-
|
16
|
-
def self.inject!(digest, env)
|
17
|
-
return if digest.nil?
|
18
|
-
|
19
|
-
# DEV: We need these to be hex encoded
|
20
|
-
env[B3_HEADER_TRACE_ID] = digest.trace_id.to_s(16)
|
21
|
-
env[B3_HEADER_SPAN_ID] = digest.span_id.to_s(16)
|
22
|
-
|
23
|
-
if digest.trace_sampling_priority
|
24
|
-
sampling_priority = Helpers.clamp_sampling_priority(
|
25
|
-
digest.trace_sampling_priority
|
26
|
-
)
|
27
|
-
env[B3_HEADER_SAMPLED] = sampling_priority.to_s
|
28
|
-
end
|
29
|
-
|
30
|
-
env
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.extract(env)
|
34
|
-
# Extract values from headers
|
35
|
-
# DEV: B3 doesn't have "origin"
|
36
|
-
headers = Parser.new(env)
|
37
|
-
trace_id = headers.id(B3_HEADER_TRACE_ID, 16)
|
38
|
-
span_id = headers.id(B3_HEADER_SPAN_ID, 16)
|
39
|
-
# We don't need to try and convert sampled since B3 supports 0/1 (AUTO_REJECT/AUTO_KEEP)
|
40
|
-
sampling_priority = headers.number(B3_HEADER_SAMPLED)
|
41
|
-
|
42
|
-
# Return early if this propagation is not valid
|
43
|
-
return unless trace_id && span_id
|
44
|
-
|
45
|
-
TraceDigest.new(
|
46
|
-
trace_id: trace_id,
|
47
|
-
span_id: span_id,
|
48
|
-
trace_sampling_priority: sampling_priority
|
49
|
-
)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
|
3
|
-
require_relative 'parser'
|
4
|
-
require_relative '../helpers'
|
5
|
-
require_relative 'ext'
|
6
|
-
require_relative '../../trace_digest'
|
7
|
-
|
8
|
-
module Datadog
|
9
|
-
module Tracing
|
10
|
-
module Distributed
|
11
|
-
module Headers
|
12
|
-
# B3Single provides helpers to inject or extract headers for B3 single header style headers
|
13
|
-
module B3Single
|
14
|
-
include Ext
|
15
|
-
|
16
|
-
def self.inject!(digest, env)
|
17
|
-
return if digest.nil?
|
18
|
-
|
19
|
-
# Header format:
|
20
|
-
# b3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
21
|
-
# https://github.com/apache/incubator-zipkin-b3-propagation/tree/7c6e9f14d6627832bd80baa87ac7dabee7be23cf#single-header
|
22
|
-
# DEV: `{SamplingState}` and `{ParentSpanId`}` are optional
|
23
|
-
|
24
|
-
# DEV: We need these to be hex encoded
|
25
|
-
header = "#{digest.trace_id.to_s(16)}-#{digest.span_id.to_s(16)}"
|
26
|
-
|
27
|
-
if digest.trace_sampling_priority
|
28
|
-
sampling_priority = Helpers.clamp_sampling_priority(
|
29
|
-
digest.trace_sampling_priority
|
30
|
-
)
|
31
|
-
header += "-#{sampling_priority}"
|
32
|
-
end
|
33
|
-
|
34
|
-
env[B3_HEADER_SINGLE] = header
|
35
|
-
|
36
|
-
env
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.extract(env)
|
40
|
-
# Header format:
|
41
|
-
# b3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
42
|
-
# https://github.com/apache/incubator-zipkin-b3-propagation/tree/7c6e9f14d6627832bd80baa87ac7dabee7be23cf#single-header
|
43
|
-
# DEV: `{SamplingState}` and `{ParentSpanId`}` are optional
|
44
|
-
|
45
|
-
headers = Parser.new(env)
|
46
|
-
value = headers.header(B3_HEADER_SINGLE)
|
47
|
-
return if value.nil?
|
48
|
-
|
49
|
-
parts = value.split('-')
|
50
|
-
trace_id = Helpers.value_to_id(parts[0], 16) unless parts.empty?
|
51
|
-
span_id = Helpers.value_to_id(parts[1], 16) if parts.length > 1
|
52
|
-
sampling_priority = Helpers.value_to_number(parts[2]) if parts.length > 2
|
53
|
-
|
54
|
-
# Return early if this propagation is not valid
|
55
|
-
return unless trace_id && span_id
|
56
|
-
|
57
|
-
TraceDigest.new(
|
58
|
-
span_id: span_id,
|
59
|
-
trace_id: trace_id,
|
60
|
-
trace_sampling_priority: sampling_priority
|
61
|
-
)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
# typed: true
|
3
|
-
|
4
|
-
require_relative 'parser'
|
5
|
-
require_relative 'ext'
|
6
|
-
require_relative '../../metadata/ext'
|
7
|
-
require_relative '../../trace_digest'
|
8
|
-
require_relative '../datadog_tags_codec'
|
9
|
-
|
10
|
-
module Datadog
|
11
|
-
module Tracing
|
12
|
-
module Distributed
|
13
|
-
module Headers
|
14
|
-
# Datadog provides helpers to inject or extract headers for Datadog style headers
|
15
|
-
module Datadog
|
16
|
-
class << self
|
17
|
-
include Ext
|
18
|
-
|
19
|
-
def inject!(digest, env)
|
20
|
-
return if digest.nil?
|
21
|
-
|
22
|
-
env[HTTP_HEADER_TRACE_ID] = digest.trace_id.to_s
|
23
|
-
env[HTTP_HEADER_PARENT_ID] = digest.span_id.to_s
|
24
|
-
env[HTTP_HEADER_SAMPLING_PRIORITY] = digest.trace_sampling_priority.to_s if digest.trace_sampling_priority
|
25
|
-
env[HTTP_HEADER_ORIGIN] = digest.trace_origin.to_s unless digest.trace_origin.nil?
|
26
|
-
|
27
|
-
inject_tags(digest, env)
|
28
|
-
|
29
|
-
env
|
30
|
-
end
|
31
|
-
|
32
|
-
def extract(env)
|
33
|
-
# Extract values from headers
|
34
|
-
headers = Parser.new(env)
|
35
|
-
trace_id = headers.id(HTTP_HEADER_TRACE_ID)
|
36
|
-
parent_id = headers.id(HTTP_HEADER_PARENT_ID)
|
37
|
-
origin = headers.header(HTTP_HEADER_ORIGIN)
|
38
|
-
sampling_priority = headers.number(HTTP_HEADER_SAMPLING_PRIORITY)
|
39
|
-
|
40
|
-
# Return early if this propagation is not valid
|
41
|
-
# DEV: To be valid we need to have a trace id and a parent id
|
42
|
-
# or when it is a synthetics trace, just the trace id.
|
43
|
-
# DEV: `Parser#id` will not return 0
|
44
|
-
return unless (trace_id && parent_id) || (origin && trace_id)
|
45
|
-
|
46
|
-
trace_distributed_tags = extract_tags(headers)
|
47
|
-
|
48
|
-
# Return new trace headers
|
49
|
-
TraceDigest.new(
|
50
|
-
span_id: parent_id,
|
51
|
-
trace_id: trace_id,
|
52
|
-
trace_origin: origin,
|
53
|
-
trace_sampling_priority: sampling_priority,
|
54
|
-
trace_distributed_tags: trace_distributed_tags,
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
# Export trace distributed tags through the `x-datadog-tags` header.
|
61
|
-
#
|
62
|
-
# DEV: This method accesses global state (the active trace) to record its error state as a trace tag.
|
63
|
-
# DEV: This means errors cannot be reported if there's not active span.
|
64
|
-
# DEV: Ideally, we'd have a dedicated error reporting stream for all of ddtrace.
|
65
|
-
# DEV: The same comment applies to the {.extract_tags}.
|
66
|
-
def inject_tags(digest, env)
|
67
|
-
return if digest.trace_distributed_tags.nil? || digest.trace_distributed_tags.empty?
|
68
|
-
|
69
|
-
if ::Datadog.configuration.tracing.x_datadog_tags_max_length <= 0
|
70
|
-
active_trace = Tracing.active_trace
|
71
|
-
active_trace.set_tag('_dd.propagation_error', 'disabled') if active_trace
|
72
|
-
return
|
73
|
-
end
|
74
|
-
|
75
|
-
encoded_tags = DatadogTagsCodec.encode(digest.trace_distributed_tags)
|
76
|
-
|
77
|
-
if encoded_tags.size > ::Datadog.configuration.tracing.x_datadog_tags_max_length
|
78
|
-
active_trace = Tracing.active_trace
|
79
|
-
active_trace.set_tag('_dd.propagation_error', 'inject_max_size') if active_trace
|
80
|
-
|
81
|
-
::Datadog.logger.warn(
|
82
|
-
"Failed to inject x-datadog-tags: tags are too large (size:#{encoded_tags.size} " \
|
83
|
-
"limit:#{::Datadog.configuration.tracing.x_datadog_tags_max_length}). This limit can be configured " \
|
84
|
-
'through the DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH environment variable.'
|
85
|
-
)
|
86
|
-
return
|
87
|
-
end
|
88
|
-
|
89
|
-
env[HTTP_HEADER_TAGS] = encoded_tags
|
90
|
-
rescue => e
|
91
|
-
active_trace = Tracing.active_trace
|
92
|
-
active_trace.set_tag('_dd.propagation_error', 'encoding_error') if active_trace
|
93
|
-
::Datadog.logger.warn(
|
94
|
-
"Failed to inject x-datadog-tags: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
95
|
-
)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Import `x-datadog-tags` header tags as trace distributed tags.
|
99
|
-
# Only tags that have the `_dd.p.` prefix are processed.
|
100
|
-
def extract_tags(headers)
|
101
|
-
tags_header = headers.header(HTTP_HEADER_TAGS)
|
102
|
-
return unless tags_header
|
103
|
-
|
104
|
-
if ::Datadog.configuration.tracing.x_datadog_tags_max_length <= 0
|
105
|
-
active_trace = Tracing.active_trace
|
106
|
-
active_trace.set_tag('_dd.propagation_error', 'disabled') if active_trace
|
107
|
-
return
|
108
|
-
end
|
109
|
-
|
110
|
-
if tags_header.size > ::Datadog.configuration.tracing.x_datadog_tags_max_length
|
111
|
-
active_trace = Tracing.active_trace
|
112
|
-
active_trace.set_tag('_dd.propagation_error', 'extract_max_size') if active_trace
|
113
|
-
|
114
|
-
::Datadog.logger.warn(
|
115
|
-
"Failed to extract x-datadog-tags: tags are too large (size:#{tags_header.size} " \
|
116
|
-
"limit:#{::Datadog.configuration.tracing.x_datadog_tags_max_length}). This limit can be configured " \
|
117
|
-
'through the DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH environment variable.'
|
118
|
-
)
|
119
|
-
return
|
120
|
-
end
|
121
|
-
|
122
|
-
tags = DatadogTagsCodec.decode(tags_header)
|
123
|
-
# Only extract keys with the expected Datadog prefix
|
124
|
-
tags.select! do |key, _|
|
125
|
-
key.start_with?(Tracing::Metadata::Ext::Distributed::TAGS_PREFIX) && key != EXCLUDED_TAG
|
126
|
-
end
|
127
|
-
tags
|
128
|
-
rescue => e
|
129
|
-
active_trace = Tracing.active_trace
|
130
|
-
active_trace.set_tag('_dd.propagation_error', 'decoding_error') if active_trace
|
131
|
-
::Datadog.logger.warn(
|
132
|
-
"Failed to extract x-datadog-tags: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
|
133
|
-
)
|
134
|
-
end
|
135
|
-
|
136
|
-
# We want to exclude tags that we don't want to propagate downstream.
|
137
|
-
EXCLUDED_TAG = '_dd.p.upstream_services'
|
138
|
-
private_constant :EXCLUDED_TAG
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# typed: false
|
2
|
-
|
3
|
-
require_relative '../helpers'
|
4
|
-
|
5
|
-
module Datadog
|
6
|
-
module Tracing
|
7
|
-
module Distributed
|
8
|
-
module Headers
|
9
|
-
# Parser provides easy access and validation methods for Rack headers
|
10
|
-
class Parser
|
11
|
-
def initialize(env)
|
12
|
-
@env = env
|
13
|
-
end
|
14
|
-
|
15
|
-
# TODO: Don't assume Rack format.
|
16
|
-
# Make distributed tracing headers apathetic.
|
17
|
-
def header(name)
|
18
|
-
rack_header = "http-#{name}".upcase!.tr('-', '_')
|
19
|
-
|
20
|
-
hdr = @env[rack_header]
|
21
|
-
|
22
|
-
# Only return the value if it is not an empty string
|
23
|
-
hdr if hdr != ''
|
24
|
-
end
|
25
|
-
|
26
|
-
def id(hdr, base = 10)
|
27
|
-
Helpers.value_to_id(header(hdr), base)
|
28
|
-
end
|
29
|
-
|
30
|
-
def number(hdr, base = 10)
|
31
|
-
Helpers.value_to_number(header(hdr), base)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
|
3
|
-
require_relative '../helpers'
|
4
|
-
require_relative 'parser'
|
5
|
-
require_relative '../headers/ext'
|
6
|
-
require_relative '../../trace_digest'
|
7
|
-
|
8
|
-
module Datadog
|
9
|
-
module Tracing
|
10
|
-
module Distributed
|
11
|
-
module Metadata
|
12
|
-
# B3 provides helpers to inject or extract metadata for B3 style headers
|
13
|
-
module B3
|
14
|
-
include Distributed::Headers::Ext
|
15
|
-
|
16
|
-
def self.inject!(digest, metadata)
|
17
|
-
return if digest.nil?
|
18
|
-
|
19
|
-
# DEV: We need these to be hex encoded
|
20
|
-
metadata[B3_HEADER_TRACE_ID] = digest.trace_id.to_s(16)
|
21
|
-
metadata[B3_HEADER_SPAN_ID] = digest.span_id.to_s(16)
|
22
|
-
|
23
|
-
if digest.trace_sampling_priority
|
24
|
-
sampling_priority = Helpers.clamp_sampling_priority(
|
25
|
-
digest.trace_sampling_priority
|
26
|
-
)
|
27
|
-
metadata[B3_HEADER_SAMPLED] = sampling_priority.to_s
|
28
|
-
end
|
29
|
-
|
30
|
-
metadata
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.extract(metadata)
|
34
|
-
# Extract values from gRPC metadata
|
35
|
-
# DEV: B3 doesn't have "origin"
|
36
|
-
metadata = Parser.new(metadata)
|
37
|
-
trace_id = metadata.id(B3_HEADER_TRACE_ID, 16)
|
38
|
-
span_id = metadata.id(B3_HEADER_SPAN_ID, 16)
|
39
|
-
# We don't need to try and convert sampled since B3 supports 0/1 (AUTO_REJECT/AUTO_KEEP)
|
40
|
-
sampling_priority = metadata.number(B3_HEADER_SAMPLED)
|
41
|
-
|
42
|
-
# Return early if this propagation is not valid
|
43
|
-
return unless trace_id && span_id
|
44
|
-
|
45
|
-
TraceDigest.new(
|
46
|
-
trace_id: trace_id,
|
47
|
-
span_id: span_id,
|
48
|
-
trace_sampling_priority: sampling_priority
|
49
|
-
)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# typed: true
|
2
|
-
|
3
|
-
require_relative 'parser'
|
4
|
-
require_relative '../helpers'
|
5
|
-
require_relative '../headers/ext'
|
6
|
-
require_relative '../../trace_digest'
|
7
|
-
|
8
|
-
module Datadog
|
9
|
-
module Tracing
|
10
|
-
module Distributed
|
11
|
-
module Metadata
|
12
|
-
# B3Single provides helpers to inject or extract metadata for B3 single header style headers
|
13
|
-
module B3Single
|
14
|
-
include Distributed::Headers::Ext
|
15
|
-
|
16
|
-
def self.inject!(digest, metadata)
|
17
|
-
return if digest.nil?
|
18
|
-
|
19
|
-
# Header format:
|
20
|
-
# b3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
21
|
-
# https://github.com/apache/incubator-zipkin-b3-propagation/tree/7c6e9f14d6627832bd80baa87ac7dabee7be23cf#single-header
|
22
|
-
# DEV: `{SamplingState}` and `{ParentSpanId`}` are optional
|
23
|
-
|
24
|
-
# DEV: We need these to be hex encoded
|
25
|
-
b3_header = "#{digest.trace_id.to_s(16)}-#{digest.span_id.to_s(16)}"
|
26
|
-
|
27
|
-
if digest.trace_sampling_priority
|
28
|
-
sampling_priority = Helpers.clamp_sampling_priority(
|
29
|
-
digest.trace_sampling_priority
|
30
|
-
)
|
31
|
-
b3_header += "-#{sampling_priority}"
|
32
|
-
end
|
33
|
-
|
34
|
-
metadata[B3_HEADER_SINGLE] = b3_header
|
35
|
-
|
36
|
-
metadata
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.extract(metadata)
|
40
|
-
# Metadata format:
|
41
|
-
# b3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
|
42
|
-
# https://github.com/apache/incubator-zipkin-b3-propagation/tree/7c6e9f14d6627832bd80baa87ac7dabee7be23cf#single-header
|
43
|
-
# DEV: `{SamplingState}` and `{ParentSpanId`}` are optional
|
44
|
-
|
45
|
-
b3_single = Parser.new(metadata).metadata_for_key(B3_HEADER_SINGLE)
|
46
|
-
return if b3_single.nil?
|
47
|
-
|
48
|
-
parts = b3_single.split('-')
|
49
|
-
trace_id = Helpers.value_to_id(parts[0], 16) unless parts.empty?
|
50
|
-
span_id = Helpers.value_to_id(parts[1], 16) if parts.length > 1
|
51
|
-
sampling_priority = Helpers.value_to_number(parts[2]) if parts.length > 2
|
52
|
-
|
53
|
-
# Return early if this propagation is not valid
|
54
|
-
return unless trace_id && span_id
|
55
|
-
|
56
|
-
TraceDigest.new(
|
57
|
-
span_id: span_id,
|
58
|
-
trace_id: trace_id,
|
59
|
-
trace_sampling_priority: sampling_priority
|
60
|
-
)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require_relative '../headers/ext'
|
2
|
-
require_relative 'parser'
|
3
|
-
|
4
|
-
module Datadog
|
5
|
-
module Tracing
|
6
|
-
module Distributed
|
7
|
-
module Metadata
|
8
|
-
# Datadog provides helpers to inject or extract metadata for Datadog style headers
|
9
|
-
class Datadog
|
10
|
-
include Distributed::Headers::Ext
|
11
|
-
|
12
|
-
def self.inject!(digest, metadata)
|
13
|
-
return if digest.nil?
|
14
|
-
|
15
|
-
metadata[GRPC_METADATA_TRACE_ID] = digest.trace_id.to_s
|
16
|
-
metadata[GRPC_METADATA_PARENT_ID] = digest.span_id.to_s
|
17
|
-
if digest.trace_sampling_priority
|
18
|
-
metadata[GRPC_METADATA_SAMPLING_PRIORITY] =
|
19
|
-
digest.trace_sampling_priority.to_s
|
20
|
-
end
|
21
|
-
metadata[GRPC_METADATA_ORIGIN] = digest.trace_origin.to_s if digest.trace_origin
|
22
|
-
|
23
|
-
metadata
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.extract(metadata)
|
27
|
-
carrier = Carrier.new(metadata)
|
28
|
-
|
29
|
-
return nil unless carrier.valid?
|
30
|
-
|
31
|
-
TraceDigest.new(
|
32
|
-
span_id: carrier.parent_id,
|
33
|
-
trace_id: carrier.trace_id,
|
34
|
-
trace_origin: carrier.origin,
|
35
|
-
trace_sampling_priority: carrier.sampling_priority
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
# opentracing.io compliant carrier object
|
40
|
-
class Carrier
|
41
|
-
include Distributed::Headers::Ext
|
42
|
-
|
43
|
-
def initialize(metadata = {})
|
44
|
-
@metadata = Parser.new(metadata || {})
|
45
|
-
end
|
46
|
-
|
47
|
-
def valid?
|
48
|
-
(trace_id && parent_id) || (origin && trace_id)
|
49
|
-
end
|
50
|
-
|
51
|
-
def trace_id
|
52
|
-
@metadata.id(GRPC_METADATA_TRACE_ID)
|
53
|
-
end
|
54
|
-
|
55
|
-
def parent_id
|
56
|
-
@metadata.id(GRPC_METADATA_PARENT_ID)
|
57
|
-
end
|
58
|
-
|
59
|
-
def sampling_priority
|
60
|
-
value = @metadata.metadata_for_key(GRPC_METADATA_SAMPLING_PRIORITY)
|
61
|
-
value && value.to_i
|
62
|
-
end
|
63
|
-
|
64
|
-
def origin
|
65
|
-
value = @metadata.metadata_for_key(GRPC_METADATA_ORIGIN)
|
66
|
-
value if value != ''
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require_relative '../helpers'
|
2
|
-
|
3
|
-
module Datadog
|
4
|
-
module Tracing
|
5
|
-
module Distributed
|
6
|
-
module Metadata
|
7
|
-
# Parser provides easy access and validation methods for metadata headers
|
8
|
-
class Parser
|
9
|
-
def initialize(metadata)
|
10
|
-
@metadata = metadata
|
11
|
-
end
|
12
|
-
|
13
|
-
def id(key, base = 10)
|
14
|
-
Helpers.value_to_id(metadata_for_key(key), base)
|
15
|
-
end
|
16
|
-
|
17
|
-
def number(key, base = 10)
|
18
|
-
Helpers.value_to_number(metadata_for_key(key), base)
|
19
|
-
end
|
20
|
-
|
21
|
-
def metadata_for_key(key)
|
22
|
-
# metadata values can be arrays (multiple headers with the same key)
|
23
|
-
value = @metadata[key]
|
24
|
-
if value.is_a?(Array)
|
25
|
-
value.first
|
26
|
-
else
|
27
|
-
value
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|