Skip to content

Commit 5051d91

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

File tree

7 files changed

+1008
-7265
lines changed

7 files changed

+1008
-7265
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/src/otlp-aws-span-exporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
5656
This is bad practice but there is no other way to access and inject SigV4 headers
5757
into the request headers before the traces get exported.
5858
*/
59-
const oldHeaders = (this as any)._delegate._transport?._transport?._parameters?.headers;
59+
const oldHeaders = (this as any)._delegate._transport?._transport?._parameters?.headers();
6060

6161
if (oldHeaders) {
6262
const request = new this.httpRequest({
@@ -81,7 +81,7 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
8181

8282
const signedRequest = await signer.sign(request);
8383

84-
(this as any)._delegate._transport._transport._parameters.headers = signedRequest.headers;
84+
(this as any)._delegate._transport._transport._parameters.headers = () => signedRequest.headers;
8585
} catch (exception) {
8686
diag.debug(
8787
`Failed to sign/authenticate the given exported Span request to OTLP XRay endpoint with error: ${exception}`
@@ -90,7 +90,7 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
9090
}
9191
}
9292

93-
await super.export(items, resultCallback);
93+
super.export(items, resultCallback);
9494
}
9595

9696
// Removes Sigv4 headers from old headers to avoid accidentally copying them to the new headers

aws-distro-opentelemetry-node-autoinstrumentation/test/otlp-aws-span-exporter.test.ts

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,27 @@ if (nodeVersion >= 16) {
6666
sandbox.restore();
6767
});
6868

