Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Migrate Supabase integration to dataCollection#21085
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,7 @@ import { | ||
| translateFiltersIntoMethods, | ||
| } from '../../../src/integrations/supabase'; | ||
| import type { PostgRESTQueryBuilder, SupabaseClientInstance } from '../../../src/integrations/supabase'; | ||
| import { resolveDataCollectionOptions } from '../../../src/utils/data-collection/resolveDataCollectionOptions'; | ||
| const tracingMocks = vi.hoisted(() => ({ | ||
| startSpan: vi.fn((_opts: unknown, cb: (span: unknown) => unknown) => { | ||
| @@ -38,23 +39,23 @@ type CreateMockSupabaseClientOptions = { | ||
| method?: string; | ||
| url?: URL | string; | ||
| body?: unknown; | ||
| /** When set, configures the mocked Sentry client `sendDefaultPii`. Omit to leave `getClient` to the test file `beforeEach`. */ | ||
| sendDefaultPii?: boolean; | ||
| /** When set, configures the mocked Sentry client's `dataCollection.userInfo`. Omit to leave `getClient` to the test file `beforeEach`. */ | ||
| dataCollectionUserInfo?: boolean; | ||
| }; | ||
| const DEFAULT_MOCK_SUPABASE_REST_URL = 'https://example.supabase.co/rest/v1/todos'; | ||
| /** Shared PATCH + query string + body shape for `sendDefaultPii` tests. */ | ||
| /** Shared PATCH + query string + body shape for operation data tests. */ | ||
| const MOCK_SUPABASE_PII_SCENARIO: Pick<CreateMockSupabaseClientOptions, 'method' | 'url' | 'body'> = { | ||
| method: 'PATCH', | ||
| url: 'https://example.supabase.co/rest/v1/users?email=eq.secret%40example.com&select=id', | ||
| body: { full_name: 'Jane Doe', phone: '555-0100' }, | ||
| }; | ||
| function createMockSupabaseClient(resolveWith: unknown, options?: CreateMockSupabaseClientOptions): unknown { | ||
| if (options?.sendDefaultPii !== undefined) { | ||
| if (options?.dataCollectionUserInfo !== undefined) { | ||
| currentScopesMocks.getClient.mockReturnValue({ | ||
| getOptions: () => ({ sendDefaultPii: options.sendDefaultPii }), | ||
| getDataCollectionOptions: () => ({ userInfo: options.dataCollectionUserInfo }), | ||
| } as any); | ||
| } | ||
| @@ -223,7 +224,7 @@ describe('Supabase Integration', () => { | ||
| }); | ||
| }); | ||
| describe('sendDefaultPii', () => { | ||
| describe('operation data collection', () => { | ||
| let captureExceptionSpy: ReturnType<typeof vi.spyOn>; | ||
| let addBreadcrumbSpy: ReturnType<typeof vi.spyOn>; | ||
| @@ -236,10 +237,10 @@ describe('Supabase Integration', () => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
| it('omits db.query, db.body, and breadcrumb query/body when sendDefaultPii is false', async () => { | ||
| it('omits db.query, db.body, and breadcrumb query/body when dataCollection.userInfo is false', async () => { | ||
| const client = createMockSupabaseClient( | ||
| { status: 200 }, | ||
| { ...MOCK_SUPABASE_PII_SCENARIO, sendDefaultPii: false }, | ||
| { ...MOCK_SUPABASE_PII_SCENARIO, dataCollectionUserInfo: false }, | ||
| ); | ||
| instrumentSupabaseClient(client); | ||
| @@ -258,8 +259,11 @@ describe('Supabase Integration', () => { | ||
| expect(breadcrumb).not.toHaveProperty('data'); | ||
| }); | ||
| it('includes db.query, db.body, and breadcrumb query/body when sendDefaultPii is true', async () => { | ||
| const client = createMockSupabaseClient({ status: 200 }, { ...MOCK_SUPABASE_PII_SCENARIO, sendDefaultPii: true }); | ||
| it('includes db.query, db.body, and breadcrumb query/body when dataCollection.userInfo is true', async () => { | ||
| const client = createMockSupabaseClient( | ||
| { status: 200 }, | ||
| { ...MOCK_SUPABASE_PII_SCENARIO, dataCollectionUserInfo: true }, | ||
| ); | ||
| instrumentSupabaseClient(client); | ||
| await (client as any).from('users').update({}).then(); | ||
| @@ -286,10 +290,95 @@ describe('Supabase Integration', () => { | ||
| ); | ||
| }); | ||
| it('omits supabase error context query/body when sendDefaultPii is false', async () => { | ||
| it('includes data when sendOperationData option is set, regardless of dataCollection.userInfo', async () => { | ||
| const client = createMockSupabaseClient( | ||
| { status: 200 }, | ||
| { ...MOCK_SUPABASE_PII_SCENARIO, dataCollectionUserInfo: false }, | ||
| ); | ||
| instrumentSupabaseClient(client, { sendOperationData: true }); | ||
| await (client as any).from('users').update({}).then(); | ||
| const spanOptions = tracingMocks.startSpan.mock.calls[0]![0] as { | ||
| name: string; | ||
| attributes: Record<string, unknown>; | ||
| }; | ||
| expect(spanOptions.name).toContain('eq(email, secret@example.com)'); | ||
| expect(spanOptions.attributes['db.query']).toEqual( | ||
| expect.arrayContaining([expect.stringContaining('secret@example.com')]), | ||
| ); | ||
| expect(spanOptions.attributes['db.body']).toEqual( | ||
| expect.objectContaining({ full_name: 'Jane Doe', phone: '555-0100' }), | ||
| ); | ||
| }); | ||
| it('sendOperationData: false takes precedence over dataCollection.userInfo: true', async () => { | ||
| const client = createMockSupabaseClient( | ||
| { status: 200 }, | ||
| { ...MOCK_SUPABASE_PII_SCENARIO, dataCollectionUserInfo: true }, | ||
| ); | ||
| instrumentSupabaseClient(client, { sendOperationData: false }); | ||
| await (client as any).from('users').update({}).then(); | ||
| const spanOptions = tracingMocks.startSpan.mock.calls[0]![0] as { | ||
| name: string; | ||
| attributes: Record<string, unknown>; | ||
| }; | ||
| expect(spanOptions.name).toContain('[redacted]'); | ||
| expect(spanOptions.attributes['db.query']).toBeUndefined(); | ||
| expect(spanOptions.attributes['db.body']).toBeUndefined(); | ||
| }); | ||
chargome marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| it('includes data when legacy sendDefaultPii: true is bridged to dataCollection.userInfo', async () => { | ||
| const resolved = resolveDataCollectionOptions({ sendDefaultPii: true }); | ||
| currentScopesMocks.getClient.mockReturnValue({ | ||
| getDataCollectionOptions: () => resolved, | ||
| } as any); | ||
| const client = createMockSupabaseClient({ status: 200 }, { ...MOCK_SUPABASE_PII_SCENARIO }); | ||
| instrumentSupabaseClient(client); | ||
| await (client as any).from('users').update({}).then(); | ||
| const spanOptions = tracingMocks.startSpan.mock.calls[0]![0] as { | ||
| name: string; | ||
| attributes: Record<string, unknown>; | ||
| }; | ||
| expect(spanOptions.name).toContain('eq(email, secret@example.com)'); | ||
| expect(spanOptions.attributes['db.query']).toEqual( | ||
| expect.arrayContaining([expect.stringContaining('secret@example.com')]), | ||
| ); | ||
| expect(spanOptions.attributes['db.body']).toEqual( | ||
| expect.objectContaining({ full_name: 'Jane Doe', phone: '555-0100' }), | ||
| ); | ||
| }); | ||
| it('redacts data when legacy sendDefaultPii is not set (bridged defaults)', async () => { | ||
| const resolved = resolveDataCollectionOptions({ sendDefaultPii: false }); | ||
| currentScopesMocks.getClient.mockReturnValue({ | ||
| getDataCollectionOptions: () => resolved, | ||
| } as any); | ||
| const client = createMockSupabaseClient({ status: 200 }, { ...MOCK_SUPABASE_PII_SCENARIO }); | ||
| instrumentSupabaseClient(client); | ||
| await (client as any).from('users').update({}).then(); | ||
| const spanOptions = tracingMocks.startSpan.mock.calls[0]![0] as { | ||
| name: string; | ||
| attributes: Record<string, unknown>; | ||
| }; | ||
| expect(spanOptions.name).toContain('[redacted]'); | ||
| expect(spanOptions.name).not.toContain('secret'); | ||
| expect(spanOptions.attributes['db.query']).toBeUndefined(); | ||
| expect(spanOptions.attributes['db.body']).toBeUndefined(); | ||
| }); | ||
| it('omits supabase error context query/body when data collection is off', async () => { | ||
| const client = createMockSupabaseClient( | ||
| { status: 400, error: { message: 'Bad request', code: '400' } }, | ||
| { ...MOCK_SUPABASE_PII_SCENARIO, sendDefaultPii: false }, | ||
| { ...MOCK_SUPABASE_PII_SCENARIO, dataCollectionUserInfo: false }, | ||
| ); | ||
| instrumentSupabaseClient(client); | ||
| @@ -328,7 +417,7 @@ describe('Supabase Integration', () => { | ||
| method: 'POST', | ||
| url: 'https://example.supabase.co/rest/v1/todos?columns=', | ||
| body: [{ title: 'Test Todo' }], | ||
| sendDefaultPii: true, | ||
| dataCollectionUserInfo: true, | ||
| }, | ||
| ); | ||
| instrumentSupabaseClient(client); | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.