open-telemetry / opentelemetry-dotnet-contrib

This repository contains set of components extending functionality of the OpenTelemetry .NET SDK. Instrumentation libraries, exporters, and other components can find their home here.
https://opentelemetry.io
Apache License 2.0
472 stars 283 forks source link

[bug] Amazon.SQS.AmazonSQSException: Attribute MD5 hash mismatch thrown on 1.1.0-beta.6 version when SQS message had attribute #2304

Open amol-kashetwar-cko opened 3 hours ago

amol-kashetwar-cko commented 3 hours ago

Component

OpenTelemetry.Instrumentation.AWS

Package Version

Package Name Version
OpenTelemetry.Instrumentation.AWS 1.1.0-beta.6

Runtime Version

net8.0

Description

When SQS messages have attribute(s), Amazon.SQS.AmazonSQSException: Attribute MD5 hash mismatch thrown on latest version.

Steps to Reproduce

Sample test on Lambda

`using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Amazon.Lambda.Core; using OpenTelemetry; using OpenTelemetry.Instrumentation.AWSLambda; using OpenTelemetry.Trace; using Amazon.SQS; using Amazon.SQS.Model;

[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]

namespace LambdaTest { public class LambdaHandlerSQS { private IAmazonSQS _sqsClient; private readonly Tracer _tracer;

    public async Task handleRequest(ILambdaContext context)
    {
        TracerProvider tracerProvider = Sdk.CreateTracerProviderBuilder()
        .AddAWSLambdaConfigurations(options => options.DisableAwsXRayContextExtraction = true)
        .AddAWSInstrumentation()
        .AddConsoleExporter()
        .SetSampler<AlwaysOnSampler>()
        .Build();

        await AWSLambdaWrapper.TraceAsync(
            tracerProvider, 
            async (input,  ctx) => await SendtoSQSAsync(ctx), 
            default(object), 
            context);
    }

    private async Task SendtoSQSAsync(ILambdaContext context)
    {
        _sqsClient = new AmazonSQSClient();

        var tasks = Enumerable.Range(1, 100).ToList().Select(async i =>
        {
            try
            {
                // Send message to the SQS queue
                var messageAttributes = new Dictionary<string, MessageAttributeValue>
                {
                    { "Attribute1", new MessageAttributeValue { StringValue = "Value1", DataType = "String" } },
                    { "Attribute2", new MessageAttributeValue { StringValue = "Value2", DataType = "String" } },
                };
                var sendMessageRequest = new SendMessageRequest
                {
                    QueueUrl = "https://sqs.us-east-1.amazonaws.com/something/TestOTel",
                    MessageBody = "This is a test message",
                    MessageAttributes = messageAttributes
                };

                var response = await _sqsClient.SendMessageAsync(sendMessageRequest);
                context.Logger.LogLine($"Message sent with ID: {response.MessageId}");

                return response.MessageId;
            }
            catch (Exception ex)
            {
                context.Logger.LogLine($"Error sending message: {ex.Message}");
                throw;
            }
        });
        await Task.WhenAll(tasks);

    }
}

}`

Expected Result

Messages should get sent to queue without exception

Actual Result

Amazon.SQS.AmazonSQSException: Attribute MD5 hash mismatch thrown

Additional Context

No response

github-actions[bot] commented 3 hours ago

Tagging component owner(s).

@srprash @ppittle @muhammad-othman @rypdal @Oberon00

muhammad-othman commented 2 hours ago

Hi @amol-kashetwar-cko, I believe this bug is similar to https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/2108, which was fixed in https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2137 but is still pending release.