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