Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/chilly-trees-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperdx/instrumentation-exception': patch
'@hyperdx/browser': patch
---

refactor: Rename error instrumentation fn name for filtering out
7 changes: 7 additions & 0 deletions .changeset/orange-cheetahs-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/otel-web': patch
'@hyperdx/browser': patch
'@hyperdx/otel-web-session-recorder': patch
---

refactor: Rename error instrumentation fn name
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ export const ERROR_INSTRUMENTATION_VERSION = '1';
export class HyperDXErrorInstrumentation extends InstrumentationBase {
private readonly _consoleErrorHandler = (original: Console['error']) => {
return (...args: any[]) => {
this.report('console.error', args);
this.hdxReport('console.error', args);
return original.apply(this, args);
};
};

private readonly _unhandledRejectionListener = (
event: PromiseRejectionEvent,
) => {
this.report('unhandledrejection', event.reason);
this.hdxReport('unhandledrejection', event.reason);
};

private readonly _errorListener = (event: ErrorEvent) => {
this.report('onerror', event);
this.hdxReport('onerror', event);
};

private readonly _documentErrorListener = (event: ErrorEvent) => {
this.report('eventListener.error', event);
this.hdxReport('eventListener.error', event);
};

constructor(config: InstrumentationConfig) {
Expand Down Expand Up @@ -83,7 +83,7 @@ export class HyperDXErrorInstrumentation extends InstrumentationBase {
);
}

protected reportError(source: string, err: Error): void {
protected hdxReportError(source: string, err: Error): void {
const msg = err.message || err.toString();
if (!useful(msg) && !err.stack) {
return;
Expand All @@ -92,7 +92,7 @@ export class HyperDXErrorInstrumentation extends InstrumentationBase {
recordException(err, {}, this.tracer);
}

protected reportString(
protected hdxReportString(
source: string,
message: string,
firstError?: Error,
Expand All @@ -109,15 +109,15 @@ export class HyperDXErrorInstrumentation extends InstrumentationBase {
recordException(e, {}, this.tracer);
}

protected reportErrorEvent(source: string, ev: ErrorEvent): void {
protected hdxReportErrorEvent(source: string, ev: ErrorEvent): void {
if (ev.error) {
this.report(source, ev.error);
this.hdxReport(source, ev.error);
} else if (ev.message) {
this.report(source, ev.message);
this.hdxReport(source, ev.message);
}
}

protected reportEvent(source: string, ev: Event): void {
protected hdxReportEvent(source: string, ev: Event): void {
// FIXME consider other sources of global 'error' DOM callback - what else can be captured here?
if (!ev.target && !useful(ev.type)) {
return;
Expand All @@ -136,7 +136,7 @@ export class HyperDXErrorInstrumentation extends InstrumentationBase {
recordException(ev, {}, this.tracer, span);
}

public report(
public hdxReport(
source: string,
arg: string | Event | ErrorEvent | Array<any>,
): void {
Expand All @@ -147,23 +147,23 @@ export class HyperDXErrorInstrumentation extends InstrumentationBase {
arg = arg[0];
}
if (arg instanceof Error) {
this.reportError(source, arg);
this.hdxReportError(source, arg);
} else if (arg instanceof ErrorEvent) {
this.reportErrorEvent(source, arg);
this.hdxReportErrorEvent(source, arg);
} else if (arg instanceof Event) {
this.reportEvent(source, arg);
this.hdxReportEvent(source, arg);
} else if (typeof arg === 'string') {
this.reportString(source, arg);
this.hdxReportString(source, arg);
} else if (arg instanceof Array) {
// if any arguments are Errors then add the stack trace even though the message is handled differently
const firstError = arg.find((x) => x instanceof Error);
this.reportString(
this.hdxReportString(
source,
arg.map((x) => stringifyValue(x)).join(' '),
firstError,
);
} else {
this.reportString(source, stringifyValue(arg)); // FIXME or JSON.stringify?
this.hdxReportString(source, stringifyValue(arg)); // FIXME or JSON.stringify?
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ describe('hyperdxIntegration', () => {
{
filename:
'https://www.hyperdx.io/_next/static/chunks/somefile.js',
function: 'Lx.report',
function: 'hdxReport',
lineno: 1,
colno: 88323,
},
{
filename:
'https://www.hyperdx.io/_next/static/chunks/somefile.js',
function: 'Lx.reportString',
function: 'hdxReportString',
lineno: 1,
colno: 88323,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,19 @@ export const _hyperdxIntegration = ((options: HyperDXOptions = {}) => {
continue;
// remove frames caused by SDK
} else if (
frame.function?.endsWith('.reportString') ||
frame.function?.endsWith('.reportError') ||
frame.function?.endsWith('.reportErrorEvent') ||
frame.function?.endsWith('.reportEvent')
frame.function?.endsWith('hdxReportString') ||
frame.function?.endsWith('hdxReportError') ||
frame.function?.endsWith('hdxReportErrorEvent') ||
frame.function?.endsWith('hdxReportEvent')
) {
continue;
// console.errors are caught and reported by the SDK in this sequence:
// anon fn -> reportString -> report
// this condition removes the anon fn after .reportString ans .report frames
} else if (frame.function?.endsWith('.report')) {
} else if (frame.function?.endsWith('hdxReport')) {
shouldRemoveNextFrameIfSameFile = frame.filename;
continue;
} else if (
frame.function?.length <= 1 &&
shouldRemoveNextFrameIfSameFile &&
frame.filename === shouldRemoveNextFrameIfSameFile
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/otel-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ export const Rum: RumOtelWebType = {
return;
}

_errorInstrumentation.report('Rum.error', args);
_errorInstrumentation.hdxReport('Rum.error', args);
},

addEventListener(name, callback): void {
Expand Down