Skip to content

Angular - errors are reported multiple times #2744

Closed
@kamilchlebek

Description

@kamilchlebek

Package + Version

  • @sentry/browser
  • @sentry/integrations

Version:

^5.19.1

Description

I'm having an issue with errors being reported multiple times. One error is correctly catched via angular ErrorHandler, second one is catched by captureException executed inside sentryWrapped function.

I tried proposed solution for angular, shown below:

// TryCatch has to be configured to disable XMLHttpRequest wrapping, as we are going to handle
// http module exceptions manually in Angular's ErrorHandler and we don't want it to capture the same error twice.
// Please note that TryCatch configuration requires at least @sentry/browser v5.16.0.
integrations: [new Sentry.Integrations.TryCatch({
    XMLHttpRequest: false,
})],

but it didn't help. To block additional error reports I had to set:

setTimeout: false

It's just a workaround that I'd rather not use, since errors may also occur outside angular.

I started debugging which setTimeout was the root cause of duplicated reports. I found that it's caused by hostReportError from rxjs ( https://github.com/ReactiveX/rxjs/blob/f5278aa89ea164caf5cf10e77d7bd00eff26fc0f/src/internal/util/hostReportError.ts#L6 )

Starting from rxjs v6.0.0 they changed the way of reporting the errors from sync to async mode.

error handling: Unhandled errors are no longer caught and rethrown, rather they are caught and scheduled to be thrown, which causes them to be reported to window.onerror or process.on('error'), depending on the environment.
https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#breaking-changes-10

As a part from investigation I tried to switch back to sync error reporting (using rxjs config.useDeprecatedSynchronousErrorHandling = true).

After this change, to stop duplicated error reports I had to set TryCatch options to eventTarget: false (setTimeout: false was no more needed).

Seems that Sentry is wrapping addEventListener for angular http client https://github.com/angular/angular/blob/master/packages/common/http/src/xhr.ts#L311. Setting XMLHttpRequest: false doesn't work.

As a temporary fix I'll probably check error report in beforeSend and skip unwanted ones, but could you fix it internally? Thanks :)

Related issues

#2533
#2532
#2169

Metadata

Metadata

Assignees

Labels

Package: angularIssues related to the Sentry Angular SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions