Skip to content

Commit 21b8e54

Browse files
cursoragentLms24
andcommitted
Add error mechanism type to captureException calls across packages
Co-authored-by: lukas.stracke <[email protected]>
1 parent 12ac49a commit 21b8e54

File tree

30 files changed

+134
-34
lines changed

30 files changed

+134
-34
lines changed

packages/aws-serverless/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ export function wrapHandler<TEvent, TResult>(
306306
if (options.captureAllSettledReasons && Array.isArray(rv) && isPromiseAllSettledResult(rv)) {
307307
const reasons = getRejectedReasons(rv);
308308
reasons.forEach(exception => {
309-
captureException(exception, scope => markEventUnhandled(scope));
309+
captureException(exception, scope => markEventUnhandled(scope, 'aws-serverless.promise'));
310310
});
311311
}
312312
} catch (e) {
313-
captureException(e, scope => markEventUnhandled(scope));
313+
captureException(e, scope => markEventUnhandled(scope, 'aws-serverless.handler'));
314314
throw e;
315315
} finally {
316316
clearTimeout(timeoutWarningTimer);

packages/aws-serverless/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ const headerGetter: TextMapGetter<APIGatewayProxyEventHeaders> = {
2626
/**
2727
* Marks an event as unhandled by adding a span processor to the passed scope.
2828
*/
29-
export function markEventUnhandled(scope: Scope): Scope {
29+
export function markEventUnhandled(scope: Scope, type = 'aws-serverless'): Scope {
3030
scope.addEventProcessor(event => {
31-
addExceptionMechanism(event, { handled: false });
31+
addExceptionMechanism(event, { handled: false, type });
3232
return event;
3333
});
3434

packages/browser/src/helpers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ export function wrap<T extends WrappableFunction, NonFunction>(
133133
return event;
134134
});
135135

136-
captureException(ex);
136+
captureException(ex, {
137+
mechanism: {
138+
handled: false,
139+
type: 'browser',
140+
},
141+
});
137142
});
138143

139144
throw ex;

packages/core/src/integrations/supabase.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A
236236
captureException(res.error, {
237237
mechanism: {
238238
handled: false,
239+
type: 'supabase',
239240
},
240241
});
241242
} else {
@@ -252,6 +253,7 @@ function instrumentAuthOperation(operation: AuthOperationFn, isAdmin = false): A
252253
captureException(err, {
253254
mechanism: {
254255
handled: false,
256+
type: 'supabase',
255257
},
256258
});
257259

@@ -417,6 +419,10 @@ function instrumentPostgRESTFilterBuilder(PostgRESTFilterBuilder: PostgRESTFilte
417419
}
418420

419421
captureException(err, {
422+
mechanism: {
423+
handled: false,
424+
type: 'supabase',
425+
},
420426
contexts: {
421427
supabase: supabaseContext,
422428
},

packages/core/src/trpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface SentryTrpcMiddlewareArguments<T> {
1919
getRawInput?: () => Promise<unknown>;
2020
}
2121

22-
const trpcCaptureContext = { mechanism: { handled: false, data: { function: 'trpcMiddleware' } } };
22+
const trpcCaptureContext = { mechanism: { handled: false, type: 'trpc', data: { function: 'trpcMiddleware' } } };
2323

2424
function captureIfError(nextResult: unknown): void {
2525
// TODO: Set span status based on what TRPCError was encountered

packages/core/src/utils/openai/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function instrumentMethod<T extends unknown[], R>(
205205
captureException(error, {
206206
mechanism: {
207207
handled: false,
208+
type: 'openai',
208209
},
209210
});
210211
span.end();
@@ -230,7 +231,12 @@ function instrumentMethod<T extends unknown[], R>(
230231
addResponseAttributes(span, result, finalOptions.recordOutputs);
231232
return result;
232233
} catch (error) {
233-
captureException(error);
234+
captureException(error, {
235+
mechanism: {
236+
handled: false,
237+
type: 'openai',
238+
},
239+
});
234240
throw error;
235241
}
236242
},

packages/core/src/utils/openai/streaming.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function processResponsesApiEvent(
9696
captureException(streamEvent, {
9797
mechanism: {
9898
handled: false,
99+
type: 'openai',
99100
},
100101
});
101102
return;

packages/google-cloud-serverless/src/gcpfunction/cloud_events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function _wrapCloudEventFunction(
4949

5050
const newCallback = domainify((...args: unknown[]) => {
5151
if (args[0] !== null && args[0] !== undefined) {
52-
captureException(args[0], scope => markEventUnhandled(scope));
52+
captureException(args[0], scope => markEventUnhandled(scope, 'google-cloud-serverless.cloud_event'));
5353
}
5454
span.end();
5555

@@ -69,7 +69,7 @@ function _wrapCloudEventFunction(
6969
return handleCallbackErrors(
7070
() => (fn as CloudEventFunctionWithCallback)(context, newCallback),
7171
err => {
72-
captureException(err, scope => markEventUnhandled(scope));
72+
captureException(err, scope => markEventUnhandled(scope, 'google-cloud-serverless.cloud_event'));
7373
},
7474
);
7575
}

packages/google-cloud-serverless/src/gcpfunction/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
5252

5353
const newCallback = domainify((...args: unknown[]) => {
5454
if (args[0] !== null && args[0] !== undefined) {
55-
captureException(args[0], scope => markEventUnhandled(scope));
55+
captureException(args[0], scope => markEventUnhandled(scope, 'google-cloud-serverless.event'));
5656
}
5757
span.end();
5858

@@ -72,7 +72,7 @@ function _wrapEventFunction<F extends EventFunction | EventFunctionWithCallback>
7272
return handleCallbackErrors(
7373
() => (fn as EventFunctionWithCallback)(data, context, newCallback),
7474
err => {
75-
captureException(err, scope => markEventUnhandled(scope));
75+
captureException(err, scope => markEventUnhandled(scope, 'google-cloud-serverless.event'));
7676
},
7777
);
7878
}

packages/google-cloud-serverless/src/gcpfunction/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function _wrapHttpFunction(fn: HttpFunction, options: Partial<WrapperOptions>):
7878
return handleCallbackErrors(
7979
() => fn(req, res),
8080
err => {
81-
captureException(err, scope => markEventUnhandled(scope));
81+
captureException(err, scope => markEventUnhandled(scope, 'google-cloud-serverless.http'));
8282
},
8383
);
8484
},

0 commit comments

Comments
 (0)