Skip to content

Commit 3b10a61

Browse files
committed
feat(sentry): migrate apps to Next instrumentation and v10 config
- migrate events-, hobbies-, and sports-helsinki to instrumentation based Sentry setup - add shared Sentry payload scrubbing utilities in components and app-level hooks - remove legacy client config files and wire beforeSend and beforeSendTransaction hooks - upgrade Sentry dependencies to ^10.52.0 across affected packages - rename Sentry env vars to TRACES and REPLAYS naming and update Docker and env examples - add SENTRY_ORG and SENTRY_PROJECT build env support - update base Next.js output tracing config and refresh lockfile Refs: TH-1465
1 parent f75e3f9 commit 3b10a61

41 files changed

Lines changed: 1520 additions & 962 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ ARG NEXT_PUBLIC_ASKEM_ENABLED
9999
ARG NEXT_PUBLIC_ALLOW_UNAUTHORIZED_REQUESTS
100100
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
101101
ARG NEXT_PUBLIC_SENTRY_DSN
102-
ARG NEXT_PUBLIC_SENTRY_TRACE_SAMPLE_RATE
103-
ARG NEXT_PUBLIC_SENTRY_REPLAY_SESSION_SAMPLE_RATE
104-
ARG NEXT_PUBLIC_SENTRY_REPLAY_ON_ERROR_SAMPLE_RATE
102+
ARG NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE
103+
ARG NEXT_PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE
104+
ARG NEXT_PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE
105+
ARG SENTRY_ORG
106+
ARG SENTRY_PROJECT
105107
ARG SENTRY_AUTH_TOKEN
106108
ARG NEXT_PUBLIC_DEBUG
107109
ARG NEXTJS_DISABLE_SENTRY

DockerfileCache

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ ARG NEXT_PUBLIC_ASKEM_ENABLED
9999
ARG NEXT_PUBLIC_ALLOW_UNAUTHORIZED_REQUESTS
100100
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
101101
ARG NEXT_PUBLIC_SENTRY_DSN
102-
ARG NEXT_PUBLIC_SENTRY_TRACE_SAMPLE_RATE
103-
ARG NEXT_PUBLIC_SENTRY_REPLAY_SESSION_SAMPLE_RATE
104-
ARG NEXT_PUBLIC_SENTRY_REPLAY_ON_ERROR_SAMPLE_RATE
102+
ARG NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE
103+
ARG NEXT_PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE
104+
ARG NEXT_PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE
105+
ARG SENTRY_ORG
106+
ARG SENTRY_PROJECT
105107
ARG SENTRY_AUTH_TOKEN
106108
ARG NEXT_PUBLIC_DEBUG
107109
ARG NEXTJS_DISABLE_SENTRY

apps/events-helsinki/.env.local.example

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ NEXT_PUBLIC_APP_ORIGIN="http://localhost:3000"
55
NEXT_PUBLIC_IMAGE_PROXY_URL="https://images.weserv.nl/?w=1024&url="
66
NEXT_PUBLIC_DEBUG="true"
77
NEXT_PUBLIC_DEFAULT_ISR_REVALIDATE_SECONDS=0
8+
SENTRY_ORG=city-of-helsinki
9+
SENTRY_PROJECT=tapahtumat-ui
810
SENTRY_AUTH_TOKEN=
911
NEXT_PUBLIC_SENTRY_DSN=
10-
NEXT_PUBLIC_SENTRY_ENVIRONMENT="develop"
11-
NEXT_PUBLIC_SENTRY_TRACE_SAMPLE_RATE="1.0"
12-
NEXT_PUBLIC_SENTRY_REPLAY_SESSION_SAMPLE_RATE="1.0"
13-
NEXT_PUBLIC_SENTRY_REPLAY_ON_ERROR_SAMPLE_RATE="1.0"
12+
NEXT_PUBLIC_SENTRY_ENVIRONMENT="local"
13+
NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE="1.0"
14+
NEXT_PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE="1.0"
15+
NEXT_PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE="1.0"
1416
NEXT_PUBLIC_CMS_HEADER_MENU_NAME_FI="Events Helsinki Header FI"
1517
NEXT_PUBLIC_CMS_HEADER_MENU_NAME_EN="Events Helsinki Header EN"
1618
NEXT_PUBLIC_CMS_HEADER_MENU_NAME_SV="Events Helsinki Header SV"

