NAME
OpenTelemetry::SDK::Logs::LoggerProvider - Provides access to SDK OpenTelemetry Loggers
SYNOPSIS
use OpenTelemetry;
# Read the globally set provider
my $provider = OpenTelemetry->logger_provider;
my $logger = $provider->logger;
$logger->emit_record( body => 'Reticulating splines' );
# Set a global logger provider
OpenTelemetry->logger_provider = $another_provider;
DESCRIPTION
This module provides a subclass of OpenTelemetry::Logs::LoggerProvider that can be used to generate instances of OpenTelemetry::SDK::Logs::Logger to emit log records. Unlike the API Logger, these ones can be used to emit OpenTelemetry::SDK::Logs::LogRecord to external collectors and processed.
METHODS
new
$provider = OpenTelemetry::SDK::Logs::LoggerProvider->new(
resource => $resource, # optional
);
Creates a new instance of the logger provider. See "logger_provider" in OpenTelemetry for a way to make this provider available to other parts of your application, or to retrieve the provider that has already been set.
Takes the following named parameters:
resource-
An instance of OpenTelemetry::SDK::Resource to be used as the base resource propagated by the log records emitted by the provided loggers. If none is set, a default one will be used.
logger
$logger = $logger_provider->logger( %args )
Takes a set of named parameters, and returns a logger that can be used to emit log records via "emit_record" in OpenTelemetry::Logs::Logger. Accepts the same parameters described in "logger" in OpenTelemetry::Logs::LoggerProvider:
name-
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. If not set, however, this class will set this to the name of the calling package.
version-
Specifies the version of the instrumentation scope, if one is available. If the "name" parameter described above was not set, the version of the calling package will be used if defined, as returned by "VERSION" in UNIVERSAL.
attributes-
A hash reference with a set of attributes for this instrumentation scope.
schema_url-
The schema URL to be recorded in the emitted data.
This logger provider will return an instance of OpenTelemetry::SDK::Logs::Logger configured to use the OpenTelemetry::SDK::InstrumentationScope identified by this "name" and "version", and holding the specified "attributes". The "schema_url" will be used merged into the "resource" that has been set for this provider, and the resulting OpenTelemetry::SDK::Resource will be used by the provided logger.
Loggers are identified by the combination of the "name", "version", and the "schema_url" resulting from the merge described above. The generated logger instance will be cached internally, and any combination of parameters that would result in an equivalent set will receive that same logger instance.
shutdown
$result = await $logger_provider->shutdown( $timeout // undef );
Takes an optional timeout value and returns a Future that will be done when this logger provider has completed shutting down. During this process, the "shutdown" method will be called on every log record processor registered with this provider using "add_log_record_processor", described below.
The value of the returned future will be one of the "Export Results" in OpenTelemetry::Constants. If any of the propagated calls returns a failure code, the result will be a failure. If a timeout is provided and this runs out while shutting down the processors, the result will be a timeout. In this last case, some log record processors might not be shut down.
force_flush
$result = await $logger_provider->force_flush( $timeout // undef );
Takes an optional timeout value and returns a Future that will be done when this logger provider has completed flushing. During this process, the "force_flush" method will be called on every log record processor registered with this provider using "add_log_record_processor", described below.
The value of the returned future will be one of the "Export Results" in OpenTelemetry::Constants. If any of the propagated calls returns a failure code, the result will be a failure. If a timeout is provided and this runs out while flushing the processors, the result will be a timeout. In this last case, some log record processors might not be flushed.
add_log_record_processor
$logger_provider = $logger_provider->add_log_record_processor($processor);
Takes an instance of a class that implements the OpenTelemetry::Logs::LogRecord::Processor role and registers it as a log record processor for log records created by the loggers this logger provider generates.
This method is chainable.
SEE ALSO
- Future
- OpenTelemetry::SDK::InstrumentationScope
- OpenTelemetry::SDK::Resource
- OpenTelemetry::SDK::Logs::LogRecord
- OpenTelemetry::SDK::Logs::Logger
- OpenTelemetry::Logs::Logger
- OpenTelemetry::Logs::LoggerProvider
COPYRIGHT AND LICENSE
This software is copyright (c) 2024 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.