Sign in

    #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::compare

    InstrumentationScope::default

    InstrumentationScope::equal

    InstrumentationScope::hash

    InstrumentationScope::hash_combine

    InstrumentationScope::name

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

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

    InstrumentationScope::not_equal

    InstrumentationScope::op_ge

    InstrumentationScope::op_gt

    InstrumentationScope::op_le

    InstrumentationScope::op_lt

    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::to_json

    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::compare

    fn Key::compare(Key, Key) -> Int

    Key::default

    fn Key::default() -> Key

    Key::equal

    fn Key::equal(Key, Key) -> Bool

    Key::hash

    fn Key::hash(self : Key) -> Int

    Key::hash_combine

    fn Key::hash_combine(Key, Hasher) -> Unit

    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

    Key::not_equal

    fn Key::not_equal(x : Key, y : Key) -> Bool

    Key::op_ge

    fn Key::op_ge(x : Key, y : Key) -> Bool

    Key::op_gt

    fn Key::op_gt(x : Key, y : Key) -> Bool

    Key::op_le

    fn Key::op_le(x : Key, y : Key) -> Bool

    Key::op_lt

    fn Key::op_lt(x : Key, y : Key) -> Bool

    Key::to_json

    fn Key::to_json(Key) -> Json

    Key::to_repr

    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::compare

    fn KeyValue::compare(KeyValue, KeyValue) -> Int

    KeyValue::equal

    fn KeyValue::equal(KeyValue, KeyValue) -> Bool

    KeyValue::hash

    fn KeyValue::hash(self : KeyValue) -> Int

    KeyValue::hash_combine

    fn KeyValue::hash_combine(KeyValue, Hasher) -> Unit

    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

    KeyValue::not_equal

    fn KeyValue::not_equal(x : KeyValue, y : KeyValue) -> Bool

    KeyValue::op_ge

    fn KeyValue::op_ge(x : KeyValue, y : KeyValue) -> Bool

    KeyValue::op_gt

    fn KeyValue::op_gt(x : KeyValue, y : KeyValue) -> Bool

    KeyValue::op_le

    fn KeyValue::op_le(x : KeyValue, y : KeyValue) -> Bool

    KeyValue::op_lt

    fn KeyValue::op_lt(x : KeyValue, y : KeyValue) -> Bool

    KeyValue::to_json

    fn KeyValue::to_json(KeyValue) -> Json

    KeyValue::to_repr

    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::default

    fn SpanContext::default() -> SpanContext

    SpanContext::empty

    fn SpanContext::empty() -> SpanContext

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

    SpanContext::equal

    fn SpanContext::equal(SpanContext, SpanContext) -> Bool

    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::not_equal

    fn SpanContext::not_equal(x : SpanContext, y : SpanContext) -> Bool

    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::to_json

    fn SpanContext::to_json(SpanContext) -> Json

    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::compare

    fn SpanId::compare(SpanId, SpanId) -> Int

    SpanId::default

    fn SpanId::default() -> SpanId

    SpanId::equal

    fn SpanId::equal(SpanId, SpanId) -> Bool

    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::hash

    fn SpanId::hash(self : SpanId) -> Int

    SpanId::hash_combine

    fn SpanId::hash_combine(SpanId, Hasher) -> Unit

    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::not_equal

    fn SpanId::not_equal(x : SpanId, y : SpanId) -> Bool

    SpanId::op_ge

    fn SpanId::op_ge(x : SpanId, y : SpanId) -> Bool

    SpanId::op_gt

    fn SpanId::op_gt(x : SpanId, y : SpanId) -> Bool

    SpanId::op_le

    fn SpanId::op_le(x : SpanId, y : SpanId) -> Bool

    SpanId::op_lt

    fn SpanId::op_lt(x : SpanId, y : SpanId) -> Bool

    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

    SpanId::to_json

    fn SpanId::to_json(SpanId) -> Json

    SpanId::to_repr

    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::compare

    fn TraceFlags::compare(TraceFlags, TraceFlags) -> Int

    TraceFlags::default

    fn TraceFlags::default() -> TraceFlags

    TraceFlags::equal

    fn TraceFlags::equal(TraceFlags, TraceFlags) -> Bool

    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::hash

    fn TraceFlags::hash(self : TraceFlags) -> Int

    TraceFlags::hash_combine

    fn TraceFlags::hash_combine(TraceFlags, Hasher) -> Unit

    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::not_equal

    fn TraceFlags::not_equal(x : TraceFlags, y : TraceFlags) -> Bool

    TraceFlags::op_ge

    fn TraceFlags::op_ge(x : TraceFlags, y : TraceFlags) -> Bool

    TraceFlags::op_gt

    fn TraceFlags::op_gt(x : TraceFlags, y : TraceFlags) -> Bool

    TraceFlags::op_le

    fn TraceFlags::op_le(x : TraceFlags, y : TraceFlags) -> Bool

    TraceFlags::op_lt

    fn TraceFlags::op_lt(x : TraceFlags, y : TraceFlags) -> Bool

    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::to_json

    fn TraceFlags::to_json(TraceFlags) -> Json

    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::compare

    fn TraceId::compare(TraceId, TraceId) -> Int

    TraceId::default

    fn TraceId::default() -> TraceId

    TraceId::equal

    fn TraceId::equal(TraceId, TraceId) -> Bool

    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::hash

    fn TraceId::hash(self : TraceId) -> Int

    TraceId::hash_combine

    fn TraceId::hash_combine(TraceId, Hasher) -> Unit

    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::not_equal

    fn TraceId::not_equal(x : TraceId, y : TraceId) -> Bool

    TraceId::op_ge

    fn TraceId::op_ge(x : TraceId, y : TraceId) -> Bool

    TraceId::op_gt

    fn TraceId::op_gt(x : TraceId, y : TraceId) -> Bool

    TraceId::op_le

    fn TraceId::op_le(x : TraceId, y : TraceId) -> Bool

    TraceId::op_lt

    fn TraceId::op_lt(x : TraceId, y : TraceId) -> Bool

    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

    TraceId::to_json

    fn TraceId::to_json(TraceId) -> Json

    TraceId::to_repr

    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::default

    fn TraceState::default() -> 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::equal

    fn TraceState::equal(TraceState, TraceState) -> Bool

    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::not_equal

    fn TraceState::not_equal(x : TraceState, y : TraceState) -> Bool

    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

    TraceState::to_json

    fn TraceState::to_json(TraceState) -> Json

    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

    Value::compare

    fn Value::compare(Value, Value) -> Int

    Value::equal

    fn Value::equal(Value, Value) -> Bool

    Value::hash

    fn Value::hash(self : Value) -> Int

    Value::hash_combine

    fn Value::hash_combine(Value, Hasher) -> Unit

    Value::not_equal

    fn Value::not_equal(x : Value, y : Value) -> Bool

    Value::op_ge

    fn Value::op_ge(x : Value, y : Value) -> Bool

    Value::op_gt

    fn Value::op_gt(x : Value, y : Value) -> Bool

    Value::op_le

    fn Value::op_le(x : Value, y : Value) -> Bool

    Value::op_lt

    fn Value::op_lt(x : Value, y : Value) -> Bool

    Value::to_json

    fn Value::to_json(Value) -> Json

    Value::to_repr

    Source Files