Otel.SDK.Trace.Tracer (otel v0.2.0)

Copy Markdown View Source

SDK implementation of the Otel.API.Trace.Tracer behaviour (trace/sdk.md §Tracer L120-L228).

All configuration (sampler, id_generator, span_limits, processors, scope) is stored in the tracer tuple at creation time. No GenServer calls during span creation for performance.

All functions are safe for concurrent use, satisfying spec trace/api.md L843-L853 (Status: Stable, #4887) — "Tracer — all methods MUST be documented that implementations need to be safe for concurrent use by default."

Public API

FunctionRole
start_span/4SDK (OTel API MUST) — trace/api.md §Span Creation L378-L414
with_span/5SDK (OTel API MAY) — trace/api.md L385 closure form
enabled?/2SDK (OTel API MUST) — trace/sdk.md L223-L227

References

  • OTel Trace SDK §Tracer: opentelemetry-specification/specification/trace/sdk.md L120-L228
  • OTel Trace API §Tracer: opentelemetry-specification/specification/trace/api.md L160-L416

Summary

Functions

SDK (OTel API MUST) — Enabled (trace/sdk.md L223-L227, Status: Development).

SDK (OTel API MUST) — Span Creation (trace/api.md §Span Creation L378-L414).

SDK (OTel API MAY) — start_span + make_current + closure + end_span in one call (trace/api.md L385).

Functions

enabled?(arg, opts \\ [])

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

SDK (OTel API MUST) — Enabled (trace/sdk.md L223-L227, Status: Development).

Spec MUST: returns false when either there are no registered SpanProcessors, or TracerConfig.enabled is false. TracerConfig itself is Development-status and not yet implemented (see Otel.SDK.Trace.TracerProvider ## Deferred Development-status features); only the no-processors leg is honoured today.

start_span(ctx, arg, 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 (OTel API MUST) — Span Creation (trace/api.md §Span Creation L378-L414).

Delegates to Otel.SDK.Trace.Span.start_span/6 for the sampler/id-generator dance, then stamps tracer-resolved fields (scope, limits, processors), runs on_start/3 on every registered processor, and inserts the span into ETS storage.

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 (OTel API MAY) — start_span + make_current + closure + end_span in one call (trace/api.md L385).

Records exception attributes and sets :error status on any raised exception / thrown value / exit, then re-raises to preserve caller-side error handling. The try/catch here is the spec-mandated exception-recording contract, not error handling per code-conventions.md.