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

AWSTracingPipelineHandler produces IL2075 warning when compiling for native AoT #1543

Closed
1 of 2 tasks
martincostello opened this issue Jan 20, 2024 · 3 comments · Fixed by #1547
Closed
1 of 2 tasks
Labels
comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS

Comments

@martincostello
Copy link
Contributor

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

Runtime version:

  • net6.0+

Is this a feature request or a bug?

  • Feature Request
  • Bug

What is the expected behavior?

When OpenTelemetry.Instrumentation.AWS is referenced in an application compiled with native AoT, there are no trim warnings.

What is the actual behavior?

1 trim warning is produced by the assembly's own code (an additional 2 are from the AWS SDK, see #1542).

C:\Coding\open-telemetry\opentelemetry-dotnet-contrib\src\OpenTelemetry.Instrumentation.AWS\Implementation\AWSTracingPipelineHandler.cs(141): Trim analysis error IL2075: OpenTelemetry.Instrumentation.AWS.Implementation.AWSTracingPipelineHandler.AddRequestSpecificInformation(Activity,IRequestContext,String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\Coding\open-telemetry\opentelemetry-dotnet-contrib\test\OpenTelemetry.AotCompatibility.TestApp\OpenTelemetry.AotCompatibility.TestApp.csproj]

This warning comes from this line:

Additional Context

Found while going through the AWS-related libraries while looking for the source of trim warnings.

I did have a look at trying to fix this one myself, but it was beyond my expertise in this case.

@martincostello martincostello added the comp:instrumentation.aws Things related to OpenTelemetry.Instrumentation.AWS label Jan 20, 2024
@martincostello
Copy link
Contributor Author

@normj Any suggestions on how to resolve this IL2075 warning?

The only things I can think of are:

  1. Suppressing the warning and trim-rooting all the AWS SDKs the application uses, which seems like it would throw away a lot of savings;
  2. Adding [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] to all of the types that derive from AmazonWebServiceRequest in the SDK assemblies (or maybe just AmazonWebServiceRequest itself?).

I tried adding the constraint on T to InvokeAsync<T>() and then adding generic versions of the problemativ method, but that only seems to work if the declaring method does that (so, PipelineHandler), and that wouldn't help with the non-generic method.

@normj
Copy link
Contributor

normj commented Jan 24, 2024

@martincostello We know the properties will be used in the request marshallers in the SDK to create the HTTP request. So the AOT compiler can't trim the properties out and we can assume they exist. I would use the System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage attribute and then just add an extra try/catch around the if block to cover somebody doing something really weird.

[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("ReflectionAnalysis", "IL2025",
            Justification = "These reflected properties were already used during the SDK's marshallers so the properties can not be trimmed.")]

@martincostello
Copy link
Contributor Author

Thanks Norm - I'll try that out later today.

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.

2 participants