Skip to content

Commit a440016

Browse files
limhjgraceqhanam
andauthored
feat: support unique credential cookie names (#560)
Co-authored-by: Quinn Hanam <[email protected]>
1 parent c2da86e commit a440016

25 files changed

+707
-150
lines changed

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
src/events/*
1+
src/events/*
2+
**/src/loader-npm-rum.ts
3+
**/src/loader-npm-rum-2.ts

.github/scripts/update_smoke_test.sh

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ GUEST_ARN=$3
55
IDENTITY_POOL=$4
66
ENDPOINT=$5
77
CDN=$6
8+
MONITOR_ID_2=$7
9+
GUEST_ARN_2=$8
10+
IDENTITY_POOL_2=$9
811
VERSION=$(npm pkg get version | sed 's/"//g')/cwr.js
912
CDN+=${VERSION}
1013

@@ -16,6 +19,12 @@ awk '{sub(/\$MONITOR_ID/,MONITOR_ID);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub
1619
awk '{sub(/\$MONITOR_ID/,MONITOR_ID);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub(/\$GUEST_ARN/,GUEST_ARN);sub(/\$IDENTITY_POOL/,IDENTITY_POOL);sub(/\$ENDPOINT/,ENDPOINT);}1' \
1720
MONITOR_ID="'$MONITOR_ID'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN="'$GUEST_ARN'" IDENTITY_POOL="'$IDENTITY_POOL'" ENDPOINT="'$ENDPOINT'" smoke/smoke-test-application-NPM-ES/src/loader-npm-rum.ts > smoke/smoke-test-application-NPM-ES/src/loader-npm-rum-tmp.ts
1821

22+
awk '{sub(/\$MONITOR_ID_2/,MONITOR_ID_2);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub(/\$GUEST_ARN_2/,GUEST_ARN_2);sub(/\$IDENTITY_POOL_2/,IDENTITY_POOL_2);sub(/\$ENDPOINT/,ENDPOINT);}1' \
23+
MONITOR_ID_2="'$MONITOR_ID_2'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN_2="'$GUEST_ARN_2'" IDENTITY_POOL_2="'$IDENTITY_POOL_2'" ENDPOINT="'$ENDPOINT'" smoke/smoke-test-application-NPM-ES/src/loader-npm-rum-2.ts > smoke/smoke-test-application-NPM-ES/src/loader-npm-rum-tmp-2.ts
24+
1925
# Module CJS
2026
awk '{sub(/\$MONITOR_ID/,MONITOR_ID);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub(/\$GUEST_ARN/,GUEST_ARN);sub(/\$IDENTITY_POOL/,IDENTITY_POOL);sub(/\$ENDPOINT/,ENDPOINT);}1' \
2127
MONITOR_ID="'$MONITOR_ID'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN="'$GUEST_ARN'" IDENTITY_POOL="'$IDENTITY_POOL'" ENDPOINT="'$ENDPOINT'" smoke/smoke-test-application-NPM-CJS/src/loader-npm-rum.ts > smoke/smoke-test-application-NPM-CJS/src/loader-npm-rum-tmp.ts
28+
29+
awk '{sub(/\$MONITOR_ID_2/,MONITOR_ID_2);sub(/\$REGION/,REGION);sub(/\$CDN/,CDN);sub(/\$GUEST_ARN_2/,GUEST_ARN_2);sub(/\$IDENTITY_POOL_2/,IDENTITY_POOL_2);sub(/\$ENDPOINT/,ENDPOINT);}1' \
30+
MONITOR_ID_2="'$MONITOR_ID_2'" REGION="'$REGION'" CDN="'$CDN'" GUEST_ARN_2="'$GUEST_ARN_2'" IDENTITY_POOL_2="'$IDENTITY_POOL_2'" ENDPOINT="'$ENDPOINT'" smoke/smoke-test-application-NPM-CJS/src/loader-npm-rum-2.ts > smoke/smoke-test-application-NPM-CJS/src/loader-npm-rum-tmp-2.ts

.github/scripts/upload_smoke_test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ aws s3api put-object --bucket $bucket --key "smoke-$version.html" --body process
77
# NPM ES
88
aws s3api put-object --bucket $bucket --key "npm/es/$version/smoke.html" --body smoke/smoke-test-application-NPM-ES/app/smoke.html --content-type "text/html"
99
aws s3api put-object --bucket $bucket --key "npm/es/$version/loader_npm_rum_tmp.js" --body smoke/smoke-test-application-NPM-ES/build/dev/loader_npm_rum_tmp.js --content-type application/x-javascript
10+
aws s3api put-object --bucket $bucket --key "npm/es/$version/loader_npm_rum_tmp_2.js" --body smoke/smoke-test-application-NPM-ES/build/dev/loader_npm_rum_tmp_2.js --content-type application/x-javascript
1011

1112
# NPM CJS
1213
aws s3api put-object --bucket $bucket --key "npm/cjs/$version/smoke.html" --body smoke/smoke-test-application-NPM-CJS/app/smoke.html --content-type "text/html"
1314
aws s3api put-object --bucket $bucket --key "npm/cjs/$version/loader_npm_rum_tmp.js" --body smoke/smoke-test-application-NPM-CJS/build/dev/loader_npm_rum_tmp.js --content-type application/x-javascript
15+
aws s3api put-object --bucket $bucket --key "npm/cjs/$version/loader_npm_rum_tmp_2.js" --body smoke/smoke-test-application-NPM-CJS/build/dev/loader_npm_rum_tmp_2.js --content-type application/x-javascript

.github/workflows/cd.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
id: update-smoke-test-gamma-cdn
7575
run: |
7676
chmod u+x .github/scripts/update_smoke_test.sh
77-
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN_GAMMA }}
77+
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN_GAMMA }} ${{ secrets.SMOKE_MONITOR_2 }} ${{ secrets.SMOKE_ARN_2 }} ${{ secrets.SMOKE_IDENTITY_2 }}
7878
7979
- name: Build Smoke Test Application - NPM/ES
8080
id: build-npm-es-application-pre-release
@@ -98,6 +98,7 @@ jobs:
9898
env:
9999
URL: ${{ secrets.SMOKE_URL }}
100100
MONITOR: ${{ secrets.SMOKE_MONITOR }}
101+
MONITOR2: ${{ secrets.SMOKE_MONITOR_2 }}
101102
ENDPOINT: ${{ secrets.SMOKE_ENDPOINT }}
102103
NAME: ${{ secrets.SMOKE_MONITOR_NAME }}
103104
INSTALL_METHOD: 'NPM-ES'
@@ -110,6 +111,7 @@ jobs:
110111
env:
111112
URL: ${{ secrets.SMOKE_URL }}
112113
MONITOR: ${{ secrets.SMOKE_MONITOR }}
114+
MONITOR_2: ${{ secrets.SMOKE_MONITOR_2 }}
113115
ENDPOINT: ${{ secrets.SMOKE_ENDPOINT }}
114116
NAME: ${{ secrets.SMOKE_MONITOR_NAME }}
115117
INSTALL_METHOD: 'NPM-CJS'
@@ -168,7 +170,7 @@ jobs:
168170
id: update-smoke-test-prod-cdn
169171
run: |
170172
chmod u+x .github/scripts/update_smoke_test.sh
171-
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }}
173+
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }} ${{ secrets.SMOKE_MONITOR_2 }} ${{ secrets.SMOKE_ARN_2 }} ${{ secrets.SMOKE_IDENTITY_2 }}
172174
173175
- name: Upload Prod Smoke Tests to CloudFront
174176
id: upload-smoke-test-prod
@@ -180,6 +182,7 @@ jobs:
180182
env:
181183
URL: ${{ secrets.SMOKE_URL }}
182184
MONITOR: ${{ secrets.SMOKE_MONITOR }}
185+
MONITOR_2: ${{ secrets.SMOKE_MONITOR_2 }}
183186
ENDPOINT: ${{ secrets.SMOKE_ENDPOINT }}
184187
NAME: ${{ secrets.SMOKE_MONITOR_NAME }}
185188
INSTALL_METHOD: 'CDN'

