-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
37 lines (34 loc) · 1004 Bytes
/
Copy pathinstrumentation.ts
File metadata and controls
37 lines (34 loc) · 1004 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
28
29
30
31
32
33
34
35
36
37
import * as Sentry from "@sentry/nextjs"
import type { Instrumentation } from "next"
export async function register() {
// Load Sentry config for the appropriate runtime
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("./sentry.server.config")
}
if (process.env.NEXT_RUNTIME === "edge") {
await import("./sentry.edge.config")
}
}
export const onRequestError: Instrumentation.onRequestError = async (
err,
request,
context
) => {
// Forward every server-side request error to Sentry
await Sentry.captureRequestError(err, request, context)
// Also log locally for observability
const error = err as Error & { digest?: string }
console.error(
JSON.stringify({
level: "error",
source: "server-request",
message: error.message,
digest: error.digest,
path: request.path,
method: request.method,
routePath: context.routePath,
routeType: context.routeType,
timestamp: new Date().toISOString(),
})
)
}