Skip to content

Commit ccc7d32

Browse files
authored
ref(core): Improve event mechanism for supabase integration (#17286)
see #17212
1 parent 735c1d8 commit ccc7d32

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/core/src/integrations/supabase.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { setHttpStatus, SPAN_STATUS_ERROR, SPAN_STATUS_OK, startSpan } from '../
1111
import type { IntegrationFn } from '../types-hoist/integration';
1212
import { debug } from '../utils/debug-logger';
1313
import { isPlainObject } from '../utils/is';
14+
import { addExceptionMechanism } from '../utils/misc';
1415

1516
const AUTH_OPERATIONS_TO_INSTRUMENT = [
1617
'reauthenticate',
@@ -236,6 +237,7 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A
236237
captureException(res.error, {
237238
mechanism: {
238239
handled: false,
240+
type: 'auto.db.supabase.auth',
239241
},
240242
});
241243
} else {
@@ -252,6 +254,7 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A
252254
captureException(err, {
253255
mechanism: {
254256
handled: false,
257+
type: 'auto.db.supabase.auth',
255258
},
256259
});
257260

@@ -408,18 +411,27 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte
408411
err.details = res.error.details;
409412
}
410413

411-
const supabaseContext: Record<string, unknown> = {};
414+
const supabaseContext: Record<string, any> = {};
412415
if (queryItems.length) {
413416
supabaseContext.query = queryItems;
414417
}
415418
if (Object.keys(body).length) {
416419
supabaseContext.body = body;
417420
}
418421

419-
captureException(err, {
420-
contexts: {
421-
supabase: supabaseContext,
422-
},
422+
captureException(err, scope => {
423+
scope.addEventProcessor(e => {
424+
addExceptionMechanism(e, {
425+
handled: false,
426+
type: 'auto.db.supabase.postgres',
427+
});
428+
429+
return e;
430+
});
431+
432+
scope.setContext('supabase', supabaseContext);
433+
434+
return scope;
423435
});
424436
}
425437

@@ -448,6 +460,7 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte
448460
return res;
449461
},
450462
(err: Error) => {
463+
// TODO: shouldn't we capture this error?
451464
if (span) {
452465
setHttpStatus(span, 500);
453466
span.end();

0 commit comments

Comments
 (0)