Jido.Otel.Tracer (Jido.Otel v1.0.0)

Copy Markdown View Source

OpenTelemetry tracer adapter for Jido.Observe.

This module implements Jido.Observe.Tracer and maps Jido span lifecycle callbacks to OpenTelemetry spans.

Summary

Types

Controls whether span_start/2 mutates process-local current span context.

Context carried from span_start/2 to stop/exception callbacks.

Functions

Finalizes a failed span, records an exception event, and marks the span as error.

Starts an OpenTelemetry span from a Jido event prefix and metadata map.

Finalizes a successful span and attaches measurements as span attributes.

Runs synchronous work inside an active OpenTelemetry span.

Types

current_span_mode()

@type current_span_mode() :: :safe | :activate_unsafe

Controls whether span_start/2 mutates process-local current span context.

:safe is OTP-safe across async boundaries and does not activate the started span as the current process span. :activate_unsafe preserves same-process activation/restore behavior.

tracer_ctx()

@type tracer_ctx() :: Jido.Otel.Tracer.Context.t()

Context carried from span_start/2 to stop/exception callbacks.

Functions

span_exception(tracer_ctx, kind, reason, stacktrace)

@spec span_exception(Jido.Observe.Tracer.tracer_ctx(), atom(), term(), list()) :: :ok

Finalizes a failed span, records an exception event, and marks the span as error.

Terminal callbacks are idempotent: first terminal call wins.

span_start(event_prefix, metadata)

Starts an OpenTelemetry span from a Jido event prefix and metadata map.

The event prefix is converted to a dot-joined span name and metadata is normalized into OpenTelemetry-compatible span attributes.

See current_span_mode/0 for current-span activation behavior.

span_stop(tracer_ctx, measurements)

Finalizes a successful span and attaches measurements as span attributes.

Terminal callbacks are idempotent: first terminal call wins.

with_span_scope(event_prefix, metadata, fun)

@spec with_span_scope(
  Jido.Observe.Tracer.event_prefix(),
  Jido.Observe.Tracer.metadata(),
  (-> result)
) :: result
when result: term()

Runs synchronous work inside an active OpenTelemetry span.

This callback is used by Jido.Observe.with_span/3 when available. Unlike async span_start/2, scoped spans intentionally activate the OTel span only for the duration of the provided function and restore the previous current span before returning.