-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.node.ts
More file actions
50 lines (42 loc) · 1.34 KB
/
Copy pathinstrumentation.node.ts
File metadata and controls
50 lines (42 loc) · 1.34 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
import { readFileSync } from "node:fs";
import { log } from "./app/lib/console";
const globalForBoot = globalThis as typeof globalThis & { __portalBooted?: boolean };
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as {
version: string;
};
function runtimeLabel(): string {
if (process.versions.bun) {
return `Bun ${process.versions.bun} · ${process.platform} ${process.arch}`;
}
return `${process.version} · ${process.platform} ${process.arch}`;
}
function originUrl(): string {
const port = process.env.PORT ?? "3000";
return `http://localhost:${port}`;
}
export function registerNode(): void {
if (globalForBoot.__portalBooted) {
return;
}
globalForBoot.__portalBooted = true;
const origin = originUrl();
const heapMb = Math.floor(process.memoryUsage().heapUsed / 1024 / 1024);
log.ready({
boot: `${process.uptime().toFixed(2)}s`,
heap: `${heapMb.toLocaleString("en")} MB`,
name: "Portal",
origin,
pid: String(process.pid),
runtime: runtimeLabel(),
version: `v${pkg.version}`,
});
}
export function logRequestError(
error: { digest: string } & Error,
request: {
method: string;
path: string;
}
): void {
log.error(`${request.method} ${request.path}`, error);
}