Skip to content

ref(core): Improve event mechanism for supabase integration #17286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions packages/core/src/integrations/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -236,6 +237,7 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A
captureException(res.error, {
mechanism: {
handled: false,
type: 'auto.db.supabase.auth',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these types are one level more specific than the trace origin on the spans (auto.db.supabase). I think this is fine.

},
});
} else {
Expand All @@ -252,6 +254,7 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A
captureException(err, {
mechanism: {
handled: false,
type: 'auto.db.supabase.auth',
},
});

Expand Down Expand Up @@ -408,18 +411,27 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte
err.details = res.error.details;
}

const supabaseContext: Record<string, unknown> = {};
const supabaseContext: Record<string, any> = {};
if (queryItems.length) {
supabaseContext.query = queryItems;
}
if (Object.keys(body).length) {
supabaseContext.body = body;
}

captureException(err, {
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;
});
}

Expand Down Expand Up @@ -448,6 +460,7 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte
return res;
},
(err: Error) => {
// TODO: shouldn't we capture this error?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onurtemizkan not sure if this is me missing something or if we should call captureException here. Can you take a look?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looks like this comes from the original implementation we ported:

https://github.com/supabase-community/sentry-integration-js/blob/9fc7be61d2890f87257c4af528271374c89c4acd/v8.js#L237-L242

I don't see a reason why we should not capture this, though.

if (span) {
setHttpStatus(span, 500);
span.end();
Expand Down