mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
c0de407fee
commit
e22deeac04
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user