Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,335 changes: 3,079 additions & 4,256 deletions package-lock.json

Large diffs are not rendered by default.

36 changes: 29 additions & 7 deletions plugins/node/opentelemetry-instrumentation-aws-sdk/.tav.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Note: tests must set `SKIP_TEST_IF_DISABLE=true` to override usage of
# `mocha --require '../../../scripts/skip-test-if.js' ...` if calling `npm test`.

"aws-sdk":
env:
- SKIP_TEST_IF_DISABLE=true
# A small subset of releases in the range [2.308.0, 3) to reduce testing time.
versions:
include: "^2.308.0"
mode: max-7
commands:
- npm run test
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v2.test.ts

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

"@aws-sdk/client-s3":
env:
- SKIP_TEST_IF_DISABLE=true
# - 3.529.0 was missing the fast-xml-parser dependency (https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.529.1)
jobs:
- node: ">=18"
versions:
include: "^3.6.1"
exclude: "3.529.0 || >=3.363.0 <=3.377.0"
mode: "max-7"
commands: npm run test
commands:
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-s3.test.ts
- mocha --require '@opentelemetry/contrib-test-utils' test/s3.test.ts
- node: "16"
versions:
include: ">=3.6.1 <3.723.0"
exclude: "3.529.0 || >=3.363.0 <=3.377.0"
mode: "max-7"
commands: npm run test
commands:
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-s3.test.ts
- mocha --require '@opentelemetry/contrib-test-utils' test/s3.test.ts
- node: "14"
versions:
include: ">=3.6.1 <3.567.0"
exclude: "3.529.0 || >=3.363.0 <=3.377.0"
mode: "max-7"
commands: npm run test
commands:
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-s3.test.ts
- mocha --require '@opentelemetry/contrib-test-utils' test/s3.test.ts

"@aws-sdk/client-sqs":
env:
- SKIP_TEST_IF_DISABLE=true
jobs:
- node: ">=18"
versions:
include: "^3.24.0"
exclude: ">=3.363.0 <=3.377.0"
mode: "max-7"
commands: npm run test
commands:
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-sqs.test.ts
- mocha --require '@opentelemetry/contrib-test-utils' test/sqs.test.ts
- node: "16"
versions:
include: ">=3.24.0 <3.723.0"
exclude: ">=3.363.0 <=3.377.0"
mode: "max-7"
commands: npm run test
commands:
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-sqs.test.ts
- mocha --require '@opentelemetry/contrib-test-utils' test/sqs.test.ts
- node: "14"
versions:
include: ">=3.24.0 <3.567.0"
exclude: ">=3.363.0 <=3.377.0"
mode: "max-7"
commands: npm run test
commands:
- mocha --require '@opentelemetry/contrib-test-utils' test/aws-sdk-v3-sqs.test.ts
- mocha --require '@opentelemetry/contrib-test-utils' test/sqs.test.ts

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"prewatch": "npm run precompile",
"prepublishOnly": "npm run compile",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
"test": "SKIP_TEST_IF_NODE_OLDER_THAN=18 nyc mocha --require '../../../scripts/skip-test-if.js' --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
"test-all-versions": "tav",
"version:update": "node ../../../scripts/version-update.js",
"watch": "tsc -w"
Expand All @@ -50,13 +50,13 @@
"@opentelemetry/semantic-conventions": "^1.27.0"
},
"devDependencies": {
"@aws-sdk/client-dynamodb": "3.85.0",
"@aws-sdk/client-kinesis": "3.85.0",
"@aws-sdk/client-lambda": "3.85.0",
"@aws-sdk/client-s3": "3.85.0",
"@aws-sdk/client-sns": "3.85.0",
"@aws-sdk/client-sqs": "3.85.0",
"@aws-sdk/types": "3.78.0",
"@aws-sdk/client-dynamodb": "^3.85.0",
"@aws-sdk/client-kinesis": "^3.85.0",
"@aws-sdk/client-lambda": "^3.85.0",
"@aws-sdk/client-s3": "^3.85.0",
"@aws-sdk/client-sns": "^3.85.0",
"@aws-sdk/client-sqs": "^3.85.0",
"@aws-sdk/types": "^3.370.0",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/contrib-test-utils": "^0.45.1",
"@opentelemetry/sdk-trace-base": "^1.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {
AwsInstrumentation,
AwsSdkRequestHookInformation,
Expand All @@ -31,26 +32,16 @@ import {
S3,
S3Client,
} from '@aws-sdk/client-s3';
import { SQS } from '@aws-sdk/client-sqs';
import { SpanKind } from '@opentelemetry/api';

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

import 'mocha';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { context, SpanStatusCode, trace, Span } from '@opentelemetry/api';
import { SpanStatusCode, Span } from '@opentelemetry/api';
import {
MESSAGINGDESTINATIONKINDVALUES_QUEUE,
MESSAGINGOPERATIONVALUES_RECEIVE,
SEMATTRS_HTTP_STATUS_CODE,
SEMATTRS_MESSAGING_DESTINATION,
SEMATTRS_MESSAGING_DESTINATION_KIND,
SEMATTRS_MESSAGING_MESSAGE_ID,
SEMATTRS_MESSAGING_OPERATION,
SEMATTRS_MESSAGING_SYSTEM,
SEMATTRS_MESSAGING_URL,
SEMATTRS_RPC_METHOD,
SEMATTRS_RPC_SERVICE,
SEMATTRS_RPC_SYSTEM,
Expand All @@ -62,7 +53,7 @@ import * as nock from 'nock';

const region = 'us-east-1';

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

describe('functional', () => {
Expand Down Expand Up @@ -285,189 +276,4 @@ describe('instrumentation-aws-sdk-v3', () => {
});
});
});

