OpentelemetryExGram.Propagator (ex_gram v0.65.0)

Copy Markdown View Source

Captures and attaches OpenTelemetry context across process boundaries.

This module provides helpers that allow the OTel context to survive GenServer calls, casts, and spawn/1 boundaries inside ExGram's internal pipeline.

When opentelemetry_api is not available, all functions in this module are no-ops compiled at build time, so there is zero runtime overhead.

Summary

Functions

Attaches a previously captured OpenTelemetry context to the current process.

Captures the current OpenTelemetry context from the calling process dictionary.

Spawns a new process with the current OpenTelemetry context propagated.

Functions

attach_ctx(ctx)

@spec attach_ctx(OpenTelemetry.Ctx.t() | :undefined | nil) :: :ok

Attaches a previously captured OpenTelemetry context to the current process.

This is a no-op when ctx is :undefined or nil (e.g. when no OTel context was active when capture_ctx/0 was called).

capture_ctx()

@spec capture_ctx() :: OpenTelemetry.Ctx.t()

Captures the current OpenTelemetry context from the calling process dictionary.

Returns the current OTel context, which can be passed to another process and restored with attach_ctx/1.

spawn(fun)

@spec spawn((-> any())) :: pid()

Spawns a new process with the current OpenTelemetry context propagated.

Captures the current OTel context before spawning, then attaches it inside the new process before calling fun. This ensures the spawned process inherits the active trace and span.

Example

OpentelemetryExGram.Propagator.spawn(fn ->
  do_some_traced_work()
end)