Datadog integration for Angular projects.
Has built-in unwrapping of HttpErrorResponse
and UncaughtPromiseError
.
Included enrichers for Logs
and RUM
:
@ngrx/store
Enrichers for Logs
can be imported from: @dineroregnskab/datadog-angular/enrichers/logs
Enrichers for RUM
can be imported from: @dineroregnskab/datadog-angular/enrichers/rum
Included filters for Logs
and RUM
:
- Discard HTTP errors with status code
0
- Discard HTTP errors with
0 Unknown Error
message
Filters for Logs
can be imported from: @dineroregnskab/datadog-angular/filters/logs
Filters for RUM
can be imported from: @dineroregnskab/datadog-angular/filters/rum
export const enricher = (log: LogsEvent, injector: Injector | null): void => {
// Append data to log object.
};
export const enricher = (
event: RumEvent,
context: RumEventDomainContext,
injector: Injector | null,
): void => {
// Append data to the event context here.
};
- For
Logs
,event
is the captured event object. New log information can be appended to this object. See https://docs.datadoghq.com/logs/log_collection/javascript/#advanced-usage for more information. - For
RUM
, see https://docs.datadoghq.com/real_user_monitoring/guide/enrich-and-control-rum-data/?tab=event for information about theevent
andcontext
properties. - The
injector
parameter is the Angular DI injector. This can be used to extract information from Angular components. The injector will benull
if the log happens beforesetNgInjector
is called.
export const filter = (
event: RumEvent,
context: RumEventDomainContext,
injector: Injector | null,
): boolean => {
// Return true to discard the log.
};
export const filter = (log: LogsEvent, injector: Injector | null): boolean => {
// Return true to discard log.
};
- For
Logs
,event
is the captured event object. New log information can be appended to this object. See https://docs.datadoghq.com/logs/log_collection/javascript/#advanced-usage for more information. - For
RUM
, see https://docs.datadoghq.com/real_user_monitoring/guide/enrich-and-control-rum-data/?tab=event for information about theevent
andcontext
properties. - The
injector
parameter is the Angular DI injector. This can be used to extract information from Angular components. The injector will benull
if the log happens beforesetNgInjector
is called.
Initializer will instrument both Logs and RUM.
main.ts
import { setNgInjector } from '@dineroregnskab/datadog-angular';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app';
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then((appRef) => {
// Save a reference to the Angular DI injector for use in logging.
setNgInjector(appRef.injector);
})
.catch((err) => console.error(err));
import { ErrorHandler, Injectable } from '@angular/core';
import { DatadogErrorHandler } from '@dineroregnskab/datadog-angular';
@Injectable()
export class CustomErrorHandler
extends DatadogErrorHandler
implements ErrorHandler
{
public constructor() {
super();
}
public handleError(error: any): void {
this.datadogLogger.error(error);
}
}