describe('custom service behavior', () => {
describe('SQS', () => {
const sqsClient = new SQS({ region });

it('sqs send add messaging attributes', async () => {
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-www-form-urlencoded')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-send.xml', 'utf8')
);
// @aws-sdk/client-sqs >=3.446.0 uses a new JSON protocol.
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-amz-json-1.0')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-send.json', 'utf8')
);

const params = {
QueueUrl:
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
MessageBody: 'payload example from v3 without batch',
};
const response = await sqsClient.sendMessage(params);
expect(getTestSpans().length).toBe(1);
const [span] = getTestSpans();

// make sure we have the general aws attributes:
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('SendMessage');
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('SQS');
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);

// custom messaging attributes
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws.sqs');
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual(
MESSAGINGDESTINATIONKINDVALUES_QUEUE
);
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
'otel-demo-aws-sdk'
);
expect(span.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
params.QueueUrl
);
expect(span.attributes[SEMATTRS_MESSAGING_MESSAGE_ID]).toEqual(
response.MessageId
);
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
});

it('sqs send message batch attributes', async () => {
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-www-form-urlencoded')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-send-batch.xml', 'utf8')
);
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-amz-json-1.0')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-send-batch.json', 'utf8')
);

const params = {
QueueUrl:
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
MessageBody: 'payload example from v3 without batch',
Entries: [
{
Id: '1000',
MessageBody: 'msg body for 1000',
},
{
Id: '1001',
MessageBody: 'msg body for 1001',
},
],
};
await sqsClient.sendMessageBatch(params);
expect(getTestSpans().length).toBe(1);
const [span] = getTestSpans();

// make sure we have the general aws attributes:
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual(
'SendMessageBatch'
);
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('SQS');
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);

// messaging semantic attributes
expect(span.attributes[SEMATTRS_MESSAGING_SYSTEM]).toEqual('aws.sqs');
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION_KIND]).toEqual(
MESSAGINGDESTINATIONKINDVALUES_QUEUE
);
expect(span.attributes[SEMATTRS_MESSAGING_DESTINATION]).toEqual(
'otel-demo-aws-sdk'
);
expect(span.attributes[SEMATTRS_MESSAGING_URL]).toEqual(
params.QueueUrl
);
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
});

it('sqs receive add messaging attributes', done => {
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-www-form-urlencoded')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-receive.xml', 'utf8')
);
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-amz-json-1.0')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-receive.json', 'utf8')
);

const params = {
QueueUrl:
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
MaxNumberOfMessages: 3,
};
sqsClient.receiveMessage(params).then(res => {
expect(getTestSpans().length).toBe(1);
const [span] = getTestSpans();

// make sure we have the general aws attributes:
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual(
'ReceiveMessage'
);
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('SQS');
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(200);
done();
});
});

// Propagating span context to SQS ReceiveMessage promise handler is
// broken with `@aws-sdk/client-sqs` v3.316.0 and later.
// https://github.com/open-telemetry/opentelemetry-js-contrib/issues/1477
it.skip('sqs receive context', done => {
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-www-form-urlencoded')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-receive.xml', 'utf8')
);
nock(`https://sqs.${region}.amazonaws.com/`)
.matchHeader('content-type', 'application/x-amz-json-1.0')
.post('/')
.reply(
200,
fs.readFileSync('./test/mock-responses/sqs-receive.json', 'utf8')
);

const params = {
QueueUrl:
'https://sqs.us-east-1.amazonaws.com/731241200085/otel-demo-aws-sdk',
MaxNumberOfMessages: 3,
};
sqsClient.receiveMessage(params).then(res => {
const receiveCallbackSpan = trace.getSpan(context.active());
expect(receiveCallbackSpan).toBeDefined();
const attributes = (receiveCallbackSpan as unknown as ReadableSpan)
.attributes;
expect(attributes[SEMATTRS_MESSAGING_OPERATION]).toMatch(
MESSAGINGOPERATIONVALUES_RECEIVE
);
done();
});
});
});
});
});
Loading