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   364957 use strict;
  3         24  
  3         87  
4 3     3   15 use warnings;
  3         5  
  3         118  
5              
6             our $VERSION = 'v0.106.0';
7              
8              
9              
10 3     3   933 use OpenTracing::GlobalTracer;
  3         23550  
  3         18  
11              
12 3     3   1558 use Scope::Context;
  3         12147  
  3         428  
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 56816 my $class = shift;
23 14 100       57 my $operation_name = scalar @_ % 2 ? shift : _context_sub_name( );
24 14         905 my %options = @_;
25            
26 14         53 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   680268468 Scope::Context->up->reap( sub { $scope->close } );
  14         37105  
33            
34             return
35 14         1166 }
36              
37              
38              
39             # _context_sub_name
40             #
41             # Returns the sub_name of our caller (caller of `start_guarded_span`)
42 5     5   26 sub _context_sub_name { Scope::Context->up->up->sub_name }
43              
44              
45              
46             1;