From 621e52f68ed3aefa344815672043b14594e8b509 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 31 Jul 2025 10:50:15 +0200 Subject: [PATCH 1/3] ref(core): Improve event `mechanism` for supabase integration --- packages/core/src/integrations/supabase.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/core/src/integrations/supabase.ts b/packages/core/src/integrations/supabase.ts index 360f31142652..739000dbc2a2 100644 --- a/packages/core/src/integrations/supabase.ts +++ b/packages/core/src/integrations/supabase.ts @@ -235,7 +235,9 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A captureException(res.error, { mechanism: { - handled: false, + // assuming handled: true because users are expected to handle returned errors + handled: true, + type: 'supabase.auth', }, }); } else { @@ -251,7 +253,9 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A captureException(err, { mechanism: { + // assuming handled: false here because this is an unexpected error handled: false, + type: 'supabase.auth', }, }); @@ -417,6 +421,11 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte } captureException(err, { + mechanism: { + // assuming handled: true here because users are expected to handle returned errors + handled: true, + type: 'supabase.db', + }, contexts: { supabase: supabaseContext, }, @@ -448,6 +457,7 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte return res; }, (err: Error) => { + // TODO: shouldn't we capture this error? if (span) { setHttpStatus(span, 500); span.end(); From 92949d3fecfab24573bb6fa2a88a2f2b11a5b672 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 1 Aug 2025 16:15:47 +0200 Subject: [PATCH 2/3] use trace origin naming --- packages/core/src/integrations/supabase.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/core/src/integrations/supabase.ts b/packages/core/src/integrations/supabase.ts index 739000dbc2a2..77156752e983 100644 --- a/packages/core/src/integrations/supabase.ts +++ b/packages/core/src/integrations/supabase.ts @@ -235,9 +235,8 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A captureException(res.error, { mechanism: { - // assuming handled: true because users are expected to handle returned errors - handled: true, - type: 'supabase.auth', + handled: false, + type: 'auto.db.supabase.auth', }, }); } else { @@ -253,9 +252,8 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A captureException(err, { mechanism: { - // assuming handled: false here because this is an unexpected error handled: false, - type: 'supabase.auth', + type: 'auto.db.supabase.auth', }, }); @@ -422,9 +420,8 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte captureException(err, { mechanism: { - // assuming handled: true here because users are expected to handle returned errors - handled: true, - type: 'supabase.db', + handled: false, + type: 'auto.db.supabase.postgres', }, contexts: { supabase: supabaseContext, From 568547482ea7e05e7695dfd9587762389ade3bc1 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 1 Aug 2025 16:30:41 +0200 Subject: [PATCH 3/3] fix type error --- packages/core/src/integrations/supabase.ts | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/core/src/integrations/supabase.ts b/packages/core/src/integrations/supabase.ts index 77156752e983..39dedadc9e04 100644 --- a/packages/core/src/integrations/supabase.ts +++ b/packages/core/src/integrations/supabase.ts @@ -11,6 +11,7 @@ import { setHttpStatus, SPAN_STATUS_ERROR, SPAN_STATUS_OK, startSpan } from '../ import type { IntegrationFn } from '../types-hoist/integration'; import { debug } from '../utils/debug-logger'; import { isPlainObject } from '../utils/is'; +import { addExceptionMechanism } from '../utils/misc'; const AUTH_OPERATIONS_TO_INSTRUMENT = [ 'reauthenticate', @@ -410,7 +411,7 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte err.details = res.error.details; } - const supabaseContext: Record = {}; + const supabaseContext: Record = {}; if (queryItems.length) { supabaseContext.query = queryItems; } @@ -418,14 +419,19 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte supabaseContext.body = body; } - captureException(err, { - mechanism: { - handled: false, - type: 'auto.db.supabase.postgres', - }, - contexts: { - supabase: supabaseContext, - }, + captureException(err, scope => { + scope.addEventProcessor(e => { + addExceptionMechanism(e, { + handled: false, + type: 'auto.db.supabase.postgres', + }); + + return e; + }); + + scope.setContext('supabase', supabaseContext); + + return scope; }); }