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 24, 2024
1 parent 1b8aa42 commit f8bc460
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 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 @@ -14,10 +14,10 @@
.github\workflows\ci.yml so that it runs for the project being added.
-->
<TrimmerRootAssembly Include="OpenTelemetry.Extensions" />
<TrimmerRootAssembly Include="OpenTelemetry.Extensions.AWS" />
<TrimmerRootAssembly Include="OpenTelemetry.Extensions.Enrichment" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.Runtime" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.AWS" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.EventCounters" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.Runtime" />
<TrimmerRootAssembly Include="OpenTelemetry.Instrumentation.StackExchangeRedis" />
<TrimmerRootAssembly Include="OpenTelemetry.ResourceDetectors.AWS" />
<TrimmerRootAssembly Include="OpenTelemetry.ResourceDetectors.Azure" />
Expand Down

0 comments on commit f8bc460

Please sign in to comment.