OpenTracing/DSL.pm

filter: Statementstmt 85.0% 34 / 40 Branchbran 0.0% 0 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 81.8% 45 / 55 CC 3 SCAR 7.3
CC
3
Cov
80%
trace
4.9
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« OpenTracing/Log.pm ↑ Summary OpenTracing/SpanProxy.pm »
1 package OpenTracing::DSL;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '1.006'; # VERSION
7 3 our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY
8  
9 3 ▶no indirect;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =encoding utf8
13  
14 =head1 NAME
15  
16 OpenTracing::DSL - application tracing
17  
18 =head1 SYNOPSIS
19  
20 use OpenTracing::DSL qw(:v1);
21  
22 trace {
23 my ($span) = @_;
24 print 'operation starts here';
25 $span->add_tag(internal_details => '...');
26 sleep 2;
27 print 'end of operation';
28 };
29  
30 =cut
31  
32 3 ▶use Syntax::Keyword::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 3 ▶use Exporter qw(import export_to_level);
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 3 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use OpenTracing::Any qw($tracer);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 3 our %EXPORT_TAGS = (
40 v1 => [qw(trace)],
41 );
42 3 our @EXPORT_OK = $EXPORT_TAGS{v1}->@*;
43  
44 =head2 trace
45  
46 Takes a block of code and provides it with an L<OpenTracing::SpanProxy>.
47  
48 trace {
49 my ($span) = @_;
50 $span->tag(
51 'extra.details' => '...'
52 );
53 } operation_name => 'your_code';
54  
55 Returns whatever your code did.
56  
57 If the block of code throws an exception, that'll cause the span to be
58 marked as an error.
59  
60 =cut
61  
62 1 ▶sub trace(&;@) {
Subroutine trace: called CC=3 SCAR=16.0
Pod documented
63 1 my ($code, %args) = @_;
64 1 ▶ $args{operation_name} //= 'unknown';
Condition50%1/2
$args{"operation_name"} //= "unknown"
l!l
01
MC/DC0%0/1
$args{"operation_name"} //= "unknown"
$args{"operation_name"}
Truth table50%1/2
A
A= $args{"operation_name"}
Aresult
11
00
65 1 my $span = $tracer->span(%args);
66 try {
67 1 return $code->($span);
68 } catch {
69 0 my $err = $@;
70 0 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $span->tag("error", 1, "operation.status", "failed"); $span->log("event", "general exception", "payload", "$err"); 1 } } or $OpenTracing::DSL::log->warnf("Exception during span exception handler - %s", $@) 0 0 0
71 0 $span->tag(
72 error => 1,
73 'operation.status' => 'failed'
74 );
75 0 $span->log(
76 event => 'general exception',
77 payload => "$err"
78 );
79 0 1
80 } or $log->warnf('Exception during span exception handler - %s', $@);
81 0 die $err;
82 } finally {
83 undef $span
84 }
85 1 }
86  
87 3 1;
88  
89 __END__
« OpenTracing/Log.pm ↑ Summary OpenTracing/SpanProxy.pm »