I'm facing a typing problem with the @datadog/browser-rum library:
Error: node_modules/@datadog/browser-rum-core/src/domain/configuration.ts:100:3
error TS2322: Type '{ applicationId: string; version: string; actionNameAttribute: string; premiumSampleRate: number; allowedTracingOrigins: readonly (string | RegExp)[]; tracingSampleRate: number; excludedActivityUrls: readonly (string | RegExp)[]; trackInteractions: boolean; trackFrustrations: boolean; trackViewsManually: boolean; de...' is not assignable to type 'RumConfiguration'.
Types of property 'allowedTracingOrigins' are incompatible.
The type 'readonly (string | RegExp)[]' is 'readonly' and cannot be assigned to the mutable type '(string | RegExp)[]'.
No TypeScript errors show up in my implementation, only in the library itself.
The dependencies used:
Angular@12
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c38353c293f2f3e253c380c78627f6279">[email protected]</a>
@datadog/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e381918c94908691ce91968ea3d7cdd2d4cdd1">[email protected]</a>
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="06686962634637342834362834">[email protected]</a>
Here's the implementation:
import {
APP_INITIALIZER,
FactoryProvider,
} from '@angular/core';
import { Environment } from '@shared/base/class/environment.class';
import { RumEvent } from '@datadog/browser-rum-core/src/rumEvent.types';
import { RumEventDomainContext } from '@datadog/browser-rum-core/src/domainContext.types';
import { datadogRum } from '@datadog/browser-rum';
function factory(...dependencies: [Environment]) {
return () => init(...dependencies);
}
function init(environment: Environment): Promise<void> {
return new Promise((resolve) => {
if (!environment.dataDog) {
return resolve();
}
datadogRum.init({
applicationId: environment?.dataDog?.applicationId,
clientToken: environment?.dataDog?.clientToken,
site: environment?.dataDog?.site,
service: environment?.dataDog?.service,
env: environment.env,
version: environment.appVersion,
sampleRate: environment?.dataDog?.sampleRate || 100,
premiumSampleRate: environment?.dataDog?.premiumSampleRate || 100,
trackInteractions: environment?.dataDog?.trackInteractions || false,
allowedTracingOrigins: [] as ReadonlyArray<any>,
beforeSend
});
datadogRum.onReady(() => resolve());
});
function beforeSend(event: RumEvent, context: RumEventDomainContext) {
if (event.view.url.includes('?')) {
event.view.url = event.view.url.split('?')[0];
}
if (event.type === 'resource' && event.resource.url.includes('?')) {
event.resource.url = event.resource.url.split('?')[0];
}
}
}
export const DatadogInitializationProvider: FactoryProvider = {
provide: APP_INITIALIZER,
useFactory: factory,
deps: [Environment],
multi: true,
};
Has anyone else faced this same issue before?
Thank you and have a wonderful day/evening!