diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/MessageAttributes.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/MessageAttributes.ts index 064e550b5f..b077ba9eb9 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/MessageAttributes.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/MessageAttributes.ts @@ -21,7 +21,6 @@ import { diag, } from '@opentelemetry/api'; import type { SQS, SNS } from 'aws-sdk'; -import type { MessageBodyAttributeMap } from 'aws-sdk/clients/sqs'; // https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html export const MAX_MESSAGE_ATTRIBUTES = 10; @@ -42,6 +41,13 @@ class ContextSetter } export const contextSetter = new ContextSetter(); +export interface AwsSdkContextObject { + [key: string]: { + StringValue?: string; + Value?: string; + }; +} + class ContextGetter implements TextMapGetter @@ -53,10 +59,10 @@ class ContextGetter } get( - carrier: SQS.MessageBodyAttributeMap | SNS.MessageAttributeMap, + carrier: AwsSdkContextObject, key: string ): undefined | string | string[] { - return carrier?.[key]?.StringValue; + return carrier?.[key]?.StringValue || carrier?.[key]?.Value; } } export const contextGetter = new ContextGetter(); @@ -78,7 +84,7 @@ export const injectPropagationContext = ( export const extractPropagationContext = ( message: SQS.Message, sqsExtractContextPropagationFromPayload: boolean | undefined -): MessageBodyAttributeMap | undefined => { +): AwsSdkContextObject | undefined => { const propagationFields = propagation.fields(); const hasPropagationFields = Object.keys( message.MessageAttributes || [] diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts index b35a0da305..5ceeb92b3b 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/sqs.test.ts @@ -458,9 +458,8 @@ describe('SQS', () => { it('should extract from payload', async () => { const traceparent = { traceparent: { - StringValue: - '00-a1d050b7c8ad93c405e7a0d94cda5b03-23a485dc98b24027-01', - DataType: 'String', + Value: '00-a1d050b7c8ad93c405e7a0d94cda5b03-23a485dc98b24027-01', + Type: 'String', }, }; instrumentation.setConfig({ @@ -478,7 +477,6 @@ describe('SQS', () => { QueueUrl: 'queue/url/for/unittests', }) .promise(); - expect(extractContextSpy.returnValues[0]?.traceparent).toStrictEqual( traceparent );