From ef1d844ff1a034838166109f1a6f736bfdd38e80 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 24 Jan 2024 10:06:00 +0000 Subject: [PATCH 1/5] [Instrumentation.AWS] Target .NET 6 Add `net6.0` TFM and fix nullability warnings. --- .../.publicApi/net6.0/PublicAPI.Shipped.txt | 1 + .../.publicApi/net6.0/PublicAPI.Unshipped.txt | 8 ++++++++ .../Implementation/AWSTracingPipelineHandler.cs | 6 +++--- .../OpenTelemetry.Instrumentation.AWS.csproj | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Shipped.txt create mode 100644 src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Unshipped.txt diff --git a/src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Shipped.txt b/src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Unshipped.txt b/src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..1362c26ff9 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.AWS/.publicApi/net6.0/PublicAPI.Unshipped.txt @@ -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? configure) -> OpenTelemetry.Trace.TracerProviderBuilder! diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs index 4ec869eedb..0a6d84bbf5 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs @@ -130,14 +130,14 @@ private static void ProcessException(Activity activity, Exception ex) 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) { - if (AWSServiceHelper.ParameterAttributeMap.TryGetValue(parameter, out string attribute)) + if (AWSServiceHelper.ParameterAttributeMap.TryGetValue(parameter, out var attribute)) { activity.SetTag(attribute, property.GetValue(request)); } @@ -176,7 +176,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; } diff --git a/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj b/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj index b473eb7bbf..6d0c8c9a86 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj +++ b/src/OpenTelemetry.Instrumentation.AWS/OpenTelemetry.Instrumentation.AWS.csproj @@ -2,7 +2,7 @@ - netstandard2.0 + net6.0;netstandard2.0 $(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion) AWS client instrumentation for OpenTelemetry .NET Instrumentation.AWS- From a70ecc6d4670a0a40ba583c16563026455063313 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 24 Jan 2024 10:06:35 +0000 Subject: [PATCH 2/5] Use simplified constructors Fix IDE0090 suggestions. --- .../Implementation/AWSTracingPipelineHandler.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs index 0a6d84bbf5..6d13dc606c 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs @@ -18,13 +18,13 @@ internal 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, 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; From 56c1a06a5f4f4c59fd13fdc62fe8c0b52bebc1c1 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 24 Jan 2024 10:07:31 +0000 Subject: [PATCH 3/5] Seal AWSTracingPipelineHandler Mark `AWSTracingPipelineHandler` as `sealed` as a hint to the JIT to devirtualize calls. --- .../Implementation/AWSTracingPipelineHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs index 6d13dc606c..4e9ecfad90 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs @@ -14,7 +14,7 @@ namespace OpenTelemetry.Instrumentation.AWS.Implementation; -internal class AWSTracingPipelineHandler : PipelineHandler +internal sealed class AWSTracingPipelineHandler : PipelineHandler { internal const string ActivitySourceName = "Amazon.AWS.AWSClientInstrumentation"; From 9bc4e73710e9285e78740d03bb9b3ef306b6cf47 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 24 Jan 2024 10:15:29 +0000 Subject: [PATCH 4/5] [Instrumentation.AWS] Resolve AoT warning Resolve AoT warning. Fixes #1543. --- .../AWSTracingPipelineHandler.cs | 22 +++++++++++++++---- ...nTelemetry.AotCompatibility.TestApp.csproj | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs index 4e9ecfad90..2383c9f8ba 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs @@ -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)) diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj index 0a8744bb88..7c7ca3a5dc 100644 --- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj +++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj @@ -15,6 +15,7 @@ --> + From 2e68c2fa74e53eb41115f37fa9d5f69023a6d3b4 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 24 Jan 2024 10:17:58 +0000 Subject: [PATCH 5/5] Update CHANGELOG Update changelog with .NET 6 and AoT changes. --- src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md index a1c1add753..b64dfe884f 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AWS/CHANGELOG.md @@ -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