Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: Add sourcemaps and error stacks in Sentry errors (#26474)

Ivan Vasilov79dbfd1ccce9
diff --git a/apps/studio/components/interfaces/Support/SupportForm.tsx b/apps/studio/components/interfaces/Support/SupportForm.tsx
index b5e217a80ba..28585d1b64d 100644
--- a/apps/studio/components/interfaces/Support/SupportForm.tsx
+++ b/apps/studio/components/interfaces/Support/SupportForm.tsx
@@ -1,11 +1,6 @@
-import { CLIENT_LIBRARIES } from 'common/constants'
-import { AlertCircle, ExternalLink, HelpCircle, Loader2, Mail, Plus, X } from 'lucide-react'
-import Link from 'next/link'
-import { useRouter } from 'next/router'
-import { ChangeEvent, useEffect, useRef, useState } from 'react'
-import toast from 'react-hot-toast'
import * as Sentry from '@sentry/nextjs'
import { useParams } from 'common'
+import { CLIENT_LIBRARIES } from 'common/constants'
import InformationBox from 'components/ui/InformationBox'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { getProjectAuthConfig } from 'data/auth/auth-config-query'
@@ -18,6 +13,12 @@ import { useFlag } from 'hooks'
import useLatest from 'hooks/misc/useLatest'
import { detectBrowser } from 'lib/helpers'
import { useProfile } from 'lib/profile'
+import { canSendTelemetry } from 'lib/telemetry'
+import { AlertCircle, ExternalLink, HelpCircle, Loader2, Mail, Plus, X } from 'lucide-react'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { ChangeEvent, useEffect, useRef, useState } from 'react'
+import toast from 'react-hot-toast'
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
@@ -76,7 +77,9 @@ const SupportForm = ({ setSentCategory }: SupportFormProps) => {
},
onError: (error) => {
toast.error(`Failed to submit support ticket: ${error.message}`)
- Sentry.captureMessage('Failed to submit Support Form: ' + error.message)
+ if (canSendTelemetry()) {
+ Sentry.captureMessage('Failed to submit Support Form: ' + error.message)
+ }
setIsSubmitting(false)
},
})
diff --git a/apps/studio/data/fetchers.ts b/apps/studio/data/fetchers.ts
index c6f2a649e6c..894d2aec78c 100644
--- a/apps/studio/data/fetchers.ts
+++ b/apps/studio/data/fetchers.ts
@@ -2,6 +2,7 @@ import * as Sentry from '@sentry/nextjs'
import { API_URL, IS_PLATFORM } from 'lib/constants'
import { getAccessToken } from 'lib/gotrue'
import { uuidv4 } from 'lib/helpers'
+import { canSendTelemetry } from 'lib/telemetry'
import createClient from 'openapi-fetch'
import type { paths } from './api' // generated from openapi-typescript
@@ -159,12 +160,14 @@ export const handleError = (error: any): never => {
throw new Error(error.message)
}
- // the error doesn't have a message or msg property, so we can't throw it as an error. Log it via Sentry so that we can
- // add handling for it.
console.error(error.stack)
- Sentry.captureMessage(
- `Unable to throw an object as error. The object has the following keys: ${Object.keys(error)}.`
- )
+ if (canSendTelemetry()) {
+ // the error doesn't have a message or msg property, so we can't throw it as an error. Log it via Sentry so that we can
+ // add handling for it.
+ Sentry.captureMessage(
+ `Unable to throw an object as error. The object has the following keys: ${Object.keys(error)}.`
+ )
+ }
// throw a generic error if we don't know what the error is. The message is intentionally vague because it might show
// up in the UI.
diff --git a/apps/studio/lib/constants/index.ts b/apps/studio/lib/constants/index.ts
index 9eb40e54dd5..f5a20630865 100644
--- a/apps/studio/lib/constants/index.ts
+++ b/apps/studio/lib/constants/index.ts
@@ -51,6 +51,8 @@ export const LOCAL_STORAGE_KEYS = {
PROJECT_LINT_IGNORE_LIST: 'supabase-project-lint-ignore-list',
QUERY_PERF_SHOW_BOTTOM_SECTION: 'supabase-query-perf-show-bottom-section',
+ // Used for storing a user id when sending reports to Sentry. The id is hashed for anonymity.
+ SENTRY_USER_ID: 'supabase-sentry-user-id',
}
export const OPT_IN_TAGS = {
diff --git a/apps/studio/lib/telemetry.ts b/apps/studio/lib/telemetry.ts
index 38f8c98263a..2bf7353414e 100644
--- a/apps/studio/lib/telemetry.ts
+++ b/apps/studio/lib/telemetry.ts
@@ -1,6 +1,8 @@
+import { Sha256 } from '@aws-crypto/sha256-browser'
+import type { NextRouter } from 'next/router'
+
import { post } from 'lib/common/fetch'
import { API_URL, IS_PLATFORM, LOCAL_STORAGE_KEYS } from 'lib/constants'
-import type { NextRouter } from 'next/router'
import type { User } from 'types'
export interface TelemetryProps {
@@ -112,6 +114,30 @@ const sendActivity = (
return post(`${API_URL}/telemetry/activity`, properties)
}
+/**
+ * Checks if the user has consented to sending telemetry data. Mainly used for Sentry reports.
+ */
+export const canSendTelemetry = () => {
+ const consent =
+ typeof window !== 'undefined'
+ ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT)
+ : null
+
+ return IS_PLATFORM && consent === 'true'
+}
+
+/**
+ * Generates a unique identifier for an anonymous user based on their gotrue id.
+ */
+export const getAnonId = async (id: string) => {
+ const hash = new Sha256()
+ hash.update(id)
+ const u8Array = await hash.digest()
+ const binString = Array.from(u8Array, (byte) => String.fromCodePoint(byte)).join('')
+ const b64encoded = btoa(binString)
+ return b64encoded
+}
+
const Telemetry = {
sendEvent,
sendIdentify,
diff --git a/apps/studio/package.json b/apps/studio/package.json
index f005e6ba3d8..9d88d32ac29 100644
--- a/apps/studio/package.json
+++ b/apps/studio/package.json
@@ -18,6 +18,7 @@
"codegen": "openapi-typescript http://localhost:8080/api-json -o data/api.d.ts && prettier --write data/api.d.ts"
},
"dependencies": {
+ "@aws-crypto/sha256-browser": "^3.0.0",
"@dagrejs/dagre": "^1.0.4",
"@graphiql/react": "^0.19.4",
"@graphiql/toolkit": "^0.9.1",
diff --git a/apps/studio/pages/_app.tsx b/apps/studio/pages/_app.tsx
index 301781d6610..79e6acff77d 100644
--- a/apps/studio/pages/_app.tsx
+++ b/apps/studio/pages/_app.tsx
@@ -23,7 +23,7 @@ import { SessionContextProvider } from '@supabase/auth-helpers-react'
import { createClient } from '@supabase/supabase-js'
import { Hydrate, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
-import { ThemeProvider, useThemeSandbox } from 'common'
+import { ThemeProvider, useThemeSandbox, useUser } from 'common'
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import relativeTime from 'dayjs/plugin/relativeTime'
@@ -52,6 +52,7 @@ import { useRootQueryClient } from 'data/query-client'
import { AuthProvider } from 'lib/auth'
import { BASE_PATH, IS_PLATFORM, LOCAL_STORAGE_KEYS } from 'lib/constants'
import { ProfileProvider } from 'lib/profile'
+import { canSendTelemetry, getAnonId } from 'lib/telemetry'
import { useAppStateSnapshot } from 'state/app-state'
import HCaptchaLoadedStore from 'stores/hcaptcha-loaded-store'
import { AppPropsWithLayout } from 'types'
@@ -111,10 +112,14 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {
)
const errorBoundaryHandler = (error: Error, info: ErrorInfo) => {
+ if (canSendTelemetry()) {
+ Sentry.withScope(function (scope) {
+ scope.setTag('globalErrorBoundary', true)
+ Sentry.captureException(error)
+ })
+ }
+
console.error(error.stack)
- Sentry.captureMessage(`Full page crash: ${error.message || 'Unknown error message'}`, {
- level: 'error',
- })
}
useEffect(() => {
@@ -145,6 +150,30 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
+ const user = useUser()
+ useEffect(() => {
+ // don't set the sentry user id if
+ // - on self-hosted or CLI
+ // - the user has not consented to telemetry
+ // - the user hasn't logged in (so that Sentry errors show null user id instead of anonymous id)
+ if (!canSendTelemetry() || !user?.id) {
+ return
+ }
+
+ const setSentryId = async () => {
+ let sentryUserId = localStorage.getItem(LOCAL_STORAGE_KEYS.SENTRY_USER_ID)
+
+ if (!sentryUserId) {
+ sentryUserId = await getAnonId(user?.id)
+ localStorage.setItem(LOCAL_STORAGE_KEYS.SENTRY_USER_ID, sentryUserId)
+ }
+ Sentry.setUser({ id: sentryUserId })
+ }
+
+ // if an error happens, continue without setting a sentry id
+ setSentryId().catch((e) => console.error(e))
+ }, [user?.id])
+
useThemeSandbox()
const isTestEnv = process.env.NEXT_PUBLIC_NODE_ENV === 'test'
diff --git a/apps/studio/sentry.client.config.ts b/apps/studio/sentry.client.config.ts
index ec65770b5cb..cc5d0576b79 100644
--- a/apps/studio/sentry.client.config.ts
+++ b/apps/studio/sentry.client.config.ts
@@ -42,8 +42,6 @@ Sentry.init({
// Original format: new Error(`Parse error: Unexpected "${text}" at line ${line} column ${col}`)
/^Parse error: Unexpected ".+" at line \d+ column \d+$/,
],
- // Allow for exception captures originating only from our own code.
- allowUrls: ['app:///_next/'],
})
// Replace dynamic query param with a template text
diff --git a/package-lock.json b/package-lock.json
index 21c6c2faaa1..ea92a6d1e69 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2101,6 +2101,7 @@
"apps/studio": {
"version": "0.0.9",
"dependencies": {
+ "@aws-crypto/sha256-browser": "^3.0.0",
"@dagrejs/dagre": "^1.0.4",
"@graphiql/react": "^0.19.4",
"@graphiql/toolkit": "^0.9.1",
@@ -3574,7 +3575,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@aws-crypto/ie11-detection/-/ie11-detection-3.0.0.tgz",
"integrity": "sha512-341lBBkiY1DfDNKai/wXM3aujNBkXR7tq1URPQDL9wi3AUbI80NR74uF1TXHMm7po1AcnFk8iu2S2IeU/+/A+Q==",
- "dev": true,
"dependencies": {
"tslib": "^1.11.1"
}
@@ -3582,14 +3582,12 @@
"node_modules/@aws-crypto/ie11-detection/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
- "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
- "dev": true
+ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/@aws-crypto/sha256-browser": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@aws-crypto/sha256-browser/-/sha256-browser-3.0.0.tgz",
"integrity": "sha512-8VLmW2B+gjFbU5uMeqtQM6Nj0/F1bro80xQXCW6CQBWgosFWXTx77aeOF5CAIAmbOK64SdMBJdNr6J41yP5mvQ==",
- "dev": true,
"dependencies": {
"@aws-crypto/ie11-detection": "^3.0.0",
"@aws-crypto/sha256-js": "^3.0.0",
@@ -3604,14 +3602,12 @@
"node_modules/@aws-crypto/sha256-browser/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
- "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
- "dev": true
+ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/@aws-crypto/sha256-js": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@aws-crypto/sha256-js/-/sha256-js-3.0.0.tgz",
"integrity": "sha512-PnNN7os0+yd1XvXAy23CFOmTbMaDxgxXtTKHybrJ39Y8kGzBATgBFibWJKH6BhytLI/Zyszs87xCOBNyBig6vQ==",
- "dev": true,
"dependencies": {
"@aws-crypto/util": "^3.0.0",
"@aws-sdk/types": "^3.222.0",
@@ -3621,14 +3617,12 @@
"node_modules/@aws-crypto/sha256-js/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
- "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
- "dev": true
+ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/@aws-crypto/supports-web-crypto": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@aws-crypto/supports-web-crypto/-/supports-web-crypto-3.0.0.tgz",
"integrity": "sha512-06hBdMwUAb2WFTuGG73LSC0wfPu93xWwo5vL2et9eymgmu3Id5vFAHBbajVWiGhPO37qcsdCap/FqXvJGJWPIg==",
- "dev": true,
"dependencies": {
"tslib": "^1.11.1"
}
@@ -3636,14 +3630,12 @@
"node_modules/@aws-crypto/supports-web-crypto/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
- "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
- "dev": true
+ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/@aws-crypto/util": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@aws-crypto/util/-/util-3.0.0.tgz",
"integrity": "sha512-2OJlpeJpCR48CC8r+uKVChzs9Iungj9wkZrl8Z041DWEWvyIHILYKCPNzJghKsivj+S3mLo6BVc7mBNzdxA46w==",
- "dev": true,
"dependencies": {
"@aws-sdk/types": "^3.222.0",
"@aws-sdk/util-utf8-browser": "^3.0.0",
@@ -3653,8 +3645,7 @@
"node_modules/@aws-crypto/util/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
- "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
- "dev": true
+ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/@aws-sdk/client-secrets-manager": {
"version": "3.468.0",
@@ -4094,7 +4085,6 @@
"version": "3.468.0",
"resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.468.0.tgz",
"integrity": "sha512-rx/9uHI4inRbp2tw3Y4Ih4PNZkVj32h7WneSg3MVgVjAoVD5Zti9KhS5hkvsBxfgmQmg0AQbE+b1sy5WGAgntA==",
- "dev": true,
"dependencies": {
"@smithy/types": "^2.7.0",
"tslib": "^2.5.0"
@@ -4121,7 +4111,6 @@
"version": "3.465.0",
"resolved": "https://registry.npmjs.org/@aws-sdk/util-locate-window/-/util-locate-window-3.465.0.tgz",
"integrity": "sha512-f+QNcWGswredzC1ExNAB/QzODlxwaTdXkNT5cvke2RLX8SFU5pYk6h4uCtWC0vWPELzOfMfloBrJefBzlarhsw==",
- "dev": true,
"dependencies": {
"tslib": "^2.5.0"
},
@@ -4168,7 +4157,6 @@
"version": "3.259.0",
"resolved": "https://registry.npmjs.org/@aws-sdk/util-utf8-browser/-/util-utf8-browser-3.259.0.tgz",
"integrity": "sha512-UvFa/vR+e19XookZF8RzFZBrw2EUkQWxiBW0yYQAhvk3C+QVGl0H3ouca8LDBlBfQKXwmW3huo/59H8rwb1wJw==",
- "dev": true,
"dependencies": {
"tslib": "^2.3.1"
}
@@ -11447,7 +11435,6 @@
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/@smithy/types/-/types-2.7.0.tgz",
"integrity": "sha512-1OIFyhK+vOkMbu4aN2HZz/MomREkrAC/HqY5mlJMUJfGrPRwijJDTeiN8Rnj9zUaB8ogXAfIOtZrrgqZ4w7Wnw==",
- "dev": true,
"dependencies": {
"tslib": "^2.5.0"
},