The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


OpenTelemetry::Trace::TracerProvider - Provides access to OpenTelemetry Tracers


    use OpenTelemetry;

    # Read the globally set provider
    my $provider = OpenTelemetry->tracer_provider;
    my $tracer   = $provider->tracer;
    my $span     = $tracer->create_span( name => 'My span' );

    # Set a global tracer provider
    OpenTelemetry->tracer_provider = $another_provider;


As implied by its name, the tracer provider is responsible for providing access to a usable instance of OpenTelemetry::Trace::Tracer, which can in turn be used to create OpenTelemetry::Trace::Span instances to mark the scope of an operation.

The provider implemented in this package returns an instance of OpenTelemetry::Trace::Tracer which is cached internally. This behaviour can be modified by inheriting from this class and providing a different implementation of the "tracer" method described below. See "tracer_provider" in OpenTelemetry for a way to set this modified version as a globally available tracer provider.



    $provider = OpenTelemetry::Trace::TracerProvider->new

Creates a new instance of the tracer provider.


    $tracer = $trace_provider->tracer( %args )

Takes a set of named parameters, and returns a tracer that can be used to generate spans via "create_span" in OpenTelemetry::Trace::Tracer. Accepted parameters are:


A name that uniquely identifies an instrumentation scope. This can be the instrumentation library, a package name, etc. This value should be set to a non-empty string.


Specifies the version of the instrumentation scope, if one is available.


A hash reference with a set of attributes for this instrumentation scope.


The schema URL to be recorded in the emitted telemetry.

The code implemented in this package ignores all arguments and returns a OpenTelemetry::Trace::Tracer, but subclasses (most notably OpenTelemetry::SDK::Trace::TracerProvider) are free to modify this.

Callers are free to cache this tracer, which tracer providers must ensure can continue to work. In the event that the configuration of the tracer provider has changed, it is the responsibility of the provider to propagate these changes to existing tracers, or to ensure that existing tracers remain usable.

That said, callers should be aware that tracer providers may change, even in limited scopes, and while the tracer provider is responsible for looking after the tracers it has generated, they are not required (and may not be capable) to alter the functioning of tracers that have been created by other providers.

If creating the tracer is expensive, then it's the tracer provider's responsibility to cache it.


This software is copyright (c) 2023 by José Joaquín Atria.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.