line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::HTTPPropagator; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
4868
|
use strict; |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
280
|
|
4
|
8
|
|
|
8
|
|
54
|
use warnings; |
|
8
|
|
|
|
|
38
|
|
|
8
|
|
|
|
|
208
|
|
5
|
8
|
|
|
8
|
|
50
|
use Moo; |
|
8
|
|
|
|
|
25
|
|
|
8
|
|
|
|
|
73
|
|
6
|
8
|
|
|
8
|
|
4379
|
use MooX::Attribute::ENV; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
103
|
|
7
|
8
|
|
|
8
|
|
2108
|
use Carp qw[ croak ]; |
|
8
|
|
|
|
|
35
|
|
|
8
|
|
|
|
|
816
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use constant { |
10
|
8
|
|
|
|
|
4168
|
STYLE_DATADOG => 'datadog', |
11
|
|
|
|
|
|
|
STYLE_B3_SINGLE => 'b3 single header', |
12
|
|
|
|
|
|
|
STYLE_B3_MULTI => 'b3multi', |
13
|
|
|
|
|
|
|
STYLE_W3C => 'tracecontext', |
14
|
|
|
|
|
|
|
STYLE_NONE => 'none', |
15
|
8
|
|
|
8
|
|
88
|
}; |
|
8
|
|
|
|
|
21
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %styles = ( |
18
|
|
|
|
|
|
|
STYLE_DATADOG ,=> 'OpenTracing::Implementation::DataDog::Propagator::DataDog', |
19
|
|
|
|
|
|
|
STYLE_B3_SINGLE ,=> 'OpenTracing::Implementation::DataDog::Propagator::B3Single', |
20
|
|
|
|
|
|
|
STYLE_B3_MULTI ,=> 'OpenTracing::Implementation::DataDog::Propagator::B3Multi', |
21
|
|
|
|
|
|
|
STYLE_W3C ,=> 'OpenTracing::Implementation::DataDog::Propagator::TraceState', |
22
|
|
|
|
|
|
|
STYLE_NONE ,=> 'OpenTracing::Implementation::DataDog::Propagator::NoOp', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has _style_extract => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
default => STYLE_DATADOG, |
28
|
|
|
|
|
|
|
env_key => [ |
29
|
|
|
|
|
|
|
'DD_TRACE_PROPAGATION_STYLE_EXTRACT', |
30
|
|
|
|
|
|
|
'DD_TRACE_PROPAGATION_STYLE', |
31
|
|
|
|
|
|
|
], |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has _style_inject => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
default => STYLE_DATADOG, |
37
|
|
|
|
|
|
|
env_key => [ |
38
|
|
|
|
|
|
|
'DD_TRACE_PROPAGATION_STYLE_INJECT', |
39
|
|
|
|
|
|
|
'DD_TRACE_PROPAGATION_STYLE', |
40
|
|
|
|
|
|
|
], |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has extractor => ( |
44
|
|
|
|
|
|
|
is => 'lazy', |
45
|
|
|
|
|
|
|
handles => [qw/extract/], |
46
|
|
|
|
|
|
|
default => sub { |
47
|
|
|
|
|
|
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
$self->make_propagator($self->_style_extract); |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has injector => ( |
53
|
|
|
|
|
|
|
is => 'lazy', |
54
|
|
|
|
|
|
|
handles => [qw/inject/], |
55
|
|
|
|
|
|
|
default => sub { |
56
|
|
|
|
|
|
|
my ($self) = @_; |
57
|
|
|
|
|
|
|
$self->make_propagator($self->_style_inject); |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub make_propagator { |
62
|
16
|
|
|
16
|
0
|
46
|
my ($self, $style) = @_; |
63
|
20
|
|
|
|
|
242
|
my @propagators = map { $_->new } map { |
64
|
16
|
|
|
|
|
63
|
s/\A\s*|\s*\z//g; |
|
20
|
|
|
|
|
139
|
|
65
|
20
|
|
33
|
|
|
112
|
$styles{$_} // croak "Unsupported propagation style: $_" |
66
|
|
|
|
|
|
|
} split ',', $style; |
67
|
16
|
100
|
|
|
|
855
|
return $propagators[0] if @propagators == 1; |
68
|
2
|
|
|
|
|
30
|
return OpenTracing::Implementation::DataDog::Propagator::Multi->new(@propagators); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::Propagator::DataDog { |
72
|
8
|
|
|
8
|
|
75
|
use Moo; |
|
8
|
|
|
|
|
51
|
|
|
8
|
|
|
|
|
51
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use constant { |
75
|
8
|
|
|
|
|
1761
|
HTTP_HEADER_TRACE_ID => "x-datadog-trace-id", |
76
|
|
|
|
|
|
|
HTTP_HEADER_SPAN_ID => "x-datadog-parent-id", |
77
|
8
|
|
|
8
|
|
3876
|
}; |
|
8
|
|
|
|
|
38
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub inject { |
80
|
4
|
|
|
4
|
0
|
30
|
my ($self, $carrier, $context) = @_; |
81
|
4
|
|
|
|
|
72
|
$carrier->header(HTTP_HEADER_TRACE_ID, $context->trace_id); |
82
|
4
|
|
|
|
|
334
|
$carrier->header(HTTP_HEADER_SPAN_ID, $context->span_id); |
83
|
4
|
|
|
|
|
254
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub extract { |
87
|
4
|
|
|
4
|
0
|
30
|
my ($self, $carrier) = @_; |
88
|
|
|
|
|
|
|
return ( |
89
|
4
|
|
|
|
|
17
|
$carrier->header(HTTP_HEADER_TRACE_ID), |
90
|
|
|
|
|
|
|
$carrier->header(HTTP_HEADER_SPAN_ID), |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::Propagator::B3Single { |
96
|
8
|
|
|
8
|
|
65
|
use Moo; |
|
8
|
|
|
|
|
24
|
|
|
8
|
|
|
|
|
77
|
|
97
|
|
|
|
|
|
|
|
98
|
8
|
|
|
8
|
|
3686
|
use constant HTTP_HEADER_B3_SINGLE => "b3"; |
|
8
|
|
|
|
|
34
|
|
|
8
|
|
|
|
|
1872
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub inject { |
101
|
2
|
|
|
2
|
0
|
14
|
my ($self, $carrier, $context) = @_; |
102
|
2
|
|
|
|
|
40
|
$carrier->header(HTTP_HEADER_B3_SINGLE, |
103
|
|
|
|
|
|
|
join '-', $context->trace_id, $context->span_id); |
104
|
2
|
|
|
|
|
154
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub extract { |
108
|
1
|
|
|
1
|
0
|
12
|
my ($self, $carrier) = @_; |
109
|
1
|
|
|
|
|
6
|
return split '-', $carrier->header(HTTP_HEADER_B3_SINGLE); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::Propagator::B3Multi { |
114
|
8
|
|
|
8
|
|
76
|
use Moo; |
|
8
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
71
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
use constant { |
117
|
8
|
|
|
|
|
1716
|
HTTP_HEADER_B3_TRACE_ID => "x-b3-traceid", |
118
|
|
|
|
|
|
|
HTTP_HEADER_B3_SPAN_ID => "x-b3-spanid", |
119
|
8
|
|
|
8
|
|
3945
|
}; |
|
8
|
|
|
|
|
53
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub inject { |
122
|
2
|
|
|
2
|
0
|
20
|
my ($self, $carrier, $context) = @_; |
123
|
2
|
|
|
|
|
37
|
$carrier->header(HTTP_HEADER_B3_TRACE_ID, $context->trace_id); |
124
|
2
|
|
|
|
|
193
|
$carrier->header(HTTP_HEADER_B3_SPAN_ID, $context->span_id); |
125
|
2
|
|
|
|
|
118
|
return; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub extract { |
129
|
2
|
|
|
2
|
0
|
24
|
my ($self, $carrier) = @_; |
130
|
|
|
|
|
|
|
return ( |
131
|
2
|
|
|
|
|
10
|
$carrier->header(HTTP_HEADER_B3_TRACE_ID), |
132
|
|
|
|
|
|
|
$carrier->header(HTTP_HEADER_B3_SPAN_ID), |
133
|
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::Propagator::TraceState { |
138
|
8
|
|
|
8
|
|
59
|
use Moo; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
61
|
|
139
|
|
|
|
|
|
|
|
140
|
8
|
|
|
8
|
|
3866
|
use constant HTTP_HEADER_TRACEPARENT => "traceparent"; |
|
8
|
|
|
|
|
42
|
|
|
8
|
|
|
|
|
1218
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub inject { |
143
|
2
|
|
|
2
|
0
|
19
|
my ($self, $carrier, $context) = @_; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# version and sampling priority not supported at the moment |
146
|
2
|
|
|
|
|
47
|
my $traceparent = sprintf '00-%032x-%016x-00', |
147
|
|
|
|
|
|
|
$context->trace_id, $context->span_id; |
148
|
2
|
|
|
|
|
82
|
$carrier->header(HTTP_HEADER_TRACEPARENT, $traceparent); |
149
|
|
|
|
|
|
|
|
150
|
2
|
|
|
|
|
134
|
return; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub extract { |
154
|
1
|
|
|
1
|
0
|
19
|
my ($self, $carrier) = @_; |
155
|
|
|
|
|
|
|
|
156
|
8
|
|
|
8
|
|
69
|
no warnings 'portable'; # ids could greater than 0xffffffff |
|
8
|
|
|
|
|
42
|
|
|
8
|
|
|
|
|
1013
|
|
157
|
|
|
|
|
|
|
|
158
|
1
|
|
|
|
|
5
|
my (undef, $trace_id, $span_id, undef) |
159
|
|
|
|
|
|
|
= split '-', $carrier->header(HTTP_HEADER_TRACEPARENT); |
160
|
1
|
|
|
|
|
60
|
return map { hex } $trace_id, $span_id; |
|
2
|
|
|
|
|
11
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::Propagator::Multi { |
165
|
8
|
|
|
8
|
|
66
|
use Moo; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
63
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
has propagators => ( |
168
|
|
|
|
|
|
|
is => 'ro', |
169
|
|
|
|
|
|
|
default => sub { [] }, |
170
|
|
|
|
|
|
|
); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
around BUILDARGS => sub { |
173
|
|
|
|
|
|
|
my ($orig, $class, @args) = @_; |
174
|
|
|
|
|
|
|
return $class->$orig({ propagators => \@args }); |
175
|
|
|
|
|
|
|
}; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub inject { |
178
|
1
|
|
|
1
|
0
|
61
|
my ($self, $carrier, $context) = @_; |
179
|
1
|
|
|
|
|
3
|
$_->inject($carrier, $context) foreach @{ $self->propagators }; |
|
1
|
|
|
|
|
10
|
|
180
|
1
|
|
|
|
|
4
|
return; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub extract { |
184
|
1
|
|
|
1
|
0
|
68
|
my ($self, $carrier) = @_; |
185
|
1
|
|
|
|
|
3
|
foreach my $extractor (@{ $self->propagators }) { |
|
1
|
|
|
|
|
8
|
|
186
|
2
|
|
|
|
|
10
|
my ($trace_id, $span_id) = $extractor->extract($carrier); |
187
|
2
|
100
|
66
|
|
|
161
|
return ($trace_id, $span_id) if defined $trace_id and defined $span_id; |
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
0
|
return; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::Propagator::NoOp { |
194
|
8
|
|
|
8
|
|
5531
|
use Moo; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
53
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
1
|
0
|
|
sub inject { } |
197
|
1
|
|
|
1
|
0
|
21
|
sub extract { undef, undef } |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |