Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ packages/stripe-app/.build/*
.vscode
*.csv
*.ndjson
.vitest
.vitest

# sentry
.env.sentry-build-plugin
12 changes: 11 additions & 1 deletion apps/web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,14 @@ PAYPAL_WEBHOOK_ID=

# Stripe Integration
STRIPE_APP_SECRET_KEY_TEST=
STRIPE_APP_SECRET_KEY=
STRIPE_APP_SECRET_KEY=

# Sentry
NEXT_PUBLIC_SENTRY_DSN=

# Sentry CLI (Set these values if you want to upload source maps to Sentry)
# https://docs.sentry.io/platforms/javascript/guides/nextjs/sourcemaps/
SENTRY_URL=
SENTRY_ORG=
SENTRY_PROJECT=
SENTRY_AUTH_TOKEN=
23 changes: 23 additions & 0 deletions apps/web/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use client";

import * as Sentry from "@sentry/nextjs";
import NextError from "next/error";
import { useEffect } from "react";

export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
useEffect(() => {
Sentry.captureException(error);
}, [error]);

return (
<html>
<body>
{/* `NextError` is the default Next.js error page component. Its type
definition requires a `statusCode` prop. However, since the App Router
does not expose status codes for errors, we simply pass 0 to render a
generic error message. */}
<NextError statusCode={0} />
</body>
</html>
);
}
10 changes: 10 additions & 0 deletions apps/web/instrumentation-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file configures the initialization of Sentry on the client.

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
debug: false,
});

export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
13 changes: 13 additions & 0 deletions apps/web/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';

export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./sentry.server.config');
}

if (process.env.NEXT_RUNTIME === 'edge') {
await import('./sentry.edge.config');
}
}

export const onRequestError = Sentry.captureRequestError;
5 changes: 4 additions & 1 deletion apps/web/lib/api/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import z from "@/lib/zod";
import { capitalize, currencyFormatter } from "@dub/utils";
import * as Sentry from "@sentry/nextjs";
import { NextResponse } from "next/server";
import { ZodError } from "zod";
import { generateErrorMessage } from "zod-error";
Expand Down Expand Up @@ -122,7 +123,7 @@ export function fromZodError(error: ZodError): ErrorResponse {
}

export function handleApiError(error: any): ErrorResponse & { status: number } {
console.error("API error occurred", error.message);
console.error(error.message);

// Zod errors
if (error instanceof ZodError) {
Expand Down Expand Up @@ -159,6 +160,8 @@ export function handleApiError(error: any): ErrorResponse & { status: number } {
};
}

Sentry.captureException(error);

// Fallback
// Unhandled errors are not user-facing, so we don't expose the actual error
return {
Expand Down
24 changes: 23 additions & 1 deletion apps/web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { PrismaPlugin } = require("@prisma/nextjs-monorepo-workaround-plugin");
const { withAxiom } = require("next-axiom");
const { withSentryConfig } = require("@sentry/nextjs");

/** @type {import('next').NextConfig} */
module.exports = withAxiom({
const nextConfig = withAxiom({
reactStrictMode: false,
transpilePackages: [
"shiki",
Expand All @@ -19,6 +20,7 @@ module.exports = withAxiom({
],
...(process.env.NODE_ENV === "production" && {
esmExternals: "loose",
instrumentationHook: true,
}),
},
webpack: (config, { webpack, isServer }) => {
Expand Down Expand Up @@ -200,3 +202,23 @@ module.exports = withAxiom({
];
},
});

module.exports = withSentryConfig(nextConfig, {
org: "dubinc",
project: "web",

// Only print logs for uploading source maps in CI
silent: !process.env.CI,

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: false,

// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: true,

debug: false,

sourcemaps: {
disable: true,
},
});
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@prisma/nextjs-monorepo-workaround-plugin": "^6.0.1",
"@radix-ui/react-hover-card": "^1.1.1",
"@react-pdf/renderer": "^4.1.5",
"@sentry/nextjs": "^9.28.1",
"@sindresorhus/slugify": "^2.2.1",
"@stripe/stripe-js": "^7.3.1",
"@tanstack/react-table": "^8.17.3",
Expand Down
11 changes: 11 additions & 0 deletions apps/web/sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// The config you add here will be used whenever one of the edge features is loaded.
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
debug: false,
environment: process.env.VERCEL_ENV || process.env.NODE_ENV,
release: process.env.VERCEL_GIT_COMMIT_SHA,
});
10 changes: 10 additions & 0 deletions apps/web/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file configures the initialization of Sentry on the server.

import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
debug: false,
environment: process.env.VERCEL_ENV || process.env.NODE_ENV,
release: process.env.VERCEL_GIT_COMMIT_SHA,
});
Loading