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

AWS Instrumenting doesn't work when AWS DynamoDb Client is created in a DI class #1953

Open
at-mk opened this issue Jul 12, 2024 · 0 comments
Labels
bug Something isn't working comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS

Comments

@at-mk
Copy link

at-mk commented Jul 12, 2024

Component

OpenTelemetry.Instrumentation.AWS

Package Version

<PackageReference Include="Amazon.Lambda.Annotations" Version="1.3.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AWS" Version="1.1.0-beta.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.AWSLambda" Version="1.3.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />

Runtime Version

net8.0

Description

I want to trace a call to DynamoDB in Xray via an OpenTelemetry collector. The Instrumentation did not recoginze it as an AWS SDK call, but as a HTTP Request. This only happens when creating the AmazonDBClient instance in a dedicated DependencyInjection class.

Steps to Reproduce

ProjectA starts the App and does the tracing with all of its instrumenting, and it calls a service method of Project B which for example sends a request to dynamo. Project B is a simple project reference, but has a DependencyInjection Extension to create a Service/Repository instance (to be called by ProjectA). When an AmazonDynamoDBClient is created in that Extension method (and registered as a Singleton to be injected in the repository class), any calls from this client are not registered by the aws instrumention library. In that case it is only registered as a HTTP request.

An example of a DI Extension method can look like this:

namespace Microsoft.Extensions.DependencyInjection;

public static class DependencyInjection
{
    public static IServiceCollection AddApplicationServices(this IServiceCollection services, RegionEndpoint r)
    {
        services.AddSingleton<IAmazonDynamoDB>(new AmazonDynamoDBClient(r));
        services.AddSingleton<IClass1, Class1>();
        return services;
    }
}

The repository/service class:

public interface IClass1
{
    public Task<string> GetAll();
}
internal class Class1 : IClass1
{
    private readonly IAmazonDynamoDB amazonDynamoDB;

    public Class1(IAmazonDynamoDB amazonDynamoDB)
    {
        this.amazonDynamoDB = amazonDynamoDB;
    }

    public async Task<string> GetAll()
    {
        var queryResponse = await amazonDynamoDB.ScanAsync(new ScanRequest("StackTableDemo"));

        var book = Document.FromAttributeMap(queryResponse.Items.Single()).ToJson();
        return book;
    }
}

When I create the client directly in the Repository/Service class, everything works as expected.

Expected Result

bilde

Actual Result

bilde

Additional Context

I don't know if this is a bug tbh or if it's just how it is by design, but i wanted to share these findings with you:)

@at-mk at-mk added the bug Something isn't working label Jul 12, 2024
@github-actions github-actions bot added the comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS label Jul 12, 2024
@at-mk at-mk changed the title AWS Instrumenting not works when AWS DynamoDb Client is created in a DI class AWS Instrumenting doesn't work when AWS DynamoDb Client is created in a DI class Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS
Projects
None yet
Development

No branches or pull requests

1 participant