Jido.Composer.OtelCtx (Jido Composer v0.6.0)

Copy Markdown View Source

Centralized OpenTelemetry context management for jido_composer.

Wraps OTel process-dictionary context save/attach/restore into safe higher-order functions with guaranteed cleanup via try/after.

All calls use apply/3 to avoid compile-time warnings when OpenTelemetry is an optional (test-only) dependency.

Summary

Functions

Attaches the given OTel context. No-op if nil or OpenTelemetry is not loaded.

Returns the current OTel context, or nil if OpenTelemetry is not loaded.

Executes fun with the given OTel context attached, then restores the previous context. If ctx is nil or OpenTelemetry is not loaded, just calls fun directly.

Functions

attach(ctx)

@spec attach(term() | nil) :: :ok

Attaches the given OTel context. No-op if nil or OpenTelemetry is not loaded.

get_current()

@spec get_current() :: term() | nil

Returns the current OTel context, or nil if OpenTelemetry is not loaded.

with_parent_context(ctx, fun)

@spec with_parent_context(term() | nil, (-> result)) :: result when result: var

Executes fun with the given OTel context attached, then restores the previous context. If ctx is nil or OpenTelemetry is not loaded, just calls fun directly.