line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OpenTracing::WrapScope; |
2
|
|
|
|
|
|
|
our $VERSION = '0.101.0'; |
3
|
6
|
|
|
6
|
|
3951667
|
use strict; |
|
6
|
|
|
|
|
61
|
|
|
6
|
|
|
|
|
192
|
|
4
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
185
|
|
5
|
6
|
|
|
6
|
|
35
|
use warnings::register; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
752
|
|
6
|
6
|
|
|
6
|
|
46
|
use B::Hooks::EndOfScope; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
59
|
|
7
|
6
|
|
|
6
|
|
503
|
use OpenTracing::GlobalTracer; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
39
|
|
8
|
6
|
|
|
6
|
|
420
|
use PerlX::Maybe; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
58
|
|
9
|
6
|
|
|
6
|
|
3047
|
use Sub::Info qw/sub_info/; |
|
6
|
|
|
|
|
41376
|
|
|
6
|
|
|
|
|
41
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
{ # transparent caller, stolen from Hook::LexWrap |
12
|
6
|
|
|
6
|
|
203
|
no warnings 'redefine'; |
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
2194
|
|
13
|
|
|
|
|
|
|
*CORE::GLOBAL::caller = sub (;$) { |
14
|
166
|
|
100
|
166
|
|
3225835225
|
my ($height) = ($_[0]||0); |
15
|
166
|
|
|
|
|
292
|
my $i=1; |
16
|
166
|
|
|
|
|
248
|
my $name_cache; |
17
|
166
|
|
|
|
|
267
|
while (1) { |
18
|
|
|
|
|
|
|
my @caller = CORE::caller() eq 'DB' |
19
|
283
|
50
|
|
|
|
1877
|
? do { package DB; CORE::caller($i++) } |
|
0
|
|
|
|
|
0
|
|
20
|
|
|
|
|
|
|
: CORE::caller($i++); |
21
|
283
|
100
|
|
|
|
792
|
return if not @caller; |
22
|
273
|
100
|
|
|
|
564
|
$caller[3] = $name_cache if $name_cache; |
23
|
273
|
100
|
|
|
|
592
|
$name_cache = $caller[0] eq __PACKAGE__ ? $caller[3] : ''; |
24
|
273
|
100
|
100
|
|
|
1010
|
next if $name_cache || $height-- != 0; |
25
|
156
|
100
|
|
|
|
827
|
return wantarray ? @_ ? @caller : @caller[0..2] : $caller[0]; |
|
|
100
|
|
|
|
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub import { |
31
|
6
|
|
|
6
|
|
71
|
my (undef, @subs) = @_; |
32
|
6
|
|
|
|
|
18
|
my $pkg = caller; |
33
|
|
|
|
|
|
|
on_scope_end { |
34
|
6
|
|
|
6
|
|
74
|
foreach my $sub (@subs) { |
35
|
15
|
|
|
|
|
37
|
install_wrapped(_qualify_sub($sub, $pkg)); |
36
|
|
|
|
|
|
|
} |
37
|
6
|
|
|
|
|
49
|
}; |
38
|
6
|
|
|
|
|
1215
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub install_wrapped { |
42
|
15
|
|
|
15
|
1
|
32
|
my ($sub) = @_; |
43
|
15
|
|
|
|
|
44
|
$sub = _qualify_sub($sub, scalar caller); |
44
|
|
|
|
|
|
|
|
45
|
15
|
50
|
|
|
|
77
|
if (not defined &$sub) { |
46
|
0
|
|
|
|
|
0
|
warnings::warn "Couldn't find sub: $sub"; |
47
|
0
|
|
|
|
|
0
|
return; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
6
|
|
|
6
|
|
56
|
no strict 'refs'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
245
|
|
51
|
6
|
|
|
6
|
|
39
|
no warnings 'redefine'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
2783
|
|
52
|
15
|
|
|
|
|
43
|
*$sub = wrapped(\&$sub); |
53
|
|
|
|
|
|
|
|
54
|
15
|
|
|
|
|
61
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub wrapped { |
58
|
15
|
|
|
15
|
1
|
28
|
my ($coderef) = @_; |
59
|
15
|
|
|
|
|
48
|
my $info = sub_info($coderef); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return sub { |
62
|
21
|
|
|
21
|
|
9982
|
my ($call_package, $call_filename, $call_line) = caller(0); |
63
|
21
|
|
|
|
|
132
|
my $call_sub = (caller(1))[3]; |
64
|
21
|
|
|
|
|
207
|
my $tracer = OpenTracing::GlobalTracer->get_global_tracer; |
65
|
|
|
|
|
|
|
my $scope = $tracer->start_active_span( |
66
|
|
|
|
|
|
|
"$info->{package}::$info->{name}", |
67
|
|
|
|
|
|
|
tags => { |
68
|
|
|
|
|
|
|
'source.subname' => $info->{name}, |
69
|
|
|
|
|
|
|
'source.file' => $info->{file}, |
70
|
|
|
|
|
|
|
'source.line' => $info->{start_line}, |
71
|
|
|
|
|
|
|
'source.package' => $info->{package}, |
72
|
21
|
|
|
|
|
367
|
maybe |
73
|
|
|
|
|
|
|
'caller.subname' => $call_sub, |
74
|
|
|
|
|
|
|
'caller.file' => $call_filename, |
75
|
|
|
|
|
|
|
'caller.line' => $call_line, |
76
|
|
|
|
|
|
|
'caller.package' => $call_package, |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
21
|
|
|
|
|
30415
|
my $result; |
81
|
21
|
|
|
|
|
50
|
my $wantarray = wantarray; # eval will have its own |
82
|
21
|
|
|
|
|
42
|
my $ok = eval { |
83
|
21
|
100
|
|
|
|
61
|
if (defined $wantarray) { |
84
|
4
|
100
|
|
|
|
22
|
$result = $wantarray ? [&$coderef] : &$coderef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
17
|
|
|
|
|
61
|
&$coderef; |
88
|
|
|
|
|
|
|
} |
89
|
20
|
|
|
|
|
8672
|
1; |
90
|
|
|
|
|
|
|
}; |
91
|
21
|
100
|
|
|
|
91
|
$scope->get_span->add_tag(error => $@) unless $ok; |
92
|
21
|
|
|
|
|
294
|
$scope->close(); |
93
|
|
|
|
|
|
|
|
94
|
21
|
100
|
|
|
|
3223
|
die $@ unless $ok; |
95
|
20
|
100
|
|
|
|
252
|
return if not defined wantarray; |
96
|
4
|
100
|
|
|
|
58
|
return wantarray ? @$result : $result; |
97
|
15
|
|
|
|
|
2432
|
}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _qualify_sub { |
101
|
30
|
|
|
30
|
|
80
|
my ($sub, $pkg) = @_; |
102
|
30
|
100
|
|
|
|
160
|
return $sub if $sub =~ /'|::/; |
103
|
15
|
|
|
|
|
112
|
return "${pkg}::$sub"; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |