Skip to content

Commit baca2a6

Browse files
committed
Move trace constructor to client method
1 parent b50e374 commit baca2a6

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "cross-fetch/polyfill";
2-
import { Sentry, Fetch } from "./index";
2+
import { Sentry } from "./index";
33

44
describe("worker sentry", () => {
55
const dsn = "https://[email protected]/789";

src/index.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ interface CallSite {
3030
/**
3131
* Parse call sites from error instance.
3232
*/
33-
function getErrorStack(error: Error): CallSite[] {
33+
function getErrorStack(
34+
error: Error,
35+
constructor: (...args: any[]) => any
36+
): CallSite[] {
3437
const prepareStackTrace = Error.prepareStackTrace;
3538
let trace: CallSite[];
3639

@@ -39,7 +42,7 @@ function getErrorStack(error: Error): CallSite[] {
3942
return prepareStackTrace?.(error, v8Trace);
4043
};
4144

42-
Error.captureStackTrace(error, getErrorStack);
45+
Error.captureStackTrace(error, constructor);
4346
error.stack; // Triggers `prepareStackTrace`.
4447
Error.prepareStackTrace = prepareStackTrace;
4548

@@ -158,7 +161,10 @@ export class Sentry {
158161
/**
159162
* Sends the exception to Sentry and returns the `Response` promise.
160163
*/
161-
captureException(error: Error, options: CaptureExceptionOptions = {}) {
164+
captureException(
165+
error: Error,
166+
options: CaptureExceptionOptions = {}
167+
): Promise<Response> {
162168
// https://develop.sentry.dev/sdk/event-payloads/
163169
const request = new Request(
164170
`https://sentry.io/api${this.sentryUrl.pathname}/store/`,
@@ -183,16 +189,18 @@ export class Sentry {
183189
value: error.message,
184190
// Ref: https://develop.sentry.dev/sdk/event-payloads/stacktrace
185191
stacktrace: {
186-
frames: getErrorStack(error).map((callSite) => ({
187-
function: callSite.getFunctionName(),
188-
filename: this.filePrefix + callSite.getFileName(),
189-
lineno: callSite.getLineNumber(),
190-
colno: callSite.getColumnNumber(),
191-
in_app: !callSite.isNative(),
192-
vars: {
193-
this: String(callSite.getThis()),
194-
},
195-
})),
192+
frames: getErrorStack(error, this.captureException).map(
193+
(callSite) => ({
194+
function: callSite.getFunctionName(),
195+
filename: this.filePrefix + callSite.getFileName(),
196+
lineno: callSite.getLineNumber(),
197+
colno: callSite.getColumnNumber(),
198+
in_app: !callSite.isNative(),
199+
vars: {
200+
this: callSite.getTypeName(),
201+
},
202+
})
203+
),
196204
},
197205
},
198206
],

0 commit comments

Comments
 (0)