Skip to content
Source
Sign inSign up
TanStack/ai

[ai-harness] Run each operation in the context of its harness.operation span #2235

Openviclafouch(GitHub profile, opens in a new tab) opened this issue 1 comment

Version: @tanstack/ai-harness 0.4.0, @tanstack/ai 1.8.0

With createHarnessHost({ observability: { tracer } }) and otelMiddleware in the harness middleware, one turn gives two traces: the harness.operation span, and the chat <model> span tree of otelMiddleware. The harness starts its spans with tracer.startSpan and never makes one the active context (src/observability.ts, parentContext and OperationTracing.started), and the chat root span of otelMiddleware takes the active context. So the chat spans of a run are never children of its operation span, even with an AsyncLocalStorageContextManager registered.

Ask: run each operation in the context of its harness.operation span (context.with(trace.setSpan(context.active(), span), ...)), so the spans of the run nest under it, as harness/deploy.md suggests when it says a child agent run is a child span.

Today we join the two traces by adding harness.run_id from ctx.runId with attributeEnricher.

  1. tanstack-source added labelsbug

  2. Thanks for the report, @viclafouch! To help us reproduce this, could you add a minimal reproduction?

    A runnable example makes fixes dramatically faster — you can fork one of the official examples, or use StackBlitz / CodeSandbox. For TypeScript-only issues, a TS Playground link works too.

    Automated triage — a maintainer will follow up.
  3. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

Sign in to join this conversation.