Skip to content

Commit

Permalink
[Instrumentation.AWS] Resolve AoT warning
Browse files Browse the repository at this point in the history
Resolve AoT warning.
Fixes open-telemetry#1543.
  • Loading branch information
martincostello committed Jan 26, 2024
1 parent 56c1a06 commit 9bc4e73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,34 @@ private static void ProcessException(Activity activity, Exception ex)
}
}

#if NET6_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(
"Trimming",
"IL2075",
Justification = "The reflected properties were already used by the AWS SDK's marshallers so the properties could not have been trimmed.")]
#endif
private static void AddRequestSpecificInformation(Activity activity, IRequestContext requestContext, string service)
{
if (AWSServiceHelper.ServiceParameterMap.TryGetValue(service, out var parameter))
{
AmazonWebServiceRequest request = requestContext.OriginalRequest;

var property = request.GetType().GetProperty(parameter);
if (property != null)
try
{
if (AWSServiceHelper.ParameterAttributeMap.TryGetValue(parameter, out var attribute))
var property = request.GetType().GetProperty(parameter);
if (property != null)
{
activity.SetTag(attribute, property.GetValue(request));
if (AWSServiceHelper.ParameterAttributeMap.TryGetValue(parameter, out var attribute))
{
activity.SetTag(attribute, property.GetValue(request));
}
}
}
catch (Exception)
{
// Guard against any reflection-related exceptions when running in AoT.
// See https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1543#issuecomment-1907667722.
}
}

if (AWSServiceType.IsDynamoDbService(service))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-->
<TrimmerRootAssembly Include="OpenTelemetry.Extensions" />
<TrimmerRootAssembly Include="OpenTelemetry.Extensions.Enrichment" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.AWS" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.AWSLambda" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.EventCounters" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.Runtime" />
Expand Down

0 comments on commit 9bc4e73

Please sign in to comment.