File Coverage

blib/lib/Log/Log4perl/OpenTracing.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 29 32 90.6


line stmt bran cond sub pod time code
1             package Log::Log4perl::OpenTracing;
2              
3 3     3   421201 use strict;
  3         27  
  3         88  
4 3     3   18 use warnings;
  3         6  
  3         119  
5              
6             our $VERSION = 'v0.1.2';
7              
8 3     3   1169 use Log::Log4perl::Layout::PatternLayout;
  3         32947  
  3         84  
9 3     3   1389 use OpenTracing::GlobalTracer;
  3         34063  
  3         22  
10              
11 3     3   1759 use Hash::Fold qw/flatten/;
  3         474566  
  3         23  
12              
13             our $OPENTRACING_NOOP_PLACEHOLDER_VALUE = '[ NoOp missing SpanContext ]';
14              
15             do {
16             local $Log::Log4perl::ALLOW_CODE_IN_CONFIG_FILE = 1;
17            
18             Log::Log4perl::Layout::PatternLayout::add_global_cspec(
19             O => \&get_opentracing_context_with_curlies
20             );
21             };
22              
23             sub get_opentracing_context_with_curlies {
24 1     1 0 7831 my ($layout, $message, $category, $priority, $caller_level) = @_;
25            
26 1         3 my $curlies = $layout->{curlies};
27 1 50       2 my %context = %{ get_opentracing_context() }
  1         3  
28             or return $OPENTRACING_NOOP_PLACEHOLDER_VALUE;
29            
30 1         22 return flatten( \%context )->{$curlies}
31             }
32              
33             sub get_opentracing_context {
34 2     2 0 4055 OpenTracing::GlobalTracer->get_global_tracer->inject_context( {} );
35             }
36              
37             1;