embabel-agent icon indicating copy to clipboard operation
embabel-agent copied to clipboard

Feature/migration observability and fix #1561 & #1588

Open azanux opened this issue 5 months ago • 2 comments

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 -> llm spans at the work site with observe{}; parent/child nesting is intrinsic, and survives parallelism (multiple agents/actions/LLM calls, user-created threads) thanks to Micrometer's ContextSnapshot cross-thread propagation.
  • Instrumentation port: the core depends only on an AgentInstrumentation SPI, never on Micrometer directly; the module supplies the @Primary adapter, falling back to NoOpAgentInstrumentation when 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-enabled master switch: when false, no spans are produced regardless of the per-tier trace-* flags; metrics keep flowing.
  • Removes the legacy reconstruction layer (EmbabelFullObservationEventListener, EmbabelTracingObservationHandler, NonEmbabelTracingObservationHandler); the standard DefaultTracingObservationHandler now bridges spans to OpenTelemetry.
  • Privacy: capture-message-content now gates all captured content (tool args/results, RAG queries, input/output values, @Tracked args), not just the chat-model span.
  • @InternalObservabilityApi opt-in marker replaces @ApiStatus.Internal; adds embabel.agent.active_duration (compute time vs wall-clock); drops dead ObservationKeys.

Fixes

  • Closes #1588 - global tracing-enabled switch 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 nodeId fields to events.
  • Fixes #1721 - status set to TERMINATED before 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-enabled off disables all spans, and each per-tier flag disables only its own spans.
  • Privacy & termination - content is omitted when capture-message-content=false; status is TERMINATED when 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 avatar Jun 13 '26 00:06 azanux

@azanux looks like the commit is not signed, thanks

igordayen avatar Jun 13 '26 09:06 igordayen

Yeah ! Will fix copilot comments and sign the commit

azanux avatar Jun 13 '26 12:06 azanux

@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.active gauge: WAITING/PAUSED/STUCK processes 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-embabel exporter 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.

azanux avatar Jun 15 '26 17:06 azanux

WELL DONE, @azanux!

igordayen avatar Jun 15 '26 19:06 igordayen