The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: Use `beforeSend` hook in Sentry to check for telemetry consent (#26700)
Ivan Vasilov71f860b28de3
diff --git a/apps/studio/components/interfaces/Support/SupportForm.tsx b/apps/studio/components/interfaces/Support/SupportForm.tsxindex d08c9919843..fd07f9c0561 100644--- a/apps/studio/components/interfaces/Support/SupportForm.tsx+++ b/apps/studio/components/interfaces/Support/SupportForm.tsx@@ -13,7 +13,6 @@ 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'@@ -79,9 +78,7 @@ const SupportForm = ({ setSentCategory, setSelectedProject }: SupportFormProps)},onError: (error) => {toast.error(`Failed to submit support ticket: ${error.message}`)- if (canSendTelemetry()) {- Sentry.captureMessage('Failed to submit Support Form: ' + error.message)- }+ Sentry.captureMessage('Failed to submit Support Form: ' + error.message)setIsSubmitting(false)},})diff --git a/apps/studio/data/fetchers.ts b/apps/studio/data/fetchers.tsindex 894d2aec78c..e9197229044 100644--- a/apps/studio/data/fetchers.ts+++ b/apps/studio/data/fetchers.ts@@ -2,7 +2,6 @@ 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@@ -161,13 +160,9 @@ export const handleError = (error: any): never => {}console.error(error.stack)- 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)}.`- )- }+ // 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.captureException(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/telemetry.ts b/apps/studio/lib/telemetry.tsindex 2bf7353414e..3b37e3a0637 100644--- a/apps/studio/lib/telemetry.ts+++ b/apps/studio/lib/telemetry.ts@@ -114,18 +114,6 @@ 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.*/diff --git a/apps/studio/pages/_app.tsx b/apps/studio/pages/_app.tsxindex 79e6acff77d..84a9254b3ea 100644--- a/apps/studio/pages/_app.tsx+++ b/apps/studio/pages/_app.tsx@@ -52,7 +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 { getAnonId } from 'lib/telemetry'import { useAppStateSnapshot } from 'state/app-state'import HCaptchaLoadedStore from 'stores/hcaptcha-loaded-store'import { AppPropsWithLayout } from 'types'@@ -112,12 +112,10 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {)const errorBoundaryHandler = (error: Error, info: ErrorInfo) => {- if (canSendTelemetry()) {- Sentry.withScope(function (scope) {- scope.setTag('globalErrorBoundary', true)- Sentry.captureException(error)- })- }+ Sentry.withScope(function (scope) {+ scope.setTag('globalErrorBoundary', true)+ Sentry.captureException(error)+ })console.error(error.stack)}@@ -152,11 +150,8 @@ function CustomApp({ Component, pageProps }: AppPropsWithLayout) {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) {+ // don't set the sentry user id if the user hasn't logged in (so that Sentry errors show null user id instead of anonymous id)+ if (!user?.id) {return}diff --git a/apps/studio/sentry.client.config.ts b/apps/studio/sentry.client.config.tsindex cc5d0576b79..c87aca25832 100644--- a/apps/studio/sentry.client.config.ts+++ b/apps/studio/sentry.client.config.ts@@ -1,10 +1,23 @@import * as Sentry from '@sentry/nextjs'+import { IS_PLATFORM } from 'common/constants/environment'+import { LOCAL_STORAGE_KEYS } from 'common/constants/local-storage'import { match } from 'path-to-regexp'Sentry.init({dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,tracesSampleRate: 0.01,debug: false,+ beforeSend(event) {+ const consent =+ typeof window !== 'undefined'+ ? localStorage.getItem(LOCAL_STORAGE_KEYS.TELEMETRY_CONSENT)+ : null++ if (IS_PLATFORM && consent === 'true') {+ return event+ }+ return null+ },integrations: [new Sentry.BrowserTracing({// TODO: update gotrue + api to support Access-Control-Request-Headers: authorization,baggage,sentry-trace,x-client-info