Skip to content

Commit

Permalink
Fix Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Nov 22, 2024
1 parent 24db0a6 commit 3158828
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/backend/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrismaInstrumentation } from "@prisma/instrumentation";
import * as Sentry from "@sentry/nextjs";
import { getEnvVariable, getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
import { getEnvVariable, getNextRuntime, getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
import { nicify } from "@stackframe/stack-shared/dist/utils/strings";
import { registerOTel } from '@vercel/otel';
import "./polyfills";
Expand All @@ -11,7 +11,7 @@ export function register() {
instrumentations: [new PrismaInstrumentation()],
});

if (getEnvVariable("NEXT_RUNTIME") === "nodejs" || getEnvVariable("NEXT_RUNTIME") === "edge") {
if (getNextRuntime() === "nodejs" || getNextRuntime() === "edge") {
Sentry.init({
dsn: getEnvVariable("NEXT_PUBLIC_SENTRY_DSN", ""),

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { nicify } from "@stackframe/stack-shared/dist/utils/strings";
import "./polyfills";

export function register() {
if (getEnvVariable("NEXT_RUNTIME") === "nodejs" || getEnvVariable("NEXT_RUNTIME") === "edge") {
if (getNextRuntime() === "nodejs" || getNextRuntime() === "edge") {
Sentry.init({
dsn: getEnvVariable("NEXT_PUBLIC_SENTRY_DSN", ""),

Expand Down
12 changes: 12 additions & 0 deletions packages/stack-shared/src/utils/env.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ export function getEnvVariable(name: string, defaultValue?: string | undefined):
Use process.env.XYZ directly instead.
`);
}
if (name === "NEXT_RUNTIME") {
throw new Error(deindent`
Can't use getEnvVariable to access the NEXT_RUNTIME environment variable because it's compiled into the client bundle.
Use getNextRuntime() instead.
`);
}

return ((process.env[name] || defaultValue) ?? throwErr(`Missing environment variable: ${name}`)) || (defaultValue ?? throwErr(`Empty environment variable: ${name}`));
}

export function getNextRuntime() {
// This variable is compiled into the client bundle, so we can't use getEnvVariable here.
return process.env.NEXT_RUNTIME;
}

export function getNodeEnvironment() {
return getEnvVariable("NODE_ENV", "");
}

0 comments on commit 3158828

Please sign in to comment.