Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface GlobalErrorsInstrumentationConfig
export class ExceptionInstrumentation extends InstrumentationBase<GlobalErrorsInstrumentationConfig> {
constructor(config: GlobalErrorsInstrumentationConfig = {}) {
super(PACKAGE_NAME, PACKAGE_VERSION, config);
this.onError = this.onError.bind(this);
}

init() {}
Expand Down Expand Up @@ -101,6 +100,7 @@ export class ExceptionInstrumentation extends InstrumentationBase<GlobalErrorsIn
}

override enable(): void {
this.onError = this.onError.bind(this);
window.addEventListener('error', this.onError);
window.addEventListener('unhandledrejection', this.onError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,15 @@ describe('ExceptionInstrumentation', () => {
});

describe('throwing an error', () => {
const instr = new ExceptionInstrumentation();
let disableInstrumentations: () => void;
beforeEach(() => {
registerInstrumentations({
instrumentations: [instr],
disableInstrumentations = registerInstrumentations({
instrumentations: [new ExceptionInstrumentation()],
});

instr.enable();
});

afterEach(() => {
instr.disable();
disableInstrumentations();
exporter.reset();
});

Expand Down Expand Up @@ -179,21 +177,24 @@ describe('ExceptionInstrumentation', () => {
'app.custom.exception': error.message.toLocaleUpperCase(),
};
};
const instr = new ExceptionInstrumentation({
applyCustomAttributes: applyCustomAttrs,
});

let disableInstrumentations: () => void;

beforeEach(() => {
registerInstrumentations({
instrumentations: [instr],
disableInstrumentations = registerInstrumentations({
instrumentations: [
new ExceptionInstrumentation({
applyCustomAttributes: applyCustomAttrs,
}),
],
});

instr.enable();
});

afterEach(() => {
instr.disable();
disableInstrumentations();
exporter.reset();
});

it('should add custom attributes to the event', async () => {
setTimeout(() => {
throwErr('Something happened!');
Expand Down
Loading