Skip to content

Fix explicit span parents in OpenTelemetry exports - #378

Open
anbuzin wants to merge 2 commits into
mainfrom
fix-otel-span-parent
Open

anbuzin wants to merge 2 commits into
mainfrom
fix-otel-span-parent

Conversation

@anbuzin

@anbuzin anbuzin commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

If you opened a span with parent= set to a live span while a different span was current, its parent_id was right, but the OpenTelemetry trace still put it under the current span. Now the export uses the live parent you pass in. If you keep the current ai.telemetry parent, a raw OpenTelemetry span in between still shows up as the exported parent.

async with ai.telemetry.span("request") as request:
    async with ai.telemetry.span("lookup"):
        async with ai.telemetry.span("progress", parent=request):
            pass  # OpenTelemetry parent: lookup before, request after

The OTel adapter deferred to the ambient OTel context for every live
framework parent. An explicit parent different from the current span
was therefore ignored in the exported tree.

Use the live parent's OTel context when it differs from the ambient
framework parent. Keep ambient OTel parenting otherwise, so user spans
can still wrap framework spans and sub-agent runs.

Cover explicit and non-current parents, raw OTel wrappers, and a mocked
sub-agent run inside a tool's own OTel span.
@anbuzin anbuzin added the fix Bug fix label Nov 20, 2026
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ai-python Ready Ready Preview, v0 Nov 20, 2026 5:21pm UTC

This branch was successfully deployed

1 active deployment
Preview — 2ebe9e45 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant