OpenTracing::AutoScope - Automagically create and close scoped spans.
MyPackage; use OpenTracing::AutoScope; sub foo { OpenTracing::AutoScope->start_guarded_span; ... }
Using the start_guarded_span class method is just a convenience around things like:
start_guarded_span
use OpenTracing::GlobalTracer qw/$TRACER/; sub foo { my $scope = $TRACER->start_active_span( 'MyPackage::foo' => { options }; my $self = shift; ... # do stuff $scope->close return $foo }
OpenTracing provides a instance method for a $tracer, called start_active_span and returns a scope object. But scope object, according to the API spec need to be closed by the programmer and it will issue a warning if not done so.
$tracer
start_active_span
But that strategy becomes very inconvenient if a programmer wants to do 'return early' or bail out half way because of some other conditions.
This being Perl, we can do better and use the feaures that would normally come on the end of scope and could use a DESTROY or DEMOLISH method. But that would still send out a warning.
DESTROY
DEMOLISH
This module will make it easy again, and a bit more. It will call close on the relevant scope it has created automagically.
close
It will also use the subroutine name as the operation name, that otherwise would be required.
Starts a scope guarded span which will automagically gets closed once the proces runs out of the current scope. And it returns nothing tp prevent programmers to explicitely close the returned scope.
It does not need an operation_name, it will default to the current subroutine name. Other than that, it accepts any or all of the options for $TRACER->start_active_span.
$TRACER->start_active_span
Theo van Hoesel <tvanhoesel@perceptyx.com>
'OpenTracing::Implementation::NoOp' is Copyright (C) 2019 .. 2020, Perceptyx Inc
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This package is distributed in the hope that it will be useful, but it is provided "as is" and without any express or implied warranties.
For details, see the full text of the license in the file LICENSE.
To install OpenTracing::AutoScope, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenTracing::AutoScope
CPAN shell
perl -MCPAN -e shell install OpenTracing::AutoScope
For more information on module installation, please visit the detailed CPAN module installation guide.