Skip to content

Commit 2da1f0c

Browse files
author
Reno
authored
refactor: Make default pagesToExclude value explicit (#180)
1 parent 92eef3c commit 2da1f0c

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ For example, the config object may look similar to the following:
2929
| guestRoleArn | String | `undefined` | The ARN of the AWS IAM role that will be assumed during anonymous authorization.<br/><br/>When this field is set (along with `identityPoolId`), the web client will attempt to retrieve temporary AWS credentials through Cognito using `AssumeRoleWithWebIdentity`. If this field is not set, you must forward credentials to the web client using the `setAwsCredentials` command. |
3030
| identityPoolId | String | `undefined` | The Amazon Cognito Identity Pool ID that will be used during anonymous authorization.<br/><br/>When this field is set (along with `guestRoleArn`), the web client will attempt to retrieve temporary AWS credentials through Cognito using `AssumeRoleWithWebIdentity`. If this field is not set, you must forward credentials to the web client using the `setAwsCredentials` command. |
3131
| pageIdFormat | String | `'PATH'` | The portion of the `window.location` that will be used as the page ID. Options include `PATH`, `HASH` and `PATH_AND_HASH`.<br/><br/>For example, consider the URL `https://amazonaws.com/home?param=true#content`<br/><br/>`PATH`: `/home`<br/>`HASH`: `#content`<br/>`PATH_AND_HASH`: `/home#content` |
32-
| pagesToInclude | RegExp[] | `[]` | A list of regular expressions which specify the `window.location` values for which the web client will record data. Pages are matched using the `RegExp.test()` function.<br/><br/>For example, when `pagesToInclude: [ /\/home/ ]`, then data from `https://amazonaws.com/home` will be included, and `https://amazonaws.com/` will not be included. |
32+
| pagesToInclude | RegExp[] | `[/.*/]` | A list of regular expressions which specify the `window.location` values for which the web client will record data, unless explicitly excluded by `pagesToExclude`. Pages are matched using the `RegExp.test()` function.<br/><br/>For example, when `pagesToInclude: [ /\/home/ ]`, then data from `https://amazonaws.com/home` will be included, and `https://amazonaws.com/` will not be included. |
3333
| pagesToExclude | RegExp[] | `[]` | A list of regular expressions which specify the `window.location` values for which the web client will record data. Pages are matched using the `RegExp.test()` function.<br/><br/>For example, when `pagesToExclude: [ /\/home/ ]`, then data from `https://amazonaws.com/home` will be excluded, and `https://amazonaws.com/` will not be excluded. |
3434
| recordResourceUrl | Boolean | `true` | When this field is `false`, the web client will not record the URLs of resources downloaded by your application.<br/><br/> Some types of resources (e.g., profile images) may be referenced by URLs which contain PII. If this applies to your application, you must set this field to `false` to comply with CloudWatch RUM's shared responsibility model. |
3535
| routeChangeComplete | Number | `100` | The interval (in milliseconds) for which when no HTTP or DOM activity has been observed, an active route change is marked as complete. Note that `routeChangeComplete` must be strictly less than `routeChangeTimeout`. |

src/event-cache/EventCache.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,14 @@ export class EventCache {
218218
*/
219219
private isCurrentUrlAllowed() {
220220
const location = document.location.toString();
221+
const exclude = this.config.pagesToExclude.some((re) =>
222+
re.test(location)
223+
);
221224

222-
if (
223-
this.config.pagesToExclude.length > 0 &&
224-
this.config.pagesToExclude.some((re) => re.test(location))
225-
) {
226-
return false;
227-
}
225+
const include = this.config.pagesToInclude.some((re) =>
226+
re.test(location)
227+
);
228228

229-
if (
230-
!this.config.pagesToInclude.length ||
231-
this.config.pagesToInclude.some((re) => re.test(location))
232-
) {
233-
return true;
234-
}
229+
return include && !exclude;
235230
}
236231
}

src/event-cache/__tests__/EventCache.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,7 @@ describe('EventCache tests', () => {
203203
// Init
204204
const EVENT1_SCHEMA = 'com.amazon.rum.event1';
205205
const eventCache: EventCache = Utils.createEventCache({
206-
...DEFAULT_CONFIG,
207-
...{
208-
pagesToInclude: [/.*/]
209-
}
206+
...DEFAULT_CONFIG
210207
});
211208
const expectedEvents: RumEvent[] = [
212209
{

src/orchestration/Orchestration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const defaultConfig = (cookieAttributes: CookieAttributes): Config => {
122122
eventPluginsToLoad: [],
123123
pageIdFormat: PageIdFormatEnum.Path,
124124
pagesToExclude: [],
125-
pagesToInclude: [],
125+
pagesToInclude: [/.*/],
126126
recordResourceUrl: true,
127127
retries: 2,
128128
routeChangeComplete: 100,

src/orchestration/__tests__/Orchestration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe('Orchestration tests', () => {
157157
eventPluginsToLoad: [],
158158
pageIdFormat: PageIdFormatEnum.Path,
159159
pagesToExclude: [],
160-
pagesToInclude: [],
160+
pagesToInclude: [/.*/],
161161
recordResourceUrl: true,
162162
retries: 2,
163163
routeChangeComplete: 100,

0 commit comments

Comments
 (0)