Skip to content

Commit 24783ec

Browse files
authored
CORE-998: add release field to sentry init (#96)
* add release field to sentry init * update ts-utils * add prop userUuid * remove wrong dependencies * wrong value for uuid
1 parent d515956 commit 24783ec

File tree

3 files changed

+1118
-8
lines changed

3 files changed

+1118
-8
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openstax/ui-components",
3-
"version": "1.18.2",
3+
"version": "1.18.3",
44
"license": "MIT",
55
"source": "./src/index.ts",
66
"types": "./dist/index.d.ts",
@@ -35,7 +35,7 @@
3535
"devDependencies": {
3636
"npm-run-all": "^4.1.5",
3737
"@ladle/react": "^2.1.2",
38-
"@openstax/ts-utils": "^1.8.0",
38+
"@openstax/ts-utils": "^1.27.6",
3939
"@playwright/test": "^1.25.0",
4040
"@testing-library/dom": "^10.4.0",
4141
"@testing-library/jest-dom": "^6.4.8",

src/components/ErrorBoundary.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const ErrorBoundary = ({
3838
sentryInit?: Sentry.BrowserOptions;
3939
errorFallbacks?: { [_: string]: JSX.Element }
4040
errorLevels?: { [_: string]: Sentry.SeverityLevel }
41+
userUuid?: string; // Optional user UUID to set in Sentry
4142
}) => {
4243
const [error, setError] = React.useState<SentryError | null>(null);
4344
const errorFallbacks: { [_: string]: JSX.Element } = { ...defaultErrorFallbacks, ...props.errorFallbacks };
@@ -48,7 +49,12 @@ export const ErrorBoundary = ({
4849
// Optionally re-render with the children so they can display inline errors with <ErrorMessage />
4950
const renderElement = error && renderFallback ? (typedFallback || fallback) : <>{children}</>;
5051

51-
type WindowWithUserData = Window & { _OX_USER_DATA?: User }
52+
type FrontendConfigType = {
53+
releaseId: string;
54+
[key: string]: unknown; // any other properties, can vary depending on the frontend config repository
55+
};
56+
57+
type WindowWithUserData = Window & { _OX_USER_DATA?: User, _OX_FRONTEND_CONFIG?: FrontendConfigType }
5258

5359
React.useEffect(() => {
5460
if (!sentryDsn && !sentryInit) {
@@ -61,6 +67,7 @@ export const ErrorBoundary = ({
6167
initCalled.current = true;
6268
Sentry.init(sentryInit || {
6369
dsn: sentryDsn,
70+
release: (window as WindowWithUserData)._OX_FRONTEND_CONFIG?.releaseId,
6471
environment: window.location.hostname,
6572
initialScope: {
6673
user: { uuid: (window as WindowWithUserData)._OX_USER_DATA?.uuid },
@@ -73,6 +80,12 @@ export const ErrorBoundary = ({
7380
});
7481
}, [sentryDsn, sentryInit]);
7582

83+
React.useEffect(() => {
84+
if (initCalled.current && (window as WindowWithUserData)._OX_USER_DATA?.uuid !== props.userUuid) {
85+
Sentry.setUser({ uuid: props.userUuid });
86+
}
87+
}, [props.userUuid]);
88+
7689
// There are two references to the render element here because the Sentry fallback (and
7790
// onError) are not used for unhandledrejection events. To support those events, we provide
7891
// setError in a context to reuse the same error state and render logic.

0 commit comments

Comments
 (0)