Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add resource and navigation event filtering #419

Merged
merged 30 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3fd4d7b
feat: add ignore callback to resource plugin config
williazz Jun 13, 2023
e44c803
docs: ResourcePlugin(ignoreEvent) callback description and example
williazz Jun 15, 2023
7258bb7
chore(release): 1.14.0
williazz Jun 21, 2023
c88e762
fix: rename Resource ignoreEvent to ignore for consistency
williazz Jun 23, 2023
744fb2a
fix: rename resource ignore test using "when... then..." format
williazz Jun 23, 2023
12a10b8
Revert "chore(release): 1.14.0"
williazz Jun 23, 2023
af330b7
fix: resource ignore returns any value that coerces into a boolean fo…
williazz Jun 23, 2023
683b219
refactor: change ignore(entry) to expect a PerformanceEntry
williazz Jun 23, 2023
4409167
docs: share ignore() between Resource and Navigation Plugin through p…
williazz Jun 23, 2023
a40218d
feat: allow NavigationPlugin to ignore level 2 events
williazz Jun 23, 2023
b3d40bc
docs: explain how performance ignore() can ignore navigation and reso…
williazz Jun 23, 2023
82f6704
fix: delete refactors that are unrelated to this PR
williazz Jun 24, 2023
98fcbda
feat: ignore events from chrome extensions by default
williazz Jun 24, 2023
903779b
fix: migrate all shared performance configuration to performance-utils
williazz Jun 26, 2023
00a0e61
Edit documentation
qhanam Jun 25, 2023
30c20ec
Revert logic inversion
qhanam Jun 26, 2023
690944c
Fix PerformanceNavigationTiming type casting
qhanam Jun 26, 2023
51cc2c8
Fix refactor revert
qhanam Jun 26, 2023
b6252a7
Fix buildResourcePlugin
qhanam Jun 26, 2023
4aa5058
Fix buildResourcePlugin
qhanam Jun 26, 2023
33b44ca
fix: change default performance config to ignore non-http(s) resource…
williazz Jun 26, 2023
b3228fc
refactor: simplify performance unit tests() to ignore all events
williazz Jun 26, 2023
287a4ca
test: add unit tests for defaultPerformanceIgnore()
williazz Jun 26, 2023
b0666a2
fix: move defaultPerformanceIgnore() unit tests to performance-utils.…
williazz Jun 26, 2023
95e6868
fix: add unit tests when entry is subclass of PerformanceEntry
williazz Jun 26, 2023
5d0ac8c
Use one type for performance config
qhanam Jun 27, 2023
6fc4f0f
Use stream filter pattern consistently
qhanam Jun 27, 2023
7c9f8db
fix: remove unecessary defaultIgnore() tests
williazz Jun 27, 2023
b8d07e1
fix: remove performance mock data helpers
williazz Jun 27, 2023
c19a350
Fix default value in docs
qhanam Jun 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/plugins/event-plugins/NavigationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,16 @@ export const NAVIGATION_EVENT_PLUGIN_ID = 'navigation';
const NAVIGATION = 'navigation';
const LOAD = 'load';

export type PartialNavigationPluginConfig = PartialPerformancePluginConfig;

export type NavigationPluginConfig = PerformancePluginConfig;

export const defaultNavigationPluginConfig = {
...defaultPerformancePluginConfig
};

