Skip to content

Workflow timing doesn't include streaming duration (NextJS + App Router + AI SDK) #613

Description

@chenlevy

I'm trying to create a workflow that contains tasks and stream back to the client using NextJS app router API.
The span and total workflow time I get only include the sync workflow tasks.
Is it possible to count the stream in total time?

My setup is illustrated below:

traceloop.initialize({
  appName: "builder_app",
  apiKey: process.env.TRACELOOP_API_KEY,
  disableBatch: true,
  traceloopSyncEnabled: false,
});

export const POST = 
  async (
    req: NextRequest & WithAuth,
    { params }: { params: { appId: string } },
  ) => {
    return await traceloop.withWorkflow({ name: "builder_workflow" }, async () => {

      // ...tasks before stream

      const resultStream = streamText({            
        experimental_telemetry: {
          isEnabled: true,
          functionId: "main_code_generation_stream",
        },
        messages,
        model,
        onFinish: async (result) => {

          // ...tasks after stream

        }
      }); 
      
      return Response.stream(resultStream);
  })
})
Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions