Otel.API.Trace.Tracer.Noop (otel v0.2.0)

Copy Markdown View Source

No-op Tracer used when no SDK is installed (spec trace/api.md §Behavior of the API in the absence of an installed SDK, L860-L874, Status: Stable).

Spec summary (L862-L874):

  • Operations MUST have no side effects and do nothing (L862-L863).
  • start_span MUST return a non-recording Span whose SpanContext comes from the parent Context when present (L865-L866).
  • If the parent Span is already non-recording, it SHOULD be returned directly without instantiating a new Span (L867-L868). Elixir's value semantics make this equivalent to returning a fresh default struct — the caller cannot observe a difference.
  • If the parent Context contains no Span, an empty non-recording Span MUST be returned: all-zero trace_id/span_id, empty TraceState, unsampled TraceFlags (L869-L871). This is the %Otel.API.Trace.SpanContext{} default struct.

enabled?/2 returns false per spec L201-L213 (Enabled is a SHOULD API; a no-op tracer is never enabled).

Registered as the default tracer by Otel.API.Trace.TracerProvider and by the SDK tracer provider when no tracer is configured.

Public API

FunctionRole
start_span/4SDK (Noop implementation) — trace/api.md L865-L871
with_span/5SDK (Noop implementation) — no-op lifecycle
enabled?/2SDK (Noop implementation) — trace/api.md L201-L213

References

  • OTel Trace API §Behavior in absence of SDK: opentelemetry-specification/specification/trace/api.md L860-L874
  • OTel Trace API §Enabled: opentelemetry-specification/specification/trace/api.md L201-L213

Summary

Functions

SDK (Noop implementation) — enabled?/2 always false (trace/api.md §Enabled L201-L213).

SDK (Noop implementation) — start_span/4 no-op per trace/api.md §"Behavior in the absence of an installed SDK" (L860-L874).

SDK (Noop implementation) — with_span/5 no-op lifecycle.

Functions

enabled?(tracer, opts \\ [])

@spec enabled?(
  tracer :: Otel.API.Trace.Tracer.t(),
  opts :: Otel.API.Trace.Tracer.enabled_opts()
) :: boolean()

SDK (Noop implementation) — enabled?/2 always false (trace/api.md §Enabled L201-L213).

A no-op tracer is by definition not enabled — no parameters can change that answer.

start_span(ctx, tracer, name, opts)

@spec start_span(
  ctx :: Otel.API.Ctx.t(),
  tracer :: Otel.API.Trace.Tracer.t(),
  name :: String.t(),
  opts :: Otel.API.Trace.Span.start_opts()
) :: Otel.API.Trace.SpanContext.t()

SDK (Noop implementation) — start_span/4 no-op per trace/api.md §"Behavior in the absence of an installed SDK" (L860-L874).

Returns the parent's SpanContext when present (L865-L866); otherwise an empty non-recording SpanContext (L869-L871).

with_span(ctx, tracer, name, opts, fun)

@spec with_span(
  ctx :: Otel.API.Ctx.t(),
  tracer :: Otel.API.Trace.Tracer.t(),
  name :: String.t(),
  opts :: Otel.API.Trace.Span.start_opts(),
  fun :: (Otel.API.Trace.SpanContext.t() -> result)
) :: result
when result: term()

SDK (Noop implementation) — with_span/5 no-op lifecycle.

Runs fun with the (non-recording) SpanContext attached to the context. Lifecycle ownership (attach/detach) is preserved so callers observe the same context-stack behaviour as a real SDK, but no recording occurs.