# `OpentelemetryExGram.Propagator`
[🔗](https://github.com/rockneurotiko/ex_gram/blob/0.65.0/lib/ex_gram/opentelemetry/propagator.ex#L2)

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.

# `attach_ctx`

```elixir
@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`

```elixir
@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`

```elixir
@spec spawn((-&gt; 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)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
