Skip to content

Commit c9bcc5a

Browse files
committed
Merge branch 'main' into sqs-batch-receive
2 parents fd7a219 + 8e08755 commit c9bcc5a

File tree

8 files changed

+3428
-4483
lines changed

8 files changed

+3428
-4483
lines changed

package-lock.json

Lines changed: 3079 additions & 4256 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
# Note: tests must set `SKIP_TEST_IF_DISABLE=true` to override usage of
2+
# `mocha --require '../../../scripts/skip-test-if.js' ...` if calling `npm test`.
3+
14
"aws-sdk":
5+
env:
6+
- SKIP_TEST_IF_DISABLE=true
27
# A small subset of releases in the range [2.308.0, 3) to reduce testing time.
38
versions:
49
include: "^2.308.0"
510
mode: max-7
611
commands:
7-
- npm run test
12+
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v2.test.ts
813

914
# Versions [3.363.0, 3.377.0] of all @aws-sdk/client-* were bad releases. See:
1015
# - https://github.com/open-telemetry/opentelemetry-js-contrib/pull/2464#issuecomment-2403652552
@@ -15,44 +20,61 @@
1520
# - 16.x dropped in v3.723.0 https://github.com/aws/aws-sdk-js-v3/pull/6775
1621

1722
"@aws-sdk/client-s3":
23+
env:
24+
- SKIP_TEST_IF_DISABLE=true
1825
# - 3.529.0 was missing the fast-xml-parser dependency (https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.529.1)
1926
jobs:
2027
- node: ">=18"
2128
versions:
2229
include: "^3.6.1"
2330
exclude: "3.529.0 || >=3.363.0 <=3.377.0"
2431
mode: "max-7"
25-
commands: npm run test
32+
commands:
33+
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-s3.test.ts
34+
- mocha --require '@opentelemetry/contrib-test-utils' test/s3.test.ts
2635
- node: "16"
2736
versions:
2837
include: ">=3.6.1 <3.723.0"
2938
exclude: "3.529.0 || >=3.363.0 <=3.377.0"
3039
mode: "max-7"
31-
commands: npm run test
40+
commands:
41+
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-s3.test.ts
42+
- mocha --require '@opentelemetry/contrib-test-utils' test/s3.test.ts
3243
- node: "14"
3344
versions:
3445
include: ">=3.6.1 <3.567.0"
3546
exclude: "3.529.0 || >=3.363.0 <=3.377.0"
3647
mode: "max-7"
37-
commands: npm run test
48+
commands:
49+
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-s3.test.ts
50+
- mocha --require '@opentelemetry/contrib-test-utils' test/s3.test.ts
3851

3952
"@aws-sdk/client-sqs":
53+
env:
54+
- SKIP_TEST_IF_DISABLE=true
4055
jobs:
4156
- node: ">=18"
4257
versions:
4358
include: "^3.24.0"
4459
exclude: ">=3.363.0 <=3.377.0"
4560
mode: "max-7"
46-
commands: npm run test
61+
commands:
62+
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-sqs.test.ts
63+
- mocha --require '@opentelemetry/contrib-test-utils' test/sqs.test.ts
4764
- node: "16"
4865
versions:
4966
include: ">=3.24.0 <3.723.0"
5067
exclude: ">=3.363.0 <=3.377.0"
5168
mode: "max-7"
52-
commands: npm run test
69+
commands:
70+
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-sqs.test.ts
71+
- mocha --require '@opentelemetry/contrib-test-utils' test/sqs.test.ts
5372
- node: "14"
5473
versions:
5574
include: ">=3.24.0 <3.567.0"
5675
exclude: ">=3.363.0 <=3.377.0"
5776
mode: "max-7"
58-
commands: npm run test
77+
commands:
78+
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-sqs.test.ts
79+
- mocha --require '@opentelemetry/contrib-test-utils' test/sqs.test.ts
80+

