DataDog/HTTPPropagator.pm

filter: Statementstmt 98.2% 113 / 115 Branchbran 100% 4 / 4 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 97.0% 33 / 34 Podpod 0.0% 0 / 13 totaltotal 88.5% 154 / 174 CC 7 SCAR 4.3
CC
7
Cov
97%
extract
4.1
make_propagator
3.0
__ANON__
2.0
CRAP 1.5
« DataDog/Client.pm ↑ Summary DataDog/Span.pm »
1 package OpenTracing::Implementation::DataDog::HTTPPropagator;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use MooX::Attribute::ENV;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Carp qw[ croak ];
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 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 };
16  
17 8 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 8 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 8 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 8 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
47 8 my ($self) = @_;
48 8 $self->make_propagator($self->_style_extract);
49 },
50 8 );
51  
52 has injector => (
53 is => 'lazy',
54 handles => [qw/inject/],
55 8 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 8 my ($self) = @_;
57 8 $self->make_propagator($self->_style_inject);
58 },
59 8 );
60  
61 16 ▶sub make_propagator {
Subroutine make_propagator: called CC=3 SCAR=11.0
Pod undocumented
62 16 my ($self, $style) = @_;
63 20 my @propagators = map { $_->new } map {
64 16 s/\A\s*|\s*\z//g;
65 20 ▶ $styles{$_} // croak "Unsupported propagation style: $_"
Condition50%1/2
$styles{$_} // croak("Unsupported propagation style: $_")
l!l
200
MC/DC0%0/1
$styles{$_} // croak("Unsupported propagation style: $_")
$styles{$_}
Truth table50%1/2
A
A= $styles{$_}
Aresult
11
00
66 } split ',', $style;
67 16 ▶ return $propagators[0] if @propagators == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @propagators == 1 14 2 16
68 2 return OpenTracing::Implementation::DataDog::Propagator::Multi->new(@propagators);
69 }
70  
71 8 package OpenTracing::Implementation::DataDog::Propagator::DataDog {
72 8 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 8 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
75 8 HTTP_HEADER_TRACE_ID => "x-datadog-trace-id",
76 HTTP_HEADER_SPAN_ID => "x-datadog-parent-id",
77 8 };
78  
79 4 ▶ sub inject {
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
80 4 my ($self, $carrier, $context) = @_;
81 4 $carrier->header(HTTP_HEADER_TRACE_ID, $context->trace_id);
82 4 $carrier->header(HTTP_HEADER_SPAN_ID, $context->span_id);
83 4 return;
84 }
85  
86 4 ▶ sub extract {
Subroutine extract: called CC=1 SCAR=0.0
Pod undocumented
87 4 my ($self, $carrier) = @_;
88 return (
89 4 $carrier->header(HTTP_HEADER_TRACE_ID),
90 $carrier->header(HTTP_HEADER_SPAN_ID),
91 );
92 }
93 }
94  
95 8 package OpenTracing::Implementation::DataDog::Propagator::B3Single {
96 8 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
97  
98 8 ▶ use constant HTTP_HEADER_B3_SINGLE => "b3";
Subroutine BEGIN: called CC=1 SCAR=0.0
99  
100 2 ▶ sub inject {
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
101 2 my ($self, $carrier, $context) = @_;
102 2 $carrier->header(HTTP_HEADER_B3_SINGLE,
103 join '-', $context->trace_id, $context->span_id);
104 2 return;
105 }
106  
107 1 ▶ sub extract {
Subroutine extract: called CC=1 SCAR=0.0
Pod undocumented
108 1 my ($self, $carrier) = @_;
109 1 return split '-', $carrier->header(HTTP_HEADER_B3_SINGLE);
110 }
111 }
112  
113 8 package OpenTracing::Implementation::DataDog::Propagator::B3Multi {
114 8 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 8 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
117 8 HTTP_HEADER_B3_TRACE_ID => "x-b3-traceid",
118 HTTP_HEADER_B3_SPAN_ID => "x-b3-spanid",
119 8 };
120  
121 2 ▶ sub inject {
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
122 2 my ($self, $carrier, $context) = @_;
123 2 $carrier->header(HTTP_HEADER_B3_TRACE_ID, $context->trace_id);
124 2 $carrier->header(HTTP_HEADER_B3_SPAN_ID, $context->span_id);
125 2 return;
126 }
127  
128 2 ▶ sub extract {
Subroutine extract: called CC=1 SCAR=0.0
Pod undocumented
129 2 my ($self, $carrier) = @_;
130 return (
131 2 $carrier->header(HTTP_HEADER_B3_TRACE_ID),
132 $carrier->header(HTTP_HEADER_B3_SPAN_ID),
133 );
134 }
135 }
136  
137 8 package OpenTracing::Implementation::DataDog::Propagator::TraceState {
138 8 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
139  
140 8 ▶ use constant HTTP_HEADER_TRACEPARENT => "traceparent";
Subroutine BEGIN: called CC=1 SCAR=0.0
141  
142 2 ▶ sub inject {
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
143 2 my ($self, $carrier, $context) = @_;
144  
145 # version and sampling priority not supported at the moment
146 2 my $traceparent = sprintf '00-%032x-%016x-00',
147 $context->trace_id, $context->span_id;
148 2 $carrier->header(HTTP_HEADER_TRACEPARENT, $traceparent);
149  
150 2 return;
151 }
152  
153 1 ▶ sub extract {
Subroutine extract: called CC=1 SCAR=0.0
Pod undocumented
154 1 my ($self, $carrier) = @_;
155  
156 8 ▶ no warnings 'portable'; # ids could greater than 0xffffffff
Subroutine BEGIN: called CC=1 SCAR=0.0
157  
158 1 my (undef, $trace_id, $span_id, undef)
159 = split '-', $carrier->header(HTTP_HEADER_TRACEPARENT);
160 1 return map { hex } $trace_id, $span_id;
161 }
162 }
163  
164 8 package OpenTracing::Implementation::DataDog::Propagator::Multi {
165 8 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
166  
167 has propagators => (
168 is => 'ro',
169 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
170 8 );
171  
172 2 ▶ around BUILDARGS => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
173 2 my ($orig, $class, @args) = @_;
174 2 return $class->$orig({ propagators => \@args });
175 8 };
176  
177 1 ▶ sub inject {
Subroutine inject: called CC=2 SCAR=6.9
Pod undocumented
178 1 my ($self, $carrier, $context) = @_;
179 1 $_->inject($carrier, $context) foreach @{ $self->propagators };
180 1 return;
181 }
182  
183 1 ▶ sub extract {
Subroutine extract: called CC=4 SCAR=14.1
Pod undocumented
184 1 my ($self, $carrier) = @_;
185 1 foreach my $extractor (@{ $self->propagators }) {
186 2 my ($trace_id, $span_id) = $extractor->extract($carrier);
187 2 ▶ return ($trace_id, $span_id) if defined $trace_id and defined $span_id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $trace_id and defined $span_id 1 1 2
Condition66%2/3
defined $trace_id and defined $span_id
!ll&&!rl&&r
101
MC/DC50%1/2
defined $trace_id and defined $span_id
defined $trace_id defined $span_id
Truth table66%2/3
A and B
A= defined $trace_idB= defined $span_id
ABresult
0X0
100
111
188 }
189 0 return;
190 }
191 }
192  
193 8 package OpenTracing::Implementation::DataDog::Propagator::NoOp {
194 8 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196 1 ▶ sub inject { }
Subroutine inject: called CC=1 SCAR=0.0
Pod undocumented
197 1 ▶ sub extract { undef, undef }
Subroutine extract: called CC=1 SCAR=0.0
Pod undocumented
198 }
199  
200 8 1;
« DataDog/Client.pm ↑ Summary DataDog/Span.pm »