Skip to content

OpenTelemetry Extension

from sqlspec.extensions.otel import enable_tracing

Helper function for enabling OpenTelemetry distributed tracing spans on ObservabilityConfig. See the Observability Guide for usage examples.

Tracing Configuration Helper

enable_tracing

enable_tracing(
    *,
    base_config=None,
    tracer_provider=None,
    tracer_provider_factory=None,
    resource_attributes=None,
    enable_spans=True,
)

Return an ObservabilityConfig with OpenTelemetry spans enabled.

Parameters:

Name Type Description Default
base_config ObservabilityConfig | None

Existing observability config to extend. When omitted a new instance is created.

None
tracer_provider Any | None

Optional provider instance to reuse. Mutually exclusive with tracer_provider_factory.

None
tracer_provider_factory Callable[[], Any] | None

Callable that returns a tracer provider when spans are first used.

None
resource_attributes dict[str, Any] | None

Additional attributes to attach to every span.

None
enable_spans bool

Allow disabling spans while keeping the rest of the config.

True

Returns:

Type Description
ObservabilityConfig

ObservabilityConfig with telemetry options configured for OpenTelemetry.