@probara/angular
v0.4.0
Published
Probara error monitoring for Angular: an ErrorHandler, router context and an HttpClient interceptor on top of @probara/browser.
Maintainers
Readme
@probara/angular
Error monitoring for Angular with Probara, on top of
@probara/browser: the errors Angular's ErrorHandler gets are sent as
unhandled errors, each event carries the route it happened on, failed navigations become
breadcrumbs, and HttpClient failures of the URLs you choose are sent as events. It re-exports the
whole @probara/browser API (captureException, setUser, withScope…).
Requires Angular 19 or later. Events report the SDK probara.javascript.angular with this
package's version, and list @probara/browser among its packages.
Install
npm install @probara/angularStart
Add provideProbara to your application's providers, with the DSN of your Probara project:
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter } from '@angular/router';
import { probaraHttpInterceptor, provideProbara } from '@probara/angular';
bootstrapApplication(AppComponent, {
providers: [
provideProbara({
dsn: 'https://<public key>@<probara api host>/',
release: '[email protected]',
environment: 'production',
httpErrors: { targets: ['https://api.shop.example/payments'] },
}),
provideRouter(routes),
provideHttpClient(withInterceptors([probaraHttpInterceptor])),
],
});provideProbara starts @probara/browser when the app starts (it takes every
@probara/browser option), and replaces Angular's ErrorHandler
with ProbaraErrorHandler. Call either provideProbara or init, not both. With zone.js, it starts
@probara/browser outside Angular's zone, so its listeners, timers and replay never run change
detection; your beforeSend runs outside the zone too.
What is sent
- Errors. Everything Angular's
ErrorHandlergets, as unhandled errors (mechanism: angular). The error is still logged to the console as Angular does (ERROR …); passlogErrors: falseto stop that. For anHttpErrorResponse, the error behind it is sent, orHttp failure response for <url>: <status> <body>; a 400, 401 or 404 response is never sent. - Routes. Each event is tagged
routewith the path of the route it happened on, such as/projects/:projectId/errors/:issueId. - Navigations. Each router navigation is a
navigationbreadcrumb with the URL and the route paths it wentfromandto; failed navigations areangular.routerbreadcrumbs.@probara/browseralso records the clicks, the console and every HttpClient request. - HttpClient failures. With
probaraHttpInterceptor, a failed response whose URL starts with one ofhttpErrors.targets(or matches a regular expression) and whose status is inhttpErrors.statuses(500–599 unless given) is sent as an event, once:ProbaraErrorHandlerleaves it out if it reaches it too. 400, 401 and 404 are never sent. A response whose server already sent the error with@probara/node(it names it inprobara-replay-event) is never sent again. - Replays. With
replay: { enabled: true }, once Probara asks for the replay of an error, the tab keeps uploading its replay, and every later error of the tab links to it. Requests tohttpErrors.targets(orreplay.propagationTargets) carryprobara-replay-id, so the server errors they cause show that replay too (how it works).
Use your own ErrorHandler
ProbaraErrorHandler needs no injection: extend it, or create it yourself.
{ provide: ErrorHandler, useFactory: () => new ProbaraErrorHandler({ logErrors: false }) }License
Apache-2.0
