NAME

OpenTelemetry::SDK::Exporter::Console - An OpenTelemetry span exporter that prints to the console

SYNOPSIS

BEGIN { $ENV{OTEL_TRACES_EXPORTER} = 'console' }
use OpenTelemetry::SDK;

# Exported spans will be printed to the console

# Or set it manually
OpenTelemetry->tracer_provider->add_span_processor(
    OpenTelemetry::SDK::Trace::Span::Processor::Simple->new(
        OpenTelemetry::SDK::Exporter::Console->new
    ),
);

DESCRIPTION

This module provide a span exporter that prints exported spans to the console. It is unlikely this will be used in production environments, but it may be useful during development.

METHODS

This class implements the OpenTelemetry::Exporter role. Please consult that module's documentation for details on the behaviours it provides.

new

$exporter = OpenTelemetry::SDK::Exporter::Console->new(
    handle  => $handle     // *STDERR,
    encoder => sub { ... } // \&Data::Dumper::Dumper || \&encode_json,
);

Create a new exporter. Takes an optional handle parameter which will be used as the target for printing. By default, this will be set to standard error.

It also takes an encoder parameter that can be set to a code reference to be used for encoding the telemetry data before printing it to the handle. The encoder will be called with a hash reference representing the nested data to export, and it should return a string serialising that data.

If no encoder is provided, the exporter will default to using "Dumper" in Data::Dumper. This default can be modified by setting the OTEL_PERL_EXPORTER_CONSOLE_FORMAT environment variable. Currently, the only supported value is json, in which case the data will be encoded with "encode" in JSON::MaybeXS.

The behaviour of the default encoder can be further configured by specifying options following a comma after the name of the encoder. These options should be a list of comma-separated key-value pairs, where the key and the value are separated with an equal sign (eg. foo=1,bar=2). Any spaces will be taken as part of the keys or values they fall into. The resulting pairs will be passed directly as arguments to "new" in JSON::MaybeXS or Data::Dumper as appropriate.

The default configuration for Data::Dumper is equivalent to setting this variable to data-dumper,Indent=0,Terse=1,Sortkeys=1. The one for JSON::MaybeXS is equivalent to setting it to json,canonical=1,utf8=1. When using a custom configuration, take note that user-provided values are added to these instead of replacing them.

As an example, this means that if you wanted to use non-canonical JSON encoding, you'd have to set the following variables:

OTEL_PERL_EXPORTER_CONSOLE_FORMAT=json,canonical=0

SEE ALSO

OpenTelemetry::Exporter
OpenTelemetry::SDK
OpenTelemetry::SDK::Trace::Span::Processor::Simple

COPYRIGHT AND LICENSE

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.