-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathscenario-span-streaming.mjs
More file actions
27 lines (24 loc) · 890 Bytes
/
scenario-span-streaming.mjs
File metadata and controls
27 lines (24 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as Sentry from '@sentry/node';
import { generateText } from 'ai';
import { MockLanguageModelV1 } from 'ai/test';
async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
// Single long message so truncation must crop it
const longContent = 'A'.repeat(50_000);
await generateText({
experimental_telemetry: { isEnabled: true },
model: new MockLanguageModelV1({
doGenerate: async () => ({
rawCall: { rawPrompt: null, rawSettings: {} },
finishReason: 'stop',
usage: { promptTokens: 10, completionTokens: 5 },
text: 'Response',
}),
}),
messages: [{ role: 'user', content: longContent }],
});
});
// Flush is required when span streaming is enabled to ensure streamed spans are sent before the process exits
await Sentry.flush(2000);
}
run();