Skip to content

Commit eddeb55

Browse files
committed
browser: Fixed mechanism for wrapped functions and eventFromObject thingy
1 parent 2e1b6d6 commit eddeb55

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

packages/browser/src/integrations/helpers.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ export function ignoreNextOnError(): void {
3030
*/
3131
export function wrap(
3232
fn: SentryWrappedFunction,
33-
options?: {
34-
mechanism?: object;
35-
},
33+
options: {
34+
mechanism?: Mechanism;
35+
} = {},
3636
before?: SentryWrappedFunction,
3737
): any {
3838
try {
@@ -66,10 +66,16 @@ export function wrap(
6666
ignoreNextOnError();
6767

6868
getCurrentHub().withScope(async () => {
69-
getCurrentHub().addEventProcessor(async (event: SentryEvent) => ({
70-
...event,
71-
...(options && options.mechanism),
72-
}));
69+
getCurrentHub().addEventProcessor(async (event: SentryEvent) => {
70+
const processedEvent = { ...event };
71+
72+
if (options.mechanism) {
73+
processedEvent.exception = processedEvent.exception || {};
74+
processedEvent.exception.mechanism = options.mechanism;
75+
}
76+
77+
return processedEvent;
78+
});
7379

7480
getCurrentHub().captureException(ex);
7581
});

packages/browser/src/integrations/trycatch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class TryCatch implements Integration {
2020
args[0] = wrap(originalCallback, {
2121
mechanism: {
2222
data: { function: original.name || '<anonymous>' },
23+
handled: true,
2324
type: 'instrument',
2425
},
2526
});
@@ -37,6 +38,7 @@ export class TryCatch implements Integration {
3738
function: 'requestAnimationFrame',
3839
handler: (original && original.name) || '<anonymous>',
3940
},
41+
handled: true,
4042
type: 'instrument',
4143
},
4244
}),
@@ -70,6 +72,7 @@ export class TryCatch implements Integration {
7072
handler: ((fn as any) as SentryWrappedFunction).name || '<anonymous>',
7173
target,
7274
},
75+
handled: true,
7376
type: 'instrument',
7477
},
7578
});
@@ -124,6 +127,7 @@ export class TryCatch implements Integration {
124127
handler: ((fn as any) as SentryWrappedFunction).name || '<anonymous>',
125128
target,
126129
},
130+
handled: true,
127131
type: 'instrument',
128132
},
129133
},

packages/browser/src/parsers.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SentryEvent, StackFrame } from '@sentry/types';
22
import { limitObjectDepthToSize, serializeKeysToEventMessage } from '@sentry/utils/object';
33
import * as md5proxy from 'md5';
4-
import { StackFrame as TraceKitStackFrame, StackTrace as TraceKitStackTrace } from './tracekit';
4+
import { computeStackTrace, StackFrame as TraceKitStackFrame, StackTrace as TraceKitStackTrace } from './tracekit';
55

66
// Workaround for Rollup issue with overloading namespaces
77
// https://github.com/rollup/rollup/issues/1267#issuecomment-296395734
@@ -10,21 +10,25 @@ const md5 = ((md5proxy as any).default || md5proxy) as (input: string) => string
1010
const STACKTRACE_LIMIT = 50;
1111

1212
/** JSDoc */
13-
export function getEventOptionsFromPlainObject(exception: {}): {
14-
extra: {
15-
__serialized__: object;
16-
};
17-
fingerprint: [string];
18-
message: string;
19-
} {
13+
export function eventFromPlainObject(exception: {}, syntheticException: Error | null): SentryEvent {
2014
const exceptionKeys = Object.keys(exception).sort();
21-
return {
15+
const event: SentryEvent = {
2216
extra: {
2317
__serialized__: limitObjectDepthToSize(exception),
2418
},
2519
fingerprint: [md5(exceptionKeys.join(''))],
2620
message: `Non-Error exception captured with keys: ${serializeKeysToEventMessage(exceptionKeys)}`,
2721
};
22+
23+
if (syntheticException) {
24+
const stacktrace = computeStackTrace(syntheticException);
25+
const frames = prepareFramesForEvent(stacktrace.stack);
26+
event.stacktrace = {
27+
frames,
28+
};
29+
}
30+
31+
return event;
2832
}
2933

3034
/** JSDoc */

0 commit comments

Comments
 (0)