plugins/node/opentelemetry-instrumentation-aws-sdk/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"prewatch": "npm run precompile",
3636
"prepublishOnly": "npm run compile",
3737
"tdd": "npm run test -- --watch-extensions ts --watch",
38-
"test": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
38+
"test": "SKIP_TEST_IF_NODE_OLDER_THAN=18 nyc mocha --require '../../../scripts/skip-test-if.js' --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
3939
"test-all-versions": "tav",
4040
"version:update": "node ../../../scripts/version-update.js",
4141
"watch": "tsc -w"
@@ -50,13 +50,13 @@
5050
"@opentelemetry/semantic-conventions": "^1.27.0"
5151
},
5252
"devDependencies": {
53-
"@aws-sdk/client-dynamodb": "3.85.0",
54-
"@aws-sdk/client-kinesis": "3.85.0",
55-
"@aws-sdk/client-lambda": "3.85.0",
56-
"@aws-sdk/client-s3": "3.85.0",
57-
"@aws-sdk/client-sns": "3.85.0",
58-
"@aws-sdk/client-sqs": "3.85.0",
59-
"@aws-sdk/types": "3.78.0",
53+
"@aws-sdk/client-dynamodb": "^3.85.0",
54+
"@aws-sdk/client-kinesis": "^3.85.0",
55+
"@aws-sdk/client-lambda": "^3.85.0",
56+
"@aws-sdk/client-s3": "^3.85.0",
57+
"@aws-sdk/client-sns": "^3.85.0",
58+
"@aws-sdk/client-sqs": "^3.85.0",
59+
"@aws-sdk/types": "^3.370.0",
6060
"@opentelemetry/api": "^1.3.0",
6161
"@opentelemetry/contrib-test-utils": "^0.45.1",
6262
"@opentelemetry/sdk-trace-base": "^1.8.0",

plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts renamed to plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3-s3.test.ts

Lines changed: 4 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
import {
1718
AwsInstrumentation,
1819
AwsSdkRequestHookInformation,
@@ -31,39 +32,28 @@ import {
3132
S3,
3233
S3Client,
3334
} from '@aws-sdk/client-s3';
34-
import { SQS } from '@aws-sdk/client-sqs';
35-
import { propagation, SpanKind } from '@opentelemetry/api';
35+
import { SpanKind } from '@opentelemetry/api';
3636

3737
// set aws environment variables, so tests in non aws environment are able to run
3838
process.env.AWS_ACCESS_KEY_ID = 'testing';
3939
process.env.AWS_SECRET_ACCESS_KEY = 'testing';
4040

4141
import 'mocha';
42-
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
43-
import { context, SpanStatusCode, trace, Span } from '@opentelemetry/api';
42+
import { SpanStatusCode, Span } from '@opentelemetry/api';
4443
import {
45-
ATTR_URL_FULL,
46-
MESSAGINGOPERATIONVALUES_RECEIVE,
4744
SEMATTRS_HTTP_STATUS_CODE,
48-
SEMATTRS_MESSAGING_OPERATION,
49-
SEMATTRS_MESSAGING_SYSTEM,
5045
SEMATTRS_RPC_METHOD,
5146
SEMATTRS_RPC_SERVICE,
5247
SEMATTRS_RPC_SYSTEM,
5348
} from '@opentelemetry/semantic-conventions';
54-
import {
55-
ATTR_MESSAGING_BATCH_MESSAGE_COUNT,
56-
ATTR_MESSAGING_DESTINATION_NAME,
57-
ATTR_MESSAGING_MESSAGE_ID,
58-
} from '../src/semconv';
5949
import { AttributeNames } from '../src/enums';
6050
import { expect } from 'expect';
6151
import * as fs from 'fs';
6252
import * as nock from 'nock';
6353

6454
const region = 'us-east-1';
6555

66-
describe('instrumentation-aws-sdk-v3', () => {
56+
describe('instrumentation-aws-sdk-v3 (client-s3)', () => {
6757
const s3Client = new S3({ region });
6858

6959
describe('functional', () => {
@@ -286,202 +276,4 @@ describe('instrumentation-aws-sdk-v3', () => {
286276
});
287277
});
288278
});
289-
290-
describe('custom service behavior', () => {
291-
describe('SQS', () => {
292-
const sqsClient = new SQS({ region });
293-
294-
it('sqs send add messaging attributes', async () => {
295-
nock(`https://sqs.${region}.amazonaws.com/`)
296-
.matchHeader('content-type', 'application/x-www-form-urlencoded')
297-
.post('/')
298-
.reply(
299-
200,
300-
fs.readFileSync('./test/mock-responses/sqs-send.xml', 'utf8')
301-
);
302-
// @aws-sdk/client-sqs >=3.446.0 uses a new JSON protocol.
303-
nock(`https://sqs.${region}.amazonaws.com/`)
304-
.matchHeader('content-type', 'application/x-amz-json-1.0')
305-
.post('/')
306-
.reply(
307-
200,
308-
fs.readFileSync('./test/mock-responses/sqs-send.json', 'utf8')
309-
);
310-
311-
const params = {
312-
QueueUrl:
313-
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
314-
MessageBody: 'payload example from v3 without batch',
315-
};
316-
const response = await sqsClient.sendMessage(params);
317-
expect(getTestSpans().length).toBe(1);
318-
const [span] = getTestSpans();
319-
320-
// make sure we have the general aws attributes:
321-
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
322-
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('SendMessage');
323-
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('SQS');
324-
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
325-
326-
// custom messaging attributes
327-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws_sqs');
328-
expect(span.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toEqual(
329-
'otel-demo-aws-sdk'
330-
);
331-
expect(span.attributes[ATTR_URL_FULL]).toEqual(params.QueueUrl);
332-
expect(span.attributes[ATTR_MESSAGING_MESSAGE_ID]).toEqual(
333-
response.MessageId
334-
);
335-
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
336-
});
337-
338-
it('sqs send message batch attributes', async () => {
339-
nock(`https://sqs.${region}.amazonaws.com/`)
340-
.matchHeader('content-type', 'application/x-www-form-urlencoded')
341-
.post('/')
342-
.reply(
343-
200,
344-
fs.readFileSync('./test/mock-responses/sqs-send-batch.xml', 'utf8')
345-
);
346-
nock(`https://sqs.${region}.amazonaws.com/`)
347-
.matchHeader('content-type', 'application/x-amz-json-1.0')
348-
.post('/')
349-
.reply(
350-
200,
351-
fs.readFileSync('./test/mock-responses/sqs-send-batch.json', 'utf8')
352-
);
353-
354-
const params = {
355-
QueueUrl:
356-
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
357-
MessageBody: 'payload example from v3 without batch',
358-
Entries: [
359-
{
360-
Id: '1000',
361-
MessageBody: 'msg body for 1000',
362-
},
363-
{
364-
Id: '1001',
365-
MessageBody: 'msg body for 1001',
366-
},
367-
],
368-
};
369-
await sqsClient.sendMessageBatch(params);
370-
expect(getTestSpans().length).toBe(1);
371-
const [span] = getTestSpans();
372-
373-
// make sure we have the general aws attributes:
374-
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
375-
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual(
376-
'SendMessageBatch'
377-
);
378-
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('SQS');
379-
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
380-
381-
// messaging semantic attributes
382-
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws_sqs');
383-
expect(span.attributes[ATTR_MESSAGING_DESTINATION_NAME]).toEqual(
384-
'otel-demo-aws-sdk'
385-
);
386-
expect(span.attributes[ATTR_URL_FULL]).toEqual(params.QueueUrl);
387-
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
388-
});
389-
390-
it('sqs receive add messaging attributes', done => {
391-
nock(`https://sqs.${region}.amazonaws.com/`)
392-
.matchHeader('content-type', 'application/x-www-form-urlencoded')
393-
.post('/')
394-
.reply(
395-
200,
396-
fs.readFileSync('./test/mock-responses/sqs-receive.xml', 'utf8')
397-
);
398-
nock(`https://sqs.${region}.amazonaws.com/`)
399-
.matchHeader('content-type', 'application/x-amz-json-1.0')
400-
.post('/')
401-
.reply(
402-
200,
403-
fs.readFileSync('./test/mock-responses/sqs-receive.json', 'utf8')
404-
);
405-
406-
const params = {
407-
QueueUrl:
408-
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
409-
MaxNumberOfMessages: 3,
410-
};
411-
sqsClient.receiveMessage(params).then(res => {
412-
expect(getTestSpans().length).toBe(1);
413-
const [span] = getTestSpans();
414-
415-
// make sure we have the general aws attributes:
416-
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
417-
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual(
418-
'ReceiveMessage'
419-
);
420-
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('SQS');
421-
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
422-
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
423-
expect(span.attributes[ATTR_MESSAGING_BATCH_MESSAGE_COUNT]).toEqual(
424-
2
425-
);
426-
expect(span.links.length).toBe(2);
427-
428-
const messages = res.Messages || [];
429-
expect(messages.length).toEqual(span.links.length);
430-
431-
for (let i = 0; i < span.links.length; i++) {
432-
const link = span.links[i];
433-
const messageId = messages[i].MessageId;
434-
const traceparent =
435-
messages[i].MessageAttributes?.traceparent.StringValue?.split(
436-
'-'
437-
) || [];
438-
const traceId = traceparent[1];
439-
const spanId = traceparent[2];
440-
expect(link.attributes?.[ATTR_MESSAGING_MESSAGE_ID]).toEqual(
441-
messageId
442-
);
443-
expect(link.context.traceId).toEqual(traceId);
444-
expect(link.context.spanId).toEqual(spanId);
445-
}
446-
done();
447-
});
448-
});
449-
450-
// Propagating span context to SQS ReceiveMessage promise handler is
451-
// broken with `@aws-sdk/client-sqs` v3.316.0 and later.
452-
// https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1477
453-
it.skip('sqs receive context', done => {
454-
nock(`https://sqs.${region}.amazonaws.com/`)
455-
.matchHeader('content-type', 'application/x-www-form-urlencoded')
456-
.post('/')
457-
.reply(
458-
200,
459-
fs.readFileSync('./test/mock-responses/sqs-receive.xml', 'utf8')
460-
);
461-
nock(`https://sqs.${region}.amazonaws.com/`)
462-
.matchHeader('content-type', 'application/x-amz-json-1.0')
463-
.post('/')
464-
.reply(
465-
200,
466-
fs.readFileSync('./test/mock-responses/sqs-receive.json', 'utf8')
467-
);
468-
469-
const params = {
470-
QueueUrl:
471-
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
472-
MaxNumberOfMessages: 3,
473-
};
474-
sqsClient.receiveMessage(params).then(res => {
475-
const receiveCallbackSpan = trace.getSpan(context.active());
476-
expect(receiveCallbackSpan).toBeDefined();
477-
const attributes = (receiveCallbackSpan as unknown as ReadableSpan)
478-
.attributes;
479-
expect(attributes[SEMATTRS_MESSAGING_OPERATION]).toMatch(
480-
MESSAGINGOPERATIONVALUES_RECEIVE
481-
);
482-
done();
483-
});
484-
});
485-
});
486-
});
487279
});

0 commit comments

Comments
 (0)