.github/workflows/cdn_rollback.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
id: update-smoke-test
6767
run: |
6868
chmod u+x .github/scripts/update_smoke_test.sh
69-
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }} >> processed_smoke.html
69+
.github/scripts/update_smoke_test.sh ${{ secrets.SMOKE_MONITOR }} ${{ secrets.SMOKE_REGION }} ${{ secrets.SMOKE_ARN }} ${{ secrets.SMOKE_IDENTITY }} ${{ secrets.CONFIG_ENDPOINT }} ${{ secrets.CDN }} ${{ secrets.SMOKE_MONITOR_2 }} ${{ secrets.SMOKE_ARN_2 }} ${{ secrets.SMOKE_IDENTITY_2 }} >> processed_smoke.html
7070
7171
- name: Upload Smoke Test to CloudFront
7272
id: upload-smoke-test
@@ -81,6 +81,7 @@ jobs:
8181
env:
8282
URL: ${{ secrets.SMOKE_URL }}
8383
MONITOR: ${{ secrets.SMOKE_MONITOR }}
84+
MONITOR_2: ${{ secrets.SMOKE_MONITOR_2 }}
8485
ENDPOINT: ${{ secrets.SMOKE_ENDPOINT }}
8586
NAME: ${{ secrets.SMOKE_MONITOR_NAME }}
8687
run: npm run smoke:headless

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ For example, the config object may look similar to the following:
5151
| path | String | `/` | See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#define_where_cookies_are_sent |
5252
| sameSite | Boolean | `true` | See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#define_where_cookies_are_sent |
5353
| secure | Boolean | `true` | See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#define_where_cookies_are_sent |
54-
| unique | Boolean | `false` | When this field is `false`, the session cookie name is `cwr_s`. When this field is `true`, the session cookie name is `cwr_s_[AppMonitor Id]`.<br/><br/>Set this field to `true` when multiple AppMonitors will monitor the same page. For example, this might be the case if one AppMonitor is used for logged-in users, and a second AppMonitor is used for guest users. |
54+
| unique | Boolean | `false` | When this field is `false`, the session cookie name is `cwr_s` and the credential cookie name is `cwr_c`. When this field is `true`, the session cookie name is `cwr_s_[AppMonitor Id]` and the credential cookie name is `cwr_c_[AppMonitor Id]`.<br/><br/>Set this field to `true` when multiple AppMonitors will monitor the same page. For example, this might be the case if one AppMonitor is used for logged-in users, and a second AppMonitor is used for guest users. |
5555

