mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
chore(common): send Studio empty-body diagnostics to Sentry unsampled
filterSentryEvent keeps 1% of non-crash events, which would leave almost nothing of a once-per-session warning. Exempt events tagged `empty_body_diagnostic` from sampling; only Studio's empty-body reporter sets that tag, so www and docs are unaffected. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UefDak8XYLMi9aiEjDPXc5
This commit is contained in:
4 files changed
+39
-4
No files matched your search
@@ -87,7 +87,11 @@ describe('reportEmptyBodyResponse', () => {
|
||||
expect(context).toMatchObject({
|
||||
level: 'warning',
|
||||
fingerprint: ['empty-body-response', '/platform/projects/{ref}/a'],
|
||||
tags: { endpoint: '/platform/projects/{ref}/a', probe_has_body: 'true' },
|
||||
tags: {
|
||||
endpoint: '/platform/projects/{ref}/a',
|
||||
probe_has_body: 'true',
|
||||
empty_body_diagnostic: 'true',
|
||||
},
|
||||
extra: {
|
||||
method: 'GET',
|
||||
status: 200,
|
||||
|
||||
@@ -161,7 +161,7 @@ export async function reportEmptyBodyResponse({
|
||||
Sentry.captureMessage('Empty response body on successful API request', {
|
||||
level: 'warning',
|
||||
fingerprint: ['empty-body-response', endpoint],
|
||||
tags: { endpoint, probe_has_body },
|
||||
tags: { endpoint, probe_has_body, empty_body_diagnostic: 'true' },
|
||||
extra: { ...context, ...probeContext },
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -51,6 +51,30 @@ describe('which errors get sent to Sentry', () => {
|
||||
expect(filterSentryEvent(event, enabled) === event).toBe(isSent)
|
||||
})
|
||||
|
||||
it.each([true, 'true'])(
|
||||
'sends every Studio empty-body diagnostic without sampling: %s',
|
||||
(tag) => {
|
||||
const random = vi.spyOn(Math, 'random').mockReturnValue(0.99)
|
||||
const event = { tags: { empty_body_diagnostic: tag } }
|
||||
expect(filterSentryEvent(event, enabled)).toBe(event)
|
||||
expect(event.tags).toEqual({ empty_body_diagnostic: tag, codeSampleRate: '1' })
|
||||
expect(random).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
|
||||
it.each([false, 'false', null])(
|
||||
'still samples events whose empty-body diagnostic tag is not set: %s',
|
||||
(tag) => {
|
||||
vi.spyOn(Math, 'random').mockReturnValue(0.99)
|
||||
expect(filterSentryEvent({ tags: { empty_body_diagnostic: tag } }, enabled)).toBeNull()
|
||||
}
|
||||
)
|
||||
|
||||
it('drops empty-body diagnostics when reporting is turned off', () => {
|
||||
const tags = { empty_body_diagnostic: 'true' }
|
||||
expect(filterSentryEvent({ tags }, { isPlatform: true, hasConsent: false })).toBeNull()
|
||||
})
|
||||
|
||||
it.each([undefined, false, 'false', null, 1])(
|
||||
'drops errors from outside the app unless marked as a page crash: %s',
|
||||
(tag) => {
|
||||
|
||||
@@ -3,6 +3,7 @@ type SentryEventTags = {
|
||||
globalErrorBoundary?: string | number | boolean | null
|
||||
third_party_code?: string | number | boolean | null
|
||||
codeSampleRate?: string | number | boolean | null
|
||||
empty_body_diagnostic?: string | number | boolean | null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +23,18 @@ export function filterSentryEvent<T extends SentryEventTags>(
|
||||
const isThirdPartyOnly =
|
||||
event.tags?.third_party_code === true || event.tags?.third_party_code === 'true'
|
||||
|
||||
// Studio's once-per-session empty-body diagnostic is too rare to sample
|
||||
const isUnsampled =
|
||||
isErrorBoundaryCrash ||
|
||||
event.tags?.empty_body_diagnostic === true ||
|
||||
event.tags?.empty_body_diagnostic === 'true'
|
||||
|
||||
if (isThirdPartyOnly && !isErrorBoundaryCrash) return null
|
||||
if (!isErrorBoundaryCrash && Math.random() >= NON_CRASH_ERROR_SAMPLE_RATE) return null
|
||||
if (!isUnsampled && Math.random() >= NON_CRASH_ERROR_SAMPLE_RATE) return null
|
||||
|
||||
event.tags = {
|
||||
...event.tags,
|
||||
codeSampleRate: isErrorBoundaryCrash ? '1' : NON_CRASH_ERROR_SAMPLE_RATE.toString(),
|
||||
codeSampleRate: isUnsampled ? '1' : NON_CRASH_ERROR_SAMPLE_RATE.toString(),
|
||||
}
|
||||
|
||||
return event
|
||||
|
||||
Reference in new issue
Block a user