Skip to content

Commit 0c62076

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 0c62076

50 files changed

Lines changed: 1533 additions & 1091 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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ FROM ${BUILDER_FROM_IMAGE} AS builder
8484
ARG PROJECT
8585
ARG CMS_ORIGIN
8686
ARG SKIP_BUILD_STATIC_GENERATION
87+
ARG NEXT_DISABLE_SOURCEMAPS
8788
ARG FEDERATION_ROUTER_ENDPOINT
8889
ARG LINKEDEVENTS_EVENT_ENDPOINT
8990
ARG NEXT_PUBLIC_APP_ORIGIN
@@ -98,10 +99,13 @@ ARG NEXT_PUBLIC_ASKEM_API_KEY_SV
9899
ARG NEXT_PUBLIC_ASKEM_ENABLED
99100
ARG NEXT_PUBLIC_ALLOW_UNAUTHORIZED_REQUESTS
100101
ARG NEXT_PUBLIC_SENTRY_ENVIRONMENT
102+
ARG NEXT_PUBLIC_SENTRY_RELEASE
101103
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
104+
ARG NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE
105+
ARG NEXT_PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE
106+
ARG NEXT_PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE
107+
ARG SENTRY_ORG
108+
ARG SENTRY_PROJECT
105109
ARG SENTRY_AUTH_TOKEN
106110
ARG NEXT_PUBLIC_DEBUG
107111
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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ 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_RELEASE=
14+
NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE="1.0"
15+
NEXT_PUBLIC_SENTRY_REPLAYS_SESSION_SAMPLE_RATE="1.0"
16+
NEXT_PUBLIC_SENTRY_REPLAYS_ON_ERROR_SAMPLE_RATE="1.0"
1417
NEXT_PUBLIC_CMS_HEADER_MENU_NAME_FI="Events Helsinki Header FI"
1518
NEXT_PUBLIC_CMS_HEADER_MENU_NAME_EN="Events Helsinki Header EN"
1619
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@
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/core": "^10.52.0",
55+
"@sentry/nextjs": "^10.52.0",
56+
"@sentry/react": "^10.52.0",
5657
"@svgr/webpack": "8.1.0",
5758
"@types/jsdom": "21.1.7",
5859
"@types/lodash": "^4.17.20",

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

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
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+
release: process.env.NEXT_PUBLIC_SENTRY_RELEASE,
12+
// Adjust this value in production, or use tracesSampler for greater control
13+
// @see https://develop.sentry.dev/sdk/performance/
14+
// To turn it off, remove the line
15+
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
16+
tracesSampleRate: Number.parseFloat(
17+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
18+
),
19+
normalizeDepth: 3,
20+
integrations: [Sentry.extraErrorDataIntegration({ depth: 3 })],
21+
beforeSend,
22+
beforeSendTransaction,
23+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
24+
debug: false,
25+
});
26+
}
Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
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+
release: process.env.NEXT_PUBLIC_SENTRY_RELEASE,
12+
// Adjust this value in production, or use tracesSampler for greater control
13+
// @see https://develop.sentry.dev/sdk/performance/
14+
// To turn it off, remove the line
15+
// @see https://github.com/getsentry/sentry-javascript/discussions/4503#discussioncomment-2143116
16+
tracesSampleRate: Number.parseFloat(
17+
process.env.NEXT_PUBLIC_SENTRY_TRACES_SAMPLE_RATE || '0'
18+
),
19+
normalizeDepth: 3,
20+
integrations: [Sentry.extraErrorDataIntegration({ depth: 3 })],
21+
beforeSend,
22+
beforeSendTransaction,
23+
// Setting this option to true will print useful information to the console while you're setting up Sentry.
24+
debug: false,
25+
});
26+
}

apps/events-helsinki/sonar-project.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ sonar.coverage.exclusions= \
2222
src/pages/**/*.tsx, \
2323
src/pages/api/healthz.ts, \
2424
src/pages/api/readiness.ts, \
25-
src/lib/**
25+
src/lib/**, \
26+
src/instrumentation.ts, \
27+
src/instrumentation-client.ts

0 commit comments

Comments
 (0)