apps/events-helsinki/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ report
4141

4242
.vscode/
4343

44-
certificates
44+
certificates
45+
# Sentry Config File
46+
.env.sentry-build-plugin

apps/events-helsinki/next.config.mjs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { withSentryConfig } from '@sentry/nextjs';
12
import packageJson from './package.json' with { type: 'json' };
23
import i18nRoutes from './i18nRoutes.config.mjs';
34
import redirectCampaignRoutes from './redirectCampaignRoutes.config.mjs';
@@ -28,11 +29,43 @@ const nonCampaignRedirects = Object.entries(redirectNonCampaignRoutes).flatMap(
2829
}))
2930
);
3031

31-
export default nextBaseConfig({
32-
packageJson,
33-
i18nRoutes,
34-
i18n: nextConfig.i18n,
35-
async redirects() {
36-
return [...campaignRedirects, ...nonCampaignRedirects];
37-
},
38-
});
32+
export default withSentryConfig(
33+
nextBaseConfig({
34+
packageJson,
35+
i18nRoutes,
36+
i18n: nextConfig.i18n,
37+
async redirects() {
38+
return [...campaignRedirects, ...nonCampaignRedirects];
39+
},
40+
}),
41+
{
42+
// Suppresses source map uploading logs during build
43+
silent: false,
44+
45+
// For all available options, see:
46+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
47+
48+
// Upload a larger set of source maps for prettier stack traces (increases build time)
49+
widenClientFileUpload: true,
50+
51+
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
52+
// This can increase your server load as well as your hosting bill.
53+
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
54+
// side errors will fail.
55+
tunnelRoute: '/monitoring',
56+
57+
webpack: {
58+
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
59+
// See the following for more information:
60+
// https://docs.sentry.io/product/crons/
61+
// https://vercel.com/docs/cron-jobs
62+
automaticVercelMonitors: true,
63+
64+
// Tree-shaking options for reducing bundle size
65+
treeshake: {
66+
// Automatically tree-shake Sentry logger statements to reduce bundle size
67+
removeDebugLogging: true,
68+
},
69+
},
70+
}
71+
);

apps/events-helsinki/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
"@city-of-helsinki/react-helsinki-headless-cms": "3.0.1",
5151
"@events-helsinki/common-i18n": "workspace:^",
5252
"@events-helsinki/components": "workspace:^",
53-
"@sentry/browser": "9.38.0",
54-
"@sentry/nextjs": "9.38.0",
55-
"@sentry/react": "9.38.0",
53+
"@sentry/browser": "^10.52.0",
54+
"@sentry/nextjs": "^10.52.0",
55+
"@sentry/react": "^10.52.0",
5656
"@svgr/webpack": "8.1.0",
5757
"@types/jsdom": "21.1.7",
5858
"@types/lodash": "^4.17.20",

apps/events-helsinki/sentry.client.config.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
1-
// This file configures the initialization of Sentry on the server.
2-
// The config you add here will be used whenever the server handles a request.
3-
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4-
1+
import {
2+
beforeSend,
3+
beforeSendTransaction,
4+
} from '@events-helsinki/components/sentry/utils';
55
import * as Sentry from '@sentry/nextjs';
66

7-
Sentry.init({
8-
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
9-
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
10-
// Adjust this value in production, or use tracesSampler for greater control
11-
// @see https://develop.sentry.dev/sdk/performance/
12-
// To turn it off, remove the line
13-
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
14-
tracesSampleRate: parseFloat(
15-
process.env.NEXT_PUBLIC_SENTRY_TRACE_SAMPLE_RATE ?? '0.1'
16-
),
17-
// ...
18-
// Note: if you want to override the automatic release value, do not set a
19-
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
20-
// that it will also get attached to your source maps
21-
beforeSend: async (event, hint) => {
22-
if (process.env.NODE_ENV === 'development') {
23-
// eslint-disable-next-line no-console
24-
console.log('Sentry event', event);
25-
// eslint-disable-next-line no-console
26-
console.log('Sentry hint', hint);
27-
}
28-
return event;
29-
},
30-
});
7+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
8+
Sentry.init({
9+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
10+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
11+
// Adjust this value in production, or use tracesSampler for greater control
12+
// @see https://develop.sentry.dev/sdk/performance/
13+
// To turn it off, remove the line
14+
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
15+
tracesSampleRate: parseFloat(
16+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
17+
),
18+
normalizeDepth: 3,
19+
integrations: [Sentry.extraErrorDataIntegration({ depth: 3 })],
20+
// Note: if you want to override the automatic release value, do not set a
21+
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
22+
// that it will also get attached to your source maps
23+
beforeSend,
24+
beforeSendTransaction,
25+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
26+
debug: false,
27+
});
28+
}
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
// This file configures the initialization of Sentry on the server.
2-
// The config you add here will be used whenever the server handles a request.
3-
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4-
1+
import {
2+
beforeSend,
3+
beforeSendTransaction,
4+
} from '@events-helsinki/components/sentry/utils';
55
import * as Sentry from '@sentry/nextjs';
66

