| 1 | package OpenTracing::Any; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 6 | our $VERSION = '1.006'; # VERSION | |||||||||
| 7 | 6 | our $AUTHORITY = 'cpan:TEAM'; # AUTHORITY | |||||||||
| 8 | |||||||||||
| 9 | 6 | ▶ | no indirect; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 6 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | =encoding utf8 | ||||||||||
| 13 | |||||||||||
| 14 | =head1 NAME | ||||||||||
| 15 | |||||||||||
| 16 | OpenTracing::Any - application tracing | ||||||||||
| 17 | |||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||
| 19 | |||||||||||
| 20 | use OpenTracing::Any qw($tracer); | ||||||||||
| 21 | { | ||||||||||
| 22 | my $span = $tracer->span(operation_name => 'whatever'); | ||||||||||
| 23 | $span->add_tag(xyz => 'abc'); | ||||||||||
| 24 | sleep 3; | ||||||||||
| 25 | } | ||||||||||
| 26 | # at this point the span will be finished and have an approximate timing of ~3s | ||||||||||
| 27 | |||||||||||
| 28 | =head1 DESCRIPTION | ||||||||||
| 29 | |||||||||||
| 30 | This provides a tracer to the current package. By default it will be given the | ||||||||||
| 31 | package variable name C<< $tracer >>, but you can override this by providing a | ||||||||||
| 32 | different name: | ||||||||||
| 33 | |||||||||||
| 34 | use OpenTracing::Any qw($renamed_tracer_variable); | ||||||||||
| 35 | $renamed_tracer_variable->span(...); | ||||||||||
| 36 | |||||||||||
| 37 | See L<OpenTracing::Tracer> for more details on available methods. | ||||||||||
| 38 | |||||||||||
| 39 | See also: L<Log::Any>. | ||||||||||
| 40 | |||||||||||
| 41 | =cut | ||||||||||
| 42 | |||||||||||
| 43 | 6 | ▶ | use OpenTracing; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | 10 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||
| 46 | 10 | my ($class, @args) = @_; | |||||||||
| 47 | 10 | ▶ | die 'too many parameters when loading OpenTracing::Any - expects a single variable name' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | if @args > 1; | ||||||||||
| 49 | |||||||||||
| 50 | # Normally we'd expect the caller to provide a variable name - but if they don't, | ||||||||||
| 51 | # '$tracer' seems as good a default as any | ||||||||||
| 52 | 9 | my ($injected_variable) = (@args, '$tracer'); | |||||||||
| 53 | 9 | ▶ | my ($bare_name) = $injected_variable =~ /^\$(\w+)$/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | or die 'invalid injected variable name ' . $injected_variable; | ||||||||||
| 55 | |||||||||||
| 56 | 8 | my ($pkg) = caller; | |||||||||
| 57 | 8 | my $fully_qualified = $pkg . '::' . $bare_name; | |||||||||
| 58 | { | ||||||||||
| 59 | 6 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 60 | # This mostly does what we'd want if we're called at compiletime before any code actually tries | ||||||||||
| 61 | # to use the injected variable - but as soon as the compiler sees $SomeModule::tracer it'll happily | ||||||||||
| 62 | # tell the symbol table about it and trigger this check. Thus, it's currently disabled, and | ||||||||||
| 63 | # since Log::Any also skips the check it seems we're in good company. | ||||||||||
| 64 | # require B; | ||||||||||
| 65 | # die $pkg . ' already has a variable called ' . $injected_variable if B::svref_2object(\*$fully_qualified)->SV->$*; | ||||||||||
| 66 | 8 | *{$fully_qualified} = \(OpenTracing->global_tracer()); | |||||||||
| 67 | } | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 6 | 1; | |||||||||
| 71 | |||||||||||
| 72 | __END__ | ||||||||||