The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

OpenTracing::AutoScope - Automagically create and close scoped spans.

SYNOPSIS

    MyPackage;
    
    use OpenTracing::AutoScope;
    
    sub foo {
        OpenTracing::AutoScope->start_guarded_span;
        
        ...
        
    }

DESCRIPTION

Using the start_guarded_span class method is just a convenience around things like:

    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.

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.

This module will make it easy again, and a bit more. It will call close on the relevant scope it has created automagically.

It will also use the subroutine name as the operation name, that otherwise would be required.

CLASS METHODS

start_guarded_span

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.

AUTHOR

Theo van Hoesel <tvanhoesel@perceptyx.com>

COPYRIGHT AND LICENSE

'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.