diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md b/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md index 81fa0799b1..3b7f744f0b 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/CHANGELOG.md @@ -11,6 +11,10 @@ ([#1295](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1295)) * BREAKING: Target `net6.0` instead of `netstandard2.0` ([#1545](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1545)) +* Add support for native AoT. + `Amazon.Lambda.*` NuGet package dependencies have been upgraded, see package + dependencies for details. + ([#1544](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1544)) ## 1.2.0-beta.1 diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs index 0202903329..51663ffb88 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/Implementation/AWSMessagingUtils.cs @@ -5,9 +5,9 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Text.Json; using Amazon.Lambda.SNSEvents; using Amazon.Lambda.SQSEvents; -using Newtonsoft.Json; using OpenTelemetry.Context.Propagation; namespace OpenTelemetry.Instrumentation.AWSLambda.Implementation; @@ -132,7 +132,7 @@ internal static PropagationContext ExtractParentContext(SNSEvent.SNSMessage? mes { try { - snsMessage = JsonConvert.DeserializeObject(body); + snsMessage = JsonSerializer.Deserialize(body, SourceGenerationContext.Default.SNSMessage); } catch (Exception) { diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj b/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj index 0f519fc865..994ba449a7 100644 --- a/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/OpenTelemetry.Instrumentation.AWSLambda.csproj @@ -8,12 +8,11 @@ - - - - + + + + - diff --git a/src/OpenTelemetry.Instrumentation.AWSLambda/SourceGenerationContext.cs b/src/OpenTelemetry.Instrumentation.AWSLambda/SourceGenerationContext.cs new file mode 100644 index 0000000000..312add0f92 --- /dev/null +++ b/src/OpenTelemetry.Instrumentation.AWSLambda/SourceGenerationContext.cs @@ -0,0 +1,20 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +using System.Text.Json.Serialization; +using Amazon.Lambda.SNSEvents; + +namespace OpenTelemetry.Instrumentation.AWSLambda; + +/// +/// "Source Generation" is feature added to System.Text.Json in .NET 6.0. +/// This is a performance optimization that avoids runtime reflection when performing serialization. +/// Serialization metadata will be computed at compile-time and included in the assembly. +/// . +/// . +/// . +/// +[JsonSerializable(typeof(SNSEvent.SNSMessage))] +internal sealed partial class SourceGenerationContext : JsonSerializerContext +{ +} diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj index 911c7baf57..0a8744bb88 100644 --- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj +++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj @@ -14,10 +14,10 @@ .github\workflows\ci.yml so that it runs for the project being added. --> - - + +