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
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ RUN rm .env*
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
ARG ENV_FILE=.env

ARG SENTRY_AUTH_TOKEN
ENV SENTRY_AUTH_TOKEN=$SENTRY_AUTH_TOKEN
ARG NEXT_PUBLIC_SENTRY_DSN
ENV NEXT_PUBLIC_SENTRY_DSN=$NEXT_PUBLIC_SENTRY_DSN
#NOTE: Make sure to put the following en variable after setting up corepack
ENV NODE_ENV=production

# Sentry (SENTRY_AUTH_TOKEN, NEXT_PUBLIC_SENTRY_DSN) is not set here on purpose:
# add them to the file copied in as $ENV_FILE (e.g. .env.staging) and/or pass them
# as environment variables in the docker build job so Next/Sentry read a single source of truth.
COPY ./$ENV_FILE ./.env
RUN pnpm build

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ pnpm dev:staging
pnpm dev:production
```

## Error monitoring (Sentry)

- **Build**: provide `SENTRY_AUTH_TOKEN` and `NEXT_PUBLIC_SENTRY_DSN` via the same mechanism you use for the rest of the app (e.g. `.env` in CI, or the `ENV_FILE` used in a Docker build). The Dockerfile does **not** set Sentry variables, so they are not duplicated or overridden at the image layer; they must be present in that env when `pnpm build` runs for source map upload and a baked-in browser DSN.
- **Tuning (optional)**: `NEXT_PUBLIC_SENTRY_TRACES_SAMPLE`, `SENTRY_TRACES_SAMPLE` (server/edge), `NEXT_PUBLIC_SENTRY_REPLAY_SESSION`, `NEXT_PUBLIC_SENTRY_REPLAY_ON_ERROR`, `NEXT_PUBLIC_SENTRY_ENABLE_LOGS`, `NEXT_PUBLIC_SENTRY_CONSOLE` — see [`src/sentry/sharedOptions.ts`](./src/sentry/sharedOptions.ts).
- **Spotlight (local dev)**: set `SENTRY_SPOTLIGHT=true` only when you run [Spotlight](https://spotlightjs.com) alongside the app; otherwise it is off to avoid failed requests and noisy warnings in the server log.
- **Vercel**: this repo may disable Sentry source map upload on Vercel to avoid build timeouts; see `sourcemaps` in `next.config.mjs`.

## Tools

Most recent parts of the code rely on API generated from our backend's swagger configuration. With the backend running locally (on localhost:3001), you can generate the latest version of the API using:
Expand Down
62 changes: 29 additions & 33 deletions instrumentation-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// 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 {
Expand All @@ -11,33 +10,30 @@ import {
captureRouterTransitionStart,
} from '@sentry/nextjs';
import { isProduction } from './src/utils/isProduction';
import {
getSentryBaseOptions,
getSentryClientReplaySampleRates,
shouldSendConsoleToSentryInProduction,
} from './src/sentry/sharedOptions';
import './src/utils/instrumentation/lifiSdkConfig';

init({
enabled: !!process.env.NEXT_PUBLIC_SENTRY_DSN,
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
environment: process.env.NEXT_PUBLIC_ENVIRONMENT || 'development',

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: isProduction ? 0.1 : 1.0,
const base = getSentryBaseOptions('client');
const replay = getSentryClientReplaySampleRates();

// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: !isProduction,
const clientIntegrations = [browserTracingIntegration()];

replaysOnErrorSampleRate: 0.4,

// 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: isProduction ? 0.4 : 1.0,

// Enable logs to be sent to Sentry
enableLogs: true,
if (!isProduction || shouldSendConsoleToSentryInProduction()) {
clientIntegrations.push(
consoleLoggingIntegration({
levels: isProduction ? ['error'] : ['log', 'warn', 'error'],
}),
);
}

integrations: [
// send console.log, console.warn, and console.error calls as logs to Sentry
consoleLoggingIntegration({ levels: ['log', 'warn', 'error'] }),
browserTracingIntegration(),
],
init({
...base,
...replay,
integrations: clientIntegrations,
});

if (typeof window !== 'undefined') {
Expand All @@ -52,15 +48,15 @@ if (typeof window !== 'undefined') {
});
}

// Log Sentry initialization status
const client = getClient();
console.log('[Sentry Client] Initialized:', {
enabled: !!process.env.NEXT_PUBLIC_SENTRY_DSN,
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN
? '✓ DSN configured'
: '✗ DSN missing',
environment: process.env.NEXT_PUBLIC_ENVIRONMENT || 'development',
isClientActive: !!client,
});
if (base.debug) {
const client = getClient();

console.log('[Sentry Client] Initialized:', {
enabled: base.enabled,
dsn: base.dsn ? 'configured' : 'missing',
environment: base.environment,
isClientActive: !!client,
});
}

export const onRouterTransitionStart = captureRouterTransitionStart;
10 changes: 10 additions & 0 deletions new-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ declare namespace NodeJS {
NEXT_PUBLIC_ADDRESSABLE_TID: string;
NEXT_PUBLIC_GOOGLE_ANALYTICS_TRACKING_ID: string;
SENTRY_AUTH_TOKEN: string;
SENTRY_SPOTLIGHT?: string;
NEXT_PUBLIC_SENTRY_DSN?: string;
SENTRY_TRACES_SAMPLE?: string;
NEXT_PUBLIC_SENTRY_TRACES_SAMPLE?: string;
NEXT_PUBLIC_SENTRY_REPLAY_SESSION?: string;
NEXT_PUBLIC_SENTRY_REPLAY_ON_ERROR?: string;
NEXT_PUBLIC_SENTRY_ENABLE_LOGS?: string;
NEXT_PUBLIC_SENTRY_CONSOLE?: string;
STORYBOOK?: string;
NEXT_PUBLIC_STORYBOOK?: string;
NEXT_PUBLIC_CUSTOM_RPCS: string;
NEXT_PUBLIC_DKEY: string;
NEXT_PUBLIC_WIDGET_INTEGRATOR: string;
Expand Down
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default withSentryConfig(withBundleAnalyzerConfig, {
// 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",
tunnelRoute: '/monitoring',

sourcemaps: {
disable: process.env.VERCEL === '1', // Disable on Vercel to avoid timeouts
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@
"@mysten/dapp-kit-react": "^2.0.0",
"@mysten/sui": "^2.15.0",
"@safe-global/safe-apps-sdk": "^9.1.0",
"@sentry/browser": "^10.38.0",
"@sentry/nextjs": "^10.38.0",
"@sentry/react": "^10.38.0",
"@solana/client": "1.7.0",
"@solana/kit": "^6.5.0",
"@solana/react-hooks": "1.4.1",
Expand Down
Loading
Loading