Skip to content

Commit

Permalink
feat: sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
ixahmedxi committed Jun 7, 2024
1 parent e3c0bc6 commit f85741f
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ UPSTASH_REDIS_REST_URL=<your-upstash-rest-url>
UPSTASH_REDIS_REST_TOKEN=<your-upstash-rest-token>

# Resend
RESEND_API_KEY=<your-resend-api-key>
RESEND_API_KEY=<your-resend-api-key>

# Sentry
NEXT_PUBLIC_SENTRY_DSN=<your-sentry-dsn>
SENTRY_ORG=<your-sentry-org>
SENTRY_PROJECT=<your-sentry-project>
SENTRY_AUTH_TOKEN=<your-sentry-auth-token>
6 changes: 6 additions & 0 deletions .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ jobs:
# Resend
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}

# Sentry
NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
# Resend
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}

# Sentry
NEXT_PUBLIC_SENTRY_DSN: ${{ secrets.NEXT_PUBLIC_SENTRY_DSN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
Binary file modified bun.lockb
Binary file not shown.
8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import playwright from 'eslint-plugin-playwright';
import * as regexpPlugin from 'eslint-plugin-regexp';
import pluginSecurity from 'eslint-plugin-security';
import tseslint from 'typescript-eslint';
import globals from 'globals';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -75,6 +76,11 @@ export default tseslint.config(
projectService: true,
tsconfigRootDir: __dirname,
},
globals: {
...globals.node,
...globals.browser,
...globals.es2024,
},
},
settings: {
react: {
Expand All @@ -100,6 +106,8 @@ export default tseslint.config(
{ checksVoidReturn: { attributes: false } },
],

'@typescript-eslint/dot-notation': 'off',

'@typescript-eslint/no-unnecessary-condition': [
'error',
{
Expand Down
12 changes: 11 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fileURLToPath } from 'node:url';

import createJiti from 'jiti';
import { withSentryConfig } from '@sentry/nextjs';

const jiti = createJiti(fileURLToPath(import.meta.url));

Expand All @@ -25,4 +26,13 @@ const nextConfig = {
},
};

export default nextConfig;
export default withSentryConfig(nextConfig, {
org: process.env['SENTRY_ORG'] ?? '',
project: process.env['SENTRY_PROJECT'] ?? '',
silent: !process.env['CI'],
widenClientFileUpload: true,
tunnelRoute: '/monitoring',
hideSourceMaps: true,
disableLogger: true,
automaticVercelMonitors: true,
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"db:up": "drizzle-kit up",
"dev": "next dev --turbo",
"dev": "next dev",
"email:dev": "SKIP_ENV_VALIDATION=true email dev --port 3001 --dir src/emails/templates",
"format": "pnpm format:write",
"format:check": "prettier \"**/*\" --ignore-unknown --list-different",
Expand Down Expand Up @@ -65,6 +65,7 @@
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@react-email/components": "^0.0.19",
"@sentry/nextjs": "^8.8.0",
"@t3-oss/env-nextjs": "^0.10.1",
"@tanstack/react-query": "^5.40.1",
"@trpc/client": "next",
Expand Down Expand Up @@ -131,6 +132,7 @@
"eslint-plugin-security": "^3.0.0",
"eslint-plugin-tailwindcss": "^3.17.3",
"eslint-plugin-testing-library": "^6.2.2",
"globals": "^15.4.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.5",
"markdownlint": "^0.34.0",
Expand Down
16 changes: 16 additions & 0 deletions sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { env } from '@/env';
import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn: env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 1,
debug: false,
replaysOnErrorSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
integrations: [
Sentry.replayIntegration({
maskAllText: true,
blockAllMedia: true,
}),
],
});
8 changes: 8 additions & 0 deletions sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { env } from '@/env';
import * as Sentry from '@sentry/nextjs';

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

Sentry.init({
dsn: env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 1,
debug: false,
});
19 changes: 19 additions & 0 deletions src/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 src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@ export const env = createEnv({

// Clerk
CLERK_SECRET_KEY: z.string(),

// Sentry
SENTRY_ORG: z.string(),
SENTRY_PROJECT: z.string(),
SENTRY_AUTH_TOKEN: z.string(),
},
client: {
// Clerk
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string(),

// Sentry
NEXT_PUBLIC_SENTRY_DSN: z.string().url(),
},

experimental__runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
process.env['NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY'],
NEXT_PUBLIC_SENTRY_DSN: process.env['NEXT_PUBLIC_SENTRY_DSN'],
},

skipValidation: !!process.env['SKIP_ENV_VALIDATION'],
Expand Down
9 changes: 9 additions & 0 deletions src/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');
}
}

0 comments on commit f85741f

Please sign in to comment.