Skip to content

Commit 519cbfe

Browse files
dreamorosisdangol
andauthored
chore(commons): concatenate PT UA to AWS_SDK_UA_APP_ID when one is set (#4374)
Co-authored-by: Swopnil Dangol <swopnildangol@gmail.com>
1 parent 4942af6 commit 519cbfe

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

packages/commons/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { PT_VERSION } from './version.js';
22

33
if (!process.env.AWS_SDK_UA_APP_ID) {
4-
process.env.AWS_SDK_UA_APP_ID = `PT/NO-OP/${PT_VERSION}`;
4+
process.env.AWS_SDK_UA_APP_ID = `PT/TEST/${PT_VERSION}`;
5+
} else {
6+
process.env.AWS_SDK_UA_APP_ID = `${process.env.AWS_SDK_UA_APP_ID}/PT/TEST/${PT_VERSION}`;
57
}
68

79
export { addUserAgentMiddleware, isSdkClient } from './awsSdkUtils.js';

packages/commons/tests/unit/awsSdkUtils.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeAll, describe, expect, it, vi } from 'vitest';
1+
import { describe, expect, it, vi } from 'vitest';
22
import { customUserAgentMiddleware } from '../../src/awsSdkUtils.js';
33
import {
44
addUserAgentMiddleware,
@@ -8,14 +8,11 @@ import {
88

99
vi.hoisted(() => {
1010
process.env.AWS_EXECUTION_ENV = '';
11+
process.env.AWS_SDK_UA_APP_ID = 'test';
1112
});
1213

1314
describe('Helpers: awsSdk', () => {
1415
describe('Function: userAgentMiddleware', () => {
15-
beforeAll(() => {
16-
vi.spyOn(console, 'warn').mockImplementation(() => ({}));
17-
});
18-
1916
it('handles gracefully failures in adding a middleware and only log a warning', () => {
2017
// Prepare
2118
const client = {
@@ -25,13 +22,10 @@ describe('Helpers: awsSdk', () => {
2522
},
2623
},
2724
};
28-
const warningSpy = vi
29-
.spyOn(console, 'warn')
30-
.mockImplementation(() => ({}));
3125

3226
// Act & Assess
3327
expect(() => addUserAgentMiddleware(client, 'my-feature')).not.toThrow();
34-
expect(warningSpy).toHaveBeenCalledTimes(1);
28+
expect(console.warn).toHaveBeenCalledTimes(1);
3529
});
3630

3731
it('should return and do nothing if the client already has a Powertools UA middleware', async () => {
@@ -88,6 +82,11 @@ describe('Helpers: awsSdk', () => {
8882
});
8983
});
9084

85+
it('concatenates the PT AWS_SDK_UA_APP_ID when one is already set', () => {
86+
// Assess
87+
expect(process.env.AWS_SDK_UA_APP_ID).toEqual(`test/PT/TEST/${version}`);
88+
});
89+
9190
describe('Function: customUserAgentMiddleware', () => {
9291
it('returns a middleware function', () => {
9392
// Prepare

0 commit comments

Comments
 (0)