From a68bb0572b4c8ea8eb243ab0fbca5210cfe5f9e4 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 13:33:27 +0000 Subject: [PATCH 01/11] Make some AWS projects AoT compatible Make `OpenTelemetry.ResourceDetectors.AWS` and `OpenTelemetry.Sampler.AWS` AoT compatible. --- .github/workflows/ci.yml | 2 ++ .../AWSEBSResourceDetector.cs | 6 ++++- .../AWSEC2ResourceDetector.cs | 4 ++++ .../AWSEKSResourceDetector.cs | 4 ++++ .../Models/AWSEC2IdentityDocumentModel.cs | 7 ++++++ .../Models/AWSEKSClusterDataModel.cs | 2 +- .../Models/AWSEKSClusterInformationModel.cs | 5 +++- .../ResourceDetectorUtils.cs | 18 ++++++++++++++ .../SourceGenerationContext.cs | 24 +++++++++++++++++++ .../AWSXRaySamplerClient.cs | 21 ++++++++++++++-- .../GetSamplingRulesResponse.cs | 2 +- .../GetSamplingTargetsRequest.cs | 2 +- .../GetSamplingTargetsResponse.cs | 2 +- .../SourceGenerationContext.cs | 23 ++++++++++++++++++ ...nTelemetry.AotCompatibility.TestApp.csproj | 2 ++ 15 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 src/OpenTelemetry.ResourceDetectors.AWS/SourceGenerationContext.cs create mode 100644 src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 813abdb5a8..7895e35c64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -343,7 +343,9 @@ jobs: if: | contains(needs.detect-changes.outputs.changes, 'eventcounters') || contains(needs.detect-changes.outputs.changes, 'runtime') + || contains(needs.detect-changes.outputs.changes, 'aws') || contains(needs.detect-changes.outputs.changes, 'azure') + || contains(needs.detect-changes.outputs.changes, 'container') || contains(needs.detect-changes.outputs.changes, 'host') || contains(needs.detect-changes.outputs.changes, 'processdetector') || contains(needs.detect-changes.outputs.changes, 'processruntime') diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs index 5bd0a07b2d..1fb8fd1616 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs @@ -14,7 +14,7 @@ namespace OpenTelemetry.ResourceDetectors.AWS; /// /// Resource detector for application running in AWS ElasticBeanstalk environment. /// -public sealed class AWSEBSResourceDetector : IResourceDetector +public sealed partial class AWSEBSResourceDetector : IResourceDetector { private const string AWSEBSMetadataWindowsFilePath = "C:\\Program Files\\Amazon\\XRay\\environment.conf"; #if NET6_0_OR_GREATER @@ -87,6 +87,10 @@ internal static List> ExtractResourceAttributes(AWS internal static AWSEBSMetadataModel? GetEBSMetadata(string filePath) { +#if NET6_0_OR_GREATER + return ResourceDetectorUtils.DeserializeFromFile(filePath, SourceGenerationContext.Default.AWSEBSMetadataModel); +#else return ResourceDetectorUtils.DeserializeFromFile(filePath); +#endif } } diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEC2ResourceDetector.cs b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEC2ResourceDetector.cs index 615f44ab0f..dc75368995 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEC2ResourceDetector.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEC2ResourceDetector.cs @@ -83,7 +83,11 @@ internal static List> ExtractResourceAttributes(AWS internal static AWSEC2IdentityDocumentModel? DeserializeResponse(string response) { +#if NET6_0_OR_GREATER + return ResourceDetectorUtils.DeserializeFromString(response, SourceGenerationContext.Default.AWSEC2IdentityDocumentModel); +#else return ResourceDetectorUtils.DeserializeFromString(response); +#endif } private static string GetAWSEC2Token() diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEKSResourceDetector.cs b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEKSResourceDetector.cs index 82e4ea0170..a1c560da08 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEKSResourceDetector.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEKSResourceDetector.cs @@ -116,7 +116,11 @@ internal static List> ExtractResourceAttributes(str internal static AWSEKSClusterInformationModel? DeserializeResponse(string response) { +#if NET6_0_OR_GREATER + return ResourceDetectorUtils.DeserializeFromString(response, SourceGenerationContext.Default.AWSEKSClusterInformationModel); +#else return ResourceDetectorUtils.DeserializeFromString(response); +#endif } private static string? GetEKSClusterName(string credentials, HttpClientHandler? httpClientHandler) diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEC2IdentityDocumentModel.cs b/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEC2IdentityDocumentModel.cs index bc88556a5b..4bd2f4dfef 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEC2IdentityDocumentModel.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEC2IdentityDocumentModel.cs @@ -1,17 +1,24 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +using System.Text.Json.Serialization; + namespace OpenTelemetry.ResourceDetectors.AWS.Models; internal class AWSEC2IdentityDocumentModel { + [JsonPropertyName("accountId")] public string? AccountId { get; set; } + [JsonPropertyName("availabilityZone")] public string? AvailabilityZone { get; set; } + [JsonPropertyName("region")] public string? Region { get; set; } + [JsonPropertyName("instanceId")] public string? InstanceId { get; set; } + [JsonPropertyName("instanceType")] public string? InstanceType { get; set; } } diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterDataModel.cs b/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterDataModel.cs index 7dfaeed930..0284548085 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterDataModel.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterDataModel.cs @@ -5,7 +5,7 @@ namespace OpenTelemetry.ResourceDetectors.AWS.Models; -internal class AWSEKSClusterDataModel +internal sealed class AWSEKSClusterDataModel { [JsonPropertyName("cluster.name")] public string? ClusterName { get; set; } diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterInformationModel.cs b/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterInformationModel.cs index 7a9e6f9bac..b732eb7795 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterInformationModel.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/Models/AWSEKSClusterInformationModel.cs @@ -1,9 +1,12 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +using System.Text.Json.Serialization; + namespace OpenTelemetry.ResourceDetectors.AWS.Models; -internal class AWSEKSClusterInformationModel +internal sealed class AWSEKSClusterInformationModel { + [JsonPropertyName("data")] public AWSEKSClusterDataModel? Data { get; set; } } diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs b/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs index 6b3a76815c..1f2d44db5b 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; namespace OpenTelemetry.ResourceDetectors.AWS; @@ -16,7 +17,9 @@ namespace OpenTelemetry.ResourceDetectors.AWS; /// internal static class ResourceDetectorUtils { +#if !NET6_0_OR_GREATER private static readonly JsonSerializerOptions JsonSerializerOptions = new(JsonSerializerDefaults.Web); +#endif internal static async Task SendOutRequest(string url, string method, KeyValuePair? header, HttpClientHandler? handler = null) { @@ -40,6 +43,20 @@ internal static async Task SendOutRequest(string url, string method, Key } } +#if NET6_0_OR_GREATER + internal static T? DeserializeFromFile(string filePath, JsonTypeInfo jsonTypeInfo) + { + using (var stream = GetStream(filePath)) + { + return JsonSerializer.Deserialize(stream, jsonTypeInfo); + } + } + + internal static T? DeserializeFromString(string json, JsonTypeInfo jsonTypeInfo) + { + return JsonSerializer.Deserialize(json, jsonTypeInfo); + } +#else internal static T? DeserializeFromFile(string filePath) { using (var stream = GetStream(filePath)) @@ -52,6 +69,7 @@ internal static async Task SendOutRequest(string url, string method, Key { return JsonSerializer.Deserialize(json, JsonSerializerOptions); } +#endif internal static Stream GetStream(string filePath) { diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/SourceGenerationContext.cs b/src/OpenTelemetry.ResourceDetectors.AWS/SourceGenerationContext.cs new file mode 100644 index 0000000000..003f5b1d5d --- /dev/null +++ b/src/OpenTelemetry.ResourceDetectors.AWS/SourceGenerationContext.cs @@ -0,0 +1,24 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#if NET6_0_OR_GREATER +using System.Text.Json.Serialization; +using OpenTelemetry.ResourceDetectors.AWS.Models; + +namespace OpenTelemetry.ResourceDetectors.AWS; + +/// +/// "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(AWSEBSMetadataModel))] +[JsonSerializable(typeof(AWSEC2IdentityDocumentModel))] +[JsonSerializable(typeof(AWSEKSClusterInformationModel))] +internal sealed partial class SourceGenerationContext : JsonSerializerContext +{ +} +#endif diff --git a/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs b/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs index b911038376..0b16ac5a89 100644 --- a/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs +++ b/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs @@ -38,7 +38,13 @@ public async Task> GetSamplingRules() try { - GetSamplingRulesResponse? getSamplingRulesResponse = JsonSerializer.Deserialize(responseJson); + GetSamplingRulesResponse? getSamplingRulesResponse = JsonSerializer +#if NET6_0_OR_GREATER + .Deserialize(responseJson, SourceGenerationContext.Default.GetSamplingRulesResponse); +#else + .Deserialize(responseJson); +#endif + if (getSamplingRulesResponse is not null) { if (getSamplingRulesResponse.SamplingRuleRecords is not null) @@ -66,7 +72,14 @@ public async Task> GetSamplingRules() public async Task GetSamplingTargets(GetSamplingTargetsRequest getSamplingTargetsRequest) { - var content = new StringContent(JsonSerializer.Serialize(getSamplingTargetsRequest), Encoding.UTF8, this.jsonContentType); + var json = JsonSerializer +#if NET6_0_OR_GREATER + .Serialize(getSamplingTargetsRequest, SourceGenerationContext.Default.GetSamplingTargetsRequest); +#else + .Serialize(getSamplingTargetsRequest); +#endif + + var content = new StringContent(json, Encoding.UTF8, this.jsonContentType); using var request = new HttpRequestMessage(HttpMethod.Post, this.getSamplingTargetsEndpoint) { @@ -78,7 +91,11 @@ public async Task> GetSamplingRules() try { GetSamplingTargetsResponse? getSamplingTargetsResponse = JsonSerializer +#if NET6_0_OR_GREATER + .Deserialize(responseJson, SourceGenerationContext.Default.GetSamplingTargetsResponse); +#else .Deserialize(responseJson); +#endif return getSamplingTargetsResponse; } diff --git a/src/OpenTelemetry.Sampler.AWS/GetSamplingRulesResponse.cs b/src/OpenTelemetry.Sampler.AWS/GetSamplingRulesResponse.cs index 44d1dd2743..e43a88c1ac 100644 --- a/src/OpenTelemetry.Sampler.AWS/GetSamplingRulesResponse.cs +++ b/src/OpenTelemetry.Sampler.AWS/GetSamplingRulesResponse.cs @@ -6,7 +6,7 @@ namespace OpenTelemetry.Sampler.AWS; -internal class GetSamplingRulesResponse +internal sealed class GetSamplingRulesResponse { [JsonPropertyName("NextToken")] public string? NextToken { get; set; } diff --git a/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsRequest.cs b/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsRequest.cs index d24c96bd51..9702995e91 100644 --- a/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsRequest.cs +++ b/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsRequest.cs @@ -6,7 +6,7 @@ namespace OpenTelemetry.Sampler.AWS; -internal class GetSamplingTargetsRequest +internal sealed class GetSamplingTargetsRequest { public GetSamplingTargetsRequest(List documents) { diff --git a/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsResponse.cs b/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsResponse.cs index 7ec53f577b..772d37dca0 100644 --- a/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsResponse.cs +++ b/src/OpenTelemetry.Sampler.AWS/GetSamplingTargetsResponse.cs @@ -6,7 +6,7 @@ namespace OpenTelemetry.Sampler.AWS; -internal class GetSamplingTargetsResponse +internal sealed class GetSamplingTargetsResponse { public GetSamplingTargetsResponse( double lastRuleModification, diff --git a/src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs b/src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs new file mode 100644 index 0000000000..239c7dcfcc --- /dev/null +++ b/src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs @@ -0,0 +1,23 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#if NET6_0_OR_GREATER +using System.Text.Json.Serialization; + +namespace OpenTelemetry.Sampler.AWS; + +/// +/// "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(GetSamplingRulesResponse))] +[JsonSerializable(typeof(GetSamplingTargetsRequest))] +[JsonSerializable(typeof(GetSamplingTargetsResponse))] +internal sealed partial class SourceGenerationContext : JsonSerializerContext +{ +} +#endif diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj index f2e95fd1b0..7cb3befbb9 100644 --- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj +++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj @@ -16,10 +16,12 @@ + + From 41fbd66356c277c4c0d9e506e6bb892040db3c61 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 13:40:19 +0000 Subject: [PATCH 02/11] Validate ResourceDetectors.Container AoT Test that `OpenTelemetry.ResourceDetectors.Container` is AoT compatible. --- .github/workflows/ci.yml | 1 + .../OpenTelemetry.AotCompatibility.TestApp.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7895e35c64..13933dd524 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -349,6 +349,7 @@ jobs: || contains(needs.detect-changes.outputs.changes, 'host') || contains(needs.detect-changes.outputs.changes, 'processdetector') || contains(needs.detect-changes.outputs.changes, 'processruntime') + || contains(needs.detect-changes.outputs.changes, 'resourcedetectors') || contains(needs.detect-changes.outputs.changes, 'aottestapp') || contains(needs.detect-changes.outputs.changes, 'build') || contains(needs.detect-changes.outputs.changes, 'redis') diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj index 7cb3befbb9..8ffe41e905 100644 --- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj +++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj @@ -18,6 +18,7 @@ + From 62abc29d5bae4c721ffb49b3dd046283d5dbcaef Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 13:50:03 +0000 Subject: [PATCH 03/11] Make Extensions.Enrichment AoT compatible Add annotations to make OpenTelemetry.Extensions.Enrichment AoT compatible. --- .github/workflows/ci.yml | 1 + .../TraceEnrichmentProviderBuilderExtensions.cs | 5 +++++ .../TraceEnrichmentServiceCollectionExtensions.cs | 5 +++++ .../OpenTelemetry.AotCompatibility.TestApp.csproj | 1 + 4 files changed, 12 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13933dd524..ca2ec473f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -346,6 +346,7 @@ jobs: || contains(needs.detect-changes.outputs.changes, 'aws') || contains(needs.detect-changes.outputs.changes, 'azure') || contains(needs.detect-changes.outputs.changes, 'container') + || contains(needs.detect-changes.outputs.changes, 'enrichment') || contains(needs.detect-changes.outputs.changes, 'host') || contains(needs.detect-changes.outputs.changes, 'processdetector') || contains(needs.detect-changes.outputs.changes, 'processruntime') diff --git a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs index 8596ce52ad..ff7ded583c 100644 --- a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using System; +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; using OpenTelemetry.Internal; using OpenTelemetry.Trace; @@ -23,7 +24,11 @@ public static class TraceEnrichmentProviderBuilderExtensions /// /// Add this enricher *before* exporter related Activity processors. /// +#if NET6_0_OR_GREATER + public static TracerProviderBuilder AddTraceEnricher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this TracerProviderBuilder builder) +#else public static TracerProviderBuilder AddTraceEnricher(this TracerProviderBuilder builder) +#endif where T : TraceEnricher { Guard.ThrowIfNull(builder); diff --git a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs index 9a20e64e6a..5db45eac73 100644 --- a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs +++ b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.Extensions.DependencyInjection.Extensions; using OpenTelemetry.Extensions.Enrichment; @@ -25,7 +26,11 @@ public static class TraceEnrichmentServiceCollectionExtensions /// /// Add this enricher *before* exporter related Activity processors. /// +#if NET6_0_OR_GREATER + public static IServiceCollection AddTraceEnricher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this IServiceCollection services) +#else public static IServiceCollection AddTraceEnricher(this IServiceCollection services) +#endif where T : TraceEnricher { Guard.ThrowIfNull(services); diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj index 8ffe41e905..66ccd0d51a 100644 --- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj +++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj @@ -13,6 +13,7 @@ When adding projects here please also update the verify-aot-compat job in .github\workflows\ci.yml so that it runs for the project being added. --> + From f64fe3aeb73a1cb18b0bace029ff2ab0a481912d Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 13:58:57 +0000 Subject: [PATCH 04/11] Update CHANGELOGs Update CHANGELOGS. --- src/OpenTelemetry.Extensions.Enrichment/CHANGELOG.md | 5 +++++ src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md | 2 ++ src/OpenTelemetry.Sampler.AWS/CHANGELOG.md | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/OpenTelemetry.Extensions.Enrichment/CHANGELOG.md b/src/OpenTelemetry.Extensions.Enrichment/CHANGELOG.md index 825c32f0d0..642075cb3f 100644 --- a/src/OpenTelemetry.Extensions.Enrichment/CHANGELOG.md +++ b/src/OpenTelemetry.Extensions.Enrichment/CHANGELOG.md @@ -1 +1,6 @@ # Changelog + +## Unreleased + +* Make Extensions.Enrichment AoT compatible. + ([#1541](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1541)) diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md b/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md index 20b95715c6..ce557cfc68 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md +++ b/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md @@ -8,6 +8,8 @@ ([#1350](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1350)) * BREAKING: All Resource Detector classes marked as `sealed`. ([#1510](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1510)) +* Make OpenTelemetry.ResourceDetectors.AWS and OpenTelemetry.Sampler.AWS AoT compatible. + ([#1541](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1541)) ## 1.3.0-beta.1 diff --git a/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md b/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md index a28f47d696..26f56c6055 100644 --- a/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md +++ b/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md @@ -10,3 +10,6 @@ Initial release of `OpenTelemetry.Sampler.AWS`. * Update OpenTelemetry SDK version to `1.7.0`. ([#1486](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1486)) + +* Make OpenTelemetry.ResourceDetectors.AWS and OpenTelemetry.Sampler.AWS AoT compatible. + ([#1541](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1541)) From b730615aabe0ad00635635e92500b773f5ac0e72 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 14:00:16 +0000 Subject: [PATCH 05/11] Remove partial modifier Leftovers from local refactoring before a68bb0572b4c8ea8eb243ab0fbca5210cfe5f9e4. --- .../AWSEBSResourceDetector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs index 1fb8fd1616..442ffe406c 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/AWSEBSResourceDetector.cs @@ -14,7 +14,7 @@ namespace OpenTelemetry.ResourceDetectors.AWS; /// /// Resource detector for application running in AWS ElasticBeanstalk environment. /// -public sealed partial class AWSEBSResourceDetector : IResourceDetector +public sealed class AWSEBSResourceDetector : IResourceDetector { private const string AWSEBSMetadataWindowsFilePath = "C:\\Program Files\\Amazon\\XRay\\environment.conf"; #if NET6_0_OR_GREATER From 2b3721871f8b16198f1ce2374ff4f9915ab5072c Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 14:02:34 +0000 Subject: [PATCH 06/11] Fix IDE0005 warning Fix IDE0005 warning. --- .../ResourceDetectorUtils.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs b/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs index 1f2d44db5b..331f8d86dd 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs +++ b/src/OpenTelemetry.ResourceDetectors.AWS/ResourceDetectorUtils.cs @@ -7,7 +7,9 @@ using System.Net.Http; using System.Text; using System.Text.Json; +#if !NETFRAMEWORK using System.Text.Json.Serialization.Metadata; +#endif using System.Threading.Tasks; namespace OpenTelemetry.ResourceDetectors.AWS; From e909a69c29fb493d09493f1bf239a680f67865fd Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 14:03:44 +0000 Subject: [PATCH 07/11] Fix IDE0005 warnings Fix IDE0005 warnings. --- .../TraceEnrichmentProviderBuilderExtensions.cs | 2 ++ .../TraceEnrichmentServiceCollectionExtensions.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs index ff7ded583c..d0f412ed06 100644 --- a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 using System; +#if NET6_0_OR_GREATER using System.Diagnostics.CodeAnalysis; +#endif using Microsoft.Extensions.DependencyInjection; using OpenTelemetry.Internal; using OpenTelemetry.Trace; diff --git a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs index 5db45eac73..b78210a488 100644 --- a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs +++ b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 using System; +#if NET6_0_OR_GREATER using System.Diagnostics.CodeAnalysis; +#endif using System.Linq; using Microsoft.Extensions.DependencyInjection.Extensions; using OpenTelemetry.Extensions.Enrichment; From ffd8f28ac9fca2efced7fcccfb23ddd2bcc57da2 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 14:40:40 +0000 Subject: [PATCH 08/11] Fix-up filters - Add new filters for AWS and resource detector projects. - Add new filter for projects validated by AoT that don't otherwise fall under an existing category. --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca2ec473f1..6c29a94e30 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,8 +21,10 @@ jobs: build: ['build/**', '.github/**/*.yml', '!.github/workflows/package-*'] shared: ['src/Shared/**'] code: ['**.cs', '.editorconfig'] + aot: ['src/OpenTelemetry.Extensions.Enrichment/**'] aottestapp: ['test/OpenTelemetry.AotCompatibility.TestApp/**'] aspnet: ['*/OpenTelemetry.Instrumentation.AspNet*/**', 'examples/AspNet/**', '!**/*.md'] + aws: ['*/OpenTelemetry.*.AWS*/**', '!**/*.md'] azure: ['*/OpenTelemetry.ResourceDetectors.Azure*/**', '!**/*.md'] eventcounters: ['*/OpenTelemetry.Instrumentation.EventCounters*/**', 'examples/event-counters/**', '!**/*.md'] extensions: ['*/OpenTelemetry.Extensions/**', '*/OpenTelemetry.Extensions.Tests/**', '!**/*.md'] @@ -35,6 +37,7 @@ jobs: processdetector: ['*/OpenTelemetry.ResourceDetectors.Process/**', '*/OpenTelemetry.ResourceDetectors.Process.Tests/**', '!**/*.md'] processruntime: ['*/OpenTelemetry.ResourceDetectors.ProcessRuntime/**', '*/OpenTelemetry.ResourceDetectors.ProcessRuntime.Tests/**', '!**/*.md'] redis: ['*/OpenTelemetry.Instrumentation.StackExchangeRedis*/**', 'examples/redis/**', '!**/*.md'] + resourcedetectors: ['*/OpenTelemetry.ResourceDetectors.*/**', '!**/*.md'] runtime: ['*/OpenTelemetry.Instrumentation.Runtime*/**', 'examples/runtime-instrumentation/**', '!**/*.md'] wcf: ['*/OpenTelemetry.Instrumentation.Wcf*/**', 'examples/wcf/**', '!**/*.md'] solution: [ @@ -345,12 +348,11 @@ jobs: || contains(needs.detect-changes.outputs.changes, 'runtime') || contains(needs.detect-changes.outputs.changes, 'aws') || contains(needs.detect-changes.outputs.changes, 'azure') - || contains(needs.detect-changes.outputs.changes, 'container') - || contains(needs.detect-changes.outputs.changes, 'enrichment') || contains(needs.detect-changes.outputs.changes, 'host') || contains(needs.detect-changes.outputs.changes, 'processdetector') || contains(needs.detect-changes.outputs.changes, 'processruntime') || contains(needs.detect-changes.outputs.changes, 'resourcedetectors') + || contains(needs.detect-changes.outputs.changes, 'aot') || contains(needs.detect-changes.outputs.changes, 'aottestapp') || contains(needs.detect-changes.outputs.changes, 'build') || contains(needs.detect-changes.outputs.changes, 'redis') From d773cb63f452a082348b67db80cb8ec8a6016487 Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 14:47:00 +0000 Subject: [PATCH 09/11] Validate OpenTelemetry.Extensions for AoT Add OpenTelemetry.Extensions to the AoT test app. --- .github/workflows/ci.yml | 1 + .../OpenTelemetry.AotCompatibility.TestApp.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c29a94e30..c5dc47e66f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -348,6 +348,7 @@ jobs: || contains(needs.detect-changes.outputs.changes, 'runtime') || contains(needs.detect-changes.outputs.changes, 'aws') || contains(needs.detect-changes.outputs.changes, 'azure') + || contains(needs.detect-changes.outputs.changes, 'extensions') || contains(needs.detect-changes.outputs.changes, 'host') || contains(needs.detect-changes.outputs.changes, 'processdetector') || contains(needs.detect-changes.outputs.changes, 'processruntime') diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj index 66ccd0d51a..6a53dae272 100644 --- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj +++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj @@ -13,6 +13,7 @@ When adding projects here please also update the verify-aot-compat job in .github\workflows\ci.yml so that it runs for the project being added. --> + From 3e7d7063ff3afe72394a4eec7889479dd3e955cf Mon Sep 17 00:00:00 2001 From: martincostello Date: Sat, 20 Jan 2024 14:49:40 +0000 Subject: [PATCH 10/11] Validate OpenTelemetry.Extensions.AWS for AoT Add OpenTelemetry.Extensions.AWS to the AoT test app. --- .../OpenTelemetry.AotCompatibility.TestApp.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj index 6a53dae272..911c7baf57 100644 --- a/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj +++ b/test/OpenTelemetry.AotCompatibility.TestApp/OpenTelemetry.AotCompatibility.TestApp.csproj @@ -14,6 +14,7 @@ .github\workflows\ci.yml so that it runs for the project being added. --> + From 90e4567504e987b56d312fb36b2a9d01e2aecc09 Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Mon, 22 Jan 2024 16:35:46 +0000 Subject: [PATCH 11/11] Update CHANGELOGs Only mention the relevant change in each file. --- src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md | 2 +- src/OpenTelemetry.Sampler.AWS/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md b/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md index ce557cfc68..d8e4dd31be 100644 --- a/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md +++ b/src/OpenTelemetry.ResourceDetectors.AWS/CHANGELOG.md @@ -8,7 +8,7 @@ ([#1350](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1350)) * BREAKING: All Resource Detector classes marked as `sealed`. ([#1510](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1510)) -* Make OpenTelemetry.ResourceDetectors.AWS and OpenTelemetry.Sampler.AWS AoT compatible. +* Make OpenTelemetry.ResourceDetectors.AWS native AoT compatible. ([#1541](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1541)) ## 1.3.0-beta.1 diff --git a/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md b/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md index 26f56c6055..0d912d6711 100644 --- a/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md +++ b/src/OpenTelemetry.Sampler.AWS/CHANGELOG.md @@ -11,5 +11,5 @@ Initial release of `OpenTelemetry.Sampler.AWS`. * Update OpenTelemetry SDK version to `1.7.0`. ([#1486](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1486)) -* Make OpenTelemetry.ResourceDetectors.AWS and OpenTelemetry.Sampler.AWS AoT compatible. +* Make OpenTelemetry.Sampler.AWS native AoT compatible. ([#1541](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1541))