Download frontend/src/instrumentation.ts from new-arc/vector: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/instrumentation.ts
- Command line
-
hf download hf://spaces/new-arc/vector/frontend/src/instrumentation.ts
-
curl -L -o instrumentation.ts https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/instrumentation.ts
1.01 kB
| import type { Instrumentation } from "next"; | |
| function firstHeader(value: string | string[] | undefined) { | |
| return Array.isArray(value) ? value[0] : value; | |
| } | |
| export const onRequestError: Instrumentation.onRequestError = async (error, request, context) => { | |
| if (process.env.NEXT_RUNTIME !== "nodejs") return; | |
| const { distinctIdFromCookie, getPostHogServer } = await import("@/server/posthog"); | |
| const posthog = getPostHogServer(); | |
| if (!posthog) return; | |
| const traceId = firstHeader(request.headers["x-trace-id"]); | |
| try { | |
| await posthog.captureExceptionImmediate(error, distinctIdFromCookie(firstHeader(request.headers.cookie)), { | |
| platform: "web-server", | |
| path: request.path, | |
| method: request.method, | |
| route_path: context.routePath, | |
| route_type: context.routeType, | |
| router_kind: context.routerKind, | |
| ...(traceId ? { trace_id: traceId } : {}), | |
| }); | |
| } catch (captureError) { | |
| console.error("Failed to report request error to PostHog", captureError); | |
| } | |
| }; | |