Skip to content

Commit 43e1177

Browse files
authored
feat: update Sentry (#2204)
* feat: set up `@sentry/react` - replace `@sentry/core` and `@sentry/browser` with `@sentry/react` - remove manual exception handling from `ErrorBoundary`, as `@sentry/react` is capable of handling it - where possible, add tags to initial scope in Sentry initialisation - send Sentry events in any environment, annotating with `import.meta.env.MODE` * feat(ci): upload sourcemaps and release info to Sentry * fix: remove unneeded `console.log`
1 parent 33d893c commit 43e1177

File tree

7 files changed

+93
-64
lines changed

7 files changed

+93
-64
lines changed

.github/workflows/release.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ jobs:
248248
tag: ${{ steps.tags.outputs.version-tag }}
249249
allowUpdates: true
250250
replacesArtifacts: true
251-
prerelease: ${{ steps.pre-release.outputs.is-pre-release }}
251+
prerelease: ${{ needs.pre-release.outputs.is-pre-release }}
252252
artifacts: release-artifacts/**/*.charm
253253
body: |
254254
Published `${{ steps.tags.outputs.version-tag }}` to Charmhub on `${{ needs.pre-release.outputs.promote-channel || needs.pre-release.outputs.channel }}` channel.
@@ -258,3 +258,33 @@ jobs:
258258
# Changelog
259259
260260
${{ needs.pre-release.outputs.changelog }}
261+
262+
sentry-release:
263+
name: "Create Sentry release"
264+
runs-on: ubuntu-24.04
265+
266+
needs: [pre-release]
267+
268+
defaults:
269+
run:
270+
shell: bash
271+
272+
steps:
273+
- uses: actions/checkout@v6
274+
275+
- name: Install dependencies
276+
run: yarn install
277+
278+
- name: Build dashboard with sourcemaps
279+
run: yarn run vite build --sourcemap=hidden
280+
281+
- name: "Create Sentry release"
282+
uses: getsentry/action-release@v3
283+
env:
284+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
285+
SENTRY_ORG: canonical-ax
286+
SENTRY_PROJECT: juju-dashboard
287+
with:
288+
environment: production
289+
version: ${{ needs.pre-release.outputs.version }}
290+
sourcemaps: "./build"

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
"@canonical/rebac-admin": "0.0.1-alpha.12",
5757
"@curvenote/ansi-to-react": "7.0.0",
5858
"@reduxjs/toolkit": "2.6.1",
59-
"@sentry/browser": "9.10.1",
60-
"@sentry/core": "9.10.1",
59+
"@sentry/react": "10.35.0",
6160
"@tanstack/react-query": "5.71.0",
6261
"axios": "1.8.4",
6362
"classnames": "2.5.1",

src/components/ErrorBoundary/ErrorBoundary.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {
44
Notification,
55
Strip,
66
} from "@canonical/react-components";
7-
import * as Sentry from "@sentry/browser";
8-
import type { Extras } from "@sentry/core";
97
import type { PropsWithChildren } from "react";
108
import { Component } from "react";
119

@@ -32,16 +30,6 @@ export default class ErrorBoundary extends Component<Props, State> {
3230
};
3331
}
3432

35-
componentDidCatch(error: Error, info: unknown) {
36-
if (import.meta.env.PROD && window.jujuDashboardConfig?.analyticsEnabled) {
37-
Sentry.withScope((scope) => {
38-
scope.setExtras(info as Extras);
39-
const eventId = Sentry.captureException(error);
40-
this.setState({ eventId });
41-
});
42-
}
43-
}
44-
4533
render() {
4634
const { error, hasError } = this.state;
4735
const { children } = this.props;

src/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Notification, Strip } from "@canonical/react-components";
2-
import * as Sentry from "@sentry/browser";
2+
import * as Sentry from "@sentry/react";
33
import type { LogLevelDesc } from "loglevel";
44
import { StrictMode } from "react";
55
import type { Root } from "react-dom/client";
@@ -23,11 +23,18 @@ export enum Label {
2323
POLLING_ERROR = "Error while trying to connect and start polling.",
2424
}
2525

