-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
55 lines (48 loc) · 1.66 KB
/
instrumentation.ts
File metadata and controls
55 lines (48 loc) · 1.66 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as Sentry from "@sentry/nextjs";
export async function register() {
// Bump the per-attribute length cap before Sentry's OTEL SDK reads env. The
// AI SDK stores full prompt messages and tool-call args/results as span
// attributes, which routinely exceed the 1024 default. 64 KB keeps the full
// conversation history on `ai.prompt.messages` and tool inputs/outputs so
// traces in Sentry show the whole agent interaction.
if (!process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT) {
process.env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT = "65536";
}
try {
const { register } = await import("./src/lib/evlog");
register();
} catch (error) {
console.error("Failed to register evlog during startup.", error);
}
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("./sentry.server.config");
}
if (process.env.NEXT_RUNTIME === "edge") {
await import("./sentry.edge.config");
}
}
export async function onRequestError(
...args: Parameters<typeof Sentry.captureRequestError>
): Promise<ReturnType<typeof Sentry.captureRequestError>> {
const [error, request, context] = args;
try {
const { onRequestError: evlogOnRequestError } = await import("./src/lib/evlog");
evlogOnRequestError(
error as { digest?: string } & Error,
request as {
path: string;
method: string;
headers: Record<string, string>;
},
context as {
routerKind: string;
routePath: string;
routeType: string;
renderSource: string;
},
);
} catch {
// Best-effort evlog emission must not prevent Sentry/Next.js error handling.
}
return Sentry.captureRequestError(...args);
}