Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Sentry #846

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ dist/
# vercel
.vercel

# Sentry Config File
.sentryclirc

# tinybird
.venv
.tinyb
Expand Down
12 changes: 11 additions & 1 deletion apps/web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ CRON_SECRET=

# Pangea - Retrieve reputation for a domain.
# Get your Pange API Key here: https://pangea.cloud/docs/admin-guide/tokens/
PANGEA_API_KEY=
PANGEA_API_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=
19 changes: 19 additions & 0 deletions apps/web/app/global-error.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

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

export default function GlobalError({ error }) {
useEffect(() => {
Sentry.captureException(error);
}, [error]);

return (
<html>
<body>
<Error />
</body>
</html>
);
}
9 changes: 9 additions & 0 deletions apps/web/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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");
}
}
3 changes: 3 additions & 0 deletions 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 } 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 @@ -155,6 +156,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
19 changes: 16 additions & 3 deletions apps/web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const { withSentryConfig } = require("@sentry/nextjs");
const { withAxiom } = require("next-axiom");

const REDIRECT_SEGMENTS = [
"pricing",
"blog",
Expand All @@ -7,17 +10,18 @@ const REDIRECT_SEGMENTS = [
"_static",
];

const { withAxiom } = require("next-axiom");

/** @type {import('next').NextConfig} */
module.exports = withAxiom({
nextConfig = withAxiom({
reactStrictMode: false,
experimental: {
serverComponentsExternalPackages: [
"@react-email/components",
"@react-email/render",
"@react-email/tailwind",
],

// The instrumentation hook is required for Sentry to work on the serverside
instrumentationHook: true,
},
webpack: (config, { webpack, isServer }) => {
if (isServer) {
Expand Down Expand Up @@ -209,3 +213,12 @@ module.exports = withAxiom({
];
},
});

module.exports = withSentryConfig(nextConfig, {
silent: false, // Can be used to suppress logs
org: "dubinc",
project: "web",
hideSourceMaps: true,
debug: true,
disableLogger: true,
});
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@radix-ui/react-hover-card": "^1.1.1",
"@react-email/components": "^0.0.14",
"@react-email/render": "^0.0.12",
"@sentry/nextjs": "8.19.0",
"@sindresorhus/slugify": "^2.2.1",
"@splinetool/react-spline": "^2.2.6",
"@splinetool/runtime": "^1.2.8",
Expand Down
6 changes: 6 additions & 0 deletions apps/web/sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
debug: false,
});
6 changes: 6 additions & 0 deletions apps/web/sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as Sentry from "@sentry/nextjs";

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
debug: false,
});
6 changes: 6 additions & 0 deletions apps/web/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as Sentry from "@sentry/nextjs";

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