File Coverage

blib/lib/OpenTracing/Implementation/DataDog/ScopeManager.pm
Criterion Covered Total %
statement 7 7 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 10 100.0


line stmt bran cond sub pod time code
1             package OpenTracing::Implementation::DataDog::ScopeManager;
2              
3              
4              
5             =head1 NAME
6              
7             OpenTracing::Implementation::DataDog::ScopeManager - Keep track of active scopes
8              
9             =head1 SYNOPSIS
10              
11             my $span = $TRACER->build_span( ... );
12            
13             my $scope_manager = $TRACER->get_scope_manager;
14            
15             my $scope = $scope_manager->build_scope(
16             span => $span,
17             finish_span_on_close => true,
18             );
19            
20             ...
21            
22             $scope->close;
23              
24             =cut
25              
26             our $VERSION = 'v0.46.2';
27              
28 12     12   870735 use Moo;
  12         21621  
  12         95  
29              
30 12     12   14902 use OpenTracing::Implementation::DataDog::Scope;
  12         54  
  12         1862  
31              
32             has '+active_scope' => (
33             clearer => 'final_scope',
34             );
35              
36             =head1 DELEGATED INSTANCE METHODS
37              
38              
39              
40             =head2 build_scope
41              
42             This method will build a new C<Scope> object, that, when C<close> is being
43             called (which you should), the current scope is being set back as the active
44             scope.
45              
46             See L<OpenTracing::Roles::ScopeManager> for the description of the method.
47              
48             =cut
49              
50             sub build_scope {
51             my $self = shift;
52             my $options = { @_ };
53            
54             my $current_scope = $self->get_active_scope;
55            
56             my $scope = OpenTracing::Implementation::DataDog::Scope->new(
57             span => $options->{ span },
58             finish_span_on_close => $options->{ finish_span_on_close },
59             on_close => sub {
60             $current_scope ?
61             $self->set_active_scope( $current_scope )
62             :
63             $self->final_scope() #clear
64             }
65             );
66            
67             return $scope
68             }
69              
70              
71              
72             BEGIN {
73 12     12   108 with 'OpenTracing::Role::ScopeManager';
74             }
75              
76              
77              
78             =head1 SEE ALSO
79              
80             =over
81              
82             =item L<OpenTracing::Implementation::DataDog>
83              
84             Sending traces to DataDog using Agent.
85              
86             =item L<OpenTracing::Role::ScopeManager>
87              
88             Role for OpenTracing implementations.
89              
90             =back
91              
92              
93              
94             =head1 AUTHOR
95              
96             Theo van Hoesel <tvanhoesel@perceptyx.com>
97              
98              
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             'OpenTracing::Implementation::DataDog'
103             is Copyright (C) 2019 .. 2021, Perceptyx Inc
104              
105             This library is free software; you can redistribute it and/or modify it under
106             the terms of the Artistic License 2.0.
107              
108             This package is distributed in the hope that it will be useful, but it is
109             provided "as is" and without any express or implied warranties.
110              
111             For details, see the full text of the license in the file LICENSE.
112              
113              
114             =cut
115              
116             1;