line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Adapter::OpenTracing; |
2
|
|
|
|
|
|
|
# ABSTRACT: provides Log::Any support for OpenTracing spans |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
114912
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use parent qw(Log::Any::Adapter::Base); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
61
|
no indirect; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
13
|
1
|
|
|
1
|
|
50
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=encoding utf8 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Log::Any::Adapter::OpenTracing - Log::Any support for OpenTracing spans |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use OpenTracing::DSL qw(:v1); |
24
|
|
|
|
|
|
|
use Log::Any qw($log); |
25
|
|
|
|
|
|
|
use Log::Any::Adapter qw(OpenTracing); |
26
|
|
|
|
|
|
|
trace { |
27
|
|
|
|
|
|
|
$log->info('Messages in a span should be logged'); |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
$log->info('Messages outside a span would not be logged'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This L implementation provides support for log messages attached |
34
|
|
|
|
|
|
|
to L instances. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
It's most likely to be useful in conjunction with L, |
37
|
|
|
|
|
|
|
so that you keep STDERR/file logging and augment spans whenever they are active. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
43
|
use Log::Any::Adapter::Util (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
42
|
1
|
|
|
1
|
|
13
|
use OpenTracing::Any qw($tracer); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Copied directly from Log::Any::Adapter::Stderr |
45
|
|
|
|
|
|
|
my $trace_level = Log::Any::Adapter::Util::numeric_level('trace'); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub init { |
48
|
3
|
|
|
3
|
0
|
194
|
my ($self) = @_; |
49
|
3
|
50
|
33
|
|
|
15
|
if ( exists $self->{log_level} && $self->{log_level} =~ /\D/ ) { |
50
|
0
|
|
|
|
|
0
|
my $numeric_level = Log::Any::Adapter::Util::numeric_level( $self->{log_level} ); |
51
|
0
|
0
|
|
|
|
0
|
if ( !defined($numeric_level) ) { |
52
|
0
|
|
|
|
|
0
|
require Carp; |
53
|
0
|
|
|
|
|
0
|
Carp::carp( sprintf 'Invalid log level "%s". Defaulting to "%s"', $self->{log_level}, 'trace' ); |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
0
|
$self->{log_level} = $numeric_level; |
56
|
|
|
|
|
|
|
} |
57
|
3
|
50
|
|
|
|
17
|
if ( !defined $self->{log_level} ) { |
58
|
3
|
|
|
|
|
10
|
$self->{log_level} = $trace_level; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::logging_methods() ) { |
63
|
1
|
|
|
1
|
|
313
|
no strict 'refs'; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
203
|
|
64
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($method); |
65
|
|
|
|
|
|
|
*{$method} = sub { |
66
|
3
|
|
|
3
|
|
125
|
my ( $self, $text ) = @_; |
67
|
3
|
50
|
|
|
|
10
|
return if $method_level > $self->{log_level}; |
68
|
3
|
100
|
|
|
|
12
|
return unless my $span = $tracer->current_span; |
69
|
2
|
|
|
|
|
18
|
$span->log($text); |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
foreach my $method ( Log::Any::Adapter::Util::detection_methods() ) { |
74
|
1
|
|
|
1
|
|
8
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
162
|
|
75
|
|
|
|
|
|
|
my $base = substr( $method, 3 ); |
76
|
|
|
|
|
|
|
my $method_level = Log::Any::Adapter::Util::numeric_level($base); |
77
|
|
|
|
|
|
|
*{$method} = sub { |
78
|
4
|
|
|
4
|
|
10726
|
return !!( $method_level <= $_[0]->{log_level} ); |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 AUTHOR |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Tom Molesworth C<< TEAM@cpan.org >> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 LICENSE |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Copyright Tom Molesworth 2019-2020. Licensed under the same terms as Perl itself. |
91
|
|
|
|
|
|
|
|