Skip to content

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

Add sample rate to fetcher (#38785)

Jordi Enric506b20734fe8
diff --git a/apps/studio/data/feedback/support-ticket-send.ts b/apps/studio/data/feedback/support-ticket-send.ts
index c981690ccb0..4da7133a7a9 100644
--- a/apps/studio/data/feedback/support-ticket-send.ts
+++ b/apps/studio/data/feedback/support-ticket-send.ts
@@ -57,7 +57,7 @@ export async function sendSupportTicket({
if (error) {
handleError(error, {
- alwaysCapture: true,
+ sampleRate: 1,
sentryContext: {
tags: {
dashboardSupportForm: true,
diff --git a/apps/studio/data/fetchers.ts b/apps/studio/data/fetchers.ts
index f0ca332c3b5..16884d714b8 100644
--- a/apps/studio/data/fetchers.ts
+++ b/apps/studio/data/fetchers.ts
@@ -135,15 +135,12 @@ export const {
} = client
type HandleErrorOptions = {
- alwaysCapture?: boolean
sentryContext?: Parameters<typeof Sentry.captureException>[1]
+ sampleRate?: number
}
export const handleError = (error: unknown, options: HandleErrorOptions = {}): never => {
if (error && typeof error === 'object') {
- if (options.alwaysCapture) {
- Sentry.captureException(error, options.sentryContext)
- }
const errorMessage =
'msg' in error && typeof error.msg === 'string'
? error.msg
@@ -157,6 +154,12 @@ export const handleError = (error: unknown, options: HandleErrorOptions = {}): n
const retryAfter =
'retryAfter' in error && typeof error.retryAfter === 'number' ? error.retryAfter : undefined
+ const shouldCapture = Math.random() < (options?.sampleRate ?? 0.2) // 20% sample rate
+
+ if (shouldCapture) {
+ Sentry.captureException(error, options.sentryContext)
+ }
+
if (errorMessage) {
throw new ResponseError(errorMessage, errorCode, requestId, retryAfter)
}
@@ -166,10 +169,6 @@ export const handleError = (error: unknown, options: HandleErrorOptions = {}): n
console.error(error.stack)
}
- // 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, options.sentryContext)
-
// 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.
throw new ResponseError(undefined)
diff --git a/apps/studio/data/permissions/permissions-query.ts b/apps/studio/data/permissions/permissions-query.ts
index 783ed966bd3..3da0588c662 100644
--- a/apps/studio/data/permissions/permissions-query.ts
+++ b/apps/studio/data/permissions/permissions-query.ts
@@ -18,7 +18,6 @@ export async function getPermissions(signal?: AbortSignal) {
// since those may require investigation if they spike
const sendError = statusCode >= 500 || statusCode === 'unknown'
handleError(error, {
- alwaysCapture: sendError,
sentryContext: {
tags: {
permissionsQuery: true,