Skip to content

Commit

Permalink
[Instrumentation.AWS] Support .NET 6 and resolve AoT warning (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
martincostello authored Jan 26, 2024
1 parent 94ab73f commit a8f7bb8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#nullable enable
OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions
OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions.AWSClientInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions.SuppressDownstreamInstrumentation.get -> bool
OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions.SuppressDownstreamInstrumentation.set -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddAWSInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Instrumentation.AWS.AWSClientInstrumentationOptions!>? configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Updated dependency on AWS .NET SDK to version 3.7.300.
([#1542](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1542))
* Add target for `net6.0`.
([#1547](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1547))
* Add support for native AoT.
([#1547](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1547))

## 1.1.0-beta.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

namespace OpenTelemetry.Instrumentation.AWS.Implementation;

internal class AWSTracingPipelineHandler : PipelineHandler
internal sealed class AWSTracingPipelineHandler : PipelineHandler
{
internal const string ActivitySourceName = "Amazon.AWS.AWSClientInstrumentation";

private static readonly AWSXRayPropagator AwsPropagator = new AWSXRayPropagator();
private static readonly AWSXRayPropagator AwsPropagator = new();
private static readonly Action<IDictionary<string, string>, string, string> Setter = (carrier, name, value) =>
{
carrier[name] = value;
};

private static readonly ActivitySource AWSSDKActivitySource = new ActivitySource(ActivitySourceName);
private static readonly ActivitySource AWSSDKActivitySource = new(ActivitySourceName);

private readonly AWSClientInstrumentationOptions options;

Expand Down 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 string parameter))
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 string 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 Expand Up @@ -176,7 +190,7 @@ private static string FetchRequestId(IRequestContext requestContext, IResponseCo
else
{
var request_headers = requestContext.Request.Headers;
if (string.IsNullOrEmpty(request_id) && request_headers.TryGetValue("x-amzn-RequestId", out string req_id))
if (string.IsNullOrEmpty(request_id) && request_headers.TryGetValue("x-amzn-RequestId", out var req_id))
{
request_id = req_id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Description>AWS client instrumentation for OpenTelemetry .NET</Description>
<MinVerTagPrefix>Instrumentation.AWS-</MinVerTagPrefix>
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 a8f7bb8

Please sign in to comment.