refactor: reorganize imports and enhance Sentry integration

- Added missing Sentry imports in instrumentation-client and instrument modules.
- Reorganized import statements across various files for improved clarity and consistency.
- Updated Sentry initialization in the instrument module to prevent duplicate OpenTelemetry registration.
- Cleaned up unused comments and streamlined the code structure in server and API files.
This commit is contained in:
mantrakp04
2026-06-22 16:44:12 -07:00
parent 8ad5c827ff
commit 531a497fa3
12 changed files with 27 additions and 36 deletions
-4
View File
@@ -1,7 +1,3 @@
// `dist/vercel.mjs` is the tsdown-built bundle that only exists after `turbo build`.
// `api/index.ts` must import the built bundle at runtime (so Vercel traces the right
// externalized deps), but TS can't resolve it before a build. Type it from the source
// entry so the editor and the Vercel `@vercel/node` builder get full type fidelity.
declare module "*/dist/vercel.mjs" {
const app: typeof import("../src/server/vercel").default;
export default app;
-11
View File
@@ -1,14 +1,3 @@
// Vercel serverless entry for the Elysia backend.
//
// We do NOT bundle the whole backend graph here (the `@/*` and `next/*` alias
// resolution + heavy native deps are handled by tsdown). Instead this thin
// function re-exports the already-built handler bundle (`dist/vercel.mjs`,
// produced by `tsdown` during `turbo build`), and Vercel's function builder
// only has to trace the externalized native deps (prisma, sharp, bcrypt,
// oidc-provider, pg) from node_modules.
//
// All requests are routed here via the `rewrites` rule in vercel.json, so the
// Elysia app does its own routing/version-rewrite against the original URL.
import app from "../dist/vercel.mjs";
export const config = {
+1 -1
View File
@@ -2,10 +2,10 @@
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/browser/
import * as Sentry from "@sentry/browser";
import { getBrowserCompatibilityReport } from "@hexclave/shared/dist/utils/browser-compat";
import { sentryBaseConfig } from "@hexclave/shared/dist/utils/sentry";
import { nicify } from "@hexclave/shared/dist/utils/strings";
import * as Sentry from "@sentry/browser";
Sentry.init({
...sentryBaseConfig,
+2 -2
View File
@@ -1,6 +1,6 @@
import "@/polyfills";
import "./server/env-expand";
import "@/instrument";
import "@/polyfills";
import { app } from "./server/app";
import "./server/env-expand";
export default app;
+9 -3
View File
@@ -1,11 +1,11 @@
import { getEnvVariable, getNodeEnvironment } from "@hexclave/shared/dist/utils/env";
import { sentryBaseConfig } from "@hexclave/shared/dist/utils/sentry";
import { nicify } from "@hexclave/shared/dist/utils/strings";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { PrismaInstrumentation } from "@prisma/instrumentation";
import * as Sentry from "@sentry/node";
import { getEnvVariable, getNodeEnvironment } from "@hexclave/shared/dist/utils/env";
import { sentryBaseConfig } from "@hexclave/shared/dist/utils/sentry";
import { nicify } from "@hexclave/shared/dist/utils/strings";
import { initPerfStats } from "./lib/dev-perf-stats";
globalThis.global = globalThis;
@@ -47,6 +47,12 @@ export function registerBackendInstrumentation() {
Sentry.init({
...sentryBaseConfig,
// We run our own OpenTelemetry NodeSDK above (for Prisma + the dev OTLP exporter), which already
// registers the global trace/context/propagation APIs. Without this flag, @sentry/node (v10 is
// OpenTelemetry-native) tries to register them again, logging "Attempted duplicate registration
// of API: trace/propagation/context". Skipping Sentry's OTel setup lets the NodeSDK own it while
// error capture continues to work normally.
skipOpenTelemetrySetup: true,
dsn: getEnvVariable("NEXT_PUBLIC_SENTRY_DSN", ""),
enabled: getNodeEnvironment() !== "development" && !getEnvVariable("CI", ""),
beforeSend(event, hint) {
+1 -1
View File
@@ -1,4 +1,4 @@
export {};
export { };
declare global {
// RequestInit is defined as an interface by lib.dom; interface merging is the
+7 -7
View File
@@ -1,13 +1,13 @@
import { Elysia } from "elysia";
import { node } from "@elysiajs/node";
import { parseCookieHeader, requestContextALS, type RequestContext } from "@/lib/next-compat/request-context";
import { serializeSetCookie } from "@/lib/next-compat/headers";
import { createNextRequestShim } from "./next-request-shim";
import { httpMethodNames } from "@/generated/route-modules";
import { serializeSetCookie } from "@/lib/next-compat/headers";
import { NextNotFoundError } from "@/lib/next-compat/navigation";
import { matchRoute, MalformedRouteParamError } from "./registry";
import { runRequestPipeline } from "./middleware";
import { parseCookieHeader, requestContextALS, type RequestContext } from "@/lib/next-compat/request-context";
import { node } from "@elysiajs/node";
import { getEnvVariable, getNodeEnvironment } from "@hexclave/shared/dist/utils/env";
import { Elysia } from "elysia";
import { runRequestPipeline } from "./middleware";
import { createNextRequestShim } from "./next-request-shim";
import { MalformedRouteParamError, matchRoute } from "./registry";
const globalSecurityHeaders = {
"Cross-Origin-Opener-Policy": "same-origin",
+2 -2
View File
@@ -1,8 +1,8 @@
import { getEnvVariable, getNodeEnvironment } from "@hexclave/shared/dist/utils/env";
import { wait } from "@hexclave/shared/dist/utils/promises";
import apiVersions from "@/generated/api-versions.json";
import routes from "@/generated/routes.json";
import { SmartRouter } from "@/smart-router";
import { getEnvVariable, getNodeEnvironment } from "@hexclave/shared/dist/utils/env";
import { wait } from "@hexclave/shared/dist/utils/promises";
const DEV_RATE_LIMIT_MAX_REQUESTS = 100;
const DEV_RATE_LIMIT_WINDOW_MS = 10_000;
+1 -1
View File
@@ -1,5 +1,5 @@
import type { NextRequest } from "next/server";
import { NextURL } from "@/lib/next-compat/server";
import type { NextRequest } from "next/server";
type NodeRequestInit = RequestInit & {
duplex?: "half",
+2 -2
View File
@@ -1,9 +1,9 @@
import "@/polyfills";
import "./env-expand";
import "@/instrument";
import "@/polyfills";
import { getEnvVariable } from "@hexclave/shared/dist/utils/env";
import { runAsynchronously } from "@hexclave/shared/dist/utils/promises";
import { app } from "./app";
import "./env-expand";
const portPrefix = getEnvVariable("NEXT_PUBLIC_HEXCLAVE_PORT_PREFIX", "81");
const port = Number(getEnvVariable("PORT", getEnvVariable("BACKEND_PORT", `${portPrefix}02`)));
+1 -1
View File
@@ -1,5 +1,5 @@
import "@/polyfills";
import "@/instrument";
import "@/polyfills";
import { app } from "./app";
export default app;
+1 -1
View File
@@ -1,8 +1,8 @@
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
import { readFileSync } from "node:fs";
import { builtinModules } from "node:module";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
import { defineConfig, type Rolldown, type UserConfig } from "tsdown";
// @ts-expect-error - this is a workspace tsdown helper imported from source.
import { createBasePlugin } from "../../configs/tsdown/plugins.ts";