Tracing Vercel AI SDK Stream Response with Braintrust #5255
Unanswered
meleksomai
asked this question in
Help
Replies: 2 comments 1 reply
-
Have you reported this w/ braintrust? Most likely the issue is on their end. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hey! That didn't work for me, so I ended up implementing our own spans. Something like this: import { streamWithContinuation } from "@/app/api/websites/utils/stream-with-continuation";
import { anthropic } from "@ai-sdk/anthropic";
import { type CoreMessage, createDataStreamResponse } from "ai";
import { initLogger, wrapAISDKModel } from "braintrust";
const logger = initLogger({
projectName: env.NEXT_PUBLIC_ENVIRONMENT_NAME,
apiKey: env.BRAINTRUST_API_KEY,
});
export const maxDuration = 250;
const model = wrapAISDKModel(anthropic("claude-3-7-sonnet-latest"));
export async function POST(req: Request) {
try {
const requestData = (await req.json()) as {
...
};
return await logger.traced(
async (span) => {
const input = {
...
};
span.log({
input,
});
return createDataStreamResponse({
onError: (error) => {
span.log({
error: {
errorMessage:
error instanceof Error ? error.message : String(error),
errorStack: error instanceof Error ? error.stack : undefined,
errorName: error instanceof Error ? error.name : undefined,
},
});
span.end();
return "An error occurred.";
},
execute: async (dataStream) => {
await streamWithContinuation({
model,
initialMessages: [...],
dataStream,
maxTokens: 8192,
maxContinuations: 3,
abortSignal: req.signal,
});
},
});
},
{
name: "...",
},
);
} catch (error) {
console.error("Error in POST /api/your-route:", error);
throw error;
}
}
Hope that helps! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We're running into an issue with Braintrust logging and streaming responses. We're using streamText and createDataStreamResponse from Vercel AI SDK with Braintrust's wrapTraced and traced approach, but only the first stream is being captured in the logs.
Here's a simplified example of what we're trying to do:
The issue seems to be that while we're wrapping the main function with wrapTraced, the individual streams within the streamText function aren't being properly traced. We've tried:
Has anyone else encountered this issue or have suggestions on how to properly trace streaming responses with Braintrust?
Thanks in advance for any help!
Beta Was this translation helpful? Give feedback.
All reactions