File Coverage

blib/lib/OpenTracing/Implementation/DataDog/Tracer.pm
Criterion Covered Total %
statement 27 27 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod n/a
total 36 36 100.0


line stmt bran cond sub pod time code
1             package OpenTracing::Implementation::DataDog::Tracer;
2              
3 4     4   564118 use strict;
  4         38  
  4         119  
4 4     4   23 use warnings;
  4         9  
  4         208  
5              
6              
7             our $VERSION = 'v0.40.0.6-TRIAL';
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::Agent';
17             use aliased 'OpenTracing::Implementation::DataDog::ScopeManager';
18            
19             my $TRACER = Tracer->new(
20             agent => Agent->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 4     4   1372 use syntax 'maybe';
  4         76041  
  4         22  
39              
40 4     4   13282 use Moo;
  4         21399  
  4         27  
41              
42             with 'OpenTracing::Role::Tracer';
43              
44 4     4   6224 use aliased 'OpenTracing::Implementation::DataDog::Agent';
  4         1525  
  4         36  
45 4     4   467 use aliased 'OpenTracing::Implementation::DataDog::ScopeManager';
  4         11  
  4         28  
46 4     4   518 use aliased 'OpenTracing::Implementation::DataDog::SpanContext';
  4         11  
  4         25  
47              
48 4     4   2623 use Ref::Util qw/is_plain_hashref/;
  4         2336  
  4         324  
49 4     4   33 use Types::Standard qw/Object/;
  4         10  
  4         39  
50              
51              
52              
53             =head1 DESCRIPTION
54              
55             This is a L<OpenTracing SpanContext|OpenTracing::Interface::SpanContext>
56             compliant implementation with DataDog specific extentions
57              
58             =cut
59              
60              
61              
62             =head1 EXTENDED ATTRIBUTES
63              
64             =cut
65              
66              
67              
68             =head2 C<scope_manager>
69              
70             A L<OpenTracing::Types::ScopeManger> that now defaults to a
71             L<DataDog::ScopeManger|OpenTracing::Implementation::DataDog::ScopeManager>
72              
73             =cut
74              
75             has '+scope_manager' => (
76             default => sub { ScopeManager->new },
77             );
78              
79              
80              
81             =head1 DATADOG SPECIFIC ATTRIBUTES
82              
83             =cut
84              
85              
86              
87             =head2 C<agent>
88              
89             An agent that has a C<send_span> method that will get called on a `on_finish`.
90              
91             See L<DataDog::Agent|OpenTracing::Implementation::DataDog::Agent> for more.
92              
93             It also accepts a plain hash refference with key-value pairs suitable to
94             construct a Agent.
95              
96             =cut
97              
98             has agent => (
99             is => 'lazy',
100             isa => Object,
101             handles => [qw/send_span/],
102             coerce
103             => sub { is_plain_hashref $_[0] ? Agent->new( %{$_[0]} ) : $_[0] },
104             default => sub { {} }, # XXX this does not return an Object !!!
105             );
106              
107              
108              
109             sub extract_context {
110             undef
111             }
112              
113              
114              
115             sub inject_context { ... }
116              
117              
118              
119             sub build_span {
120             my $self = shift;
121             my %opts = @_;
122            
123             my $span = Span->new(
124            
125             operation_name => $opts{ operation_name },
126            
127             child_of => $opts{ child_of },
128            
129             maybe
130             start_time => $opts{ start_time },
131            
132             maybe
133             tags => $opts{ tags },
134            
135             context => $opts{ context },
136            
137             on_finish => sub {
138             my $span = shift;
139             $self->send_span( $span )
140             },
141            
142             );
143            
144             return $span
145             }
146              
147              
148              
149             sub build_context {
150             my $self = shift;
151             my %opts = @_;
152            
153             my $span_context = SpanContext->new(
154            
155             resource_name => $opts{ resource_name },
156            
157             maybe
158             service_name => $opts{ service_name },
159            
160             maybe
161             service_type => $opts{ service_type },
162             );
163            
164             return $span_context
165             }
166              
167             =head1 SEE ALSO
168              
169             =over
170              
171             =item L<OpenTracing::Implementation::DataDog>
172              
173             Sending traces to DataDog using Agent.
174              
175             =item L<OpenTracing::Role::Tracer>
176              
177             Role for OpenTracing Implementations.
178              
179             =back
180              
181              
182              
183             =head1 AUTHOR
184              
185             Theo van Hoesel <tvanhoesel@perceptyx.com>
186              
187              
188              
189             =head1 COPYRIGHT AND LICENSE
190              
191             'OpenTracing::Implementation::DataDog'
192             is Copyright (C) 2019 .. 2020, Perceptyx Inc
193              
194             This library is free software; you can redistribute it and/or modify it under
195             the terms of the Artistic License 2.0.
196              
197             This package is distributed in the hope that it will be useful, but it is
198             provided "as is" and without any express or implied warranties.
199              
200             For details, see the full text of the license in the file LICENSE.
201              
202              
203             =cut
204              
205             1;