Skip to content

Commit

Permalink
feat: provide getIgnoreUrls function (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
codecapitano authored Nov 13, 2024
1 parent c3b314f commit bd41a14
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Improvement (`@grafana/faro-web-sdk`): Guards user session stringifier against circular object
references (#715)

- Feat (`@grafana/faro-web-sdk`): Provide a `getIgnoreUrls()` function to easily retrieve the
configured ignoreUrls (#732)

## 1.11.0

- Improvement (`@grafana/faro-web-sdk`): The console instrumentation now sends an `Error` signal
Expand Down
2 changes: 2 additions & 0 deletions packages/web-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,5 @@ export {
SESSION_INACTIVITY_TIME,
STORAGE_KEY,
} from './instrumentations/session';

export { getIgnoreUrls } from './utils/url';
2 changes: 2 additions & 0 deletions packages/web-sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export {
} from './webStorage';

export { throttle } from './throttle';

export { getIgnoreUrls } from './url';
9 changes: 9 additions & 0 deletions packages/web-sdk/src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { faro } from '@grafana/faro-core';
import type { Transport } from '@grafana/faro-core';

/**
* Get all configured ignore URLs.
*/
export function getIgnoreUrls() {
return faro.transports.transports.flatMap((transport: Transport) => transport.getIgnoreUrls());
}
45 changes: 45 additions & 0 deletions packages/web-sdk/src/utils/urls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BaseTransport, initializeFaro, VERSION } from '@grafana/faro-core';
import type { Patterns, TransportItem } from '@grafana/faro-core';
import { mockConfig } from '@grafana/faro-core/src/testUtils';

import { getIgnoreUrls } from './url';

class MockTransport extends BaseTransport {
readonly name = '@grafana/transport-mock';
readonly version = VERSION;

items: TransportItem[] = [];

constructor(private ignoreURLs: Patterns = []) {
super();
}

send(items: TransportItem[]): void | Promise<void> {
this.items.push(...items);
}

override isBatched(): boolean {
return true;
}

override getIgnoreUrls(): Patterns {
return (this.ignoreURLs ?? ([] as Patterns[])).concat(this.config.ignoreUrls ?? []);
}
}

describe('Urls', () => {
it('should return the correct ignore urls for the given configuration', () => {
const transport = new MockTransport(['http://foo.com']);

initializeFaro(
mockConfig({
transports: [transport],
ignoreUrls: ['http://example.com', 'http://example2.com/test'],
})
);

const urls = getIgnoreUrls();

expect(urls).toEqual(['http://foo.com', 'http://example.com', 'http://example2.com/test']);
});
});

0 comments on commit bd41a14

Please sign in to comment.