Skip to content

Commit

Permalink
Merge pull request #21 from Design-System-Project/feat/monitoring
Browse files Browse the repository at this point in the history
add integration with sentry monitoring
  • Loading branch information
tomasfrancisco authored Aug 29, 2024
2 parents ed1a63e + 5f3de14 commit 99dde7c
Show file tree
Hide file tree
Showing 9 changed files with 1,509 additions and 15 deletions.
9 changes: 9 additions & 0 deletions apps/dashboard/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ declare module '*.svg' {

export default content;
}

declare global {
namespace globalThis {
// eslint-disable-next-line no-var
var EdgeRuntime: string;
}
}

export {};
36 changes: 35 additions & 1 deletion apps/dashboard/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withSentryConfig } from '@sentry/nextjs';
import { fileURLToPath } from 'node:url';
import createJiti from 'jiti';
const jiti = createJiti(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -41,4 +42,37 @@ const nextConfig = {
typescript: { ignoreBuildErrors: true },
};

export default nextConfig;
export default withSentryConfig(nextConfig, {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

org: 'ds-pro',
project: 'javascript-nextjs',

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

// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

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

// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
tunnelRoute: '/monitoring',

// Hides source maps from generated client bundles
hideSourceMaps: true,

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

// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
});
1 change: 1 addition & 0 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@octokit/app": "^15.1.0",
"@octokit/auth-oauth-app": "^8.1.1",
"@octokit/core": "^6.1.2",
"@sentry/nextjs": "^8",
"@supabase/ssr": "^0.4.0",
"@supabase/supabase-js": "^2.45.0",
"@t3-oss/env-core": "^0.11.0",
Expand Down
29 changes: 29 additions & 0 deletions apps/dashboard/sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This file configures the initialization of Sentry on the client.
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

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

Sentry.init({
dsn: 'https://bee796b3d7d7f0364e1dc326183331f0@o4507860870299648.ingest.de.sentry.io/4507860871872592',

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
replaysOnErrorSampleRate: 1.0,

// This sets the sample rate to be 10%. You may want this to be 100% while
// in development and sample at a lower rate in production
replaysSessionSampleRate: 0.1,

// You can remove this option if you're not planning to use the Sentry Session Replay feature:
integrations: [
Sentry.replayIntegration({
// Additional Replay configuration goes in here, for example:
maskAllText: true,
blockAllMedia: true,
}),
],
});
16 changes: 16 additions & 0 deletions apps/dashboard/sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
// 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.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

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

Sentry.init({
dsn: 'https://bee796b3d7d7f0364e1dc326183331f0@o4507860870299648.ingest.de.sentry.io/4507860871872592',

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,
});
18 changes: 18 additions & 0 deletions apps/dashboard/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

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

Sentry.init({
dsn: 'https://bee796b3d7d7f0364e1dc326183331f0@o4507860870299648.ingest.de.sentry.io/4507860871872592',

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false,

// Uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: process.env.NODE_ENV === 'development',
});
28 changes: 28 additions & 0 deletions apps/dashboard/src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client';

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

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

return (
<html lang="en">
<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>
);
}
7 changes: 7 additions & 0 deletions apps/dashboard/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export async function register() {
if (typeof globalThis.EdgeRuntime !== 'string') {
await import('../sentry.server.config');
} else {
await import('../sentry.edge.config');
}
}
Loading

0 comments on commit 99dde7c

Please sign in to comment.