File Coverage

blib/lib/OpenTracing/SpanProxy.pm
Criterion Covered Total %
statement 30 40 75.0
branch 3 4 75.0
condition n/a
subroutine 14 24 58.3
pod 3 18 16.6
total 50 86 58.1


line stmt bran cond sub pod time code
1             package OpenTracing::SpanProxy;
2              
3 3     3   22 use strict;
  3         5  
  3         106  
4 3     3   16 use warnings;
  3         5  
  3         211  
5              
6             our $VERSION = '1.006'; # VERSION
7             our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8              
9 3     3   19 use parent qw(OpenTracing::Common);
  3         6  
  3         14  
10              
11 3     3   173 no indirect;
  3         5  
  3         16  
12 3     3   137 use utf8;
  3         6  
  3         21  
13              
14             =encoding utf8
15              
16             =head1 NAME
17              
18             OpenTracing::SpanProxy - wrapper around an L
19              
20             =head1 DESCRIPTION
21              
22             This is the wrapper class that user code would normally receive when working
23             with spans. It allows the creation of nested subspans, and will automatically
24             mark the span as complete when the proxy object is discarded.
25              
26             For methods available here, see L.
27              
28             =cut
29              
30             =head2 span
31              
32             Returns the L instance that this wraps.
33              
34             =cut
35              
36 19     19 1 92 sub span { shift->{span} }
37              
38             =head2 log
39              
40             Writes a log entry to the L.
41              
42             =cut
43              
44 1     1 0 3 sub id { shift->span->id }
45              
46 2     2 0 6 sub trace_id { shift->span->trace_id }
47              
48 1     1 0 5 sub parent_id { shift->span->parent_id }
49              
50 0     0 1 0 sub log { shift->span->log(@_) }
51              
52 0     0 0 0 sub logs { shift->span->logs }
53              
54 0     0 0 0 sub tags { shift->span->tags }
55              
56 0     0 0 0 sub tag { shift->span->tag(@_) }
57              
58 0     0 0 0 sub reference { shift->span->reference(@_) }
59              
60 0     0 0 0 sub references { shift->span->references }
61              
62 0     0 0 0 sub start_time { shift->span->start_time }
63              
64 0     0 0 0 sub finish_time { shift->span->finish_time }
65              
66 3     3 0 13 sub duration { shift->span->duration(@_) }
67              
68 1     1 0 5 sub finish { shift->span->finish(@_) }
69              
70 1     1 0 5 sub is_finished { shift->span->is_finished }
71              
72 0     0 0 0 sub operation_name { shift->span->operation_name }
73              
74 0     0 0 0 sub flags { shift->span->flags }
75              
76             =head2 new_span
77              
78             Creates a new sub-span under this L instance.
79              
80             =cut
81              
82             sub new_span {
83 1     1 1 7 my ($self, $name, %args) = @_;
84 1         15 my $parent = $self->span;
85 1         5 @args{qw(trace_id parent_id)} = (
86             $parent->trace_id,
87             $parent->id,
88             );
89 1         47 $parent->tracer->span(
90             operation_name => $name,
91             %args
92             );
93             }
94              
95             =head2 DESTROY
96              
97             Called on destruction, will mark completion on the span by calling
98             L.
99              
100             =cut
101              
102             sub DESTROY {
103 4     4   13436 my ($self) = @_;
104 4 50       18 return if ${^GLOBAL_PHASE} eq 'DESTRUCT';
105 4 100       12 $self->span->finish unless $self->span->is_finished;
106 4         18 delete $self->{span};
107             }
108              
109             1;
110              
111             __END__