NAME

OpenTelemetry::Propagator::TraceContext::TraceParent - Represents a TraceParent in a W3C TraceContext

SYNOPSIS

use OpenTelemetry;
use OpenTelemetry::Propagator::TraceContext::TraceParent;

my $span = OpenTelemetry->span_from_context;
my $traceparent = OpenTelemetry::Propagator::TraceContext::TraceParent
    ->from_span_context( $span->context );

my $roundtrip = OpenTelemetry::Propagator::TraceContext::TraceParent
    ->from_string( $traceparent->to_string );

DESCRIPTION

This class can be used to represent the trace parent as defined in a W3C TraceContext. It contains methods to parse traceparent header strings, as well as to generate them.

METHODS

new

$new = OpenTelemetry::Propagator::TraceContext::TraceParent->new(
    trace_id    => $trace_id,
    span_id     => $span_id,
    trace_flags => $trace_flags,
    version     => $version // 0,
);

Constructs a new trace parent from scratch. Takes the following named parameters:

span_id

An 8-byte binary ID for the span this span context should be connected to. Defaults to a new random trace ID as returned by "generate_span_id" in OpenTelemetry::Trace.

trace_id

A 16-byte binary ID for the trace this span context should be connected to. Defaults to a new random trace ID as returned by "generate_trace_id" in OpenTelemetry::Trace.

trace_flags

An instance of OpenTelemetry::Propagator::TraceContext::TraceFlags with details about the trace. See that module's documentation for more details. Defaults to an empty set of flags. =over

version

A numeric version identifier. Defaults to 0, which at the moment of writing is the only version in existence.

This raw constructor is mostly of used internally. Most commonly, a trace parent will be constructed either from the data in a OpenTelemetry::Trace::SpanContext with the from_span_context, or from a header string with "from_string". Both of these constructors are described inn more detail below.

from_span_context

$new = OpenTelemetry::Propagator::TraceContext::TraceParent->from_span_context(
    $span_context,
);

Takes a positional OpenTelemetry::Trace::SpanContext and constructs a new trace parent from the data it contains.

from_string

$new = OpenTelemetry::Propagator::TraceContext::TraceParent->from_string(
    $header_string
);

Takes a positional string, such as the one that could be found in a traceparent header. This method will parse the string and return the trace parent that string represents.

See "to_string" below for a way to generate this string.

to_string

$string = $traceparent->to_string;

Returns the trace parent stringified as defined in the W3C TraceContext format. This string is suitable to be used as the value eg. in a header for further propagation.

Passing this string to "from_string" will return an equivalent trace parent.

SEE ALSO

OpenTelemetry::Trace
OpenTelemetry::Propagator::TraceContext
OpenTelemetry::Propagator::TraceContext::TraceFlags
OpenTelemetry::Trace::SpanContext
W3C TraceContext format

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.