Role/Tracer.pm

filter: Statementstmt 97.3% 74 / 76 Branchbran 81.8% 18 / 22 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 94.4% 17 / 18 Podpod 100% 3 / 3 totaltotal 91.1% 113 / 124 CC 13 SCAR 12.3
CC
13
Cov
92%
start_span
8.2
get_active_span
3.0
start_active_span
3.0
CRAP 3.4
↑ Summary Role/Scope.pm »
1 package OpenTracing::Role::Tracer;
2  
3 7 our $VERSION = 'v0.82.0';
4  
5 7 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use syntax qw/maybe/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use OpenTracing::Types qw/ScopeManager Span SpanContext is_Span is_SpanContext/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Ref::Util qw/is_plain_hashref/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Role::Declare -lax;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Types::Common::Numeric qw/PositiveOrZeroNum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use Types::Standard qw/Maybe HashRef Object Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 has scope_manager => (
17 is => 'ro',
18 isa => ScopeManager,
19 reader => 'get_scope_manager',
20 default => sub {
21 0 ▶ require 'OpenTracing::Implementation::NoOp::ScopeManager';
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 return OpenTracing::Implementation::NoOp::ScopeManager->new
23 },
24 7 );
25  
26 sub get_active_span {
27 2 ▶ my $self = shift;
Subroutine get_active_span: called CC=3 SCAR=11.0
Pod documented
28
29 2 ▶ my $scope_manager = $self->get_scope_manager
Branch: 1 branch
BranchTrueFalseTotal
my $scope_manager = $self->get_scope_manager or croak("Can't get a 'ScopeManager'") 0 2 2
30 or croak "Can't get a 'ScopeManager'";
31
32 2 ▶ my $scope = $scope_manager->get_active_scope
Branch: 1 branch
BranchTrueFalseTotal
my $scope = $scope_manager->get_active_scope or return 1 1 2
33 or return;
34
35 1 return $scope->get_span;
36 }
37  
38 sub start_active_span {
39 5 ▶ my $self = shift;
Subroutine start_active_span: called CC=3 SCAR=11.0
Pod documented
40 5 ▶ my $operation_name = shift
Branch: 1 branch
BranchTrueFalseTotal
my $operation_name = shift() or croak("Missing required operation_name") 0 5 5
41 or croak "Missing required operation_name";
42 5 my $opts = { @_ };
43
44 my $finish_span_on_close =
45 exists( $opts->{ finish_span_on_close } ) ?
46 !! delete $opts->{ finish_span_on_close }
47 : !undef
48 5 ▶ ; # use 'truthness' of param if provided, or set to 'true' otherwise
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'finish_span_on_close'} ? : 3 2 5
49
50 5 my $span = $self->start_span( $operation_name => %$opts );
51
52 5 my $scope_manager = $self->get_scope_manager();
53 5 my $scope = $scope_manager->activate_span( $span,
54 finish_span_on_close => $finish_span_on_close
55 );
56
57 5 return $scope
58 }
59  
60 sub start_span {
61 2 ▶ my $self = shift;
Subroutine start_span: called CC=8 SCAR=21.0
Pod documented
62
63 2 ▶ my $operation_name = shift
Branch: 1 branch
BranchTrueFalseTotal
my $operation_name = shift() or croak("Missing required operation_name") 0 2 2
64 or croak "Missing required operation_name";
65 2 my $opts = { @_ };
66
67 2 my $start_time = delete $opts->{ start_time };
68 2 my $ignore_active_span = delete $opts->{ ignore_active_span };
69 2 my $child_of = delete $opts->{ child_of };
70 2 my $tags = delete $opts->{ tags };
71
72 2 ▶ $child_of //= $self->get_active_span()
Branch: 1 branch
BranchTrueFalseTotal
unless $ignore_active_span 1 1 2
Condition33%1/3
$child_of //= $self->get_active_span
l!l&&r!l&&!r
001
MC/DC0%0/2
$child_of //= $self->get_active_span
$child_of $self->get_active_span
Truth table33%1/3
A //= B
A= $child_ofB= $self->get_active_span
ABresult
1X1
011
000
73 unless $ignore_active_span;
74
75 2 my $context;
76
77 2 ▶ $context = $child_of
Branch: 1 branch
BranchTrueFalseTotal
if is_SpanContext($child_of) 1 1 2
78 if is_SpanContext($child_of);
79
80 2 ▶ $context = $child_of->get_context
Branch: 1 branch
BranchTrueFalseTotal
if is_Span($child_of) 0 2 2
81 if is_Span($child_of);
82
83 2 ▶ $context = $context->new_clone->with_trace_id( $context->trace_id )
Branch: 1 branch
BranchTrueFalseTotal
if is_SpanContext($context) 1 1 2
84 if is_SpanContext($context);
85
86 2 ▶ $context = $self->build_context( )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context 1 1 2
87 unless defined $context;
88
89 2 my $span = $self->build_span(
90 operation_name => $operation_name,
91 context => $context,
92
93 maybe
94 child_of => $child_of,
95
96 maybe
97 start_time => $start_time,
98
99 maybe
100 tags => $tags,
101 );
102 #
103 # we should get rid of passing 'child_of' or the not exisitng 'follows_from'
104 # these are merely helpers to define 'references'.
105
106 2 return $span
107 }
108  
109 instance_method extract_context(
110 Str $carrier_format,
111 Object $carrier
112 7 ▶) :ReturnMaybe(SpanContext) {}
Subroutine BEGIN: called CC=1 SCAR=0.0
113  
114  
115 instance_method inject_context(
116 Str $carrier_format,
117 Object $carrier,
118 SpanContext $span_context
119 7 ▶) :Return(Object) {}
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121  
122 instance_method build_span (
123 Str :$operation_name,
124 SpanContext :$context,
125 Maybe[ SpanContext | Span ] :$child_of,
126 Maybe[ PositiveOrZeroNum ] :$start_time,
127 Maybe[ HashRef[Str] ] :$tags,
128 7 ▶) :Return (Span) { };
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130  
131 instance_method build_context (
132 %span_context_args,
133 ) :Return (SpanContext) {
134 ( HashRef[Str] )->assert_valid( { %span_context_args } );
135 7 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137  
138 BEGIN {
139 # use Role::Tiny::With;
140 with 'OpenTracing::Interface::Tracer'
141 7 ▶ if $ENV{OPENTRACING_INTERFACE};
Subroutine BEGIN: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"OPENTRACING_INTERFACE"} 2 5 7
142 }
143  
144  
145  
146 7 1;
↑ Summary Role/Scope.pm »