File Coverage

blib/lib/OpenTelemetry/Propagator/Composite.pm
Criterion Covered Total %
statement 51 51 100.0
branch 2 2 100.0
condition 11 22 50.0
subroutine 10 10 100.0
pod 0 4 0.0
total 74 89 83.1


line stmt bran cond sub pod time code
1 1     1   263792 use Object::Pad;
  1         15609  
  1         6  
2             # ABSTRACT: A composite context propagator for OpenTelemetry
3              
4             package OpenTelemetry::Propagator::Composite;
5              
6             our $VERSION = '0.033';
7              
8 1     1   788 class OpenTelemetry::Propagator::Composite :does(OpenTelemetry::Propagator) {
  1         3  
  1         135  
9 1     1   102 use List::Util qw( uniq first );
  1         3  
  1         123  
10 1     1   539 use OpenTelemetry::Propagator::TextMap;
  1         5  
  1         65  
11 1     1   11 use OpenTelemetry::X;
  1         4  
  1         34  
12 1     1   599 use OpenTelemetry::Common ();
  1         4  
  1         1601  
13              
14             my $logger = OpenTelemetry::Common::internal_logger;
15              
16             field @injectors;
17             field @extractors;
18              
19 3     3 0 3041 sub BUILDARGS ( $, @args ) {
  3         7  
  3         9  
20 3         33 my %return = (
21             extractors => [ grep $_->can('extract'), @args ],
22             injectors => [ grep $_->can('inject'), @args ],
23             );
24              
25             $logger->warnf('No suitable propagators when constructing Composite propagator')
26             if @args
27 2   50     16 && ! @{ $return{extractors} // [] }
28 3 100 100     41 && ! @{ $return{injectors} // [] };
  1   50     13  
      66        
29              
30 3         197 %return;
31             }
32              
33             ADJUSTPARAMS ($params) {
34             @injectors = @{ delete $params->{injectors} // [] };
35             @extractors = @{ delete $params->{extractors} // [] };
36             }
37              
38             method inject (
39 1         3 $carrier,
  1         2  
40 1         1 $context = undef,
41             $setter = undef
42 1     1 0 6 ) {
  1         2  
  1         2  
43 1   33     4 $context //= OpenTelemetry::Context->current;
44 1   33     9 $setter //= OpenTelemetry::Propagator::TextMap::SETTER;
45              
46 1         5 $_->inject( $carrier, $context, $setter ) for @injectors;
47 1         11 return $self;
48             }
49              
50             method extract (
51 1         7 $carrier,
  1         1  
52 1         2 $context = undef,
53             $getter = undef
54 1     1 0 4 ) {
  1         2  
  1         2  
55 1   33     16 $context //= OpenTelemetry::Context->current;
56 1   33     12 $getter //= OpenTelemetry::Propagator::TextMap::GETTER;
57              
58 1         2 my $ctx = $context;
59 1         10 $ctx = $_->extract( $carrier, $ctx, $getter ) for @extractors;
60 1         12 return $ctx;
61             }
62              
63 1     1 0 1878 method keys () {
  1         6  
  1         2  
64 1         11 uniq map $_->keys, @injectors, @extractors
65             }
66             }