symfonic.observability.otel.exporter¶
exporter ¶
Factory for OTelExporter -- the single gated entry into the OTEL surface.
This module is intentionally free of opentelemetry imports at module
top level. The factory imports the OTEL-laden sibling modules
(tracer.py, callback_bridge.py, framework_bridge.py) inside
OTelExporter.build() so a disabled config never pulls OTEL into
sys.modules.
See .claude/docs/2026-05-22-otel-exporter-design.md §8 for the
lazy-import contract and §7 for the bridge-adapter rationale.
OTelExporter ¶
Public factory for the OTEL exporter handles.
Used as::
handles = OTelExporter.build(
endpoint=config.otel_endpoint,
service_name=config.otel_service_name,
capture_prompts=config.otel_capture_prompts,
)
Returns None when the SDK is not installed (the validator on
FrameworkConfig should already have rejected otel_enabled=True
in that case, but the factory keeps a belt-and-braces check for the
direct-test path).
build
staticmethod
¶
build(
*,
endpoint: str | None,
service_name: str,
capture_prompts: bool,
span_exporter: Any | None = None,
use_batch_processor: bool | None = None,
) -> OTelExporterHandles | None
Construct the tracer + bridges. Imports the OTEL surface lazily.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str | None
|
OTLP target URL or |
required |
service_name
|
str
|
|
required |
capture_prompts
|
bool
|
Privacy gate for prompt / tool args / outputs. |
required |
span_exporter
|
Any | None
|
Optional pre-built exporter for tests. When supplied, the OTLP gRPC exporter is NOT constructed. |
None
|
use_batch_processor
|
bool | None
|
Optional override; tests pass |
None
|
Returns:
| Type | Description |
|---|---|
OTelExporterHandles | None
|
|
OTelExporterHandles | None
|
could not be imported. The |
OTelExporterHandles | None
|
validator is the primary gate; this fallback exists so direct |
OTelExporterHandles | None
|
callers (tests) get a typed signal instead of an |
Source code in src/symfonic/observability/otel/exporter.py
OTelExporterHandles
dataclass
¶
OTelExporterHandles(
callback_bridge: CallbackBridge,
framework_bridge: FrameworkBridge,
tracer: OTelTracer,
)
Bundle of references the engine wires into its registration sites.
The engine prepends callback_bridge to per-invocation callback
lists, hands framework_bridge to the framework-hook dispatcher,
and keeps tracer for the start_run_span context manager plus
shutdown on agent close.
register_into ¶
Append the two bridges to their respective registration sites.
Both lists are mutated in place. The engine owns the lists, so the exporter does not need to track membership separately. Tests can verify wiring by inspecting the lists after construction.
Source code in src/symfonic/observability/otel/exporter.py
build_if_enabled ¶
Convenience wrapper: return handles when config.otel_enabled.
Used by SymfonicAgent.__init__ so the engine site stays a
single-line statement. When otel_enabled is False this function
returns None without touching any module under
symfonic.observability.otel.tracer/etc, preserving the zero-cost
invariant.