69-
it('Should inject SigV4 Headers successfully', async () => {
69+
it('Should inject SigV4 Headers successfully', done => {
7070
const exporter = new mockModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
7171

72-
scope.on('request', (req, interceptor, body) => {
73-
const headers = req.headers;
74-
expect(headers).toHaveProperty(AUTHORIZATION_HEADER.toLowerCase());
75-
expect(headers).toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase());
76-
expect(headers).toHaveProperty(X_AMZ_DATE_HEADER.toLowerCase());
77-
78-
expect(headers[AUTHORIZATION_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_HEADER);
79-
expect(headers[X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_SECURITY_TOKEN);
80-
expect(headers[X_AMZ_DATE_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_X_AMZ_DATE);
72+
exporter
73+
.export([], () => {})
74+
.then(() => {
75+
scope.on('request', (req, interceptor, body) => {
76+
const headers = req.headers;
77+
expect(headers).toHaveProperty(AUTHORIZATION_HEADER.toLowerCase());
78+
expect(headers).toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase());
79+
expect(headers).toHaveProperty(X_AMZ_DATE_HEADER.toLowerCase());
8180

82-
expect(headers['content-type']).toBe('application/x-protobuf');
83-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
84-
});
81+
expect(headers[AUTHORIZATION_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_HEADER);
82+
expect(headers[X_AMZ_SECURITY_TOKEN_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_SECURITY_TOKEN);
83+
expect(headers[X_AMZ_DATE_HEADER.toLowerCase()]).toBe(EXPECTED_AUTH_X_AMZ_DATE);
8584

86-
await exporter.export([], () => {});
85+
expect(headers['content-type']).toBe('application/x-protobuf');
86+
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
87+
done();
88+
});
89+
});
8790
});
8891

8992
describe('Should not inject SigV4 headers if dependencies are missing', () => {
@@ -95,42 +98,35 @@ if (nodeVersion >= 16) {
9598
];
9699

97100
dependencies.forEach(dependency => {
98-
it(`should not sign headers if missing dependency: ${dependency}`, async () => {
101+
it(`should not sign headers if missing dependency: ${dependency}`, done => {
99102
const exporter = new OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
100103

101-
scope.on('request', (req, interceptor, body) => {
102-
const headers = req.headers;
103-
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
104-
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
105-
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
106-
107-
expect(headers['content-type']).toBe('application/x-protobuf');
108-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
109-
});
110-
111104
Object.keys(require.cache).forEach(key => {
112105
delete require.cache[key];
113106
});
114107
const requireStub = sandbox.stub(require('module'), '_load');
115108
requireStub.withArgs(dependency).throws(new Error(`Cannot find module '${dependency}'`));
116109
requireStub.callThrough();
117110

118-
await exporter.export([], () => {});
111+
exporter
112+
.export([], () => {})
113+
.then(() => {
114+
scope.on('request', (req, interceptor, body) => {
115+
const headers = req.headers;
116+
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
117+
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
118+
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
119+
120+
expect(headers['content-type']).toBe('application/x-protobuf');
121+
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
122+
done();
123+
});
124+
});
119125
});
120126
});
121127
});
122128

123-
it('should not inject SigV4 headers if failure to sign headers', async () => {
124-
scope.on('request', (req, interceptor, body) => {
125-
const headers = req.headers;
126-
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
127-
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
128-
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
129-
130-
expect(headers['content-type']).toBe('application/x-protobuf');
131-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
132-
});
133-
129+
it('should not inject SigV4 headers if failure to sign headers', done => {
134130
const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', {
135131
'@smithy/signature-v4': {
136132
SignatureV4: class MockSignatureV4 {
@@ -141,22 +137,25 @@ if (nodeVersion >= 16) {
141137
},
142138
});
143139

144-
const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT);
145-
146-
await exporter.export([], () => {});
147-
});
140+
const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
148141

149-
it('should not inject SigV4 headers if failure to retrieve credentials', async () => {
150-
scope.on('request', (req, interceptor, body) => {
151-
const headers = req.headers;
152-
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
153-
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
154-
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
142+
exporter
143+
.export([], () => {})
144+
.then(() => {
145+
scope.on('request', (req, interceptor, body) => {
146+
const headers = req.headers;
147+
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
148+
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
149+
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
155150

156-
expect(headers['content-type']).toBe('application/x-protobuf');
157-
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
158-
});
151+
expect(headers['content-type']).toBe('application/x-protobuf');
152+
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
153+
done();
154+
});
155+
});
156+
});
159157

158+
it('should not inject SigV4 headers if failure to retrieve credentials', done => {
160159
const stubbedModule = proxyquire('../src/otlp-aws-span-exporter', {
161160
'@aws-sdk/credential-provider-node': {
162161
defaultProvider: () => async () => {
@@ -165,9 +164,22 @@ if (nodeVersion >= 16) {
165164
},
166165
});
167166

168-
const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT);
167+
const exporter = new stubbedModule.OTLPAwsSpanExporter(XRAY_OTLP_ENDPOINT + XRAY_OTLP_ENDPOINT_PATH);
169168

170-
await exporter.export([], () => {});
169+
exporter
170+
.export([], () => {})
171+
.then(() => {
172+
scope.on('request', (req, interceptor, body) => {
173+
const headers = req.headers;
174+
expect(headers).not.toHaveProperty(AUTHORIZATION_HEADER);
175+
expect(headers).not.toHaveProperty(X_AMZ_DATE_HEADER);
176+
expect(headers).not.toHaveProperty(X_AMZ_SECURITY_TOKEN_HEADER);
177+
178+
expect(headers['content-type']).toBe('application/x-protobuf');
179+
expect(headers['user-agent']).toMatch(/^OTel-OTLP-Exporter-JavaScript\/\d+\.\d+\.\d+$/);
180+
done();
181+
});
182+
});
171183
});
172184
});
173185
}

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');

contract-tests/tests/test/amazon/misc/resource_attributes_test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def assert_resource_attributes(self, service_name):
5858
target_spans: List[Span] = []
5959
for resource_scope_span in resource_scope_spans:
6060
# pylint: disable=no-member
61-
if resource_scope_span.span.name == "tcp.connect":
61+
if resource_scope_span.span.name == "GET" and resource_scope_span.span.kind == Span.SPAN_KIND_CLIENT:
6262
target_spans.append(resource_scope_span.resource_spans)
6363

6464
self.assertEqual(len(target_spans), 1)

0 commit comments

Comments
 (0)