-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Add Supabase Queues support #15921
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
onurtemizkan
wants to merge
10
commits into
develop
Choose a base branch
from
onur/supabase-queues
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,900
−40
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d3c0f13
feat(core): Add Supabase Queues support
onurtemizkan 44c9d4b
Replace chained .map().filter() with for loop
onurtemizkan dbd1768
Preserve PostgrestFilterBuilder method chaining for generic RPC instr…
onurtemizkan 358098d
Properly end spans in generic RPC instrumentation
onurtemizkan ddf80bd
Avoid overwriting specific HTTP error status
onurtemizkan cdb104c
Only set batch message count for batch consumer spans
onurtemizkan 3fd7452
Combine .some() and .map() into single pass for metadata cleanup
onurtemizkan 611a647
Distinguish queue producer and consumer error mechanisms
onurtemizkan a363946
Reuse `messageId` from `processConsumerSpanData` instead of recomputi…
onurtemizkan a155526
Remove `receive` alias and fix generic RPC span attributes
onurtemizkan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
dev-packages/browser-integration-tests/suites/integrations/supabase/generic-rpc/init.js
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { createClient } from '@supabase/supabase-js'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| const supabaseClient = createClient('https://test.supabase.co', 'test-key'); | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.browserTracingIntegration(), Sentry.supabaseIntegration({ supabaseClient })], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
|
|
||
| // Simulate generic RPC call | ||
| async function callGenericRpc() { | ||
| try { | ||
| await supabaseClient.rpc('my_custom_function', { param1: 'value1' }); | ||
| } catch (error) { | ||
| Sentry.captureException(error); | ||
| } | ||
| } | ||
|
|
||
| callGenericRpc(); |
58 changes: 58 additions & 0 deletions
58
dev-packages/browser-integration-tests/suites/integrations/supabase/generic-rpc/test.ts
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import type { Page } from '@playwright/test'; | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
|
||
| async function mockSupabaseRoute(page: Page) { | ||
| await page.route('**/rpc/my_custom_function', route => { | ||
| return route.fulfill({ | ||
| status: 200, | ||
| body: JSON.stringify({ result: 'success' }), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| const bundle = process.env.PW_BUNDLE || ''; | ||
| // We only want to run this in non-CDN bundle mode | ||
| if (bundle.startsWith('bundle')) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| sentryTest( | ||
| 'should capture exactly one db span for generic RPC calls (no double instrumentation)', | ||
| async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| return; | ||
| } | ||
|
|
||
| await mockSupabaseRoute(page); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const event = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
| const dbSpans = event.spans?.filter(({ op }) => op === 'db'); | ||
|
|
||
| // Should have exactly one db span (not doubled by PostgREST instrumentation) | ||
| expect(dbSpans).toHaveLength(1); | ||
|
|
||
| expect(dbSpans![0]).toMatchObject({ | ||
| description: 'rpc(my_custom_function)', | ||
| parent_span_id: event.contexts?.trace?.span_id, | ||
| span_id: expect.any(String), | ||
| start_timestamp: expect.any(Number), | ||
| timestamp: expect.any(Number), | ||
| trace_id: event.contexts?.trace?.trace_id, | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'db', | ||
| 'sentry.origin': 'auto.db.supabase', | ||
| 'db.system': 'postgresql', | ||
| 'db.operation': 'rpc', | ||
| 'db.params': { param1: 'value1' }, | ||
| }), | ||
| }); | ||
| }, | ||
| ); |
34 changes: 34 additions & 0 deletions
34
dev-packages/browser-integration-tests/suites/integrations/supabase/queues-rpc/init.js
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { createClient } from '@supabase/supabase-js'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| const supabaseClient = createClient('https://test.supabase.co', 'test-key', { | ||
| db: { | ||
| schema: 'pgmq_public', | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.browserTracingIntegration(), Sentry.supabaseIntegration({ supabaseClient })], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
|
|
||
| // Simulate queue operations | ||
| async function performQueueOperations() { | ||
| try { | ||
| await supabaseClient.rpc('send', { | ||
| queue_name: 'todos', | ||
| message: { title: 'Test Todo' }, | ||
| }); | ||
|
|
||
| await supabaseClient.rpc('pop', { | ||
| queue_name: 'todos', | ||
| }); | ||
| } catch (error) { | ||
| Sentry.captureException(error); | ||
| } | ||
| } | ||
|
|
||
| performQueueOperations(); | ||
82 changes: 82 additions & 0 deletions
82
dev-packages/browser-integration-tests/suites/integrations/supabase/queues-rpc/test.ts
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import type { Page } from '@playwright/test'; | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
|
||
| async function mockSupabaseRoute(page: Page) { | ||
| await page.route('**/rpc/send', route => { | ||
| return route.fulfill({ | ||
| status: 200, | ||
| body: JSON.stringify([0]), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| await page.route('**/rpc/pop', route => { | ||
| return route.fulfill({ | ||
| status: 200, | ||
| body: JSON.stringify([ | ||
| { | ||
| msg_id: 0, | ||
| }, | ||
| ]), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| const bundle = process.env.PW_BUNDLE || ''; | ||
| // We only want to run this in non-CDN bundle mode | ||
| if (bundle.startsWith('bundle')) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| sentryTest('should capture Supabase queue spans from client.rpc', async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| return; | ||
| } | ||
|
|
||
| await mockSupabaseRoute(page); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const event = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
| const queueSpans = event.spans?.filter(({ op }) => op?.startsWith('queue.')); | ||
|
|
||
| expect(queueSpans).toHaveLength(2); | ||
|
|
||
| expect(queueSpans![0]).toMatchObject({ | ||
| description: 'publish todos', | ||
| parent_span_id: event.contexts?.trace?.span_id, | ||
| span_id: expect.any(String), | ||
| start_timestamp: expect.any(Number), | ||
| timestamp: expect.any(Number), | ||
| trace_id: event.contexts?.trace?.trace_id, | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'queue.publish', | ||
| 'sentry.origin': 'auto.db.supabase.queue.producer', | ||
| 'messaging.destination.name': 'todos', | ||
| 'messaging.message.id': '0', | ||
| }), | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| expect(queueSpans![1]).toMatchObject({ | ||
| description: 'process todos', | ||
| parent_span_id: event.contexts?.trace?.span_id, | ||
| span_id: expect.any(String), | ||
| start_timestamp: expect.any(Number), | ||
| timestamp: expect.any(Number), | ||
| trace_id: event.contexts?.trace?.trace_id, | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'queue.process', | ||
| 'sentry.origin': 'auto.db.supabase.queue.consumer', | ||
| 'messaging.destination.name': 'todos', | ||
| 'messaging.message.id': '0', | ||
| }), | ||
| }); | ||
| }); | ||
34 changes: 34 additions & 0 deletions
34
...es/browser-integration-tests/suites/integrations/supabase/queues-schema-qualified/init.js
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { createClient } from '@supabase/supabase-js'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| const supabaseClient = createClient('https://test.supabase.co', 'test-key', { | ||
| db: { | ||
| schema: 'pgmq_public', | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.browserTracingIntegration(), Sentry.supabaseIntegration({ supabaseClient })], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
|
|
||
| // Simulate queue operations | ||
| async function performQueueOperations() { | ||
| try { | ||
| await supabaseClient.rpc('pgmq.send', { | ||
| queue_name: 'todos', | ||
| message: { title: 'Test Todo' }, | ||
| }); | ||
|
|
||
| await supabaseClient.rpc('pgmq.pop', { | ||
| queue_name: 'todos', | ||
| }); | ||
| } catch (error) { | ||
| Sentry.captureException(error); | ||
| } | ||
| } | ||
|
|
||
| performQueueOperations(); |
82 changes: 82 additions & 0 deletions
82
...es/browser-integration-tests/suites/integrations/supabase/queues-schema-qualified/test.ts
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import type { Page } from '@playwright/test'; | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
|
||
| async function mockSupabaseRoute(page: Page) { | ||
| await page.route('**/rpc/pgmq.send', route => { | ||
| return route.fulfill({ | ||
| status: 200, | ||
| body: JSON.stringify([0]), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| await page.route('**/rpc/pgmq.pop', route => { | ||
| return route.fulfill({ | ||
| status: 200, | ||
| body: JSON.stringify([ | ||
| { | ||
| msg_id: 0, | ||
| }, | ||
| ]), | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| const bundle = process.env.PW_BUNDLE || ''; | ||
| // We only want to run this in non-CDN bundle mode | ||
| if (bundle.startsWith('bundle')) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| sentryTest('should capture Supabase queue spans from schema-qualified RPC names', async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| return; | ||
| } | ||
|
|
||
| await mockSupabaseRoute(page); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const event = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
| const queueSpans = event.spans?.filter(({ op }) => op?.startsWith('queue.')); | ||
|
|
||
| expect(queueSpans).toHaveLength(2); | ||
|
|
||
| expect(queueSpans![0]).toMatchObject({ | ||
| description: 'publish todos', | ||
| parent_span_id: event.contexts?.trace?.span_id, | ||
| span_id: expect.any(String), | ||
| start_timestamp: expect.any(Number), | ||
| timestamp: expect.any(Number), | ||
| trace_id: event.contexts?.trace?.trace_id, | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'queue.publish', | ||
| 'sentry.origin': 'auto.db.supabase.queue.producer', | ||
| 'messaging.destination.name': 'todos', | ||
| 'messaging.message.id': '0', | ||
| }), | ||
| }); | ||
|
|
||
| expect(queueSpans![1]).toMatchObject({ | ||
| description: 'process todos', | ||
| parent_span_id: event.contexts?.trace?.span_id, | ||
| span_id: expect.any(String), | ||
| start_timestamp: expect.any(Number), | ||
| timestamp: expect.any(Number), | ||
| trace_id: event.contexts?.trace?.trace_id, | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'queue.process', | ||
| 'sentry.origin': 'auto.db.supabase.queue.consumer', | ||
| 'messaging.destination.name': 'todos', | ||
| 'messaging.message.id': '0', | ||
| }), | ||
| }); | ||
| }); |
34 changes: 34 additions & 0 deletions
34
dev-packages/browser-integration-tests/suites/integrations/supabase/queues-schema/init.js
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| import { createClient } from '@supabase/supabase-js'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| const supabaseClient = createClient('https://test.supabase.co', 'test-key', { | ||
| db: { | ||
| schema: 'pgmq_public', | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [Sentry.browserTracingIntegration(), Sentry.supabaseIntegration({ supabaseClient })], | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
|
|
||
| // Simulate queue operations | ||
| async function performQueueOperations() { | ||
| try { | ||
| await supabaseClient.schema('pgmq_public').rpc('send', { | ||
| queue_name: 'todos', | ||
| message: { title: 'Test Todo' }, | ||
| }); | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| await supabaseClient.schema('pgmq_public').rpc('pop', { | ||
| queue_name: 'todos', | ||
| }); | ||
| } catch (error) { | ||
| Sentry.captureException(error); | ||
| } | ||
| } | ||
|
|
||
| performQueueOperations(); | ||
Oops, something went wrong.
Oops, something went wrong.
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.