| 1 | package OpenTracing::Implementation::DataDog::ScopeManager; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | OpenTracing::Implementation::DataDog::ScopeManager - Keep track of active scopes | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | duno | ||||||||||
| 10 | |||||||||||
| 11 | =cut | ||||||||||
| 12 | |||||||||||
| 13 | our $VERSION = 'v0.30.1'; | ||||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | # with 'OpenTracing::Role::ScopeManager'; | ||||||||||
| 18 | # | ||||||||||
| 19 | # moved to the bottom, so Moo can install methods that are required | ||||||||||
| 20 | |||||||||||
| 21 | 2 | ▶ | use OpenTracing::Implementation::DataDog::Scope; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 2 | ▶ | use Types::Interface qw/ObjectDoesInterface/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 2 | ▶ | use Types::Standard qw/Maybe/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | has _active_scope => ( | ||||||||||
| 30 | is => 'rwp', | ||||||||||
| 31 | isa => Maybe[ObjectDoesInterface['OpenTracing::Role::Scope']], | ||||||||||
| 32 | reader => 'get_active_scope', | ||||||||||
| 33 | ); | ||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | sub activate_span { | ||||||||||
| 38 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
activate_span: not called CC=3 SCAR=24.8
| |||||||||||
| 39 | 0 | ▶ | my $span = shift or croak "Missing OpenTracing Span"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | my $options = { @_ }; | |||||||||
| 42 | |||||||||||
| 43 | # remove the `finish_span_on_close` option, which is for this method only! | ||||||||||
| 44 | my $finish_span_on_close = | ||||||||||
| 45 | exists( $options->{ finish_span_on_close } ) ? | ||||||||||
| 46 | !! delete $options->{ finish_span_on_close } | ||||||||||
| 47 | : !undef | ||||||||||
| 48 | 0 | ▶ | ; # use 'truthness' of param if provided, or set to 'true' otherwise | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | 0 | my $scope = $self->_build_scope( $span, | |||||||||
| 51 | finish_span_on_close => $finish_span_on_close | ||||||||||
| 52 | ); | ||||||||||
| 53 | |||||||||||
| 54 | 0 | $self->_set__active_scope( $scope ); | |||||||||
| 55 | |||||||||||
| 56 | 0 | return $scope | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | sub _build_scope { | ||||||||||
| 62 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_scope: not called CC=2 SCAR=17.9
| |||||||||||
| 63 | 0 | my $span = shift; | |||||||||
| 64 | 0 | my $options = { @_ }; | |||||||||
| 65 | |||||||||||
| 66 | # remove the `finish_span_on_close` option, which is for this method only! | ||||||||||
| 67 | my $finish_span_on_close = | ||||||||||
| 68 | exists( $options->{ finish_span_on_close } ) ? | ||||||||||
| 69 | !! delete $options->{ finish_span_on_close } | ||||||||||
| 70 | : !undef | ||||||||||
| 71 | 0 | ▶ | ; # use 'truthness' of param if provided, or set to 'true' otherwise | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | |||||||||||
| 73 | 0 | my $current_scope = $self->get_active_scope; | |||||||||
| 74 | |||||||||||
| 75 | my $scope = OpenTracing::Implementation::DataDog::Scope->new( | ||||||||||
| 76 | span => $span, | ||||||||||
| 77 | finish_span_on_close => $finish_span_on_close, | ||||||||||
| 78 | after_close => sub { | ||||||||||
| 79 | 0 | ▶ | $self->_set__active_scope( $current_scope ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 80 | } | ||||||||||
| 81 | 0 | ); | |||||||||
| 82 | |||||||||||
| 83 | 0 | return $scope | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | with 'OpenTracing::Role::ScopeManager'; | ||||||||||
| 88 | |||||||||||
| 89 | 1; | ||||||||||