From 094fd6fa32f117117b4970548334737d9edb7804 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 6 Dec 2023 08:27:17 -0800 Subject: [PATCH] test(instrumentation-aws-sdk): fix SQS mock responses for @aws-sdk/client-sqs versions using the AWS JSON 1.0 protocol (#1844) Versions 3.446.0 and later switched to a new JSON protocol. https://github.com/aws/aws-sdk-js-v3/blob/main/clients/client-sqs/CHANGELOG.md#34460-2023-11-08 Refs: https://github.com/open-telemetry/opentelemetry-js-contrib/pull/1838#issuecomment-1834359339 --- .../test/aws-sdk-v3.test.ts | 26 +++++++++++++++++++ .../test/mock-responses/sqs-receive.json | 1 + .../test/mock-responses/sqs-send-batch.json | 1 + .../test/mock-responses/sqs-send.json | 1 + 4 files changed, 29 insertions(+) create mode 100644 plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-receive.json create mode 100644 plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send-batch.json create mode 100644 plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send.json diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts index 0fb17f7ffd..037ec3498c 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts @@ -284,11 +284,20 @@ describe('instrumentation-aws-sdk-v3', () => { 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: @@ -332,11 +341,20 @@ describe('instrumentation-aws-sdk-v3', () => { 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', @@ -386,11 +404,19 @@ describe('instrumentation-aws-sdk-v3', () => { it('sqs receive add messaging attributes and 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: diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-receive.json b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-receive.json new file mode 100644 index 0000000000..4364a2ea35 --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-receive.json @@ -0,0 +1 @@ +{"Messages":[{"Body":"this is my message (2307033890})","MD5OfBody":"b3680c27aa9744d16f2e029896334eae","MD5OfMessageAttributes":"5950d8c7b3cbb18c417e7f66c6f82d9e","MessageAttributes":{"foo":{"DataType":"String","StringValue":"bar"},"traceparent":{"DataType":"String","StringValue":"00-65c5a84e1765162e832a4c4044dc32fe-3b6a4abbb380ab2c-01"}},"MessageId":"a900c3d5-cb9f-464b-bfa6-a87bfb23ba24","ReceiptHandle":"AQEBnpw+996e8vN28rC+vlDxxROQOi3DCW+d9oceXGMv04Qig/ZvzEhgMRomuFl/7V6gXMHaIrUy9wcwtRNk6SCZqEKQmbN8Nq6qBhhPuHBG/T3XOtH+08PXzyZIICKhR1T3pAA7whx5WdyMCPdgixZ4iSxIld/bUJq674ZwSFI0WmyuTPm+MHeRv3acrnBo4LYsoBiH+Os/q0M5PQlIYPQRPoDBG641wDQLl+wpzSLw6bZ4u9zdxwPqFkb5uM0IfGPJ9UGLIioUQdkUOeEXzoLVS5XVdplv8YwW5vR8gqKWVVPTrFJD9JgqY8NooEW9CGnG5ZAYKria9Z74wg/nvs3xOUPaFb3rW6IXlVuOPUcuv/XldYYptal1qtMOaf6Ey7jWAhRf3NlQlV+N23VZoVkZJg=="},{"Body":"this is my message (9319347981})","MD5OfBody":"17923d0bc19740ab7cdf3d4f90358fe0","MD5OfMessageAttributes":"d313e8c714b6ff03f76aa659db3d6579","MessageAttributes":{"foo":{"DataType":"String","StringValue":"bar"},"traceparent":{"DataType":"String","StringValue":"00-8433a08a7ae1fcf970613f22c5f36ded-ff784ac86e916f09-01"}},"MessageId":"c47a6ac0-3e17-4ad5-8bc6-307a1eafd982","ReceiptHandle":"AQEBQValbysrkwXcupWaqlW4dZcof9K9ISnOsPDppVkjaJ5s0fe4Natx9CEtC0AjNRqalMGmgzbRAkwqCu5YvK4m4rDOAoX2pGbcqcaHJdJuyvwTsHcELUzn9ZvuwQWO/EQlnJ9F8ZU7hBHnLQiQfHEfyzjaK6P9CgYuxHM9mBU+hfIautLVqvlHo0kZcbQiLJfIlObmY7pTRjDuontgm0GJtKEx/tXB8j5dCuhfu1uWKd1al+vQLbXpKEk+/pO4+G/KDi19wmJsW3O0sgzn5pM84SVXYfINDUPUntj8KMZR18Aej8bxa1rGc1tkjh0cGPMqh9ATZwTOLmAVFEikrti/oL+qBXb69bVnC3apcCOadqKKHJBHhUOiXip2kwmSwkQGmEamGycYKqyBDubCM3Wx2w=="}]} diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send-batch.json b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send-batch.json new file mode 100644 index 0000000000..8ac870351b --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send-batch.json @@ -0,0 +1 @@ +{"Successful":[{"Id":"2","MD5OfMessageAttributes":"00b09cf2da4bbec1942ac9267da95ca1","MD5OfMessageBody":"e9034f46f1c1154c29b0e9e9fbbfaf2e","MessageId":"2772edfc-3015-4944-a590-5da1a725c347","SequenceNumber":"18882322551367407872"},{"Id":"3","MD5OfMessageAttributes":"00b09cf2da4bbec1942ac9267da95ca1","MD5OfMessageBody":"85d01a8241acecfff98fa295248146db","MessageId":"508037b9-db3f-4010-b6a5-864d089fa7c9","SequenceNumber":"18882322551367407873"},{"Id":"4","MD5OfMessageBody":"b936fc67f3bf35b807018792ca01a53e","MessageId":"ee18e64b-caad-47f7-9c26-298b03404041","SequenceNumber":"18882322551367407874"}]} diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send.json b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send.json new file mode 100644 index 0000000000..6bd5ba17ab --- /dev/null +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/mock-responses/sqs-send.json @@ -0,0 +1 @@ +{"MD5OfMessageAttributes":"4fdeb9d03aa9063f7b9eccb7429d23f4","MD5OfMessageBody":"89ca049a00b657d53acb784d93c83ee9","MessageId":"35de59a8-cdcc-4f55-9734-d73434058622","SequenceNumber":"18882322551347440128"}