7-
Sentry.init({
8-
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
9-
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
10-
// Adjust this value in production, or use tracesSampler for greater control
11-
// @see https://develop.sentry.dev/sdk/performance/
12-
// To turn it off, remove the line
13-
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
14-
tracesSampleRate: parseFloat(
15-
process.env.NEXT_PUBLIC_SENTRY_TRACE_SAMPLE_RATE ?? '0.1'
16-
),
17-
// ...
18-
// Note: if you want to override the automatic release value, do not set a
19-
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
20-
// that it will also get attached to your source maps
21-
beforeSend: async (event, hint) => {
22-
if (process.env.NODE_ENV === 'development') {
23-
// eslint-disable-next-line no-console
24-
console.log('Sentry event', event);
25-
// eslint-disable-next-line no-console
26-
console.log('Sentry hint', hint);
27-
}
28-
return event;
29-
},
30-
});
7+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
8+
Sentry.init({
9+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
10+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
11+
// Adjust this value in production, or use tracesSampler for greater control
12+
// @see https://develop.sentry.dev/sdk/performance/
13+
// To turn it off, remove the line
14+
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
15+
tracesSampleRate: parseFloat(
16+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
17+
),
18+
normalizeDepth: 3,
19+
integrations: [Sentry.extraErrorDataIntegration({ depth: 3 })],
20+
beforeSend,
21+
beforeSendTransaction,
22+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
23+
debug: false,
24+
});
25+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This file configures the initialization of Sentry on the client.
2+
// The added config here will be used whenever a users loads a page in their browser.
3+
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
4+
5+
import {
6+
beforeSend,
7+
beforeSendTransaction,
8+
} from '@events-helsinki/components/sentry/utils';
9+
import { thirdPartyErrorFilterIntegration } from '@sentry/core';
10+
import * as Sentry from '@sentry/nextjs';
11+
import {
12+
captureRouterTransitionStart,
13+
replayIntegration,
14+
} from '@sentry/nextjs';
15+
16+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
17+
Sentry.init({
18+
beforeSend,
19+
beforeSendTransaction,
20+
normalizeDepth: 3,
21+
integrations: [
22+
replayIntegration(),
23+
Sentry.extraErrorDataIntegration({ depth: 3 }),
24+
thirdPartyErrorFilterIntegration({
25+
filterKeys: process.env.SENTRY_PROJECT
26+
? [process.env.SENTRY_PROJECT]
27+
: [],
28+
behaviour: 'drop-error-if-contains-third-party-frames',
29+
}),
30+
],
31+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
32+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
33+
release: process.env.NEXT_PUBLIC_SENTRY_RELEASE,
34+
ignoreErrors: [
35+
'ResizeObserver loop completed with undelivered notifications',
36+
'ResizeObserver loop limit exceeded',
37+
],
38+
tracesSampleRate: parseFloat(
39+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
40+
),
41+
tracePropagationTargets: (
42+
process.env.NEXT_PUBLIC_SENTRY_TRACE_PROPAGATION_TARGETS || ''
43+
).split(','),
44+
replaysSessionSampleRate: parseFloat(
45+
process.env.NEXT_PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE || '0'
46+
),
47+
replaysOnErrorSampleRate: parseFloat(
48+
process.env.NEXT_PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE || '0'
49+
),
50+
debug: false,
51+
});
52+
}
53+
54+
export const onRouterTransitionStart = captureRouterTransitionStart;

0 commit comments

Comments
 (0)