| 1 | package OpenTracing::Batch; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.006'; # VERSION | |||||||||||||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use parent qw(OpenTracing::Common); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | no indirect; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =encoding utf8 | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | OpenTracing::Batch - represents a group of zero or more spans | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | A batch of spans is used for submitting results to an opentracing endpoint. | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | Once you've created a batch, take a look at L</new_span> and the L<OpenTracing::SpanProxy> | ||||||||||||||||||||
| 25 | class. | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =cut | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 1 | ▶ | use Time::HiRes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 1 | ▶ | use Scalar::Util (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 1 | ▶ | use OpenTracing::Process; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head1 METHODS | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =head2 process | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | Returns the L<OpenTracing::Process> that this batch applies to. Each batch is | ||||||||||||||||||||
| 39 | submitted from a single process. | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | sub process { shift->{process} //= OpenTracing::Process->new } | ||||||||||||||||||
|
Subroutine
process: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
+(shift())->{"process"} //= "OpenTracing::Process"->new
MC/DC0%0/2
+(shift())->{"process"} //= "OpenTracing::Process"->new
+(shift())->{"process"}
"OpenTracing::Process"->new
Truth table0%0/3
A //= B
A= +(shift())->{"process"}B= "OpenTracing::Process"->new
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =head2 spans | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | Returns an arrayref of L<OpenTracing::Span> instances. | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | sub spans { | ||||||||||||||||||
|
Subroutine
spans: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 52 | 0 | ▶ | shift->{spans} //= [] | ||||||||||||||||||
|
Condition0%0/2
+(shift())->{"spans"} //= []
MC/DC0%0/1
+(shift())->{"spans"} //= []
+(shift())->{"spans"}
Truth table0%0/2
A
A= +(shift())->{"spans"}
| |||||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =head2 span_list | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | Returns a list of L<OpenTracing::Span> instances. | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | ▶ | sub span_list { | ||||||||||||||||||
|
Subroutine
span_list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 62 | 0 | ▶ | (shift->{spans} //= [])->@* | ||||||||||||||||||
|
Condition0%0/2
+(shift())->{"spans"} //= []
MC/DC0%0/1
+(shift())->{"spans"} //= []
+(shift())->{"spans"}
Truth table0%0/2
A
A= +(shift())->{"spans"}
| |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =head2 add_span | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | Adds a new L<OpenTracing::Span> instance to this batch. | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | ▶ | sub add_span { | ||||||||||||||||||
|
Subroutine
add_span: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 72 | 0 | my ($self, $span) = @_; | |||||||||||||||||||
| 73 | 0 | push $self->{spans}->@*, $span; | |||||||||||||||||||
| 74 | 0 | Scalar::Util::weaken($span->{batch}); | |||||||||||||||||||
| 75 | 0 | $span | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =head2 new_span | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Creates a new L<OpenTracing::Span>, adds it to this batch, and returns an | ||||||||||||||||||||
| 81 | L<OpenTracing::SpanProxy> instance (which will automatically mark the end | ||||||||||||||||||||
| 82 | of the span when it's destroyed). | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | This is most likely to be the method you'll want for working with spans | ||||||||||||||||||||
| 85 | in user code. | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | sub new_span { | ||||||||||||||||||
|
Subroutine
new_span: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 90 | 0 | my ($self, $name, %args) = @_; | |||||||||||||||||||
| 91 | 0 | $args{operation_name} = $name; | |||||||||||||||||||
| 92 | 0 | ▶ | $args{start_time} //= Time::HiRes::time() * 1_000_000; | ||||||||||||||||||
|
Condition0%0/2
$args{"start_time"} //= &Time::HiRes::time() * 1000000
MC/DC0%0/1
$args{"start_time"} //= &Time::HiRes::time() * 1000000
$args{"start_time"}
Truth table0%0/2
A
A= $args{"start_time"}
| |||||||||||||||||||||
| 93 | 0 | $self->add_span( | |||||||||||||||||||
| 94 | my $span = OpenTracing::Span->new( | ||||||||||||||||||||
| 95 | batch => $self, | ||||||||||||||||||||
| 96 | %args | ||||||||||||||||||||
| 97 | ) | ||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||
| 99 | 0 | return OpenTracing::SpanProxy->new(span => $span) | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =head2 DESTROY | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | Triggers callbacks when the batch is discarded. Normally used by the transport | ||||||||||||||||||||
| 105 | mechanism to ensure that the batch is sent over to the tracing endpoint. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 110 | 0 | my ($self) = @_; | |||||||||||||||||||
| 111 | 0 | ▶ | return if ${^GLOBAL_PHASE} eq 'DESTRUCT'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | my $on_destroy = delete $self->{on_destroy} | ||||||||||||||||||||
| 113 | 0 | ▶ | or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 0 | $self->$on_destroy; | |||||||||||||||||||
| 115 | 0 | return; | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||