Skip to content

Commit a21068d

Browse files
committed
update tests, fix sdk devdep versions
1 parent 4fa2feb commit a21068d

File tree

4 files changed

+940
-7209
lines changed

4 files changed

+940
-7209
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@
7474
"@aws-sdk/client-bedrock-agent-runtime": "3.632.0",
7575
"@aws-sdk/client-bedrock-runtime": "3.632.0",
7676
"@aws-sdk/client-kinesis": "3.632.0",
77-
"@aws-sdk/client-lambda": "^3.632.0",
77+
"@aws-sdk/client-lambda": "3.632.0",
7878
"@aws-sdk/client-s3": "3.632.0",
79-
"@aws-sdk/client-secrets-manager": "^3.632.0",
80-
"@aws-sdk/client-sfn": "^3.632.0",
81-
"@aws-sdk/client-sns": "^3.632.0",
79+
"@aws-sdk/client-secrets-manager": "3.632.0",
80+
"@aws-sdk/client-sfn": "3.632.0",
81+
"@aws-sdk/client-sns": "3.632.0",
8282
"@opentelemetry/contrib-test-utils": "^0.45.0",
8383
"@smithy/protocol-http": "^5.0.1",
8484
"@smithy/signature-v4": "^5.0.1",

aws-distro-opentelemetry-node-autoinstrumentation/test/patches/extended-instrumentations/aws-lambda.test.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('AwsLambdaInstrumentationPatch', () => {
2929
assert.strictEqual(result.length, 0);
3030
});
3131

32-
it('should fallback to .cjs if .js does not exist', () => {
32+
it('should fallback to .mjs if .js does not exist', () => {
3333
process.env.LAMBDA_TASK_ROOT = '/var/task';
3434
process.env._HANDLER = 'src/index.handler';
3535

@@ -43,10 +43,10 @@ describe('AwsLambdaInstrumentationPatch', () => {
4343

4444
const result = instrumentation.init();
4545

46-
assert.strictEqual(result[0].name, '/var/task/src/index.cjs');
46+
assert.strictEqual(result[0].name, '/var/task/src/index.mjs');
4747
});
4848

49-
it('should fallback to .mjs when .js and .cjs do not exist', () => {
49+
it('should fallback to .cjs when .js and .mjs do not exist', () => {
5050
process.env.LAMBDA_TASK_ROOT = '/var/task';
5151
process.env._HANDLER = 'src/index.handler';
5252

@@ -60,7 +60,7 @@ describe('AwsLambdaInstrumentationPatch', () => {
6060

6161
const result = instrumentation.init();
6262

63-
assert.strictEqual(result[0].name, '/var/task/src/index.mjs');
63+
assert.strictEqual(result[0].name, '/var/task/src/index.cjs');
6464
});
6565

6666
it('should instrument CommonJS handler correctly', () => {
@@ -79,23 +79,6 @@ describe('AwsLambdaInstrumentationPatch', () => {
7979
assert.strictEqual(result[0].files.length, 1);
8080
assert(debugStub.calledWithMatch('Instrumenting lambda handler', sinon.match.object));
8181
});
82-
83-
it('should return ESM instrumentation for .mjs files or when HANDLER_IS_ESM is set', () => {
84-
process.env.LAMBDA_TASK_ROOT = '/var/task';
85-
process.env._HANDLER = 'src/index.handler';
86-
process.env.HANDLER_IS_ESM = 'true'; // ESM environment variable set
87-
88-
sinon.stub(path, 'basename').returns('index.handler');
89-
sinon.stub(fs, 'statSync').throws(new Error('File not found')); // No .js or .cjs file exists
90-
91-
const result = instrumentation.init();
92-
93-
assert.strictEqual(result.length, 1);
94-
assert.strictEqual(result[0].name, '/var/task/src/index.mjs');
95-
assert(result[0] instanceof InstrumentationNodeModuleDefinition);
96-
assert.strictEqual(result[0].files.length, 0); //
97-
delete process.env.HANDLER_IS_ESM;
98-
});
9982
});
10083

10184
it('should apply and remove patches correctly for a MJS handler', () => {
@@ -105,23 +88,24 @@ describe('AwsLambdaInstrumentationPatch', () => {
10588

10689
// Mock the module exports object with a sample function
10790
const fakeModuleExports = { handler: sinon.stub() };
91+
sinon.stub(fs, 'statSync').returns({} as any); // Mock that the .js file exists
10892

10993
const wrapSpy = sinon.spy(instrumentation, '_wrap' as any);
11094
const unwrapSpy = sinon.spy(instrumentation, '_unwrap' as any);
11195

11296
const result = instrumentation.init()[0];
11397
// Ensure result contains patch and unpatch functions
114-
assert(result.patch, 'patch function should be defined');
115-
assert(result.unpatch, 'unpatch function should be defined');
98+
assert(result.files[0].patch, 'patch function should be defined');
99+
assert(result.files[0].unpatch, 'unpatch function should be defined');
116100

117101
// Call the patch function with the mocked module exports
118-
result.patch(fakeModuleExports);
102+
result.files[0].patch(fakeModuleExports);
119103

120104
// Assert that wrap is called after patching
121105
assert(wrapSpy.calledOnce, '_wrap should be called once when patch is applied');
122106

123107
// Call the unpatch function with the mocked module exports
124-
result.unpatch(fakeModuleExports);
108+
result.files[0].unpatch(fakeModuleExports);
125109

126110
// Assert that unwrap is called after unpatching
127111
assert(unwrapSpy.calledOnce, '_unwrap should be called once when unpatch is called');

0 commit comments

Comments
 (0)