line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenTracing::DSL; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
72068
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
76
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.006'; # VERSION |
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
no indirect; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
10
|
1
|
|
|
1
|
|
645
|
use utf8; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
5
|
|
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
|
1
|
|
|
1
|
|
581
|
use Syntax::Keyword::Try; |
|
1
|
|
|
|
|
2366
|
|
|
1
|
|
|
|
|
5
|
|
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
86
|
use Exporter qw(import export_to_level); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
1
|
|
502
|
use Log::Any qw($log); |
|
1
|
|
|
|
|
11779
|
|
|
1
|
|
|
|
|
4
|
|
37
|
1
|
|
|
1
|
|
2619
|
use OpenTracing::Any qw($tracer); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
40
|
|
|
|
|
|
|
v1 => [qw(trace)], |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
our @EXPORT_OK = $EXPORT_TAGS{v1}->@*; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 trace |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Takes a block of code and provides it with an L. |
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
|
|
|
|
|
|
|
sub trace(&;@) { |
63
|
1
|
|
|
1
|
1
|
95
|
my ($code, %args) = @_; |
64
|
1
|
|
50
|
|
|
9
|
$args{operation_name} //= 'unknown'; |
65
|
1
|
|
|
|
|
7
|
my $span = $tracer->span(%args); |
66
|
|
|
|
|
|
|
try { |
67
|
|
|
|
|
|
|
return $code->($span); |
68
|
|
|
|
|
|
|
} catch { |
69
|
|
|
|
|
|
|
my $err = $@; |
70
|
|
|
|
|
|
|
eval { |
71
|
|
|
|
|
|
|
$span->tag( |
72
|
|
|
|
|
|
|
error => 1, |
73
|
|
|
|
|
|
|
'operation.status' => 'failed' |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
$span->log( |
76
|
|
|
|
|
|
|
event => 'general exception', |
77
|
|
|
|
|
|
|
payload => "$err" |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
1 |
80
|
|
|
|
|
|
|
} or $log->warnf('Exception during span exception handler - %s', $@); |
81
|
|
|
|
|
|
|
die $err; |
82
|
|
|
|
|
|
|
} finally { |
83
|
|
|
|
|
|
|
undef $span |
84
|
|
|
|
|
|
|
} |
85
|
1
|
|
|
|
|
6
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |