Skip to content

Conversation

@onurtemizkan
Copy link
Collaborator

@onurtemizkan onurtemizkan commented Mar 28, 2025

Resolves: #14611

Summary:

Sample Queue Event: Link

  • Adds queue spans and breadcrumbs for Supabase Queue operations.
    • Usage with supabaseClient.rpc('<queue_op>', ...)
    • Usage with supabaseClient.schema(...).rpc('queue_op', ...)
  • Mapped operations to their respective op names documented here
    • producer ops: send, send_batch
    • consumer op: pop
  • Added browser integration tests, and e2e tests.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 28, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.64 kB - -
@sentry/browser - with treeshaking flags 23.13 kB - -
@sentry/browser (incl. Tracing) 41.26 kB - -
@sentry/browser (incl. Tracing, Profiling) 45.54 kB - -
@sentry/browser (incl. Tracing, Replay) 79.51 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.2 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.21 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.38 kB - -
@sentry/browser (incl. Feedback) 41.31 kB - -
@sentry/browser (incl. sendFeedback) 29.31 kB - -
@sentry/browser (incl. FeedbackAsync) 34.24 kB - -
@sentry/react 26.32 kB - -
@sentry/react (incl. Tracing) 43.24 kB - -
@sentry/vue 29.13 kB -0.01% -1 B 🔽
@sentry/vue (incl. Tracing) 43.05 kB - -
@sentry/svelte 24.65 kB - -
CDN Bundle 26.9 kB - -
CDN Bundle (incl. Tracing) 41.8 kB - -
CDN Bundle (incl. Tracing, Replay) 78.07 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 83.56 kB - -
CDN Bundle - uncompressed 78.89 kB - -
CDN Bundle (incl. Tracing) - uncompressed 124.01 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 239.2 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 251.96 kB - -
@sentry/nextjs (client) 45.36 kB - -
@sentry/sveltekit (client) 41.67 kB - -
@sentry/node-core 50.81 kB -0.01% -1 B 🔽
@sentry/node 157.88 kB +0.01% +1 B 🔺
@sentry/node - without tracing 92.69 kB - -
@sentry/aws-serverless 106.42 kB +0.01% +3 B 🔺

View base workflow run

@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch from bbadd60 to e7b3370 Compare March 31, 2025 09:44
@onurtemizkan onurtemizkan force-pushed the onur/supabase-integration branch from 1bc2897 to d387514 Compare March 31, 2025 10:26
@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch from e7b3370 to 56a2d84 Compare March 31, 2025 14:12
@onurtemizkan onurtemizkan linked an issue Mar 31, 2025 that may be closed by this pull request
@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch from 56a2d84 to 13d60e0 Compare March 31, 2025 14:25
@onurtemizkan onurtemizkan force-pushed the onur/supabase-integration branch 4 times, most recently from 423397d to 556703c Compare April 14, 2025 15:26
Base automatically changed from onur/supabase-integration to develop April 17, 2025 13:35
@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch from 13d60e0 to 74869e4 Compare April 22, 2025 14:16
@onurtemizkan onurtemizkan marked this pull request as ready for review April 24, 2025 09:32
@onurtemizkan onurtemizkan requested review from lforst and smeubank April 24, 2025 09:33
@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch from e63915a to 719c8b6 Compare April 24, 2025 14:11
},
},
async span => {
return (Reflect.apply(target, thisArg, argumentsList) as Promise<unknown>).then((res: unknown) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also end the span when it throws/rejects? We can also set the status of the span then.

name: 'supabase.db.rpc',
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.supabase',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can add the messaging.system attribute to be 'supabase' as described in https://develop.sentry.dev/sdk/telemetry/traces/modules/queues/

Comment on lines 238 to 239
const isProducerSpan = argumentsList[0] === 'enqueue';
const isConsumerSpan = argumentsList[0] === 'dequeue';
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if this recently changed, but here they show send and pop as rpc args: https://supabase.com/docs/guides/queues/quickstart#enqueueing-and-dequeueing-messages 🤔

@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch 4 times, most recently from fb8eeb1 to a8da234 Compare May 31, 2025 20:58
@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch 2 times, most recently from ff2f804 to 5ce5ee9 Compare June 23, 2025 15:58
@onurtemizkan onurtemizkan requested review from AbhiPrasad and Lms24 June 23, 2025 23:39
@AbhiPrasad
Copy link
Member

@sentry review

@seer-by-sentry
Copy link

On it! We are reviewing the PR and will provide feedback shortly.

@seer-by-sentry
Copy link

PR Description

This pull request introduces instrumentation for Supabase queue operations using pgmq, enabling Sentry to capture spans and breadcrumbs for queue publishing and processing. This provides visibility into asynchronous task execution within Supabase applications.

Click to see more

Key Technical Changes

The key technical changes include: 1) Instrumenting the rpc method of the Supabase client to detect queue operations (send, send_batch, pop). 2) Creating spans for queue publish and process operations, capturing relevant metadata like queue name and message ID. 3) Adding breadcrumbs for queue operations to provide context in Sentry events. 4) Modifying queue messages to inject Sentry trace context for distributed tracing. 5) Adding e2e tests to verify the instrumentation in a Next.js application.

