Skip to content

Commit c8bc3be

Browse files
williazzlimhjgrace
andauthored
feat: add metadata field "aws:releaseId" (#648)
Co-authored-by: Grace Lim <[email protected]>
1 parent cc96a7e commit c8bc3be

File tree

13 files changed

+100
-16
lines changed

13 files changed

+100
-16
lines changed

app/smoke.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
telemetries: ['performance', 'errors', 'http', 'interaction'],
3535
allowCookies: true,
3636
enableXRay: true,
37-
useBeacon: false
37+
useBeacon: false,
38+
releaseId: '2.1.7'
3839
});
3940
</script>
4041

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+
| releaseId | String | `undefined` | The releaseId will be used to retrieve source map(s), if any, when RUM service unminifies JavaScript error stack traces. It should be unique to each application release and match regex ^[a-zA-Z0-9_\-:/\.]{1,200}$, including size limit of 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. |

smoke/smoke-test-application-CDN/smoke.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
'x-api-key': 'a1b2c3d4e5f6',
4040
'content-type': 'application/json'
4141
},
42-
useBeacon: false
42+
useBeacon: false,
43+
releaseId: '2.1.7'
4344
});
4445
</script>
4546

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ try {
1414
cookieAttributes: {
1515
unique: true
1616
},
17-
useBeacon: false
17+
useBeacon: false,
18+
releaseId: '2.1.7'
1819
};
1920

2021
const APPLICATION_ID: string = $MONITOR_ID_2;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ try {
2121
'x-api-key': 'a1b2c3d4e5f6',
2222
'content-type': 'application/json'
2323
},
24-
useBeacon: false
24+
useBeacon: false,
25+
releaseId: '2.1.7'
2526
};
2627

2728
const APPLICATION_ID: string = $MONITOR_ID;

src/__smoke-test__/ingestion-integ.spec.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,19 @@ test('when event with custom attributes is sent then the event is ingested', asy
422422
const pageViews = getEventsByType(requestBody, PAGE_VIEW_EVENT_TYPE);
423423
const eventIds = getEventIds(pageViews);
424424

425+
const customAttributes = [
426+
'customAttributeKeyAtRuntime1=customAttributeValueAtRuntime1',
427+
'customAttributeKeyAtRuntime2=customAttributeValueAtRuntime2',
428+
'custom_attribute_key_at_runtime=customAttributeValueAtRuntime',
429+
'valid:customAttributeKeyAtRuntime=customAttributeValueAtRuntime'
430+
];
431+
432+
const additionalMetadataAttributes = ['aws:releaseId=2.1.7'];
433+
const expectedMetadataAttributes = [
434+
...customAttributes,
435+
...additionalMetadataAttributes
436+
];
437+
425438
// One initial load, one route change
426439
expect(eventIds.length).toEqual(2);
427440
const isIngestionCompleted = await verifyIngestionWithRetry(
@@ -430,12 +443,7 @@ test('when event with custom attributes is sent then the event is ingested', asy
430443
timestamp,
431444
MONITOR_NAME,
432445
5,
433-
[
434-
'customAttributeKeyAtRuntime1=customAttributeValueAtRuntime1',
435-
'customAttributeKeyAtRuntime2=customAttributeValueAtRuntime2',
436-
'custom_attribute_key_at_runtime=customAttributeValueAtRuntime',
437-
'valid:customAttributeKeyAtRuntime=customAttributeValueAtRuntime'
438-
]
446+
expectedMetadataAttributes
439447
);
440448
expect(isIngestionCompleted).toEqual(true);
441449
});

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+
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
@@ -110,6 +110,7 @@ export type PartialCookieAttributes = Partial<CookieAttributes>;
110110

111111
export interface Config {
112112
allowCookies: boolean;
113+
releaseId?: string;
113114
batchLimit: number;
114115
client: string;
115116
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.releaseId
277280
};
278281
}
279282

0 commit comments

Comments
 (0)