Install @sentry/nextjs
into your Next.js project:
npm install --save @sentry/nextjs
Run the Sentry Wizard and provide your GlitchTip URL:
npx @sentry/wizard --url=https://your-server-url
Following the wizard's instructions will connect your app to GlitchTip. You can verify GlitchTip is now monitoring your app by adding a link that will generate a simple error:
<button
onClick={() => {
throw Error("Generic Error Message");
}}
className={styles.card}
>
Generic Error Message
</button>
Then check your GlitchTip Issues page to see the error.
SDK options are set in two separate config files:
sentry.server.config.js
and sentry.client.config.js
(or .ts for TypeScript)
Both files may contain the same values, or be set differently.
import * as Sentry from "@sentry/nextjs";
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
Sentry.init({
dsn: SENTRY_DSN || "YOUR GLITCHTIP DSN HERE",
});
Configuration options include:
process.env.NODE_ENV
by default.You can send performance transactions to GlitchTip to monitor your app's speed. In your sentry.server.config.js
and sentry.client.config.js
files, set the tracesSampleRate
variable to a number between 0 and 1. This will determine what percentage of transactions are sent to GlitchTip.
import * as Sentry from "@sentry/nextjs";
const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN;
Sentry.init({
dsn: SENTRY_DSN || "YOUR GLITCHTIP DSN HERE",
tracesSampleRate: 0.1,
});
To support Next.js API routes, wrap the routes in your next.config.js
file as seen here.
import { withSentry } from "@sentry/nextjs";
function handler(req, res) {
res.status(200).json({ bar: "foo" });
}
export default withSentry(handler);