#OpenTelemetry Common API Types

    This package contains data structures shared by traces, logs, metrics, resource detection, and propagation.

    #Main groups

    • Attributes: Key, Value, KeyValue
    • Trace identity: TraceId, SpanId, TraceFlags, TraceState, SpanContext
    • Instrumentation metadata: InstrumentationScope Host runtime helpers live in internal/utils; they are intentionally not part of this public common package.

    #Design notes

    • TraceId and SpanId validate byte width on construction.
    • TraceFlags keeps only the low 8 bits, matching the W3C traceparent representation.
    • TraceState stores entries in a map and can serialize to and from the HTTP tracestate header shape.
    • InstrumentationScope records the library name, version, schema URL, and scope attributes attached to emitted telemetry.

    InstrumentationScope

    pub struct InstrumentationScope {
    name : String
    version : String?
    schema_url : String?
    attributes : Array[KeyValue]
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Identifies the instrumentation library or component that produced telemetry. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScope::attributes

    Returns the scope attributes. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScope::builder

    fn InstrumentationScope::builder(name : StringView) -> InstrumentationScopeBuilder

    Starts building an instrumentation scope for the given library name. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScope::name

    fn InstrumentationScope::name(self : InstrumentationScope) -> String

    Returns the scope name. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScope::schema_url

    fn InstrumentationScope::schema_url(self : InstrumentationScope) -> String?

    Returns the optional schema URL applied to telemetry from this scope. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScope::version

    fn InstrumentationScope::version(self : InstrumentationScope) -> String?

    Returns the optional scope version. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScopeBuilder

    pub struct InstrumentationScopeBuilder {
    name : String
    version : String?
    schema_url : String?
    attributes : Array[KeyValue]
    }

    Builder for InstrumentationScope. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScopeBuilder::build

    Finishes the scope builder. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScopeBuilder::with_attributes

    Sets the attributes attached to this scope. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScopeBuilder::with_schema_url

    fn InstrumentationScopeBuilder::with_schema_url(self : InstrumentationScopeBuilder, schema_url : StringView) -> InstrumentationScopeBuilder

    Sets the schema URL attached to this scope. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    InstrumentationScopeBuilder::with_version

    Sets the instrumentation library version. Spec: https://opentelemetry.io/docs/specs/otel/common/instrumentation-scope/

    Key

    pub struct Key {
    name : String
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Shared attribute key used across traces, logs, metrics, and resources. Spec: https://opentelemetry.io/docs/specs/otel/common/#attribute
    impl Default for Key

    Key::as_string

    fn Key::as_string(self : Key) -> String

    Returns the original key name. Spec: https://opentelemetry.io/docs/specs/otel/common/#attribute

    Key::new

    fn Key::new(name : StringView) -> Key

    Creates a key from its canonical string representation. Spec: https://opentelemetry.io/docs/specs/otel/common/#attribute

    KeyValue

    pub struct KeyValue {
    key : Key
    value : Value
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Pair of attribute key and value. Spec: https://opentelemetry.io/docs/specs/otel/common/#attribute

    KeyValue::new

    fn KeyValue::new(key : StringView, value : Value) -> KeyValue

    Creates a key/value pair using a string key. Spec: https://opentelemetry.io/docs/specs/otel/common/#attribute

    SpanContext

    pub struct SpanContext {
    trace_id : TraceId
    span_id : SpanId
    trace_flags : TraceFlags
    is_remote : Bool
    trace_state : TraceState
    } derive(Eq, ToJson,
    Debug
    )

    Immutable span identity and propagation state carried in contexts, spans, logs, and links. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    SpanContext::empty

    fn SpanContext::empty() -> SpanContext

    Returns an empty invalid span context. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    SpanContext::is_remote

    fn SpanContext::is_remote(self : SpanContext) -> Bool

    Returns whether this context came from an inbound carrier. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#isremote

    SpanContext::is_sampled

    fn SpanContext::is_sampled(self : SpanContext) -> Bool

    Reports whether the sampled bit is set. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    SpanContext::is_valid

    fn SpanContext::is_valid(self : SpanContext) -> Bool

    Reports whether both trace ID and span ID are valid. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#isvalid

    SpanContext::new

    fn SpanContext::new(trace_id : TraceId, span_id : SpanId, trace_flags? : TraceFlags, is_remote? : Bool, trace_state? : TraceState) -> SpanContext

    Creates a span context with explicit trace identity, flags, and state. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    SpanContext::span_id

    fn SpanContext::span_id(self : SpanContext) -> SpanId

    Returns the span ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    SpanContext::trace_flags

    fn SpanContext::trace_flags(self : SpanContext) -> TraceFlags

    Returns the trace flags. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    SpanContext::trace_id

    fn SpanContext::trace_id(self : SpanContext) -> TraceId

    Returns the trace ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    SpanContext::trace_state

    fn SpanContext::trace_state(self : SpanContext) -> TraceState

    Returns the trace state. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    SpanContext::with_remote

    fn SpanContext::with_remote(self : SpanContext, is_remote : Bool) -> SpanContext

    Returns a copy with the remote/local marker updated. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#isremote

    SpanId

    pub struct SpanId {
    bytes : Bytes
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    8-byte span identifier. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext
    impl Default for SpanId

    SpanId::bytes

    fn SpanId::bytes(self : SpanId) -> Bytes

    Returns the raw bytes backing this span ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    SpanId::from_bytes

    fn SpanId::from_bytes(bytes : Bytes) -> SpanId?

    Creates a span ID from raw bytes when the width is correct. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    SpanId::from_hex

    fn SpanId::from_hex(hex : StringView) -> SpanId?

    Parses a 16-character hexadecimal span ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    SpanId::invalid

    fn SpanId::invalid() -> SpanId

    Returns the invalid all-zero span ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    SpanId::is_valid

    fn SpanId::is_valid(self : SpanId) -> Bool

    Reports whether this span ID has the correct width and is not all zeros. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#isvalid

    SpanId::to_hex

    fn SpanId::to_hex(self : SpanId) -> String

    Returns the lowercase hexadecimal representation of this span ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    TraceFlags

    pub struct TraceFlags {
    flags : UInt
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Low 8 bits of the W3C trace flags field. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    TraceFlags::from_hex

    fn TraceFlags::from_hex(value : StringView) -> TraceFlags?

    Parses the two-character lowercase or uppercase hex form used by traceparent. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    TraceFlags::is_sampled

    fn TraceFlags::is_sampled(self : TraceFlags) -> Bool

    Returns whether the sampled bit is set. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    TraceFlags::new

    fn TraceFlags::new(flags : UInt) -> TraceFlags

    Creates trace flags while masking away bits outside the W3C byte. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    TraceFlags::to_hex

    fn TraceFlags::to_hex(self : TraceFlags) -> String

    Serializes trace flags into the two-character lowercase hex form used by traceparent. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    TraceFlags::with_sampled

    fn TraceFlags::with_sampled(self : TraceFlags, sampled : Bool) -> TraceFlags

    Returns a copy with the sampled bit toggled. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    TraceId

    pub struct TraceId {
    bytes : Bytes
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    16-byte trace identifier. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext
    impl Default for TraceId

    TraceId::bytes

    fn TraceId::bytes(self : TraceId) -> Bytes

    Returns the raw bytes backing this trace ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    TraceId::from_bytes

    fn TraceId::from_bytes(bytes : Bytes) -> TraceId?

    Creates a trace ID from raw bytes when the width is correct. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    TraceId::from_hex

    fn TraceId::from_hex(hex : StringView) -> TraceId?

    Parses a 32-character hexadecimal trace ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    TraceId::invalid

    fn TraceId::invalid() -> TraceId

    Returns the invalid all-zero trace ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#spancontext

    TraceId::is_valid

    fn TraceId::is_valid(self : TraceId) -> Bool

    Reports whether this trace ID has the correct width and is not all zeros. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#isvalid

    TraceId::to_hex

    fn TraceId::to_hex(self : TraceId) -> String

    Returns the lowercase hexadecimal representation of this trace ID. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#retrieving-the-traceid-and-spanid

    TraceState

    pub struct TraceState {
    entries : Map[String, String]
    } derive(Eq, ToJson,
    Debug
    )

    Parsed representation of the W3C tracestate header. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    TraceState::empty

    fn TraceState::empty() -> TraceState

    Returns an empty trace state. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    TraceState::entries

    fn TraceState::entries(self : TraceState) -> Map[String, String]

    Returns a copy of all trace state entries. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    TraceState::from_header

    fn TraceState::from_header(value : StringView) -> TraceState

    Parses a tracestate header value, ignoring malformed members. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    TraceState::get

    fn TraceState::get(self : TraceState, key : StringView) -> String?

    Looks up one trace state member by key. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    TraceState::new

    fn TraceState::new(entries : Map[String, String]) -> TraceState

    Creates trace state from a full entry map. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    TraceState::set

    fn TraceState::set(self : TraceState, key : StringView, value : StringView) -> TraceState

    Returns a copy with one key updated or inserted. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    TraceState::to_header

    fn TraceState::to_header(self : TraceState) -> String?

    Serializes the trace state into a tracestate header value. Spec: https://opentelemetry.io/docs/specs/otel/trace/api/#tracestate

    Value

    pub(all) enum Value {
    Bool(Bool)
    Int64(Int64)
    Double(Double)
    String(String)
    Bytes(Bytes)
    Array(Array[Value])
    } derive(Compare, Eq, Hash, ToJson,
    Debug
    )

    Attribute value supported by this SDK implementation. Spec: https://opentelemetry.io/docs/specs/otel/common/#anyvalue

    Source Files