Otel.Trace.Status (otel v0.4.1)

Copy Markdown View Source

A Span's Status (spec trace/api.md §Set Status, Status: Stable).

A Status is a code (:unset, :ok, or :error) plus an optional description. Per spec L574 "Description MUST only be used with the Error StatusCode value" and L599-L600 "Description MUST be IGNORED for StatusCode Ok & Unset values"new/2 enforces this by discarding the description for non-:error codes. opentelemetry-erlang's opentelemetry:status/2 applies the same rule because both implementations follow the spec mandate.

Per spec L590-L592 the codes form a total order Ok > Error > Unset: setting :ok overrides prior/future attempts to set :error or :unset. That ordering is enforced at the Span level (the SetStatus call site), not by this type module.

Public API

FunctionRole
new/2Application (Convenience) — Build a Status struct

References

  • OTel Trace API §Set Status: opentelemetry-specification/specification/trace/api.md L565-L610

Summary

Types

A Span status code (spec trace/api.md L580-L588).

t()

A Span Status struct (spec trace/api.md §Set Status, L570-L575).

Functions

Application (Convenience) — Build a Status struct for Otel.Trace.Span.set_status/2.

Types

code()

@type code() :: :unset | :ok | :error

A Span status code (spec trace/api.md L580-L588).

  • :unset — default; no explicit status set.
  • :ok — the operation has been validated by the developer or operator to have completed successfully.
  • :error — the operation contains an error; pair with a description to explain.

t()

@type t() :: %Otel.Trace.Status{code: code(), description: String.t()}

A Span Status struct (spec trace/api.md §Set Status, L570-L575).

Fields:

  • code — one of :unset, :ok, :error.
  • description — human-readable message. Per spec L574 only meaningful when code == :error; for :ok / :unset the field is kept empty to honour the MUST IGNORE rule (L599-L600). An empty description is equivalent to a not-present one (spec L575).

Functions

new(opts \\ %{})

@spec new(opts :: map()) :: t()

Application (Convenience) — Build a Status struct for Otel.Trace.Span.set_status/2.

Per spec L599-L600 "Description MUST be IGNORED for StatusCode Ok & Unset values" — only :error preserves description; :ok and :unset discard it.

Per spec L575 an empty description is equivalent to a not-present one, so the default "" is a natural no-description sentinel.