-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
68 lines (61 loc) · 1.87 KB
/
Copy pathinstrumentation.ts
File metadata and controls
68 lines (61 loc) · 1.87 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
56
57
58
59
60
61
62
63
64
65
66
67
68
import { buildErrorLogFields, logEvent, logPathFromUrl } from "@/lib/app-logging";
import { assertSecureProductionConfig } from "@/lib/startup-config";
type OrganelleLoggingGlobal = typeof globalThis & {
__organelleNoteRequestErrorLogged?: (digest: string) => void;
};
type RequestErrorRequest = {
method?: string;
path?: string;
url?: string;
};
type RequestErrorContext = {
routerKind?: string;
routePath?: string;
routeType?: string;
renderSource?: string;
revalidateReason?: string;
};
export async function register() {
assertSecureProductionConfig();
// Dynamic import stays inside the nodejs branch so Edge webpack never pulls postgres/`net`.
if (process.env.NEXT_RUNTIME === "nodejs") {
const { registerSystemHealthLogs } = await import("@/lib/system-health");
registerSystemHealthLogs();
}
}
export function onRequestError(
error: unknown,
request: RequestErrorRequest,
context: RequestErrorContext,
) {
const method = request.method ?? "GET";
const path = logPathFromUrl(request.path ?? request.url);
logEvent({
level: "error",
logger: "next.request",
message: `Server request error on ${method} ${path}`,
fields: {
http_method: method,
http_path: path,
http_status_code: 500,
router_kind: context.routerKind,
route_path: context.routePath,
route_type: context.routeType,
render_source: context.renderSource,
revalidate_reason: context.revalidateReason,
...buildErrorLogFields(error),
},
});
if (process.env.NEXT_RUNTIME === "nodejs") {
const digest =
error instanceof Error &&
typeof (error as Error & { digest?: string }).digest === "string"
? (error as Error & { digest?: string }).digest
: undefined;
if (digest) {
(globalThis as OrganelleLoggingGlobal).__organelleNoteRequestErrorLogged?.(
digest,
);
}
}
}