Skip to content

Commit 76a5fa4

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 76a5fa4

41 files changed

Lines changed: 1493 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: 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 { beforeSend, beforeSendTransaction } from '@events-helsinki/components';
52
import * as Sentry from '@sentry/nextjs';
63

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-
});
4+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
5+
Sentry.init({
6+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
7+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
8+
// Adjust this value in production, or use tracesSampler for greater control
9+
// @see https://develop.sentry.dev/sdk/performance/
10+
// To turn it off, remove the line
11+
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
12+
tracesSampleRate: parseFloat(
13+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
14+
),
15+
normalizeDepth: 3,
16+
integrations: [Sentry.extraErrorDataIntegration({ depth: 3 })],
17+
// Note: if you want to override the automatic release value, do not set a
18+
// `release` value here - use the environment variable `SENTRY_RELEASE`, so
19+
// that it will also get attached to your source maps
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: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
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 { beforeSend, beforeSendTransaction } from '@events-helsinki/components';
52
import * as Sentry from '@sentry/nextjs';
63

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-
});
4+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
5+
Sentry.init({
6+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
7+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
8+
// Adjust this value in production, or use tracesSampler for greater control
9+
// @see https://develop.sentry.dev/sdk/performance/
10+
// To turn it off, remove the line
11+
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
12+
tracesSampleRate: parseFloat(
13+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
14+
),
15+
normalizeDepth: 3,
16+
integrations: [Sentry.extraErrorDataIntegration({ depth: 3 })],
17+
beforeSend,
18+
beforeSendTransaction,
19+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
20+
debug: false,
21+
});
22+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 { beforeSend, beforeSendTransaction } from '@events-helsinki/components';
6+
import { thirdPartyErrorFilterIntegration } from '@sentry/core';
7+
import * as Sentry from '@sentry/nextjs';
8+
import {
9+
captureRouterTransitionStart,
10+
replayIntegration,
11+
} from '@sentry/nextjs';
12+
13+
if (process.env.NEXT_PUBLIC_SENTRY_DSN) {
14+
Sentry.init({
15+
beforeSend,
16+
beforeSendTransaction,
17+
normalizeDepth: 3,
18+
integrations: [
19+
replayIntegration(),
20+
Sentry.extraErrorDataIntegration({ depth: 3 }),
21+
thirdPartyErrorFilterIntegration({
22+
filterKeys: process.env.SENTRY_PROJECT
23+
? [process.env.SENTRY_PROJECT]
24+
: [],
25+
behaviour: 'drop-error-if-contains-third-party-frames',
26+
}),
27+
],
28+
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
29+
environment: process.env.NEXT_PUBLIC_SENTRY_ENVIRONMENT,
30+
release: process.env.NEXT_PUBLIC_SENTRY_RELEASE,
31+
ignoreErrors: [
32+
'ResizeObserver loop completed with undelivered notifications',
33+
'ResizeObserver loop limit exceeded',
34+
],
35+
tracesSampleRate: parseFloat(
36+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
37+
),
38+
tracePropagationTargets: (
39+
process.env.NEXT_PUBLIC_SENTRY_TRACE_PROPAGATION_TARGETS || ''
40+
).split(','),
41+
replaysSessionSampleRate: parseFloat(
42+
process.env.NEXT_PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE || '0'
43+
),
44+
replaysOnErrorSampleRate: parseFloat(
45+
process.env.NEXT_PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE || '0'
46+
),
47+
debug: false,
48+
});
49+
}
50+
51+
export const onRouterTransitionStart = captureRouterTransitionStart;

0 commit comments

Comments
 (0)