Feature/migration observability and fix #1561 & #1588
Summary
Reworks the observability module so span hierarchy is captured at emission time - rather than afterwards by an event listener maintaining nodeId/parent maps and timing heuristics. Also adds a single master switch to turn tracing on/off.
After studying several approaches to eliminate the concurrency issues and the stuck/unclosed spans on chat termination, direct instrumentation emerged as the only solution that is structurally correct: rebuilding hierarchy after the fact is inherently racy under parallelism - no amount of tuning the reconstruction logic fixes that. Migrating to direct instrumentation makes the core changes more substantial, but it resolves every outstanding bug at once and provides a solid foundation for the upcoming Embabel evaluation feature.
What changed
- Direct instrumentation: the core opens the
agent -> action -> tool_loop -> llmspans at the work site withobserve{}; parent/child nesting is intrinsic, and survives parallelism (multiple agents/actions/LLM calls, user-created threads) thanks to Micrometer'sContextSnapshotcross-thread propagation. - Instrumentation port: the core depends only on an
AgentInstrumentationSPI, never on Micrometer directly; the module supplies the@Primaryadapter, falling back toNoOpAgentInstrumentationwhen absent - "no module = no spans" is structural, not a flag. - Attributes live in
GlobalObservationConventions (observability module); the core carries only thin contexts - no tracing logic. - Point events (LLM/embedding invocations, RAG, ranking, planning, state transitions, lifecycle, tool calls, replanning, goal) are emitted as child spans by a small event listener - no held scope, so no leaks.
- New
embabel.agent.platform.observability.tracing-enabledmaster switch: whenfalse, no spans are produced regardless of the per-tiertrace-*flags; metrics keep flowing. - Removes the legacy reconstruction layer (
EmbabelFullObservationEventListener,EmbabelTracingObservationHandler,NonEmbabelTracingObservationHandler); the standardDefaultTracingObservationHandlernow bridges spans to OpenTelemetry. - Privacy:
capture-message-contentnow gates all captured content (tool args/results, RAG queries, input/output values,@Trackedargs), not just the chat-model span. @InternalObservabilityApiopt-in marker replaces@ApiStatus.Internal; addsembabel.agent.active_duration(compute time vs wall-clock); drops deadObservationKeys.
Fixes
- Closes #1588 - global
tracing-enabledswitch instead of toggling all per-tier flags. - Closes #1561 - reliable parent/child hierarchy: it is now captured at emission and holds under heavy parallelism, instead of being reconstructed (the fragility the issue describes). Achieves the issue's goal without adding
nodeIdfields to events. - Fixes #1721 - status set to
TERMINATEDbefore termination events fire, so listeners see the correct terminal status .
Testing
All tests pass. The old reconstruction tests were replaced by simpler, focused ones:
- Parallelism (the core point of #1561) - using a real OpenTelemetry exporter, we check that:
- a child running on another thread is correctly attached to its parent span;
- a failing call closes its span and marks it as an error;
- several runs in parallel never get mixed up.
- Span tree - we run a real agent and check we get one span for the run, with the action spans nested inside it. With tracing off, no spans are created.
- Attributes - each span carries the right data (agent name, status, model, ...).
- Per-event spans - every event type (LLM call, tool call, RAG, ranking, planning, lifecycle, ...) produces its span, and its
trace-*flag turns it off. - Switches (the point of #1588) - turning
tracing-enabledoff disables all spans, and each per-tier flag disables only its own spans. - Privacy & termination - content is omitted when
capture-message-content=false; status isTERMINATEDwhen the termination event fires (#1721).
Note: this work underpins the upcoming Embabel evaluation feature: it gives a reliable, parallelism-safe execution hierarchy plus structured per-operation instrumentation that evaluation can build on to collect and analyse agent runs.
@azanux looks like the commit is not signed, thanks
Yeah ! Will fix copilot comments and sign the commit
@igordayen
Renamed the observation package to tracing. I took the opportunity to add LangSmith exporter support, fix an MDC logging bug, and do a general review pass along the way.
Migration observability.observation → observability.tracing
Renaming
- Package
observability.observation→observability.tracing(conventions, listener, filters,ObservationUtils,TrackedAspect).
Bug fixes
embabel.agent.activegauge:WAITING/PAUSED/STUCKprocesses were dropped after resume → now kept (only terminal states decrement).- Point spans:
start()/stop()are now paired to prevent span leaks on exceptions. - Unified the span attribute key and role spelling.
Additions
- LangSmith support: new
opentelemetry-exporter-embabelexporter bridges Embabel traces to LangSmith out of the box. - Cross-thread MDC + span propagation across async hops (
MdcThreadLocalAccessor, MDC & tracing registrars). - Instrumented all tool-loop transform paths via a decorator.
Tests
New tests for process resume, cross-thread MDC/tracing propagation, dropped-tier re-parenting, and tool-loop coverage.
Docs
LangSmith exporter docs + unified opentelemetry-exporter-embabel.
WELL DONE, @azanux!