Skip to content

Commit 3ce404b

Browse files
committed
fix: Correctly detect and remove wrapped function frames
1 parent 17a965c commit 3ce404b

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

packages/browser/rollup.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ export default [
8686
// Uglify has to be at the end of compilation, BUT before the license banner
8787
plugins: bundleConfig.plugins
8888
.slice(0, -1)
89-
.concat(uglify())
89+
.concat(
90+
uglify({
91+
mangle: {
92+
reserved: ['addBreadcrumb', 'captureException', 'captureMessage', 'sentryWrapped'],
93+
},
94+
}),
95+
)
9096
.concat(bundleConfig.plugins.slice(-1)),
9197
}),
9298
];

packages/browser/src/integrations/helpers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentHub, withScope } from '@sentry/core';
1+
import { captureException, getCurrentHub, withScope } from '@sentry/core';
22
import { Mechanism, SentryEvent, SentryWrappedFunction } from '@sentry/types';
33
import { isFunction } from '@sentry/utils/is';
44
import { htmlTreeAsString } from '@sentry/utils/misc';
@@ -57,7 +57,7 @@ export function wrap(
5757
return fn;
5858
}
5959

60-
const wrapped: SentryWrappedFunction = function(this: any): void {
60+
const sentryWrapped: SentryWrappedFunction = function(this: any): void {
6161
if (before && isFunction(before)) {
6262
before.apply(this, arguments);
6363
}
@@ -96,7 +96,7 @@ export function wrap(
9696
return processedEvent;
9797
});
9898

99-
getCurrentHub().captureException(ex, { originalException: ex });
99+
captureException(ex);
100100
});
101101

102102
throw ex;
@@ -108,20 +108,20 @@ export function wrap(
108108
try {
109109
for (const property in fn) {
110110
if (Object.prototype.hasOwnProperty.call(fn, property)) {
111-
wrapped[property] = fn[property];
111+
sentryWrapped[property] = fn[property];
112112
}
113113
}
114114
} catch (_oO) {} // tslint:disable-line:no-empty
115115

116-
wrapped.prototype = fn.prototype;
117-
fn.__sentry_wrapped__ = wrapped;
116+
sentryWrapped.prototype = fn.prototype;
117+
fn.__sentry_wrapped__ = sentryWrapped;
118118

119119
// Signal that this function has been wrapped/filled already
120120
// for both debugging and to prevent it to being wrapped/filled twice
121-
wrapped.__sentry__ = true;
122-
wrapped.__sentry_original__ = fn;
121+
sentryWrapped.__sentry__ = true;
122+
sentryWrapped.__sentry_original__ = fn;
123123

124-
return wrapped;
124+
return sentryWrapped;
125125
}
126126

127127
/**

packages/browser/src/integrations/pluggable/ember.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { captureMessage, getCurrentHub, Scope, withScope } from '@sentry/core';
1+
import { captureException, captureMessage, getCurrentHub, Scope, withScope } from '@sentry/core';
22
import { Integration, SentryEvent } from '@sentry/types';
33
import { getGlobalObject } from '@sentry/utils/misc';
44

@@ -43,7 +43,7 @@ export class Ember implements Integration {
4343
if (getCurrentHub().getIntegration(Ember)) {
4444
withScope(scope => {
4545
this.addIntegrationToSdkInfo(scope);
46-
getCurrentHub().captureException(error, { originalException: error });
46+
captureException(error);
4747
});
4848
}
4949

@@ -62,7 +62,7 @@ export class Ember implements Integration {
6262
if (reason instanceof Error) {
6363
scope.setExtra('context', 'Unhandled Promise error detected');
6464
this.addIntegrationToSdkInfo(scope);
65-
getCurrentHub().captureException(reason, { originalException: reason });
65+
captureException(reason);
6666
} else {
6767
scope.setExtra('reason', reason);
6868
this.addIntegrationToSdkInfo(scope);

packages/browser/src/integrations/pluggable/vue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentHub, withScope } from '@sentry/core';
1+
import { captureException, getCurrentHub, withScope } from '@sentry/core';
22
import { Integration, SentryEvent } from '@sentry/types';
33
import { isPlainObject, isUndefined } from '@sentry/utils/is';
44
import { getGlobalObject } from '@sentry/utils/misc';
@@ -91,7 +91,7 @@ export class Vue implements Integration {
9191
return event;
9292
});
9393

94-
getCurrentHub().captureException(error, { originalException: error });
94+
captureException(error);
9595
});
9696
}
9797

packages/browser/src/parsers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,20 @@ export function prepareFramesForEvent(stack: TraceKitStackFrame[]): StackFrame[]
6464
}
6565

6666
let localStack = stack;
67+
6768
const firstFrameFunction = localStack[0].func || '';
69+
const lastFrameFunction = localStack[localStack.length - 1].func || '';
6870

71+
// If stack starts with one of our API calls, remove it (starts, meaning it's the top of the stack - aka last call)
6972
if (includes(firstFrameFunction, 'captureMessage') || includes(firstFrameFunction, 'captureException')) {
7073
localStack = localStack.slice(1);
7174
}
7275

76+
// If stack ends with one of our internal API calls, remove it (ends, meaning it's the bottom of the stack - aka top-most call)
77+
if (includes(lastFrameFunction, 'sentryWrapped')) {
78+
localStack = localStack.slice(0, -1);
79+
}
80+
7381
// The frame where the crash happened, should be the last entry in the array
7482
return localStack
7583
.map(

packages/node/src/handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentHub } from '@sentry/core';
1+
import { captureException, getCurrentHub } from '@sentry/core';
22
import { SentryEvent } from '@sentry/types';
33
import { forget } from '@sentry/utils/async';
44
import { logger } from '@sentry/utils/logger';
@@ -271,7 +271,7 @@ export function errorHandler(): (
271271
next(error);
272272
return;
273273
}
274-
getCurrentHub().captureException(error, { originalException: error });
274+
captureException(error);
275275
next(error);
276276
};
277277
}

0 commit comments

Comments
 (0)