Skip to content

Commit 42f986a

Browse files
williazzlimhjgrace
authored andcommitted
feat: add metadata field "aws:releaseId" (#592)
1 parent 0f40cbf commit 42f986a

File tree

7 files changed

+76
-4
lines changed

7 files changed

+76
-4
lines changed

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For example, the config object may look similar to the following:
1919
| Field Name | Type | Default | Description |
2020
| --- | --- | --- | --- |
2121
| allowCookies | Boolean | `false` | Enable the web client to set and read two cookies: a session cookie named `cwr_s` and a user cookie named `cwr_u`.<br/><br/>`cwr_s` stores session data including an anonymous session ID (uuid v4) created by the web client. This allows CloudWatch RUM to compute sessionized metrics like errors per session.<br/><br/>`cwr_u` stores an anonymous user ID (uuid v4) created by the web client. This allows CloudWatch RUM to count return visitors.<br/><br/>`true`: the web client will use cookies<br/>`false`: the web client will not use cookies. |
22+
| aws:releaseId | string | `undefined` | The application release id used to find a matching source map, if any. Must match regex `^[a-zA-Z0-9_\-:/\.]{1,200}$`, including size limit 200 |
2223
| cookieAttributes | [CookieAttributes](#cookieattributes) | `{ domain: window.location.hostname, path: '/', sameSite: 'Strict', secure: true, unique: false } ` | Cookie attributes are applied to all cookies stored by the web client, including `cwr_s` and `cwr_u`. |
2324
| sessionAttributes | [MetadataAttributes](#metadataattributes) | `{}` | Session attributes will be added the metadata of all events in the session. |
2425
| disableAutoPageView | Boolean | `false` | When this field is `false`, the web client will automatically record page views.<br/><br/>By default, the web client records page views when (1) the page first loads and (2) the browser's [history API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) is called. The page ID is `window.location.pathname`.<br/><br/>In some cases, the web client's instrumentation will not record the desired page ID. In this case, the web client's page view automation must be disabled using the `disableAutoPageView` configuration, and the application must be instrumented to record page views using the `recordPageView` command. |

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,49 @@ describe('EventCache tests', () => {
118118
});
119119
});
120120

121+
test('when aws:releaseId exists then it is added to event metadata', async () => {
122+
// Init
123+
const EVENT1_SCHEMA = 'com.amazon.rum.event1';
124+
const config = {
125+
...DEFAULT_CONFIG,
126+
...{
127+
allowCookies: false,
128+
sessionLengthSeconds: 0
129+
},
130+
'aws:releaseId': '5.2.1'
131+
};
132+
133+
const eventCache: EventCache = Utils.createEventCache(config);
134+
135+
// Run
136+
eventCache.recordPageView('/console/home');
137+
eventCache.recordEvent(EVENT1_SCHEMA, {});
138+
139+
// Assert
140+
const events = eventCache.getEventBatch();
141+
events.forEach((event) => {
142+
expect(JSON.parse(event.metadata)).toMatchObject({
143+
'aws:releaseId': '5.2.1'
144+
});
145+
});
146+
});
147+
148+
test('when aws:releaseId does NOT exist then it is NOT added to event metadata', async () => {
149+
// Init
150+
const EVENT1_SCHEMA = 'com.amazon.rum.event1';
151+
const eventCache: EventCache = Utils.createEventCache(DEFAULT_CONFIG);
152+
153+
// Run
154+
eventCache.recordPageView('/console/home');
155+
eventCache.recordEvent(EVENT1_SCHEMA, {});
156+
157+
// Assert
158+
const events = eventCache.getEventBatch();
159+
events.forEach((event) => {
160+
expect(JSON.parse(event.metadata)['aws:releaseId']).toBeUndefined();
161+
});
162+
});
163+
121164
test('when a session is not sampled then return false', async () => {
122165
// Init
123166
const config = {

src/event-schemas/meta-data.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"type": "string",
1010
"description": "Schema version."
1111
},
12+
"aws:releaseId": {
13+
"type": "string"
14+
},
1215
"browserLanguage": {
1316
"type": "string"
1417
},

src/orchestration/Orchestration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export type PartialCookieAttributes = Partial<CookieAttributes>;
109109

110110
export interface Config {
111111
allowCookies: boolean;
112+
'aws:releaseId'?: string;
112113
batchLimit: number;
113114
client: string;
114115
clientBuilder?: ClientBuilder;

src/sessions/SessionManager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export type Session = {
3232
};
3333

3434
export type Attributes = {
35+
// The custom release id, to match a source map
36+
'aws:releaseId'?: string;
3537
browserLanguage: string;
3638
browserName: string;
3739
browserVersion: string;
@@ -45,8 +47,8 @@ export type Attributes = {
4547
platformType: string;
4648
// The fully qualified domain name (i.e., host name + domain name)
4749
domain: string;
48-
// Custom attribute value types are restricted to the types: string | number | boolean
49-
[k: string]: string | number | boolean;
50+
// Custom attribute value types are restricted to the types: string | number | boolean | undefined
51+
[k: string]: string | number | boolean | undefined;
5052
};
5153

5254
/**
@@ -273,7 +275,8 @@ export class SessionManager {
273275
deviceType: ua.device.type ? ua.device.type : DESKTOP_DEVICE_TYPE,
274276
// This client is used exclusively in web applications.
275277
platformType: WEB_PLATFORM_TYPE,
276-
domain: window.location.hostname
278+
domain: window.location.hostname,
279+
'aws:releaseId': this.config['aws:releaseId']
277280
};
278281
}
279282

src/sessions/__integ__/SessionManager.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const OS_NAME = 'osName';
2626
const OS_VERSION = 'osVersion';
2727
const DEVICE_TYPE = 'deviceType';
2828
const PLATFORM_TYPE = 'platformType';
29+
const AWS_RELEASE_ID = 'aws:releaseId';
2930

3031
const button1: Selector = Selector(`#${BUTTON_ID_1}`);
3132

@@ -106,7 +107,9 @@ test('UserAgentMetaDataPlugin records user agent metadata', async (t: TestContro
106107
.expect(REQUEST_BODY.textContent)
107108
.contains(PLATFORM_TYPE)
108109
.expect(RESPONSE_STATUS.textContent)
109-
.eql(STATUS_202.toString());
110+
.eql(STATUS_202.toString())
111+
.expect(REQUEST_BODY.textContent)
112+
.notContains(AWS_RELEASE_ID);
110113
});
111114

112115
test('When custom attribute set at init, custom attribute recorded in event metadata', async (t: TestController) => {

src/sessions/__tests__/SessionManager.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,4 +846,22 @@ describe('SessionManager tests', () => {
846846
// Assert
847847
expect(actualSessionAttributes.title).toEqual(sessionAttributes.title);
848848
});
849+
850+
test('when initiated with aws:releaseId then it is in the attributes', async () => {
851+
const awsReleaseId = '2.1.7';
852+
const sessionManager = defaultSessionManager({
853+
...DEFAULT_CONFIG,
854+
'aws:releaseId': awsReleaseId
855+
});
856+
857+
const actualSessionAttributes = sessionManager.getAttributes();
858+
expect(actualSessionAttributes['aws:releaseId']).toBe(awsReleaseId);
859+
});
860+
861+
test('when initiated without aws:releaseId then it is NOT in the attributes', async () => {
862+
const sessionManager = defaultSessionManager(DEFAULT_CONFIG);
863+
864+
const actualSessionAttributes = sessionManager.getAttributes();
865+
expect(actualSessionAttributes['aws:releaseId']).toBeUndefined();
866+
});
849867
});

0 commit comments

Comments
 (0)