File Coverage

blib/lib/OpenTracing/AutoScope.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 30 30 100.0


line stmt bran cond sub pod time code
1             package OpenTracing::AutoScope;
2              
3 3     3   388216 use strict;
  3         31  
  3         88  
4 3     3   16 use warnings;
  3         7  
  3         115  
5              
6             our $VERSION = '0.101.0';
7              
8              
9              
10 3     3   908 use OpenTracing::GlobalTracer;
  3         22921  
  3         18  
11              
12 3     3   1650 use Scope::Context;
  3         13205  
  3         453  
13              
14              
15             # start_guarded_span
16             #
17             # This class-method will take an optional list of key/value pairs (same as
18             # start_active_span) which should be an even sized list.
19             # If not, we asume there is a given operation name.
20             #
21             sub start_guarded_span {
22 14     14 1 65178 my $class = shift;
23 14 100       81 my $operation_name = scalar @_ % 2 ? shift : _context_sub_name( );
24 14         1030 my %options = @_;
25            
26 14         50 my $scope = OpenTracing::GlobalTracer
27             ->get_global_tracer->start_active_span( $operation_name, %options );
28            
29             # use a closure, so we can carry over $scope until the end of the scope
30             # where this coderef will be 'reaped'
31             #
32 14     14   311319017 Scope::Context->up->reap( sub { $scope->close } );
  14         45077  
33            
34             return
35 14         1260 }
36              
37              
38              
39             # _context_sub_name
40             #
41             # Returns the sub_name of our caller (caller of `start_guarded_span`)
42 5     5   16 sub _context_sub_name { Scope::Context->up->up->sub_name }
43              
44              
45              
46             1;