26-
if (import.meta.env.PROD && window.jujuDashboardConfig?.analyticsEnabled) {
26+
if (window.jujuDashboardConfig?.analyticsEnabled) {
2727
Sentry.init({
28-
dsn: "https://5f679e274f34464194e9592a91ed65d4@sentry.is.canonical.com//29",
28+
dsn: "https://e2f2cf871a2bf7879fc7d08434f02886@o4510662863749120.ingest.de.sentry.io/4510739815858256",
29+
sendDefaultPii: false,
30+
environment: import.meta.env.MODE,
31+
initialScope: {
32+
tags: {
33+
dashboardVersion: appVersion,
34+
isJuju: window.jujuDashboardConfig?.isJuju,
35+
},
36+
},
2937
});
30-
Sentry.setTag("dashboardVersion", appVersion);
3138
}
3239

3340
const addressRegex = new RegExp(/^ws[s]?:\/\/(\S+)\//);
@@ -129,10 +136,6 @@ function bootstrap() {
129136
}
130137
}
131138

132-
if (isProduction && config.analyticsEnabled) {
133-
Sentry.setTag("isJuju", config.isJuju);
134-
}
135-
136139
reduxStore.dispatch(generalActions.storeConfig(config));
137140
reduxStore.dispatch(generalActions.storeVersion(appVersion));
138141

src/pages/ModelsIndex/ModelsIndex.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export default function Models() {
7272
// hook should return an ID that is unique across the app, but this may need to
7373
// be replaced with a more robust implementation if there are conflicts.
7474
const requestId = useId();
75-
console.log("Models", requestId);
7675
const relations =
7776
controllerUser && modelUUIDs.length
7877
? modelUUIDs.map((modelUUID) => ({

src/store/middleware/model-poller.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Client } from "@canonical/jujulib";
2-
import * as Sentry from "@sentry/browser";
2+
import * as Sentry from "@sentry/react";
33
import { isAction, type Middleware } from "redux";
44

55
import { Auth } from "auth";
@@ -121,7 +121,6 @@ export const modelPollerMiddleware: Middleware<
121121
return;
122122
}
123123

124-
const isProduction = import.meta.env.PROD;
125124
const analyticsEnabled = getAnalyticsEnabled(reduxStore.getState());
126125
const isJuju = !!getIsJuju(reduxStore.getState());
127126
const dashboardVersion = getAppVersion(reduxStore.getState()) ?? "";
@@ -138,7 +137,7 @@ export const modelPollerMiddleware: Middleware<
138137

139138
// XXX Now that we can register multiple controllers this needs
140139
// to be sent per controller.
141-
if (isProduction && analyticsEnabled) {
140+
if (analyticsEnabled) {
142141
Sentry.setTag("jujuVersion", conn.info.serverVersion);
143142
}
144143

yarn.lock

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,61 +1223,73 @@ __metadata:
12231223
languageName: node
12241224
linkType: hard
12251225

1226-
"@sentry-internal/browser-utils@npm:9.10.1":
1227-
version: 9.10.1
1228-
resolution: "@sentry-internal/browser-utils@npm:9.10.1"
1226+
"@sentry-internal/browser-utils@npm:10.35.0":
1227+
version: 10.35.0
1228+
resolution: "@sentry-internal/browser-utils@npm:10.35.0"
12291229
dependencies:
1230-
"@sentry/core": "npm:9.10.1"
1231-
checksum: 10c0/aa56c8514f2b56e7e5a53f481045bd9dcb6ecc883092319d95618294400884224d7444d9fa80f78225066c2d4009dfbf125b508703a6f1154e6fb6428c5a4228
1230+
"@sentry/core": "npm:10.35.0"
1231+
checksum: 10c0/c204302bf23703a65de967ef95a7e9e59cf6881f3e00100ee3bbfe331a7dc1f47b426925123789e04d8c5873b0b44ea46d9d644a39b881f22d466031eccc8bf3
12321232
languageName: node
12331233
linkType: hard
12341234

1235-
"@sentry-internal/feedback@npm:9.10.1":
1236-
version: 9.10.1
1237-
resolution: "@sentry-internal/feedback@npm:9.10.1"
1235+
"@sentry-internal/feedback@npm:10.35.0":
1236+
version: 10.35.0
1237+
resolution: "@sentry-internal/feedback@npm:10.35.0"
12381238
dependencies:
1239-
"@sentry/core": "npm:9.10.1"
1240-
checksum: 10c0/eff093e1b6223c353290ddcde0efab6ea614375d96bad8098e70efbad31739080d337d0807ed6fd5ab2103ec77e6b55b631f8c7daa25b7f2beb72c7aaa7fb0d6
1239+
"@sentry/core": "npm:10.35.0"
1240+
checksum: 10c0/09a47764afc0735fd1250cc5f20289b9b1ba6b53fca343ce78db3510ce68287456a3a9a6edbd03de0fa4dc3757de275f852aacaa9a273d7a1e8a2621183068fc
12411241
languageName: node
12421242
linkType: hard
12431243

1244-
"@sentry-internal/replay-canvas@npm:9.10.1":
1245-
version: 9.10.1
1246-
resolution: "@sentry-internal/replay-canvas@npm:9.10.1"
1244+
"@sentry-internal/replay-canvas@npm:10.35.0":
1245+
version: 10.35.0
1246+
resolution: "@sentry-internal/replay-canvas@npm:10.35.0"
12471247
dependencies:
1248-
"@sentry-internal/replay": "npm:9.10.1"
1249-
"@sentry/core": "npm:9.10.1"
1250-
checksum: 10c0/4352046a67cec765f6c06709e4ecafb2120fda612981e2d3a22a9e6e4eb3d456d05fb4d4f9a6b92d2701b7bb186452649377274f0fe5f2c268d700f5a1ad95c6
1248+
"@sentry-internal/replay": "npm:10.35.0"
1249+
"@sentry/core": "npm:10.35.0"
1250+
checksum: 10c0/1cd19dd533165c3dc3d69b3f10fa56a3e24a099c949632d2f67e94b99c6500acab5910435007edf6570b4e3b2418592c5c696ad9446b9a1cd5514def5a8f1257
12511251
languageName: node
12521252
linkType: hard
12531253

1254-
"@sentry-internal/replay@npm:9.10.1":
1255-
version: 9.10.1
1256-
resolution: "@sentry-internal/replay@npm:9.10.1"
1254+
"@sentry-internal/replay@npm:10.35.0":
1255+
version: 10.35.0
1256+
resolution: "@sentry-internal/replay@npm:10.35.0"
12571257
dependencies:
1258-
"@sentry-internal/browser-utils": "npm:9.10.1"
1259-
"@sentry/core": "npm:9.10.1"
1260-
checksum: 10c0/0926746aa1e779a2fd05725f66607b4e3b55e5a081969f38777d172e62f12873c4563298ab4afe83362f7c23b0a6d3cc6ca7a541e76cfc67a5454980620b8abf
1258+
"@sentry-internal/browser-utils": "npm:10.35.0"
1259+
"@sentry/core": "npm:10.35.0"
1260+
checksum: 10c0/db72b1230e893415a5497ec006e50d85146dea6baa052b8820091d0022bdac9b24c042dc538776f163b3bdfa419a629e21c686860ad068cd5389c8d7bc96a8f6
12611261
languageName: node
12621262
linkType: hard
12631263

1264-
"@sentry/browser@npm:9.10.1":
1265-
version: 9.10.1
1266-
resolution: "@sentry/browser@npm:9.10.1"
1264+
"@sentry/browser@npm:10.35.0":
1265+
version: 10.35.0
1266+
resolution: "@sentry/browser@npm:10.35.0"
12671267
dependencies:
1268-
"@sentry-internal/browser-utils": "npm:9.10.1"
1269-
"@sentry-internal/feedback": "npm:9.10.1"
1270-
"@sentry-internal/replay": "npm:9.10.1"
1271-
"@sentry-internal/replay-canvas": "npm:9.10.1"
1272-
"@sentry/core": "npm:9.10.1"
1273-
checksum: 10c0/b2e9e39be9a0168ab3ba9806e9ef87aebe6bc0f33c2f9545cad371dc6dbb0a56dc6b4b5c334e7e4305c52ea9d4a837d6e4af8b34014cb9e7c470c917da34adf5
1268+
"@sentry-internal/browser-utils": "npm:10.35.0"
1269+
"@sentry-internal/feedback": "npm:10.35.0"
1270+
"@sentry-internal/replay": "npm:10.35.0"
1271+
"@sentry-internal/replay-canvas": "npm:10.35.0"
1272+
"@sentry/core": "npm:10.35.0"
1273+
checksum: 10c0/c397667fc8284a2339352d940d9cbdc039c18d1142c13f740fef7e1b0d678c9cf16d56b7106cf95aa5102fd2d23d53bbd0e806ad92bce8d593ab9d7c9f54e7d5
12741274
languageName: node
12751275
linkType: hard
12761276

1277-
"@sentry/core@npm:9.10.1":
1278-
version: 9.10.1
1279-
resolution: "@sentry/core@npm:9.10.1"
1280-
checksum: 10c0/c7c6279dd536edd8c0eb695c6d63f00f5b9f5e6b460129c7e2f9722db92722e6b195d9da163611343a4e9d40f7c24bf4a88dd5bd3bb951d4f8acde70ce772123
1277+
"@sentry/core@npm:10.35.0":
1278+
version: 10.35.0
1279+
resolution: "@sentry/core@npm:10.35.0"
1280+
checksum: 10c0/b58b892e3528a09d71c65497fc6352f51c233b430c49be986d402194881d63ab68f34f1f920b260147acc97425edb185fa26f3f46e8cf321949e1d0b277824e2
1281+
languageName: node
1282+
linkType: hard
1283+
1284+
"@sentry/react@npm:10.35.0":
1285+
version: 10.35.0
1286+
resolution: "@sentry/react@npm:10.35.0"
1287+
dependencies:
1288+
"@sentry/browser": "npm:10.35.0"
1289+
"@sentry/core": "npm:10.35.0"
1290+
peerDependencies:
1291+
react: ^16.14.0 || 17.x || 18.x || 19.x
1292+
checksum: 10c0/f6bfc4e9f4c2db71ed9c95e96c3d8dd0c35da7e3a473dc60735de2dd83d7683bbf37ecb9080a112e23185519aa47026f0ef65b131d2823bcde6335ead9984bbf
12811293
languageName: node
12821294
linkType: hard
12831295

@@ -7421,8 +7433,7 @@ __metadata:
74217433
"@eslint/js": "npm:9.34.0"
74227434
"@playwright/test": "npm:1.52.0"
74237435
"@reduxjs/toolkit": "npm:2.6.1"
7424-
"@sentry/browser": "npm:9.10.1"
7425-
"@sentry/core": "npm:9.10.1"
7436+
"@sentry/react": "npm:10.35.0"
74267437
"@stylistic/eslint-plugin": "npm:5.1.0"
74277438
"@tanstack/react-query": "npm:5.71.0"
74287439
"@testing-library/dom": "npm:10.4.0"

0 commit comments

Comments
 (0)