Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parent/child spans for ai.generateText / ai.generateText.doGenerate #4228

Closed
rgarcia opened this issue Dec 30, 2024 · 6 comments
Closed

parent/child spans for ai.generateText / ai.generateText.doGenerate #4228

rgarcia opened this issue Dec 30, 2024 · 6 comments
Labels
bug Something isn't working external

Comments

@rgarcia
Copy link

rgarcia commented Dec 30, 2024

Description

I am using the experimental_tracing option and seeing that the spans generated are all independent traces. I was expecting there to be a way to:

  1. Pass in a parent span context so that the initial ai.generateText span is a child of something else
  2. Have the other spans created by the AI SDK, ai.generateText.doGenerate + ai.toolCalls be children of the top-level ai.generateText span.

Code example

This is what's happening (three independent traces):

image

This is what I'd like (one trace with three spans):

image

AI provider

@ai-sdk/openai@latest

Additional context

No response

@rgarcia rgarcia added the bug Something isn't working label Dec 30, 2024
@lgrammel
Copy link
Collaborator

lgrammel commented Jan 6, 2025

Which observability provider are you using? spans are linked automatically

@rgarcia
Copy link
Author

rgarcia commented Jan 6, 2025

Using Braintrust. I figured out a fix: if I make a call to the otel SDK's startActiveSpan in my code surrounding the AI SDK generateText call, then the spans generated by the AI SDK get correctly nested. Doesn't seem ideal but it works for now. If you point me to any test cases related to span nesting and trace IDs (e.g. checking that they're all under the same trace ID) I could maybe try my hand at a repro

@lgrammel lgrammel added external and removed ai/core labels Jan 7, 2025
@lgrammel
Copy link
Collaborator

lgrammel commented Jan 7, 2025

Since this works with other integrations, my hunch is that this is an issue in the braintrust integration. I've informed the braintrust team.

@aphinx
Copy link

aphinx commented Jan 8, 2025

Hello from Braintrust 👋 I played around with the integration a bit today, and for me the spans do appear to be nested correctly under a single trace without having to manually start a parent span. If you can provide some sample code or more details on your tracing setup, I'd be happy to dig further.

@lgrammel
Copy link
Collaborator

lgrammel commented Jan 8, 2025

Which versions are you using (otel versions, ai sdk versions, braintrust versions if any)

@lgrammel lgrammel closed this as completed Jan 8, 2025
@lgrammel lgrammel reopened this Jan 8, 2025
@rgarcia
Copy link
Author

rgarcia commented Jan 8, 2025

Well now I'm not sure what's going on... broke it down to the bare minimum repro and can't reproduce it anymore. Was definitely seeing it at some point though (screenshot as proof ha). I'll close the issue for now.

@rgarcia rgarcia closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external
Projects
None yet
Development

No branches or pull requests

3 participants