observability

Observability module for token tracking, cost estimation, and OpenTelemetry.

Observability module for token tracking, cost estimation, and OpenTelemetry.

class NoOpSpan[source]

Bases: object

Span that records nothing. Used when observability is disabled.

set_attribute(key, value)[source]

No-op: discard a span attribute.

Parameters:
Return type:

None

record_exception(exception)[source]

No-op: discard an exception record.

Parameters:

exception (Exception)

Return type:

None

is_recording()[source]

Return False, indicating the span is not active.

Return type:

bool

class TelemetryManager[source]

Bases: object

Manages OpenTelemetry tracing for orchestrator execution.

When observability.enabled=false (the default), all span creation returns NoOpSpan instances with zero overhead. When enabled, spans are emitted via the configured OTLP gRPC exporter.

enabled

Whether OTel tracing is active.

service_name

Service name for OTel resource.

endpoint

OTLP gRPC endpoint.

property enabled: bool

Whether OTel tracing is active.

span(name)[source]

Create a traced span. Returns NoOpSpan when disabled.

Parameters:

name (str) – Span name (e.g., “orchestrator.run”).

Yields:

A span object with set_attribute() and record_exception().

Return type:

Generator[NoOpSpan, None, None]

shutdown()[source]

Flush and shutdown the tracer provider.

Return type:

None

get_telemetry_manager()[source]

Get the global TelemetryManager instance.

Creates on first call. Returns cached instance on subsequent calls. Call reload_telemetry() after config changes.

Returns:

The global TelemetryManager.

Return type:

TelemetryManager

Classes

class NoOpSpan[source]

Bases: object

Span that records nothing. Used when observability is disabled.

set_attribute(key, value)[source]

No-op: discard a span attribute.

Parameters:
Return type:

None

record_exception(exception)[source]

No-op: discard an exception record.

Parameters:

exception (Exception)

Return type:

None

is_recording()[source]

Return False, indicating the span is not active.

Return type:

bool

class TelemetryManager[source]

Bases: object

Manages OpenTelemetry tracing for orchestrator execution.

When observability.enabled=false (the default), all span creation returns NoOpSpan instances with zero overhead. When enabled, spans are emitted via the configured OTLP gRPC exporter.

enabled

Whether OTel tracing is active.

service_name

Service name for OTel resource.

endpoint

OTLP gRPC endpoint.

property enabled: bool

Whether OTel tracing is active.

span(name)[source]

Create a traced span. Returns NoOpSpan when disabled.

Parameters:

name (str) – Span name (e.g., “orchestrator.run”).

Yields:

A span object with set_attribute() and record_exception().

Return type:

Generator[NoOpSpan, None, None]

shutdown()[source]

Flush and shutdown the tracer provider.

Return type:

None

Functions

get_telemetry_manager()[source]

Get the global TelemetryManager instance.

Creates on first call. Returns cached instance on subsequent calls. Call reload_telemetry() after config changes.

Returns:

The global TelemetryManager.

Return type:

TelemetryManager