Architecture Decisions

The primary architectural decision involves using Proxy objects to intercept calls to the Supabase client's rpc method and the schema(...).rpc(...) method. This allows for non-intrusive instrumentation without modifying the Supabase client's core code. The trace context is injected directly into the message body to propagate tracing information across queue operations.

Dependencies and Interactions

This integration depends on the @supabase/supabase-js library and interacts with Sentry's tracing and breadcrumb APIs. It also relies on the pgmq extension being enabled in the Supabase database. The integration injects Sentry trace context into queue messages, which requires consumers to be instrumented to extract and continue the trace.

Risk Considerations

Potential risks include: 1) Performance overhead due to the instrumentation, although proxies are generally performant. 2) Incorrectly identifying queue operations, leading to spurious spans. 3) Failure to propagate trace context if consumers are not properly instrumented. 4) Security implications of modifying message bodies, although the injected data is limited to Sentry trace context. 5) The modification of the arguments list in place could lead to unexpected side effects.

Notable Implementation Details

Notable implementation details include: 1) The use of continueTrace to link consumer spans to producer spans. 2) The handling of both rpc and schema(...).rpc(...) calls. 3) The injection of Sentry trace context into the message body. 4) The vendoring of SQL code from the Supabase repository to enable queue access locally.

@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch from 4f19854 to 1c518a2 Compare July 3, 2025 14:40
cursor[bot]

This comment was marked as outdated.

@smeubank
Copy link
Contributor

anybody got eyes on this anymore? 😅

@onurtemizkan onurtemizkan force-pushed the onur/supabase-queues branch from 1c518a2 to 327b57a Compare July 24, 2025 11:29
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,903 - 8,837 +1%
GET With Sentry 1,251 14% 1,275 -2%
GET With Sentry (error only) 5,898 66% 5,923 -0%
POST Baseline 1,169 - 1,153 +1%
POST With Sentry 484 41% 476 +2%
POST With Sentry (error only) 1,026 88% 1,018 +1%
MYSQL Baseline 3,231 - 3,212 +1%
MYSQL With Sentry 420 13% 366 +15%
MYSQL With Sentry (error only) 2,618 81% 2,570 +2%

View base workflow run

op: 'queue.publish',
attributes: expect.objectContaining({
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.queue.supabase.producer',
'messaging.system': 'supabase',
Copy link

Choose a reason for hiding this comment

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

Bug: Mismatched Sentry Origin for Supabase Queue spans

The unit tests for Supabase queue instrumentation expect incorrect sentry.origin values for both producer and consumer spans. The tests assert 'auto.queue.supabase.producer' and 'auto.queue.supabase.consumer', but the implementation actually sets 'auto.db.supabase.queue.producer' and 'auto.db.supabase.queue.consumer'. This mismatch causes test failures, while E2E tests correctly reflect the implementation.

Additional Locations (1)

Fix in Cursor Fix in Web

await supabaseClient.rpc('send', {
queue_name: 'todos',
msg: { title: 'Test Todo' },
});
Copy link

Choose a reason for hiding this comment

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

Bug: Inconsistent RPC Payloads Break Sentry Tracing

The Supabase RPC calls for queue operations use msg for the message payload. Sentry's queue instrumentation expects message, which prevents proper trace context injection.

Additional Locations (1)

Fix in Cursor Fix in Web

'sentry.origin': 'auto.db.supabase',
'messaging.destination.name': 'todos',
'messaging.message.id': '0',
}),
Copy link

Choose a reason for hiding this comment

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

Bug: Origin value mismatch in browser test

The browser integration test expects sentry.origin to be 'auto.db.supabase', but the actual implementation sets it to 'auto.db.supabase.queue.producer' (line 288 in supabase.ts). This mismatch means the test is checking for the wrong value and may pass incorrectly or fail unexpectedly. The same issue exists for the consumer span on lines 77-79, where the test expects 'auto.db.supabase' but the implementation uses 'auto.db.supabase.queue.consumer'.

Fix in Cursor Fix in Web

'sentry.origin': 'auto.db.supabase',
'messaging.destination.name': 'todos',
'messaging.message.id': '0',
}),
Copy link

Choose a reason for hiding this comment

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

Bug: Origin string mismatch in browser tests

The browser integration test expects sentry.origin to be 'auto.db.supabase', but the actual implementation sets it to 'auto.db.supabase.queue.producer' (line 288 in supabase.ts). This mismatch means the test is checking for the wrong value and may pass incorrectly or fail unexpectedly. The same issue exists for the consumer span on lines 77-79, where the test expects 'auto.db.supabase' but the implementation uses 'auto.db.supabase.queue.consumer'.

Fix in Cursor Fix in Web

await supabaseClient.schema('pgmq_public').rpc('send', {
queue_name: 'todos',
msg: { title: 'Test Todo' },
});
Copy link

Choose a reason for hiding this comment

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

Bug: Incorrect RPC Parameter Name in Browser Test

The browser integration test uses incorrect parameter name msg for the send RPC call, but according to the SQL migration file (line 35 of enable-queues.sql), the correct parameter name is message. This will cause the test to fail when calling the actual Supabase queue function. All e2e tests correctly use message: as the parameter name.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Supabase Queues

5 participants