Frontend Monitoring: adding ignoreUrls param to EchoSrvTransport (#95801)

* adding ignoreUrls param to EchoSrvTransport

* adding test for ignore urls

* linting

* cleaning up

* adding a new error message to the list of ignored errors
This commit is contained in:
Elliot Kirk 2024-11-11 00:15:24 -08:00 committed by GitHub
parent c0de407fee
commit e22deeac04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 4 deletions

View File

@ -1,8 +1,21 @@
import { BaseTransport, TransportItem } from '@grafana/faro-core';
import { getEchoSrv, EchoEventType, config } from '@grafana/runtime';
interface EchoSrcTransportOptions {
ignoreUrls: RegExp[];
}
export class EchoSrvTransport extends BaseTransport {
readonly name: string = 'EchoSrvTransport';
readonly version: string = config.buildInfo.version;
private ignoreUrls: RegExp[] = [];
constructor(options?: EchoSrcTransportOptions) {
super();
this.ignoreUrls = options?.ignoreUrls ?? [];
}
send(items: TransportItem[]) {
getEchoSrv().addEvent({
type: EchoEventType.GrafanaJavascriptAgent,
@ -15,6 +28,6 @@ export class EchoSrvTransport extends BaseTransport {
}
getIgnoreUrls() {
return [];
return this.ignoreUrls;
}
}

View File

@ -91,6 +91,13 @@ describe('GrafanaJavascriptAgentEchoBackend', () => {
expect(initializeFaroMock).toHaveBeenCalledTimes(1);
expect(initializeFaroMock.mock.calls[0][0].transports?.length).toEqual(2);
expect(initializeFaroMock.mock.calls[0][0].transports?.[0]).toBeInstanceOf(EchoSrvTransport);
expect(initializeFaroMock.mock.calls[0][0].transports?.[0].getIgnoreUrls()).toEqual([
new RegExp('/*/log-grafana-javascript-agent/'),
/.*.google-analytics.com*.*/,
/.*.googletagmanager.com*.*/,
/frontend-metrics/,
/\/collect(?:\/[\w]*)?$/,
]);
expect(initializeFaroMock.mock.calls[0][0].transports?.[1]).toBeInstanceOf(FetchTransport);
});

View File

@ -37,7 +37,12 @@ export interface GrafanaJavascriptAgentBackendOptions extends BrowserConfig {
ignoreUrls: RegExp[];
}
const TRACKING_URLS = [/.*.google-analytics.com*.*/, /.*.googletagmanager.com*.*/, /frontend-metrics/];
const TRACKING_URLS = [
/.*.google-analytics.com*.*/,
/.*.googletagmanager.com*.*/,
/frontend-metrics/,
/\/collect(?:\/[\w]*)?$/,
];
export class GrafanaJavascriptAgentBackend
implements EchoBackend<GrafanaJavascriptAgentEchoEvent, GrafanaJavascriptAgentBackendOptions>
@ -48,8 +53,9 @@ export class GrafanaJavascriptAgentBackend
constructor(public options: GrafanaJavascriptAgentBackendOptions) {
// configure instrumentations.
const instrumentations: Instrumentation[] = [];
const ignoreUrls = [new RegExp(`/*${options.customEndpoint}/`), ...TRACKING_URLS, ...options.ignoreUrls];
const transports: BaseTransport[] = [new EchoSrvTransport()];
const transports: BaseTransport[] = [new EchoSrvTransport({ ignoreUrls })];
// If in cross origin iframe, default to writing to instance logging endpoint
if (options.customEndpoint && !isCrossOriginIframe()) {
@ -89,8 +95,9 @@ export class GrafanaJavascriptAgentBackend
'ResizeObserver loop limit exceeded',
'ResizeObserver loop completed',
'Non-Error exception captured with keys',
'Failed sending payload to the receiver',
],
ignoreUrls: [new RegExp(`/*${options.customEndpoint}/`), ...TRACKING_URLS, ...options.ignoreUrls],
ignoreUrls,
sessionTracking: {
persistent: true,
},