/**
* This plugin records performance timing events generated during every page load/re-load activity.
* Paint, resource and performance event types make sense only if all or none are included.
* For RUM, these event types are inter-dependent. So they are recorded under one plugin.
*/
export class NavigationPlugin extends InternalPlugin {
private config: NavigationPluginConfig;
constructor(config?: PartialNavigationPluginConfig) {
private config: PerformancePluginConfig;
constructor(config?: PartialPerformancePluginConfig) {
super(NAVIGATION_EVENT_PLUGIN_ID);
this.config = { ...defaultNavigationPluginConfig, ...config };
this.config = { ...defaultPerformancePluginConfig, ...config };
}

enable(): void {
Expand Down
27 changes: 3 additions & 24 deletions src/plugins/event-plugins/ResourcePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,15 @@ export const RESOURCE_EVENT_PLUGIN_ID = 'resource';
const RESOURCE = 'resource';
const LOAD = 'load';

export type PartialResourcePluginConfig = {
recordAllTypes?: ResourceType[];
sampleTypes?: ResourceType[];
} & PartialPerformancePluginConfig;

export type ResourcePluginConfig = {
recordAllTypes: ResourceType[];
sampleTypes: ResourceType[];
} & PerformancePluginConfig;

export const defaultResourcePluginConfig = {
recordAllTypes: [ResourceType.DOCUMENT, ResourceType.SCRIPT],
sampleTypes: [
ResourceType.STYLESHEET,
ResourceType.IMAGE,
ResourceType.FONT,
ResourceType.OTHER
],
...defaultPerformancePluginConfig
};

/**
* This plugin records resource performance timing events generated during every page load/re-load.
*/
export class ResourcePlugin extends InternalPlugin {
private config: ResourcePluginConfig;
private config: PerformancePluginConfig;

constructor(config?: PartialResourcePluginConfig) {
constructor(config?: PartialPerformancePluginConfig) {
super(RESOURCE_EVENT_PLUGIN_ID);
this.config = { ...defaultResourcePluginConfig, ...config };
this.config = { ...defaultPerformancePluginConfig, ...config };
}

enable(): void {
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/event-plugins/__tests__/NavigationPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import {
mockPerformanceObjectWith,
putRumEventsDocument
} from '../../../test-utils/mock-data';
import {
NavigationPlugin,
PartialNavigationPluginConfig
} from '../NavigationPlugin';
import { NavigationPlugin } from '../NavigationPlugin';
import { context, record } from '../../../test-utils/test-utils';
import { PERFORMANCE_NAVIGATION_EVENT_TYPE } from '../../utils/constant';
import { PartialPerformancePluginConfig } from 'plugins/utils/performance-utils';

const buildNavigationPlugin = (config?: PartialNavigationPluginConfig) => {
const buildNavigationPlugin = (config?: PartialPerformancePluginConfig) => {
return new NavigationPlugin(config);
};

Expand Down
5 changes: 3 additions & 2 deletions src/plugins/event-plugins/__tests__/ResourcePlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
putRumEventsGammaDocument,
dataPlaneDocument
} from '../../../test-utils/mock-data';
import { PartialResourcePluginConfig, ResourcePlugin } from '../ResourcePlugin';
import { ResourcePlugin } from '../ResourcePlugin';
import { mockRandom } from 'jest-mock-random';
import {
context,
Expand All @@ -23,8 +23,9 @@ import {
import { PERFORMANCE_RESOURCE_EVENT_TYPE } from '../../utils/constant';
import { ResourceEvent } from '../../../events/resource-event';
import { PluginContext } from '../../types';
import { PartialPerformancePluginConfig } from 'plugins/utils/performance-utils';

const buildResourcePlugin = (config?: PartialResourcePluginConfig) => {
const buildResourcePlugin = (config?: PartialPerformancePluginConfig) => {
return new ResourcePlugin(config);
};

Expand Down
20 changes: 10 additions & 10 deletions src/plugins/utils/__tests__/performance-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultPerformanceIgnore } from '../performance-utils';
import { defaultIgnore } from '../performance-utils';
import {
mockPerformanceEntry,
mockPerformanceNavigationTiming,
Expand All @@ -12,71 +12,71 @@ describe('performance-utils', () => {
name: 'chrome-extension://localhost',
entryType: 'resource'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(true);
});
test('when resource entry is PerformanceEntry and has http URL schema then entry is not ignored', () => {
const mockEntry = mockPerformanceEntry({
name: 'http://localhost',
entryType: 'resource'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(false);
});
test('when resource entry is PerformanceEntry and has https URL schema then entry is not ignored', () => {
const mockEntry = mockPerformanceEntry({
name: 'https://localhost',
entryType: 'resource'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(false);
});

test('when entry is PerformanceResourceTiming and has non-http(s) URL-schema then entry is ignored', () => {
const mockEntry = mockPerformanceResourceTiming({
name: 'chrome-extension://localhost'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(true);
});

test('when entry is PerformanceResourceTiming and has http URL schema then the entry is not ignored', () => {
const mockEntry = mockPerformanceResourceTiming({
name: 'http://localhost'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(false);
});

test('when entry is PerformanceResourceTiming and has https URL schema then entry is not ignored', () => {
const mockEntry = mockPerformanceResourceTiming({
name: 'https://localhost'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(false);
});

test('when entry is PerformanceNavigationTiming and has non-http(s) URL schema request then entry is not ignored', () => {
const mockEntry = mockPerformanceNavigationTiming({
name: 'chrome-extension://localhost'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(false);
});

test('when entry is PerformanceNavigationTiming and has http URL schema then entry is not ignored', () => {
const mockEntry = mockPerformanceNavigationTiming({
name: 'http://localhost'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(false);
});

test('when entry is PerformanceNavigationTiming and has https URL schema then entry is not ignored', () => {
const mockEntry = mockPerformanceNavigationTiming({
name: 'https://localhost'
});
const result = defaultPerformanceIgnore(mockEntry);
const result = defaultIgnore(mockEntry);
expect(result).toBe(false);
});
});
Expand Down
23 changes: 18 additions & 5 deletions src/plugins/utils/performance-utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
export const defaultPerformanceIgnore = (entry: PerformanceEntry) =>
import { ResourceType } from '../../utils/common-utils';

export const defaultIgnore = (entry: PerformanceEntry) =>
entry.entryType === 'resource' && !/^https?:/.test(entry.name);

export type PartialPerformancePluginConfig = {
ignore?: (event: PerformanceEntry) => any;
eventLimit?: number;
ignore?: (event: PerformanceEntry) => any;
recordAllTypes?: ResourceType[];
sampleTypes?: ResourceType[];
};

export type PerformancePluginConfig = {
ignore: (event: PerformanceEntry) => any;
eventLimit: number;
ignore: (event: PerformanceEntry) => any;
recordAllTypes: ResourceType[];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: we need to update the performance config documentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation for eventLimit, recordAllTypes and sampleTypes has never existed, so there's no regression or omission with respect to this PR.

Let's close out this PR and track that separately.

sampleTypes: ResourceType[];
};

export const defaultPerformancePluginConfig = {
ignore: defaultPerformanceIgnore,
eventLimit: 10
eventLimit: 10,
ignore: defaultIgnore,
recordAllTypes: [ResourceType.DOCUMENT, ResourceType.SCRIPT],
sampleTypes: [
ResourceType.STYLESHEET,
ResourceType.IMAGE,
ResourceType.FONT,
ResourceType.OTHER
]
};