Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SendMessage with MessageAttributes on latest version of AWS SDK throws "Attribute MD5 hash mismatch" exception #1492

Closed
1 task done
jdaigle opened this issue Dec 12, 2023 · 5 comments · Fixed by #1572
Closed
1 task done
Labels
comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS

Comments

@jdaigle
Copy link

jdaigle commented Dec 12, 2023

Issue with OpenTelemetry.Instrumentation.AWS

List of all OpenTelemetry NuGet
packages
and version that you are
using (e.g. OpenTelemetry 1.3.2):

  • OpenTelemetry.Instrumentation.AWS 1.1.0-beta.2
  • AWSSDK.SQS 3.7.300.11

Runtime version (e.g. net462, net48, net6.0, net7.0 etc. You can
find this information from the *.csproj file):

  • net7.0 and net48

Is this a feature request or a bug?

  • Bug

What is the expected behavior?

Messages are sent without exceptions.

What is the actual behavior?

When we use .AddAWSInstrumentation() and then call IAmazonSQS.SendMessageAsync with a message with custom MessageAttributes, an AmazonSQSException exception is thrown with the message "Attribute MD5 hash mismatch".

Additional Context

I think that problem lies in SqsRequestContextHelper.AddAttribute, where the attributes are added to the IRequestContext parameters that is not compatible with the JSON protocol.

In the most recent versions of "AWSSDK.SQS", the SDK changed from the old XML protocol to the new JSON protocol (see https://aws.amazon.com/about-aws/whats-new/2023/11/amazon-sqs-support-json-protocol/).

It would seem the attributes are not properly added to the request, so SQS produces an MD5 hash that does not include the attributes added by OTEL. This doesn't match the MD5 hash generated by the client.

We can workaround by reverting to an older version of "AWSSDK.SQS", but that is not desirable.

@jdaigle jdaigle added the comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS label Dec 12, 2023
@Kielek
Copy link
Contributor

Kielek commented Dec 12, 2023

@srprash, @atshaw43, please check.

@birojnayak
Copy link
Contributor

Adding my name and @ppittle to follow up

@ppittle
Copy link
Member

ppittle commented Jan 23, 2024

Can reproduce issue by slightly modifying TestAWSClientInstrumentation.TestSQSSendMessageSuccessful

    [Fact]
    public void TestSQSSendMessageSuccessful()
    {
        var exportedItems = new List<Activity>();

        var parent = new Activity("parent").Start();

        using (Sdk.CreateTracerProviderBuilder()
                   .AddXRayTraceId()
                   .SetSampler(new AlwaysOnSampler())
                   .AddAWSInstrumentation()
                   .AddInMemoryExporter(exportedItems)
                   .Build())
        {
            var sqs = new AmazonSQSClient(RegionEndpoint.USEast1); // requires .awsconfig with valid creds
            string requestId = @"fakerequ-esti-dfak-ereq-uestidfakere";
            string dummyResponse = "{}";
            //CustomResponses.SetResponse(sqs, dummyResponse, requestId, true); // <-- comment to disable mocking
            var send_msg_req = new SendMessageRequest();
            send_msg_req.QueueUrl = "real-sqs-address";
            send_msg_req.MessageBody = "Hello from OT";
            send_msg_req.MessageAttributes.Add("custom", new MessageAttributeValue { StringValue = "test", DataType = "String"} );
#if NETFRAMEWORK
            sqs.SendMessage(send_msg_req);
#else
            var result = sqs.SendMessageAsync(send_msg_req).Result;
#endif
            Assert.Single(exportedItems);
            Activity awssdk_activity = exportedItems[0];

           // deleted assertions
        }
    }

Test passes with AWSSDK.SQS 3.7.100 and throws exception with AWSSDK.SQS 3.7.300

@ppittle
Copy link
Member

ppittle commented Jan 23, 2024

NOTE: AWSSDK.SQS 3.7.300 was made minimum in PR #1542

@ppittle
Copy link
Member

ppittle commented Jan 23, 2024

Investigating root cause and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants