Skip to content

Commit 68bc5b7

Browse files
committed
batch trigger external trace propagation
1 parent dd477af commit 68bc5b7

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

apps/webapp/app/routes/api.v2.tasks.batch.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ const { action, loader } = createActionApiRoute(
103103
return cachedResponse;
104104
}
105105

106-
const traceContext =
107-
traceparent && isFromWorker // If the request is from a worker, we should pass the trace context
108-
? { traceparent, tracestate }
109-
: undefined;
106+
const traceContext = isFromWorker
107+
? { traceparent, tracestate }
108+
: { external: { traceparent, tracestate } };
110109

111110
const service = new RunEngineBatchTriggerService(batchProcessingStrategy ?? undefined);
112111

apps/webapp/app/runEngine/services/batchTrigger.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type BatchProcessingOptions = z.infer<typeof BatchProcessingOptions>;
4242

4343
export type BatchTriggerTaskServiceOptions = {
4444
triggerVersion?: string;
45-
traceContext?: Record<string, string | undefined>;
45+
traceContext?: Record<string, string | undefined | Record<string, string | undefined>>;
4646
spanParentAsLink?: boolean;
4747
oneTimeUseToken?: string;
4848
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { NextResponse } from "next/server";
2+
import { tasks } from "@trigger.dev/sdk";
3+
import type { todoChat } from "@/trigger/chat";
4+
5+
export async function POST(request: Request) {
6+
const body = await request.json();
7+
8+
const handle = await tasks.batchTrigger<typeof todoChat>("todo-chat", [
9+
{
10+
payload: {
11+
input: body.input,
12+
userId: "123",
13+
},
14+
},
15+
]);
16+
17+
return NextResponse.json({ handle });
18+
}

0 commit comments

Comments
 (0)