line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenTracing::Implementation::DataDog::Tracer; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
1159856
|
use strict; |
|
8
|
|
|
|
|
77
|
|
|
8
|
|
|
|
|
227
|
|
4
|
8
|
|
|
8
|
|
46
|
use warnings; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
359
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v0.46.1'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
OpenTracing::Implementation::DataDog::Tracer - Keep track of traces |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use aliased 'OpenTracing::Implementation::DataDog::Tracer'; |
16
|
|
|
|
|
|
|
use aliased 'OpenTracing::Implementation::DataDog::Client'; |
17
|
|
|
|
|
|
|
use aliased 'OpenTracing::Implementation::DataDog::ScopeManager'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $TRACER = Tracer->new( |
20
|
|
|
|
|
|
|
client => Client->new(), |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
and later |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub foo { |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $scope = $TRACER->start_active_span( 'Operation Name' => %options ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
... |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$scope->close; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return $foo |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
8
|
|
|
8
|
|
2489
|
use syntax 'maybe'; |
|
8
|
|
|
|
|
156036
|
|
|
8
|
|
|
|
|
46
|
|
39
|
|
|
|
|
|
|
|
40
|
8
|
|
|
8
|
|
25992
|
use Moo; |
|
8
|
|
|
|
|
39522
|
|
|
8
|
|
|
|
|
57
|
|
41
|
8
|
|
|
8
|
|
14171
|
use MooX::Should; |
|
8
|
|
|
|
|
88777
|
|
|
8
|
|
|
|
|
58
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
with 'OpenTracing::Role::Tracer'; |
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
8
|
|
1963
|
use aliased 'OpenTracing::Implementation::DataDog::Client'; |
|
8
|
|
|
|
|
1533
|
|
|
8
|
|
|
|
|
68
|
|
46
|
8
|
|
|
8
|
|
1192
|
use aliased 'OpenTracing::Implementation::DataDog::ScopeManager'; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
51
|
|
47
|
8
|
|
|
8
|
|
1022
|
use aliased 'OpenTracing::Implementation::DataDog::Span'; |
|
8
|
|
|
|
|
59
|
|
|
8
|
|
|
|
|
53
|
|
48
|
8
|
|
|
8
|
|
1121
|
use aliased 'OpenTracing::Implementation::DataDog::SpanContext'; |
|
8
|
|
|
|
|
23
|
|
|
8
|
|
|
|
|
60
|
|
49
|
|
|
|
|
|
|
|
50
|
8
|
|
|
8
|
|
6694
|
use Hash::Merge; |
|
8
|
|
|
|
|
38388
|
|
|
8
|
|
|
|
|
428
|
|
51
|
8
|
|
|
8
|
|
86
|
use Ref::Util qw/is_plain_hashref/; |
|
8
|
|
|
|
|
24
|
|
|
8
|
|
|
|
|
424
|
|
52
|
8
|
|
|
8
|
|
70
|
use Types::Standard qw/Object Str/; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
232
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
This is a L<OpenTracing SpanContext|OpenTracing::Interface::SpanContext> |
59
|
|
|
|
|
|
|
compliant implementation with DataDog specific extentions |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 EXTENDED ATTRIBUTES |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 C<scope_manager> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
A L<OpenTracing::Types::ScopeManger> that now defaults to a |
74
|
|
|
|
|
|
|
L<DataDog::ScopeManger|OpenTracing::Implementation::DataDog::ScopeManager> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has '+scope_manager' => ( |
79
|
|
|
|
|
|
|
default => sub { ScopeManager->new }, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 DATADOG SPECIFIC ATTRIBUTES |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 C<client> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
A client that has a C<send_span> method that will get called on a `on_finish`. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
See L<DataDog::Client|OpenTracing::Implementation::DataDog::Client> for more. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
It also accepts a plain hash refference with key-value pairs suitable to |
97
|
|
|
|
|
|
|
construct a client object. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
has client => ( |
102
|
|
|
|
|
|
|
is => 'lazy', |
103
|
|
|
|
|
|
|
should => Object, |
104
|
|
|
|
|
|
|
handles => [qw/send_span/], |
105
|
|
|
|
|
|
|
coerce |
106
|
|
|
|
|
|
|
=> sub { is_plain_hashref $_[0] ? Client->new( %{$_[0]} ) : $_[0] }, |
107
|
|
|
|
|
|
|
default => sub { {} }, # XXX this does not return an Object !!! |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
has default_resource_name => ( |
113
|
|
|
|
|
|
|
is => 'ro', |
114
|
|
|
|
|
|
|
should => Str, |
115
|
|
|
|
|
|
|
predicate => 1, |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
has default_service_name => ( |
121
|
|
|
|
|
|
|
is => 'ro', |
122
|
|
|
|
|
|
|
should => Str, |
123
|
|
|
|
|
|
|
predicate => 1, |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
has default_service_type => ( |
129
|
|
|
|
|
|
|
is => 'ro', |
130
|
|
|
|
|
|
|
should => Str, |
131
|
|
|
|
|
|
|
predicate => 1, |
132
|
|
|
|
|
|
|
); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
has default_environment => ( |
137
|
|
|
|
|
|
|
is => 'ro', |
138
|
|
|
|
|
|
|
should => Str, |
139
|
|
|
|
|
|
|
predicate => 1, |
140
|
|
|
|
|
|
|
); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
has default_hostname => ( |
145
|
|
|
|
|
|
|
is => 'ro', |
146
|
|
|
|
|
|
|
should => Str, |
147
|
|
|
|
|
|
|
predicate => 1, |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
has default_version => ( |
153
|
|
|
|
|
|
|
is => 'ro', |
154
|
|
|
|
|
|
|
should => Str, |
155
|
|
|
|
|
|
|
predicate => 1, |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub build_span { |
161
|
|
|
|
|
|
|
my $self = shift; |
162
|
|
|
|
|
|
|
my %opts = @_; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
my $span = Span->new( |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
operation_name => $opts{ operation_name }, |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
maybe |
169
|
|
|
|
|
|
|
child_of => $opts{ child_of }, |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
maybe |
172
|
|
|
|
|
|
|
start_time => $opts{ start_time }, |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
maybe |
175
|
|
|
|
|
|
|
tags => $opts{ tags }, |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
context => $opts{ context }, |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
on_finish => sub { |
180
|
|
|
|
|
|
|
my $span = shift; |
181
|
|
|
|
|
|
|
$self->send_span( $span ) |
182
|
|
|
|
|
|
|
}, |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
return $span |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub build_context { |
192
|
|
|
|
|
|
|
my $self = shift; |
193
|
|
|
|
|
|
|
my %opts = @_; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $resource_name = delete $opts{ resource_name } |
196
|
|
|
|
|
|
|
|| $self->default_resource_name; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my $service_name = delete $opts{ service_name } |
199
|
|
|
|
|
|
|
|| $self->default_service_name; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $service_type = delete $opts{ service_type } |
202
|
|
|
|
|
|
|
|| $self->default_service_type; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
my $environment = delete $opts{ environment } |
205
|
|
|
|
|
|
|
|| $self->default_environment; |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
my $hostname = delete $opts{ hostname } |
208
|
|
|
|
|
|
|
|| $self->default_hostname; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
my $version = delete $opts{ version } |
211
|
|
|
|
|
|
|
|| $self->default_version; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
my $span_context = SpanContext->new( |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
%opts, |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
resource_name => $resource_name, |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
maybe |
220
|
|
|
|
|
|
|
service_name => $service_name, |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
maybe |
223
|
|
|
|
|
|
|
service_type => $service_type, |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
maybe |
226
|
|
|
|
|
|
|
environment => $environment, |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
maybe |
229
|
|
|
|
|
|
|
hostname => $hostname, |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
maybe |
232
|
|
|
|
|
|
|
version => $version, |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
); |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
return $span_context |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub inject_context_into_array_reference { return $_[1] } # $carrier |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub inject_context_into_hash_reference { |
246
|
|
|
|
|
|
|
my $self = shift; |
247
|
|
|
|
|
|
|
my $carrier = shift; |
248
|
|
|
|
|
|
|
my $context = shift; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
return Hash::Merge->new('RIGHT_PRECEDENT')->merge( |
251
|
|
|
|
|
|
|
$carrier, |
252
|
|
|
|
|
|
|
{ |
253
|
|
|
|
|
|
|
opentracing_context => { |
254
|
|
|
|
|
|
|
trace_id => $context->trace_id, |
255
|
|
|
|
|
|
|
span_id => $context->span_id, |
256
|
|
|
|
|
|
|
resource => $context->get_resource_name, |
257
|
|
|
|
|
|
|
service => $context->get_service_name, |
258
|
|
|
|
|
|
|
maybe |
259
|
|
|
|
|
|
|
type => $context->get_service_type, |
260
|
|
|
|
|
|
|
maybe |
261
|
|
|
|
|
|
|
environment => $context->get_environment, |
262
|
|
|
|
|
|
|
maybe |
263
|
|
|
|
|
|
|
hostname => $context->get_hostname, |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
) |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub inject_context_into_http_headers { return $_[1] } # $carrier |
273
|
|
|
|
|
|
|
sub extract_context_from_array_reference { return undef } |
274
|
|
|
|
|
|
|
sub extract_context_from_hash_reference { return undef } |
275
|
|
|
|
|
|
|
sub extract_context_from_http_headers { return undef } |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head1 SEE ALSO |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=over |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item L<OpenTracing::Implementation::DataDog> |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
Sending traces to DataDog using Agent. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item L<OpenTracing::Role::Tracer> |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
Role for OpenTracing Implementations. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=back |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head1 AUTHOR |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Theo van Hoesel <tvanhoesel@perceptyx.com> |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
'OpenTracing::Implementation::DataDog' |
302
|
|
|
|
|
|
|
is Copyright (C) 2019 .. 2021, Perceptyx Inc |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
305
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
This package is distributed in the hope that it will be useful, but it is |
308
|
|
|
|
|
|
|
provided "as is" and without any express or implied warranties. |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
For details, see the full text of the license in the file LICENSE. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=cut |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
1; |