Skip to content

Commit 4cbce18

Browse files
JPeer264claude
andcommitted
fixup! feat(cloudflare): Trace TypeSafe Jev calls in Workers AI as evaluate spans
Call TypeSafe Jev in the cloudflare-workers-send-to-sentry E2E app, so a real Workers AI binding proves that the gen_ai.evaluate span reaches Sentry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3d98a7a commit 4cbce18

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎dev-packages/e2e-tests/test-applications/cloudflare-workers-send-to-sentry/src/index.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export default {
3131
await env.AI.run('@cf/meta/llama-3.2-1b-instruct', { prompt: 'Say hi', max_tokens: 5 });
3232
return Response.json({ traceId: spanContext?.traceId });
3333
}
34+
case '/test-workers-ai-jev': {
35+
await env.AI.run('typesafe/jev', {
36+
state: 'Help! My payouts have been failing for 3 days.',
37+
questions: { is_urgent: { type: 'noul', instructions: 'Does this convey urgency?' } },
38+
});
39+
return Response.json({ traceId: spanContext?.traceId });
40+
}
3441
case '/test-span':
3542
return Response.json({ spanId: spanContext?.spanId, traceId: spanContext?.traceId });
3643
case '/test-workflow-sleep': {

‎dev-packages/e2e-tests/test-applications/cloudflare-workers-send-to-sentry/tests/send-to-sentry.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,24 @@ test('Sends a Workers AI gen_ai span to Sentry', async () => {
9393
'gen_ai.output.messages': expect.stringContaining('"role":"assistant"'),
9494
});
9595
});
96+
97+
test('Sends a Workers AI gen_ai.evaluate span for a TypeSafe Jev call to Sentry', async () => {
98+
const { traceId }: { traceId: string } = JSON.parse(await fetchFromWorker(`${workerUrl}/test-workers-ai-jev`, 200));
99+
100+
console.log(`Polling for gen_ai.evaluate span: sentry trace view ${traceTarget(traceId)}`);
101+
102+
let spanId: string | undefined;
103+
await expect
104+
.poll(() => (spanId = findSpanInTrace(traceId, 'gen_ai.evaluate')?.event_id), EVENT_POLLING_OPTIONS)
105+
.toBeDefined();
106+
107+
await expect
108+
.poll(() => fetchSpanAttributes(traceId, spanId!), EVENT_POLLING_OPTIONS)
109+
.toMatchObject({
110+
'gen_ai.operation.name': 'evaluate',
111+
'gen_ai.request.model': 'typesafe/jev',
112+
'gen_ai.response.model': expect.stringMatching(/^jev-/),
113+
'gen_ai.input.messages': expect.stringContaining('My payouts have been failing'),
114+
'gen_ai.output.messages': expect.stringContaining('"is_urgent"'),
115+
});
116+
});

0 commit comments

Comments
 (0)