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

NAME

OpenTelemetry::Trace::SpanContext - The part of an OpenTelemetry span that propagates

SYNOPSIS

    use OpenTelemetry;

    my $span = OpenTelemetry->tracer_provider->tracer->create_span(...);

    $span_context = $span->context;

    say 'Span ID:  ' . $span_context->hex_span_id;
    say 'Trace ID: ' . $span_context->hex_trace_id;

DESCRIPTION

This module represents the portion of a OpenTelemetry::Trace::Span that must be serialised and propagated as part of a distributed context. This object is immutable.

METHODS

new

    $span_context = OpenTelemetry::Trace::SpanContex->new(
        trace_flags => $trace_flags, # optional
        trace_state => $trace_state, # optional
        trace_id    => $trace_id,    # optional
        span_id     => $span_id,     # optional
        remote      => $remote // 0,
    );

Returns a new OpenTelemetry::Trace::SpanContext object. Takes a the following named parameters, all of which are optional:

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_state

An instance of OpenTelemetry::Propagator::TraceContext::TraceState carrying vendor-specific trace identification data. See that module's documentation for more details. Defaults to an empty trace state.

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.

remote

A boolean value which should be set to true if this span context was received from an external source, of false if this was locally generated. Defaults to false.

span_id

    $id = $span_context->span_id;

Returns the binary span ID that was set (or generated) at construction time.

trace_id

    $id = $span_context->trace_id;

Returns the binary trace ID that was set (or generated) at construction time.

trace_state

    $state = $span_context->trace_state;

Returns the OpenTelemetry::Propagator::TraceContext::TraceState object set (or generated) at construction time.

trace_flags

    $flags = $span_context->trace_flags;

Returns the OpenTelemetry::Propagator::TraceContext::TraceFlags object set (or generated) at construction time.

remote

    $bool = $span_context->remote;

Returns the value set at construction time, which will be true if this span context was received from an external source, or false if it was locally generated.

valid

    $bool = $span_context->valid;

Returns true if the span context's "span_id" and "trace_id" are both valid. For them to be valid, they must both have at least one non-zero byte.

hex_trace_id

    $string = $span_context->hex_trace_id;

Returns this span context's "trace_id" as a hexadecimal lowercase string.

hex_span_id

    $string = $span_context->hex_span_id;

Returns this span context's "span_id" as a hexadecimal lowercase string.

CONSTANTS

INVALID

Returns a OpenTelemetry::Trace::SpanContext object on which method calls can be made, but that can be recognised as not representing a real, valid span context.

SEE ALSO

OpenTelemetry::Trace
OpenTelemetry::Trace::Span
OpenTelemetry::Propagator::TraceContext::TraceState
OpenTelemetry::Propagator::TraceContext::TraceFlags
OpenTelemetry specification on SpanContext

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.