|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
2 | 2 | import type { Client } from '../../../src'; |
3 | 3 | import * as CurrentScopes from '../../../src/currentScopes'; |
| 4 | +import * as exports from '../../../src/exports'; |
4 | 5 | import type { SupabaseClientInstance, SupabaseResponse } from '../../../src/integrations/supabase'; |
5 | 6 | import { instrumentSupabaseClient } from '../../../src/integrations/supabase'; |
6 | 7 | import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../../src/semanticAttributes'; |
@@ -156,6 +157,37 @@ describe('Supabase Queue Instrumentation', () => { |
156 | 157 | ).rejects.toThrow('Queue send failed'); |
157 | 158 | }); |
158 | 159 |
|
| 160 | + it('should capture producer errors with producer mechanism type', async () => { |
| 161 | + const captureExceptionSpy = vi.spyOn(exports, 'captureException').mockImplementation(() => ''); |
| 162 | + |
| 163 | + await callRpc( |
| 164 | + mockRpcFunction, |
| 165 | + mockSupabaseClient, |
| 166 | + 'send', |
| 167 | + { queue_name: 'test-queue', message: { foo: 'bar' } }, |
| 168 | + ERROR_RESPONSE, |
| 169 | + ); |
| 170 | + |
| 171 | + expect(captureExceptionSpy).toHaveBeenCalledTimes(1); |
| 172 | + |
| 173 | + // Execute the scope callback to verify mechanism type |
| 174 | + const scopeCallback = captureExceptionSpy.mock.calls[0]![1] as (scope: any) => any; |
| 175 | + const mockScope = { addEventProcessor: vi.fn().mockReturnThis(), setContext: vi.fn().mockReturnThis() }; |
| 176 | + scopeCallback(mockScope); |
| 177 | + |
| 178 | + const eventProcessor = mockScope.addEventProcessor.mock.calls[0]![0]; |
| 179 | + const event = { exception: { values: [{}] } }; |
| 180 | + eventProcessor(event); |
| 181 | + |
| 182 | + expect(event.exception.values[0]).toEqual( |
| 183 | + expect.objectContaining({ |
| 184 | + mechanism: expect.objectContaining({ type: 'auto.db.supabase.queue.producer' }), |
| 185 | + }), |
| 186 | + ); |
| 187 | + |
| 188 | + captureExceptionSpy.mockRestore(); |
| 189 | + }); |
| 190 | + |
159 | 191 | it('should not mutate original params for single send or batch send', async () => { |
160 | 192 | const singleParams = { queue_name: 'test-queue', message: { foo: 'bar', nested: { value: 42 } } }; |
161 | 193 | const batchParams = { queue_name: 'test-queue', messages: [{ foo: 'bar' }, { baz: 'qux' }] }; |
@@ -308,6 +340,30 @@ describe('Supabase Queue Instrumentation', () => { |
308 | 340 | expect(processSpanCall?.[0]?.name).toBe('process test-queue'); |
309 | 341 | }); |
310 | 342 |
|
| 343 | + it('should capture consumer errors with consumer mechanism type', async () => { |
| 344 | + const captureExceptionSpy = vi.spyOn(exports, 'captureException').mockImplementation(() => ''); |
| 345 | + |
| 346 | + await callRpc(mockRpcFunction, mockSupabaseClient, 'pop', { queue_name: 'test-queue' }, ERROR_RESPONSE); |
| 347 | + |
| 348 | + expect(captureExceptionSpy).toHaveBeenCalledTimes(1); |
| 349 | + |
| 350 | + const scopeCallback = captureExceptionSpy.mock.calls[0]![1] as (scope: any) => any; |
| 351 | + const mockScope = { addEventProcessor: vi.fn().mockReturnThis(), setContext: vi.fn().mockReturnThis() }; |
| 352 | + scopeCallback(mockScope); |
| 353 | + |
| 354 | + const eventProcessor = mockScope.addEventProcessor.mock.calls[0]![0]; |
| 355 | + const event = { exception: { values: [{}] } }; |
| 356 | + eventProcessor(event); |
| 357 | + |
| 358 | + expect(event.exception.values[0]).toEqual( |
| 359 | + expect.objectContaining({ |
| 360 | + mechanism: expect.objectContaining({ type: 'auto.db.supabase.queue.consumer' }), |
| 361 | + }), |
| 362 | + ); |
| 363 | + |
| 364 | + captureExceptionSpy.mockRestore(); |
| 365 | + }); |
| 366 | + |
311 | 367 | it('should set correct attributes on consumer span', async () => { |
312 | 368 | const startSpanSpy = vi.spyOn(Tracing, 'startSpan'); |
313 | 369 |
|
|
0 commit comments