Skip to content

Commit 4f19854

Browse files
committed
Extract instrumentRpcMethod
1 parent 8f9aa98 commit 4f19854

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

packages/core/src/integrations/supabase.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -232,44 +232,37 @@ function instrumentRpcReturnedFromSchemaCall(SupabaseClient: unknown): void {
232232
if (isInstrumented((SupabaseClient as unknown as SupabaseClientConstructorType).prototype.schema)) {
233233
return;
234234
}
235-
236235
(SupabaseClient as unknown as SupabaseClientConstructorType).prototype.schema = new Proxy(
237236
(SupabaseClient as unknown as SupabaseClientConstructorType).prototype.schema,
238237
{
239238
apply(target, thisArg, argumentsList) {
240239
const supabaseInstance = Reflect.apply(target, thisArg, argumentsList);
241-
242-
(supabaseInstance as unknown as SupabaseClientConstructorType).rpc = new Proxy(
243-
(supabaseInstance as unknown as SupabaseClientInstance).rpc,
244-
{
245-
apply(target, thisArg, argumentsList) {
246-
const isProducerSpan = argumentsList[0] === 'send' || argumentsList[0] === 'send_batch';
247-
const isConsumerSpan = argumentsList[0] === 'pop';
248-
249-
if (!isProducerSpan && !isConsumerSpan) {
250-
return Reflect.apply(target, thisArg, argumentsList);
251-
}
252-
253-
if (isProducerSpan) {
254-
return instrumentRpcProducer(target, thisArg, argumentsList);
255-
} else if (isConsumerSpan) {
256-
return instrumentRpcConsumer(target, thisArg, argumentsList);
257-
}
258-
259-
// If the operation is not a queue operation, return the original function
260-
return Reflect.apply(target, thisArg, argumentsList);
261-
},
262-
},
263-
);
264-
240+
instrumentRpcMethod(supabaseInstance as unknown as SupabaseClientConstructorType);
265241
return supabaseInstance;
266242
},
267243
},
268244
);
269-
270245
markAsInstrumented((SupabaseClient as unknown as SupabaseClientConstructorType).prototype.schema);
271246
}
272247

248+
function instrumentRpcMethod(supabaseInstance: SupabaseClientConstructorType): void {
249+
supabaseInstance.rpc = new Proxy((supabaseInstance as unknown as SupabaseClientInstance).rpc, {
250+
apply(target, thisArg, argumentsList) {
251+
const isProducerSpan = argumentsList[0] === 'send' || argumentsList[0] === 'send_batch';
252+
const isConsumerSpan = argumentsList[0] === 'pop';
253+
if (!isProducerSpan && !isConsumerSpan) {
254+
return Reflect.apply(target, thisArg, argumentsList);
255+
}
256+
if (isProducerSpan) {
257+
return instrumentRpcProducer(target, thisArg, argumentsList);
258+
} else if (isConsumerSpan) {
259+
return instrumentRpcConsumer(target, thisArg, argumentsList);
260+
}
261+
return Reflect.apply(target, thisArg, argumentsList);
262+
},
263+
});
264+
}
265+
273266
function extractTraceAndBaggageFromMessage(message: { _sentry?: { sentry_trace?: string; baggage?: string } }): {
274267
sentryTrace?: string;
275268
baggage?: string;

0 commit comments

Comments
 (0)