NAME

OpenTelemetry::Exporter::OTLP::Encoder::JSON - A JSON encoder for the OTLP exporter

SYNOPSIS

use OpenTelemetry::Exporter::OTLP::Encoder::JSON;

my $encoded = OpenTelemetry::Exporter::OTLP::Encoder::JSON->new
    ->encode(\@spans);

DESCRIPTION

This is an encoder class used by OpenTelemetry::Exporter::OTLP when using the "http/json" protocol. It encodes telemetry data as a JSON string complying with the 1.0.0 version of the OTLP specification.

This encoder uses JSON::MaybeXS to find a suitable JSON encoder. Please refer to the documentation of that module for details on how you can control which encoder to use.

This class is unlikely to be of use outside the OTLP exporter.

METHODS

new

$encoder = OpenTelemetry::Exporter::OTLP::Encoder::JSON->new;

Constructs a new instance of the OpenTelemetry::Exporter::OTLP::Encoder::JSON encoder. This method takes no arguments.

encode

$encoded = $encoder->encode(\@spans);

It takes a reference to a Perl data structure, and encodes it as appropriate for this encoder. In this case, it restructures the data to suit the OTLP schema, and runs it through "serialise" before returning it.

serialise

$serialised = $encoder->serialise($data);

Takes a Perl data structure and returns it as serialised data according to the format used by this encoder. For this encoder, this returns the payload as a JSON string.

content_type

$mime = $encoder->content_type;

Returns the MIME type appropriate for the encoding used by this encoder, as a value suitable to be used as the Content-Type header in an HTTP request. For this encoder, this is equal to "application/json".

SEE ALSO

OpenTelemetry::Exporter::OTLP
The OTLP specification

ACKNOWLEDGEMENTS

Special thanks to CV-Library Ltd. for their support in the development of this library.

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.