Skip to content

Commit 35f177a

Browse files
authored
ref(deno): Update deno integrations to avoid setupOnce (#9812)
Where possible, we should use the new `processEvent` and/or `setup` hooks of the integrations, instead of `setupOnce`. This updates this for the deno integrations.
1 parent be32c1e commit 35f177a

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

packages/deno/src/integrations/context.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ export class DenoContext implements Integration {
5858
public name: string = DenoContext.id;
5959

6060
/** @inheritDoc */
61-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void): void {
62-
addGlobalEventProcessor(async (event: Event) => denoRuntime(event));
61+
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void): void {
62+
// noop
63+
}
64+
65+
/** @inheritDoc */
66+
public processEvent(event: Event): Promise<Event> {
67+
return denoRuntime(event);
6368
}
6469
}

packages/deno/src/integrations/contextlines.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ export class ContextLines implements Integration {
6767
/**
6868
* @inheritDoc
6969
*/
70-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void): void {
71-
addGlobalEventProcessor(event => this.addSourceContext(event));
70+
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void): void {
71+
// noop
72+
}
73+
74+
/** @inheritDoc */
75+
public processEvent(event: Event): Promise<Event> {
76+
return this.addSourceContext(event);
7277
}
7378

7479
/** Processes an event and adds context lines */

packages/deno/src/integrations/normalizepaths.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,32 @@ export class NormalizePaths implements Integration {
7272
public name: string = NormalizePaths.id;
7373

7474
/** @inheritDoc */
75-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void): void {
75+
public setupOnce(_addGlobalEventProcessor: (callback: EventProcessor) => void): void {
76+
// noop
77+
}
78+
79+
/** @inheritDoc */
80+
public processEvent(event: Event): Event | null {
7681
// This error.stack hopefully contains paths that traverse the app cwd
7782
const error = new Error();
7883

79-
addGlobalEventProcessor((event: Event): Event | null => {
80-
const appRoot = getAppRoot(error);
84+
const appRoot = getAppRoot(error);
8185

82-
if (appRoot) {
83-
for (const exception of event.exception?.values || []) {
84-
for (const frame of exception.stacktrace?.frames || []) {
85-
if (frame.filename && frame.in_app) {
86-
const startIndex = frame.filename.indexOf(appRoot);
86+
if (appRoot) {
87+
for (const exception of event.exception?.values || []) {
88+
for (const frame of exception.stacktrace?.frames || []) {
89+
if (frame.filename && frame.in_app) {
90+
const startIndex = frame.filename.indexOf(appRoot);
8791

88-
if (startIndex > -1) {
89-
const endIndex = startIndex + appRoot.length;
90-
frame.filename = `app://${frame.filename.substring(endIndex)}`;
91-
}
92+
if (startIndex > -1) {
93+
const endIndex = startIndex + appRoot.length;
94+
frame.filename = `app://${frame.filename.substring(endIndex)}`;
9295
}
9396
}
9497
}
9598
}
99+
}
96100

97-
return event;
98-
});
101+
return event;
99102
}
100103
}

0 commit comments

Comments
 (0)