5656
## MetadataAttributes
5757

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
"preinteg:local:nightwatch:firefox": "http-server ./build/dev -s &",
5555
"integ:local:nightwatch:firefox": "nightwatch -e firefox",
5656
"postinteg:local:nightwatch:firefox": "kill $(lsof -t -i:8080)",
57-
"smoke:local:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.local.config.ts",
58-
"smoke:local": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version npx playwright test --config=playwright.local.config.ts --headed",
59-
"smoke:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version INSTALL_METHOD=$INSTALL_METHOD npx playwright test --config=playwright.config.ts",
57+
"smoke:local:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version MONITOR_ID_2=$MONITOR_ID_2 npx playwright test --config=playwright.local.config.ts",
58+
"smoke:local": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version MONITOR_ID_2=$MONITOR_ID_2 npx playwright test --config=playwright.local.config.ts --headed",
59+
"smoke:headless": "cross-env URL=$URL MONITOR_ID=$MONITOR ENDPOINT=$ENDPOINT NAME=$NAME VERSION=$npm_package_version INSTALL_METHOD=$INSTALL_METHOD MONITOR_ID_2=$MONITOR_ID_2 npx playwright test --config=playwright.config.ts",
6060
"prepare": "husky install"
6161
},
6262
"devDependencies": {

smoke/smoke-test-application-NPM-CJS/app/smoke.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
<title>RUM Smoke Test</title>
99

1010
<script type="text/javascript" src="./loader_npm_rum_tmp.js"></script>
11+
<script>
12+
function loadScriptWithDelay() {
13+
setTimeout(function () {
14+
var script = document.createElement('script');
15+
script.type = 'text/javascript';
16+
script.src = './loader_npm_rum_tmp_2.js';
17+
document.head.appendChild(script);
18+
}, 10000); // 10 seconds
19+
}
20+
21+
// Call the function to load the script with a delay
22+
loadScriptWithDelay();
23+
</script>
1124

1225
<link
1326
rel="icon"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @ts-nocheck
2+
const { AwsRum, AwsRumConfig } = require('aws-rum-web');
3+
4+
let awsRum;
5+
6+
try {
7+
const config: AwsRumConfig = {
8+
sessionSampleRate: 1,
9+
identityPoolId: $IDENTITY_POOL_2,
10+
endpoint: $ENDPOINT,
11+
telemetries: ['performance', 'errors', 'http', 'interaction'],
12+
allowCookies: true,
13+
enableXRay: true,
14+
cookieAttributes: {
15+
unique: true
16+
}
17+
};
18+
19+
const APPLICATION_ID: string = $MONITOR_ID_2;
20+
const APPLICATION_VERSION: string = '1.0.0';
21+
const APPLICATION_REGION: string = $REGION;
22+
23+
awsRum: AwsRum = new AwsRum(
24+
APPLICATION_ID,
25+
APPLICATION_VERSION,
26+
APPLICATION_REGION,
27+
config
28+
);
29+
} catch (error) {
30+
console.log(error);
31+
throw error;
32+
}

smoke/smoke-test-application-NPM-CJS/src/loader-npm-rum.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ try {
1010
endpoint: $ENDPOINT,
1111
telemetries: ['performance', 'errors', 'http', 'interaction'],
1212
allowCookies: true,
13-
enableXRay: true
13+
enableXRay: true,
14+
cookieAttributes: {
15+
unique: true
16+
}
1417
};
1518

1619
const APPLICATION_ID: string = $MONITOR_ID;

0 commit comments

Comments
 (0)