@@ -45,11 +45,7 @@ function _processConsumerSpan(span: Span, res: SupabaseResponse, queueName: stri
4545 span . setAttribute ( 'messaging.message.retry.count' , 0 ) ;
4646 span . setStatus ( { code : res . error ? SPAN_STATUS_ERROR : SPAN_STATUS_OK } ) ;
4747
48- const breadcrumbData : Record < string , unknown > = { } ;
49- if ( queueName ) {
50- breadcrumbData [ 'messaging.destination.name' ] = queueName ;
51- }
52- _createQueueBreadcrumb ( 'queue.process' , queueName , Object . keys ( breadcrumbData ) . length ? breadcrumbData : undefined ) ;
48+ _createQueueBreadcrumb ( 'queue.process' , queueName , queueName ? { 'messaging.destination.name' : queueName } : undefined ) ;
5349
5450 if ( res . error ) {
5551 _captureQueueError ( res . error , queueName ) ;
@@ -136,9 +132,7 @@ export function _instrumentRpcConsumer(target: unknown, thisArg: unknown, argume
136132 queueName,
137133 } ) ;
138134
139- const spanName = `process ${ queueName || 'unknown' } ` ;
140- // Cloudflare pattern: op='db.queue' for valid transactions, 'queue.process' for Queue Insights.
141- // Works both as child spans and root spans.
135+ const spanName = `process ${ queueName } ` ;
142136 const spanAttributes = {
143137 [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.db.supabase.queue.consumer' ,
144138 [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'queue.process' ,
@@ -188,6 +182,8 @@ export function _instrumentRpcConsumer(target: unknown, thisArg: unknown, argume
188182 const sentryTrace = firstMessage ?. _sentry ?. sentry_trace ;
189183
190184 // Clean up _sentry metadata from messages before returning to user
185+ // Shallow copy to avoid mutating the Supabase response object
186+ let cleanedRes = res ;
191187 if ( Array . isArray ( res . data ) ) {
192188 const hasMetadata = res . data . some (
193189 item =>
@@ -199,14 +195,15 @@ export function _instrumentRpcConsumer(target: unknown, thisArg: unknown, argume
199195 ) ;
200196
201197 if ( hasMetadata ) {
202- res . data = res . data . map ( item => {
198+ const cleanedData = res . data . map ( item => {
203199 if ( item && typeof item === 'object' && item . message && typeof item . message === 'object' ) {
204200 const messageCopy = { ...( item . message as Record < string , unknown > ) } ;
205201 delete messageCopy . _sentry ;
206202 return { ...item , message : messageCopy } ;
207203 }
208204 return item ;
209205 } ) ;
206+ cleanedRes = { ...res , data : cleanedData } ;
210207 }
211208 }
212209
@@ -227,7 +224,7 @@ export function _instrumentRpcConsumer(target: unknown, thisArg: unknown, argume
227224 }
228225
229226 try {
230- const processedResponse = _processConsumerSpan ( span , res , queueName ) ;
227+ const processedResponse = _processConsumerSpan ( span , cleanedRes , queueName ) ;
231228 DEBUG_BUILD && debug . log ( 'Consumer span processed successfully' , { queueName } ) ;
232229 return processedResponse ;
233230 } catch ( err : unknown ) {
@@ -236,7 +233,7 @@ export function _instrumentRpcConsumer(target: unknown, thisArg: unknown, argume
236233 captureSupabaseError ( err , 'auto.db.supabase.queue' , { queueName } ) ;
237234
238235 span . setStatus ( { code : SPAN_STATUS_ERROR } ) ;
239- return res ;
236+ return cleanedRes ;
240237 }
241238 } ,
242239 ( err : unknown ) => {
0 commit comments