From e3a90d7ac5b0cb50ebe9838c87a6e6fe06d4dd40 Mon Sep 17 00:00:00 2001 From: joegoldman2 <147369450+joegoldman2@users.noreply.github.com> Date: Tue, 25 Jun 2024 04:48:51 +0000 Subject: [PATCH] [repo] Simplify preprocessor directives (#1924) --- .../Internal/ConnectionStringBuilder.cs | 2 +- .../Transport/MetricEtwDataTransport.cs | 6 +++--- .../MsgPackExporter/MessagePackSerializer.cs | 20 +++++++++---------- .../Transport/EtwDataTransport.cs | 4 ++-- .../TLDExporter/JsonSerializer.cs | 10 +++++----- .../Internal/ConnectionStringParser.cs | 2 +- .../Internal/EventNameManager.cs | 2 +- .../ExtensionFieldInformationManager.cs | 4 ++-- .../OneCollectorExporterEventSource.cs | 8 ++++---- .../CommonSchemaJsonSerializationHelper.cs | 4 ++-- .../CommonSchemaJsonSerializationState.cs | 8 ++++---- .../Transports/HttpJsonPostTransport.cs | 2 +- .../Internal/Transports/IHttpClient.cs | 2 +- .../OneCollectorExporterOptions.cs | 2 +- .../AWSXRayIdGenerator.cs | 2 +- .../TracerProviderBuilderExtensions.cs | 2 +- ...raceEnrichmentProviderBuilderExtensions.cs | 4 ++-- ...ceEnrichmentServiceCollectionExtensions.cs | 4 ++-- .../TracerProviderBuilderExtensions.cs | 2 +- .../AWSTracingPipelineHandler.cs | 2 +- .../AspNetCoreInstrumentationEventSource.cs | 6 +++--- .../Implementation/HttpInListener.cs | 2 +- .../Implementation/HttpInMetricsListener.cs | 11 +++++----- .../GrpcClientDiagnosticListener.cs | 4 ++-- .../HttpHandlerDiagnosticListener.cs | 10 +++++----- .../HttpHandlerMetricsDiagnosticListener.cs | 16 +++++++-------- .../RuntimeInstrumentationOptions.cs | 12 +++++------ .../RuntimeMetrics.cs | 6 +++--- .../SqlClientDiagnosticListener.cs | 4 ++-- .../SqlClientInstrumentation.cs | 6 +++--- .../TracerProviderBuilderExtensions.cs | 8 ++++---- .../RedisProfilerEntryToActivityConverter.cs | 12 +++++------ .../AWSEBSDetector.cs | 8 ++++---- .../AWSEC2Detector.cs | 2 +- .../AWSEKSDetector.cs | 2 +- .../ResourceDetectorUtils.cs | 4 ++-- .../SourceGenerationContext.cs | 2 +- .../AppServiceResourceDetector.cs | 2 +- .../AzureVmMetaDataRequestor.cs | 2 +- .../SourceGenerationContext.cs | 2 +- .../ProcessDetector.cs | 2 +- .../AWSXRaySamplerClient.cs | 6 +++--- .../SourceGenerationContext.cs | 2 +- src/Shared/AssemblyVersionExtensions.cs | 2 +- src/Shared/Guard.cs | 4 ++-- .../Options/DelegatingOptionsFactory.cs | 4 ++-- ...tionsFactoryServiceCollectionExtensions.cs | 8 ++++---- src/Shared/Options/SingletonOptionsManager.cs | 4 ++-- src/Shared/PropertyFetcher.AOT.cs | 20 +++++++++---------- ...ommonSchemaJsonSerializationHelperTests.cs | 4 ++-- .../GrpcTestHelpers/ClientTestHelpers.cs | 2 +- .../GrpcTests.client.cs | 2 +- .../GrpcTests.server.cs | 4 ++-- .../RuntimeInstrumentationOptionsTests.cs | 12 +++++------ .../RuntimeMetricsTests.cs | 6 +++--- test/Shared/TestHttpServer.cs | 4 ++-- 56 files changed, 149 insertions(+), 150 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Geneva/Internal/ConnectionStringBuilder.cs b/src/OpenTelemetry.Exporter.Geneva/Internal/ConnectionStringBuilder.cs index 9bf497c319..48c76da6c4 100644 --- a/src/OpenTelemetry.Exporter.Geneva/Internal/ConnectionStringBuilder.cs +++ b/src/OpenTelemetry.Exporter.Geneva/Internal/ConnectionStringBuilder.cs @@ -33,7 +33,7 @@ public ConnectionStringBuilder(string connectionString) continue; } -#if NET6_0_OR_GREATER +#if NET var index = token.IndexOf(EqualSign, StringComparison.Ordinal); #else var index = token.IndexOf(EqualSign); diff --git a/src/OpenTelemetry.Exporter.Geneva/Metrics/Transport/MetricEtwDataTransport.cs b/src/OpenTelemetry.Exporter.Geneva/Metrics/Transport/MetricEtwDataTransport.cs index 1c7fa8770e..121cb88d1f 100644 --- a/src/OpenTelemetry.Exporter.Geneva/Metrics/Transport/MetricEtwDataTransport.cs +++ b/src/OpenTelemetry.Exporter.Geneva/Metrics/Transport/MetricEtwDataTransport.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using System.Diagnostics.Tracing; @@ -26,7 +26,7 @@ private MetricEtwDataTransport() } [NonEvent] -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "WriteEventCore is safe when eventData object is a primitive type, which it is in this case.")] #endif public unsafe void Send(MetricEventType eventType, byte[] data, int size) @@ -41,7 +41,7 @@ public unsafe void Send(MetricEventType eventType, byte[] data, int size) } [NonEvent] -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "WriteEventCore is safe when eventData object is a primitive type, which it is in this case.")] #endif public unsafe void SendOtlpProtobufEvent(byte[] data, int size) diff --git a/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MessagePackSerializer.cs b/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MessagePackSerializer.cs index 21ed99dd71..ec3e8050b7 100644 --- a/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MessagePackSerializer.cs +++ b/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/MessagePackSerializer.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Buffers.Binary; #endif using System.Globalization; @@ -50,7 +50,7 @@ internal static class MessagePackSerializer private const int LIMIT_MAX_FIX_ARRAY_LENGTH = 15; private const int STRING_SIZE_LIMIT_CHAR_COUNT = (1 << 14) - 1; // 16 * 1024 - 1 = 16383 -#if NET6_0_OR_GREATER +#if NET private const int MAX_STACK_ALLOC_SIZE_IN_BYTES = 256; #endif @@ -187,7 +187,7 @@ public static int SerializeUInt64(byte[] buffer, int cursor, ulong value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int WriteInt16(byte[] buffer, int cursor, short value) { -#if NET6_0_OR_GREATER +#if NET BinaryPrimitives.WriteInt16BigEndian(buffer.AsSpan(cursor), value); return cursor + sizeof(short); #else @@ -204,7 +204,7 @@ public static int WriteInt16(byte[] buffer, int cursor, short value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int WriteInt32(byte[] buffer, int cursor, int value) { -#if NET6_0_OR_GREATER +#if NET BinaryPrimitives.WriteInt32BigEndian(buffer.AsSpan(cursor), value); return cursor + sizeof(int); #else @@ -223,7 +223,7 @@ public static int WriteInt32(byte[] buffer, int cursor, int value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int WriteInt64(byte[] buffer, int cursor, long value) { -#if NET6_0_OR_GREATER +#if NET BinaryPrimitives.WriteInt64BigEndian(buffer.AsSpan(cursor), value); return cursor + sizeof(long); #else @@ -246,7 +246,7 @@ public static int WriteInt64(byte[] buffer, int cursor, long value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int WriteUInt16(byte[] buffer, int cursor, ushort value) { -#if NET6_0_OR_GREATER +#if NET BinaryPrimitives.WriteUInt16BigEndian(buffer.AsSpan(cursor), value); return cursor + sizeof(ushort); #else @@ -263,7 +263,7 @@ public static int WriteUInt16(byte[] buffer, int cursor, ushort value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int WriteUInt32(byte[] buffer, int cursor, uint value) { -#if NET6_0_OR_GREATER +#if NET BinaryPrimitives.WriteUInt32BigEndian(buffer.AsSpan(cursor), value); return cursor + sizeof(uint); #else @@ -282,7 +282,7 @@ public static int WriteUInt32(byte[] buffer, int cursor, uint value) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int WriteUInt64(byte[] buffer, int cursor, ulong value) { -#if NET6_0_OR_GREATER +#if NET BinaryPrimitives.WriteUInt64BigEndian(buffer.AsSpan(cursor), value); return cursor + sizeof(ulong); #else @@ -410,7 +410,7 @@ public static int SerializeAsciiString(byte[] buffer, int cursor, string value) return cursor; } -#if NET6_0_OR_GREATER +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SerializeUnicodeString(byte[] buffer, int cursor, ReadOnlySpan value) @@ -636,7 +636,7 @@ public static int Serialize(byte[] buffer, int cursor, object obj) case DateTimeOffset v: return SerializeUtcDateTime(buffer, cursor, v.UtcDateTime); -#if NET6_0_OR_GREATER +#if NET case ISpanFormattable v: Span tmp = stackalloc char[MAX_STACK_ALLOC_SIZE_IN_BYTES / sizeof(char)]; if (v.TryFormat(tmp, out int charsWritten, string.Empty, CultureInfo.InvariantCulture)) diff --git a/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/Transport/EtwDataTransport.cs b/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/Transport/EtwDataTransport.cs index 199818de29..d35c140d23 100644 --- a/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/Transport/EtwDataTransport.cs +++ b/src/OpenTelemetry.Exporter.Geneva/MsgPackExporter/Transport/EtwDataTransport.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using System.Diagnostics.Tracing; @@ -26,7 +26,7 @@ public void InformationalEvent() } [NonEvent] -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "WriteEventCore is safe when eventData object is a primitive type, which it is in this case.")] #endif public unsafe void SendEvent(int eventId, byte[] data, int size) diff --git a/src/OpenTelemetry.Exporter.Geneva/TLDExporter/JsonSerializer.cs b/src/OpenTelemetry.Exporter.Geneva/TLDExporter/JsonSerializer.cs index 06aaa294d8..c106c55f12 100644 --- a/src/OpenTelemetry.Exporter.Geneva/TLDExporter/JsonSerializer.cs +++ b/src/OpenTelemetry.Exporter.Geneva/TLDExporter/JsonSerializer.cs @@ -18,7 +18,7 @@ internal static class JsonSerializer private const byte ASCII_CARRIAGE_RETURN = 0x0D; private const byte ASCII_HORIZONTAL_TAB = 0x09; -#if NET6_0_OR_GREATER +#if NET private const int MAX_STACK_ALLOC_SIZE_IN_BYTES = 256; #endif @@ -88,7 +88,7 @@ public static int SerializeString(byte[] buffer, int cursor, string value) return cursor; } -#if NET6_0_OR_GREATER +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SerializeString(byte[] buffer, int cursor, ReadOnlySpan value) { @@ -250,7 +250,7 @@ public static int Serialize(byte[] buffer, int cursor, object obj) { case bool v: return WriteString(buffer, cursor, v ? "true" : "false"); -#if NET6_0_OR_GREATER +#if NET case byte: case sbyte: case short: @@ -317,7 +317,7 @@ public static int Serialize(byte[] buffer, int cursor, object obj) case object[] v: return SerializeArray(buffer, cursor, v); -#if NET6_0_OR_GREATER +#if NET case ISpanFormattable v: tmp = stackalloc char[MAX_STACK_ALLOC_SIZE_IN_BYTES / sizeof(char)]; if (v.TryFormat(tmp, out charsWritten, default, CultureInfo.InvariantCulture)) @@ -410,7 +410,7 @@ private static int WriteString(byte[] buffer, int cursor, string value) return cursor; } -#if NET6_0_OR_GREATER +#if NET [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int WriteString(byte[] buffer, int cursor, ReadOnlySpan value) { diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/ConnectionStringParser.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/ConnectionStringParser.cs index da9c35457c..40e30d61db 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/ConnectionStringParser.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/ConnectionStringParser.cs @@ -21,7 +21,7 @@ public ConnectionStringParser(string connectionString) continue; } -#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER +#if NET || NETSTANDARD2_1_OR_GREATER var index = token.IndexOf(EqualSign, StringComparison.Ordinal); #else var index = token.IndexOf(EqualSign); diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/EventNameManager.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/EventNameManager.cs index 0b56f8f8d4..25ee9a0701 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/EventNameManager.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/EventNameManager.cs @@ -45,7 +45,7 @@ public EventNameManager(string defaultEventNamespace, string defaultEventName) this.defaultEventFullName = BuildEventFullName(defaultEventNamespace, defaultEventName)!; -#if NET6_0_OR_GREATER +#if NET Debug.Assert(this.defaultEventFullName != null, "this.defaultFullyQualifiedEventName was null"); #endif } diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/ExtensionFieldInformationManager.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/ExtensionFieldInformationManager.cs index 97a3735b0c..08520bd082 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/ExtensionFieldInformationManager.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/ExtensionFieldInformationManager.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Diagnostics; -#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER +#if NETSTANDARD2_1_OR_GREATER || NET using System.Diagnostics.CodeAnalysis; #endif using System.Text.Json; @@ -21,7 +21,7 @@ internal sealed class ExtensionFieldInformationManager public bool TryResolveExtensionFieldInformation( string fullFieldName, -#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER +#if NETSTANDARD2_1_OR_GREATER || NET [NotNullWhen(true)] #endif out ExtensionFieldInformation? resolvedFieldInformation) diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs index 9543edb200..389d317ac4 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/OneCollectorExporterEventSource.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using System.Diagnostics.Tracing; @@ -79,7 +79,7 @@ public void ExportExceptionThrown(string itemType, string exception) } [Event(2, Message = "Sent '{0}' batch of {1} item(s) to '{2}' transport.", Level = EventLevel.Informational)] -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primitive values.")] #endif public void TransportDataSent(string itemType, int numberOfRecords, string transportDescription) @@ -88,7 +88,7 @@ public void TransportDataSent(string itemType, int numberOfRecords, string trans } [Event(3, Message = "Wrote '{0}' batch of {1} item(s) to '{2}' sink.", Level = EventLevel.Informational)] -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primitive values.")] #endif public void SinkDataWritten(string itemType, int numberOfRecords, string sinkDescription) @@ -109,7 +109,7 @@ public void TransportExceptionThrown(string transportType, string exception) } [Event(6, Message = "Error response received by '{0}' transport. StatusCode: {1}, ErrorMessage: '{2}', ErrorDetails: '{3}'", Level = EventLevel.Error)] -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Parameters passed to WriteEvent are all primitive values.")] #endif public void HttpTransportErrorResponseReceived(string transportType, int statusCode, string errorMessage, string errorDetails) diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationHelper.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationHelper.cs index 982cab47b3..ca30a223ba 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationHelper.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationHelper.cs @@ -9,7 +9,7 @@ namespace OpenTelemetry.Exporter.OneCollector; internal static class CommonSchemaJsonSerializationHelper { -#if NET6_0_OR_GREATER +#if NET public const int MaximumStackAllocSizeInBytes = 256; #endif @@ -209,7 +209,7 @@ private static void SerializeMapValueToJson(IEnumerable destination = stackalloc char[MaximumStackAllocSizeInBytes / 2]; diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs index b7c69c8db6..cfcfc7b496 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Serialization/CommonSchemaJsonSerializationState.cs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using System.Diagnostics; -#if NET6_0_OR_GREATER +#if NET using System.Runtime.InteropServices; #endif using System.Text.Json; @@ -46,7 +46,7 @@ public void AddExtensionAttribute(KeyValuePair attribute) Debug.Assert(fieldInformation?.FieldName != null, "fieldInformation.FieldName was null"); Debug.Assert(fieldInformation?.EncodedFieldName.EncodedUtf8Bytes.Length > 0, "fieldInformation.EncodedFieldName was empty"); -#if NET6_0_OR_GREATER +#if NET ref var lookupIndex = ref CollectionsMarshal.GetValueRefOrAddDefault(this.keys, fieldInformation.ExtensionName, out var existed); if (!existed) { @@ -92,7 +92,7 @@ public void SerializeExtensionPropertiesToJson(bool writeExtensionObjectEnvelope writer.WriteStartObject(CommonSchemaJsonSerializationHelper.ExtensionsProperty); } -#if NET6_0_OR_GREATER +#if NET var allValues = CollectionsMarshal.AsSpan(this.allValues); #else var allValues = this.allValues; @@ -108,7 +108,7 @@ public void SerializeExtensionPropertiesToJson(bool writeExtensionObjectEnvelope { unsafe { -#if NET6_0_OR_GREATER +#if NET ref var attribute = ref allValues[keyLookup.ValueIndicies[i]]; #else var attribute = allValues[keyLookup.ValueIndicies[i]]; diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs index 6585c0916a..40cb7f61b4 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/HttpJsonPostTransport.cs @@ -276,7 +276,7 @@ protected override bool TryComputeLength(out long length) return true; } -#if NET6_0_OR_GREATER +#if NET protected override void SerializeToStream(Stream stream, TransportContext? context, CancellationToken cancellationToken) { this.stream.CopyTo(stream); diff --git a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs index 0bb175b248..f53f8474d5 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/Internal/Transports/IHttpClient.cs @@ -23,7 +23,7 @@ public HttpClientWrapper(HttpClient httpClient) public HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken) { -#if NET6_0_OR_GREATER +#if NET return this.httpClient.Send(request, CancellationToken.None); #else return this.httpClient.SendAsync(request, CancellationToken.None).GetAwaiter().GetResult(); diff --git a/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs b/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs index 2150a1cc9d..14300f830d 100644 --- a/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs +++ b/src/OpenTelemetry.Exporter.OneCollector/OneCollectorExporterOptions.cs @@ -51,7 +51,7 @@ internal virtual void Validate() throw new OneCollectorExporterValidationException("Instrumentation key was not specified on connection string."); } -#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER +#if NET || NETSTANDARD2_1_OR_GREATER var positionOfFirstDash = this.InstrumentationKey.IndexOf('-', StringComparison.OrdinalIgnoreCase); #else var positionOfFirstDash = this.InstrumentationKey!.IndexOf('-'); diff --git a/src/OpenTelemetry.Extensions.AWS/AWSXRayIdGenerator.cs b/src/OpenTelemetry.Extensions.AWS/AWSXRayIdGenerator.cs index 78c40219be..f55193111e 100644 --- a/src/OpenTelemetry.Extensions.AWS/AWSXRayIdGenerator.cs +++ b/src/OpenTelemetry.Extensions.AWS/AWSXRayIdGenerator.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if !NET6_0_OR_GREATER +#if !NET using System.Diagnostics; using System.Globalization; using OpenTelemetry.Internal; diff --git a/src/OpenTelemetry.Extensions.AWS/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions.AWS/TracerProviderBuilderExtensions.cs index a232660257..4ce36c65eb 100644 --- a/src/OpenTelemetry.Extensions.AWS/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Extensions.AWS/TracerProviderBuilderExtensions.cs @@ -24,7 +24,7 @@ public static TracerProviderBuilder AddXRayTraceId(this TracerProviderBuilder bu return builder; } -#if NET6_0_OR_GREATER +#if NET /// /// Replace the trace id of root activity. /// diff --git a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs index 188eb606b5..871bc63850 100644 --- a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentProviderBuilderExtensions.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using Microsoft.Extensions.DependencyInjection; @@ -25,7 +25,7 @@ public static class TraceEnrichmentProviderBuilderExtensions /// /// Add this enricher *before* exporter related Activity processors. /// -#if NET6_0_OR_GREATER +#if NET public static TracerProviderBuilder AddTraceEnricher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this TracerProviderBuilder builder) #else public static TracerProviderBuilder AddTraceEnricher(this TracerProviderBuilder builder) diff --git a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs index add67c8c8c..3741f04e0c 100644 --- a/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs +++ b/src/OpenTelemetry.Extensions.Enrichment/TraceEnrichmentServiceCollectionExtensions.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using Microsoft.Extensions.DependencyInjection.Extensions; @@ -26,7 +26,7 @@ public static class TraceEnrichmentServiceCollectionExtensions /// /// Add this enricher *before* exporter related Activity processors. /// -#if NET6_0_OR_GREATER +#if NET public static IServiceCollection AddTraceEnricher<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this IServiceCollection services) #else public static IServiceCollection AddTraceEnricher(this IServiceCollection services) diff --git a/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs index 90e4bd3b96..321369ffc1 100644 --- a/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Extensions/TracerProviderBuilderExtensions.cs @@ -33,7 +33,7 @@ public static TracerProviderBuilder AddAutoFlushActivityProcessor( Func predicate, int timeoutMilliseconds = 10000) { -#if NET6_0_OR_GREATER +#if NET ArgumentNullException.ThrowIfNull(builder); #else if (builder == null) diff --git a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs index a58298b79a..f24843c97d 100644 --- a/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs +++ b/src/OpenTelemetry.Instrumentation.AWS/Implementation/AWSTracingPipelineHandler.cs @@ -130,7 +130,7 @@ private static void ProcessException(Activity activity, Exception ex) } } -#if NET6_0_OR_GREATER +#if NET [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage( "Trimming", "IL2075", diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/AspNetCoreInstrumentationEventSource.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/AspNetCoreInstrumentationEventSource.cs index cafd0141d9..b7c1ab5970 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/AspNetCoreInstrumentationEventSource.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/AspNetCoreInstrumentationEventSource.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using System.Diagnostics.Tracing; @@ -57,7 +57,7 @@ public void RequestIsFilteredOut(string handlerName, string eventName, string op this.WriteEvent(2, handlerName, eventName, operationName); } -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe.")] #endif [Event(3, Message = "Filter threw exception, request will not be collected. HandlerName: '{0}', EventName: '{1}', OperationName: '{2}', Exception: {3}.", Level = EventLevel.Error)] @@ -66,7 +66,7 @@ public void RequestFilterException(string handlerName, string eventName, string this.WriteEvent(3, handlerName, eventName, operationName, exception); } -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "Parameters to this method are primitive and are trimmer safe.")] #endif [Event(4, Message = "Enrich threw exception. HandlerName: '{0}', EventName: '{1}', OperationName: '{2}', Exception: {3}.", Level = EventLevel.Warning)] diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs index 6a9ec0be44..7f0aa51634 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs @@ -337,7 +337,7 @@ public void OnException(Activity activity, object? payload) // See https://github.com/dotnet/aspnetcore/blob/690d78279e940d267669f825aa6627b0d731f64c/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L252 // and https://github.com/dotnet/aspnetcore/blob/690d78279e940d267669f825aa6627b0d731f64c/src/Middleware/Diagnostics/src/DeveloperExceptionPage/DeveloperExceptionPageMiddlewareImpl.cs#L174 // this makes sure that top-level properties on the payload object are always preserved. -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The event source guarantees that top level properties are preserved")] #endif static bool TryFetchException(object? payload, [NotNullWhen(true)] out Exception? exc) diff --git a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs index c0676a2484..08ab129cab 100644 --- a/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs +++ b/src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInMetricsListener.cs @@ -6,12 +6,11 @@ using System.Diagnostics.Metrics; using System.Reflection; using Microsoft.AspNetCore.Http; -using OpenTelemetry.Internal; - -#if NET6_0_OR_GREATER +#if NET using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Routing; #endif +using OpenTelemetry.Internal; using OpenTelemetry.Trace; namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation; @@ -55,12 +54,12 @@ public static void OnExceptionEventWritten(string name, object? payload) // See https://github.com/dotnet/aspnetcore/blob/690d78279e940d267669f825aa6627b0d731f64c/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L252 // and https://github.com/dotnet/aspnetcore/blob/690d78279e940d267669f825aa6627b0d731f64c/src/Middleware/Diagnostics/src/DeveloperExceptionPage/DeveloperExceptionPageMiddlewareImpl.cs#L174 // this makes sure that top-level properties on the payload object are always preserved. -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The ASP.NET Core framework guarantees that top level properties are preserved")] #endif static bool TryFetchException(object? payload, [NotNullWhen(true)] out Exception? exc) => ExceptionPropertyFetcher.TryFetch(payload, out exc) && exc != null; -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The ASP.NET Core framework guarantees that top level properties are preserved")] #endif static bool TryFetchHttpContext(object? payload, [NotNullWhen(true)] out HttpContext? ctx) @@ -86,7 +85,7 @@ public static void OnStopEventWritten(string name, object? payload) var httpMethod = TelemetryHelper.RequestDataHelper.GetNormalizedHttpMethod(context.Request.Method); tags.Add(new KeyValuePair(SemanticConventions.AttributeHttpRequestMethod, httpMethod)); -#if NET6_0_OR_GREATER +#if NET // Check the exception handler feature first in case the endpoint was overwritten var route = (context.Features.Get()?.Endpoint as RouteEndpoint ?? context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText; diff --git a/src/OpenTelemetry.Instrumentation.GrpcNetClient/Implementation/GrpcClientDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.GrpcNetClient/Implementation/GrpcClientDiagnosticListener.cs index 5742dae08b..d7d7ca78bd 100644 --- a/src/OpenTelemetry.Instrumentation.GrpcNetClient/Implementation/GrpcClientDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.GrpcNetClient/Implementation/GrpcClientDiagnosticListener.cs @@ -158,7 +158,7 @@ public void OnStartActivity(Activity activity, object? payload) // See https://github.com/grpc/grpc-dotnet/blob/ff1a07b90c498f259e6d9f4a50cdad7c89ecd3c0/src/Grpc.Net.Client/Internal/GrpcCall.cs#L1180-L1183 // this makes sure that top-level properties on the payload object are always preserved. -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The event source guarantees that top level properties are preserved")] #endif static bool TryFetchRequest(object? payload, [NotNullWhen(true)] out HttpRequestMessage? request) @@ -199,7 +199,7 @@ public void OnStopActivity(Activity activity, object? payload) // See https://github.com/grpc/grpc-dotnet/blob/ff1a07b90c498f259e6d9f4a50cdad7c89ecd3c0/src/Grpc.Net.Client/Internal/GrpcCall.cs#L1180-L1183 // this makes sure that top-level properties on the payload object are always preserved. -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The event source guarantees that top level properties are preserved")] #endif static bool TryFetchResponse(object? payload, [NotNullWhen(true)] out HttpResponseMessage? response) diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs index 61147eafc4..9201adae51 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using System.Diagnostics; -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif #if NETFRAMEWORK @@ -154,7 +154,7 @@ public void OnStartActivity(Activity activity, object payload) // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The event source guarantees that top-level properties are preserved")] #endif static bool TryFetchRequest(object payload, out HttpRequestMessage request) @@ -220,7 +220,7 @@ public void OnStopActivity(Activity activity, object payload) // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The event source guarantees that top-level properties are preserved")] #endif static TaskStatus GetRequestStatus(object payload) @@ -235,7 +235,7 @@ static TaskStatus GetRequestStatus(object payload) // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The event source guarantees that top-level properties are preserved")] #endif static bool TryFetchResponse(object payload, out HttpResponseMessage response) @@ -283,7 +283,7 @@ public void OnException(Activity activity, object payload) // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The event source guarantees that top-level properties are preserved")] #endif static bool TryFetchException(object payload, out Exception exc) diff --git a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs index eb781dbd97..84297e95ee 100644 --- a/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerMetricsDiagnosticListener.cs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using System.Diagnostics; -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using System.Diagnostics.Metrics; @@ -30,7 +30,7 @@ internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler private static readonly PropertyFetcher StopResponseFetcher = new("Response"); private static readonly PropertyFetcher StopExceptionFetcher = new("Exception"); private static readonly PropertyFetcher RequestFetcher = new("Request"); -#if NET6_0_OR_GREATER +#if NET private static readonly HttpRequestOptionsKey HttpRequestOptionsErrorKey = new(SemanticConventions.AttributeErrorType); #endif @@ -72,7 +72,7 @@ public static void OnStopEventWritten(Activity activity, object payload) if (response == null) { -#if !NET6_0_OR_GREATER +#if !NET request.Properties.TryGetValue(SemanticConventions.AttributeErrorType, out var errorType); #else request.Options.TryGetValue(HttpRequestOptionsErrorKey, out var errorType); @@ -94,7 +94,7 @@ public static void OnStopEventWritten(Activity activity, object payload) // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The System.Net.Http library guarantees that top-level properties are preserved")] #endif static bool TryFetchRequest(object payload, out HttpRequestMessage request) => @@ -102,7 +102,7 @@ static bool TryFetchRequest(object payload, out HttpRequestMessage request) => // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The System.Net.Http library guarantees that top-level properties are preserved")] #endif static bool TryFetchResponse(object payload, out HttpResponseMessage response) => @@ -117,7 +117,7 @@ public static void OnExceptionEventWritten(Activity activity, object payload) return; } -#if !NET6_0_OR_GREATER +#if !NET request.Properties.Add(SemanticConventions.AttributeErrorType, exc.GetType().FullName); #else request.Options.Set(HttpRequestOptionsErrorKey, exc.GetType().FullName); @@ -125,7 +125,7 @@ public static void OnExceptionEventWritten(Activity activity, object payload) // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The System.Net.Http library guarantees that top-level properties are preserved")] #endif static bool TryFetchException(object payload, out Exception exc) @@ -140,7 +140,7 @@ static bool TryFetchException(object payload, out Exception exc) // The AOT-annotation DynamicallyAccessedMembers in System.Net.Http library ensures that top-level properties on the payload object are always preserved. // see https://github.com/dotnet/runtime/blob/f9246538e3d49b90b0e9128d7b1defef57cd6911/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L325 -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The System.Net.Http library guarantees that top-level properties are preserved")] #endif static bool TryFetchRequest(object payload, out HttpRequestMessage request) diff --git a/src/OpenTelemetry.Instrumentation.Runtime/RuntimeInstrumentationOptions.cs b/src/OpenTelemetry.Instrumentation.Runtime/RuntimeInstrumentationOptions.cs index 6c1b2c43da..6f3a4e53ea 100644 --- a/src/OpenTelemetry.Instrumentation.Runtime/RuntimeInstrumentationOptions.cs +++ b/src/OpenTelemetry.Instrumentation.Runtime/RuntimeInstrumentationOptions.cs @@ -14,14 +14,14 @@ public class RuntimeInstrumentationOptions /// public bool? GcEnabled { get; set; } - #if NET6_0_OR_GREATER + #if NET /// /// Gets or sets a value indicating whether jitter metrics should be collected. /// public bool? JitEnabled { get; set; } #endif - #if NET6_0_OR_GREATER + #if NET /// /// Gets or sets a value indicating whether threading metrics should be collected. /// @@ -42,10 +42,10 @@ public class RuntimeInstrumentationOptions /// Gets a value indicating whether all metrics are enabled. /// internal bool IsAllEnabled => this.GcEnabled == null - #if NET6_0_OR_GREATER + #if NET && this.JitEnabled == null #endif - #if NET6_0_OR_GREATER + #if NET && this.ThreadingEnabled == null #endif && this.AssembliesEnabled == null @@ -56,14 +56,14 @@ public class RuntimeInstrumentationOptions /// internal bool IsGcEnabled => this.GcEnabled == true || this.IsAllEnabled; - #if NET6_0_OR_GREATER + #if NET /// /// Gets a value indicating whether jitter metrics is enabled. /// internal bool IsJitEnabled => this.JitEnabled == true || this.IsAllEnabled; #endif - #if NET6_0_OR_GREATER + #if NET /// /// Gets a value indicating whether threading metrics is enabled. /// diff --git a/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs b/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs index 4fb23bf5ff..1e6569adc6 100644 --- a/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.Runtime/RuntimeMetrics.cs @@ -6,7 +6,7 @@ using System.Diagnostics.Metrics; using System.Reflection; using OpenTelemetry.Internal; -#if NET6_0_OR_GREATER +#if NET using System.Threading; using JitInfo = System.Runtime.JitInfo; #endif @@ -22,7 +22,7 @@ internal sealed class RuntimeMetrics internal static readonly AssemblyName AssemblyName = Assembly.GetName(); internal static readonly Meter MeterInstance = new(AssemblyName.Name!, Assembly.GetPackageVersion()); -#if NET6_0_OR_GREATER +#if NET private const long NanosecondsPerTick = 100; #endif private const int NumberOfGenerations = 3; @@ -43,7 +43,7 @@ static RuntimeMetrics() unit: "bytes", description: "Count of bytes currently in use by objects in the GC heap that haven't been collected yet. Fragmentation and other GC committed memory pools are excluded."); -#if NET6_0_OR_GREATER +#if NET MeterInstance.CreateObservableCounter( "process.runtime.dotnet.gc.allocations.size", () => GC.GetTotalAllocatedBytes(), diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs index bf3b77c599..acbecedbb2 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlClientDiagnosticListener.cs @@ -5,13 +5,13 @@ using System.Data; using System.Diagnostics; using OpenTelemetry.Trace; -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif namespace OpenTelemetry.Instrumentation.SqlClient.Implementation; -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)] #endif internal sealed class SqlClientDiagnosticListener : ListenerHandler diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs b/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs index dfd02f558c..301f5a7891 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/SqlClientInstrumentation.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using OpenTelemetry.Instrumentation.SqlClient.Implementation; @@ -14,7 +14,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient; internal sealed class SqlClientInstrumentation : IDisposable { internal const string SqlClientDiagnosticListenerName = "SqlClientDiagnosticListener"; -#if NET6_0_OR_GREATER +#if NET internal const string SqlClientTrimmingUnsupportedMessage = "Trimming is not yet supported with SqlClient instrumentation."; #endif #if NETFRAMEWORK @@ -40,7 +40,7 @@ internal sealed class SqlClientInstrumentation : IDisposable /// Initializes a new instance of the class. /// /// Configuration options for sql instrumentation. -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(SqlClientTrimmingUnsupportedMessage)] #endif public SqlClientInstrumentation( diff --git a/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs b/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs index e35707edc7..2959484eb3 100644 --- a/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs +++ b/src/OpenTelemetry.Instrumentation.SqlClient/TracerProviderBuilderExtensions.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using Microsoft.Extensions.DependencyInjection; @@ -22,7 +22,7 @@ public static class TracerProviderBuilderExtensions /// /// being configured. /// The instance of to chain the calls. -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)] #endif public static TracerProviderBuilder AddSqlClientInstrumentation(this TracerProviderBuilder builder) @@ -34,7 +34,7 @@ public static TracerProviderBuilder AddSqlClientInstrumentation(this TracerProvi /// being configured. /// Callback action for configuring . /// The instance of to chain the calls. -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)] #endif public static TracerProviderBuilder AddSqlClientInstrumentation( @@ -49,7 +49,7 @@ public static TracerProviderBuilder AddSqlClientInstrumentation( /// Name which is used when retrieving options. /// Callback action for configuring . /// The instance of to chain the calls. -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(SqlClientInstrumentation.SqlClientTrimmingUnsupportedMessage)] #endif diff --git a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs index 9052b95031..5b3a338383 100644 --- a/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs +++ b/src/OpenTelemetry.Instrumentation.StackExchangeRedis/Implementation/RedisProfilerEntryToActivityConverter.cs @@ -7,7 +7,7 @@ using System.Reflection.Emit; using OpenTelemetry.Trace; using StackExchange.Redis.Profiling; -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; #endif @@ -56,14 +56,14 @@ internal static class RedisProfilerEntryToActivityConverter return (null, script); -#if NET6_0_OR_GREATER +#if NET [DynamicDependency("CommandAndKey", "StackExchange.Redis.Message", "StackExchange.Redis")] [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The CommandAndKey property is preserved by the above DynamicDependency")] #endif static bool GetCommandAndKey( PropertyFetcher commandAndKeyFetcher, object message, -#if NET6_0_OR_GREATER +#if NET [NotNullWhen(true)] #endif out string? value) @@ -192,7 +192,7 @@ public static void DrainSession(Activity? parentActivity, IEnumerable private static Func? CreateFieldGetter( -#if NET6_0_OR_GREATER +#if NET [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] #endif Type classType, @@ -202,7 +202,7 @@ public static void DrainSession(Activity? parentActivity, IEnumerable)getterMethod.CreateDelegate(typeof(Func)); } -#if NET6_0_OR_GREATER +#if NET else { return obj => (TField?)field.GetValue(obj); diff --git a/src/OpenTelemetry.Resources.AWS/AWSEBSDetector.cs b/src/OpenTelemetry.Resources.AWS/AWSEBSDetector.cs index d956ffb281..c17c291add 100644 --- a/src/OpenTelemetry.Resources.AWS/AWSEBSDetector.cs +++ b/src/OpenTelemetry.Resources.AWS/AWSEBSDetector.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Runtime.InteropServices; #endif using OpenTelemetry.Resources.AWS.Models; @@ -14,7 +14,7 @@ namespace OpenTelemetry.Resources.AWS; internal sealed class AWSEBSDetector : IResourceDetector { private const string AWSEBSMetadataWindowsFilePath = "C:\\Program Files\\Amazon\\XRay\\environment.conf"; -#if NET6_0_OR_GREATER +#if NET private const string AWSEBSMetadataLinuxFilePath = "/var/elasticbeanstalk/xray/environment.conf"; #endif @@ -27,7 +27,7 @@ public Resource Detect() try { string? filePath; -#if NET6_0_OR_GREATER +#if NET if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { filePath = AWSEBSMetadataWindowsFilePath; @@ -84,7 +84,7 @@ internal static List> ExtractResourceAttributes(AWS internal static AWSEBSMetadataModel? GetEBSMetadata(string filePath) { -#if NET6_0_OR_GREATER +#if NET return ResourceDetectorUtils.DeserializeFromFile(filePath, SourceGenerationContext.Default.AWSEBSMetadataModel); #else return ResourceDetectorUtils.DeserializeFromFile(filePath); diff --git a/src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs b/src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs index 57e8652f1f..d56fe184c9 100644 --- a/src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs +++ b/src/OpenTelemetry.Resources.AWS/AWSEC2Detector.cs @@ -80,7 +80,7 @@ internal static List> ExtractResourceAttributes(AWS internal static AWSEC2IdentityDocumentModel? DeserializeResponse(string response) { -#if NET6_0_OR_GREATER +#if NET return ResourceDetectorUtils.DeserializeFromString(response, SourceGenerationContext.Default.AWSEC2IdentityDocumentModel); #else return ResourceDetectorUtils.DeserializeFromString(response); diff --git a/src/OpenTelemetry.Resources.AWS/AWSEKSDetector.cs b/src/OpenTelemetry.Resources.AWS/AWSEKSDetector.cs index 6261a05b84..b32ef0f2df 100644 --- a/src/OpenTelemetry.Resources.AWS/AWSEKSDetector.cs +++ b/src/OpenTelemetry.Resources.AWS/AWSEKSDetector.cs @@ -110,7 +110,7 @@ internal static List> ExtractResourceAttributes(str internal static AWSEKSClusterInformationModel? DeserializeResponse(string response) { -#if NET6_0_OR_GREATER +#if NET return ResourceDetectorUtils.DeserializeFromString(response, SourceGenerationContext.Default.AWSEKSClusterInformationModel); #else return ResourceDetectorUtils.DeserializeFromString(response); diff --git a/src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs b/src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs index d68b708d4b..0c4318e5c7 100644 --- a/src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs +++ b/src/OpenTelemetry.Resources.AWS/ResourceDetectorUtils.cs @@ -17,7 +17,7 @@ namespace OpenTelemetry.Resources.AWS; /// internal static class ResourceDetectorUtils { -#if !NET6_0_OR_GREATER +#if !NET private static readonly JsonSerializerOptions JsonSerializerOptions = new(JsonSerializerDefaults.Web); #endif @@ -43,7 +43,7 @@ internal static async Task SendOutRequest(string url, string method, Key } } -#if NET6_0_OR_GREATER +#if NET internal static T? DeserializeFromFile(string filePath, JsonTypeInfo jsonTypeInfo) { using (var stream = GetStream(filePath)) diff --git a/src/OpenTelemetry.Resources.AWS/SourceGenerationContext.cs b/src/OpenTelemetry.Resources.AWS/SourceGenerationContext.cs index 3c14a8df70..51f0b9a4d5 100644 --- a/src/OpenTelemetry.Resources.AWS/SourceGenerationContext.cs +++ b/src/OpenTelemetry.Resources.AWS/SourceGenerationContext.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Text.Json.Serialization; using OpenTelemetry.Resources.AWS.Models; diff --git a/src/OpenTelemetry.Resources.Azure/AppServiceResourceDetector.cs b/src/OpenTelemetry.Resources.Azure/AppServiceResourceDetector.cs index 44c8cfb39e..71b0c03a5c 100644 --- a/src/OpenTelemetry.Resources.Azure/AppServiceResourceDetector.cs +++ b/src/OpenTelemetry.Resources.Azure/AppServiceResourceDetector.cs @@ -64,7 +64,7 @@ public Resource Detect() string? websiteResourceGroup = Environment.GetEnvironmentVariable(ResourceAttributeConstants.AppServiceResourceGroupEnvVar); string websiteOwnerName = Environment.GetEnvironmentVariable(ResourceAttributeConstants.AppServiceOwnerNameEnvVar) ?? string.Empty; -#if NET6_0_OR_GREATER +#if NET int idx = websiteOwnerName.IndexOf('+', StringComparison.Ordinal); #else int idx = websiteOwnerName.IndexOf("+", StringComparison.Ordinal); diff --git a/src/OpenTelemetry.Resources.Azure/AzureVmMetaDataRequestor.cs b/src/OpenTelemetry.Resources.Azure/AzureVmMetaDataRequestor.cs index 182ca89af5..41b0460c57 100644 --- a/src/OpenTelemetry.Resources.Azure/AzureVmMetaDataRequestor.cs +++ b/src/OpenTelemetry.Resources.Azure/AzureVmMetaDataRequestor.cs @@ -20,7 +20,7 @@ internal static class AzureVmMetaDataRequestor if (res != null) { -#if NET6_0_OR_GREATER +#if NET return JsonSerializer.Deserialize(res, SourceGenerationContext.Default.AzureVmMetadataResponse); #else return JsonSerializer.Deserialize(res); diff --git a/src/OpenTelemetry.Resources.Azure/SourceGenerationContext.cs b/src/OpenTelemetry.Resources.Azure/SourceGenerationContext.cs index 3f1a36bc8f..5fb96f1861 100644 --- a/src/OpenTelemetry.Resources.Azure/SourceGenerationContext.cs +++ b/src/OpenTelemetry.Resources.Azure/SourceGenerationContext.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Text.Json.Serialization; namespace OpenTelemetry.Resources.Azure; diff --git a/src/OpenTelemetry.Resources.Process/ProcessDetector.cs b/src/OpenTelemetry.Resources.Process/ProcessDetector.cs index 4b1c1257c8..57dffe6425 100644 --- a/src/OpenTelemetry.Resources.Process/ProcessDetector.cs +++ b/src/OpenTelemetry.Resources.Process/ProcessDetector.cs @@ -17,7 +17,7 @@ public Resource Detect() return new Resource(new List>(2) { new(ProcessSemanticConventions.AttributeProcessOwner, Environment.UserName), -#if NET6_0_OR_GREATER +#if NET new(ProcessSemanticConventions.AttributeProcessPid, Environment.ProcessId), #else new(ProcessSemanticConventions.AttributeProcessPid, System.Diagnostics.Process.GetCurrentProcess().Id), diff --git a/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs b/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs index a50b4d2391..758a0817fd 100644 --- a/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs +++ b/src/OpenTelemetry.Sampler.AWS/AWSXRaySamplerClient.cs @@ -38,7 +38,7 @@ public async Task> GetSamplingRules() try { GetSamplingRulesResponse? getSamplingRulesResponse = JsonSerializer -#if NET6_0_OR_GREATER +#if NET .Deserialize(responseJson, SourceGenerationContext.Default.GetSamplingRulesResponse); #else .Deserialize(responseJson); @@ -72,7 +72,7 @@ public async Task> GetSamplingRules() public async Task GetSamplingTargets(GetSamplingTargetsRequest getSamplingTargetsRequest) { var json = JsonSerializer -#if NET6_0_OR_GREATER +#if NET .Serialize(getSamplingTargetsRequest, SourceGenerationContext.Default.GetSamplingTargetsRequest); #else .Serialize(getSamplingTargetsRequest); @@ -90,7 +90,7 @@ public async Task> GetSamplingRules() try { GetSamplingTargetsResponse? getSamplingTargetsResponse = JsonSerializer -#if NET6_0_OR_GREATER +#if NET .Deserialize(responseJson, SourceGenerationContext.Default.GetSamplingTargetsResponse); #else .Deserialize(responseJson); diff --git a/src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs b/src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs index 239c7dcfcc..08bcf6bc22 100644 --- a/src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs +++ b/src/OpenTelemetry.Sampler.AWS/SourceGenerationContext.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Text.Json.Serialization; namespace OpenTelemetry.Sampler.AWS; diff --git a/src/Shared/AssemblyVersionExtensions.cs b/src/Shared/AssemblyVersionExtensions.cs index 1ae08c8d15..a3a9a4f274 100644 --- a/src/Shared/AssemblyVersionExtensions.cs +++ b/src/Shared/AssemblyVersionExtensions.cs @@ -26,7 +26,7 @@ public static string GetPackageVersion(this Assembly assembly) var informationalVersion = assembly.GetCustomAttribute()?.InformationalVersion; Debug.Assert(!string.IsNullOrEmpty(informationalVersion), "AssemblyInformationalVersionAttribute was not found in assembly"); -#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER +#if NET || NETSTANDARD2_1_OR_GREATER var indexOfPlusSign = informationalVersion!.IndexOf('+', StringComparison.Ordinal); #else var indexOfPlusSign = informationalVersion!.IndexOf('+'); diff --git a/src/Shared/Guard.cs b/src/Shared/Guard.cs index 3222a307b3..aec04ccd08 100644 --- a/src/Shared/Guard.cs +++ b/src/Shared/Guard.cs @@ -21,7 +21,7 @@ #pragma warning disable SA1403 // File may only contain a single namespace #pragma warning disable SA1649 // File name should match first type name -#if !NET6_0_OR_GREATER +#if !NET namespace System.Runtime.CompilerServices { /// Allows capturing of the expressions passed to a method. @@ -38,7 +38,7 @@ public CallerArgumentExpressionAttribute(string parameterName) } #endif -#if !NET6_0_OR_GREATER && !NETSTANDARD2_1_OR_GREATER +#if !NET && !NETSTANDARD2_1_OR_GREATER namespace System.Diagnostics.CodeAnalysis { /// Specifies that an output is not even if diff --git a/src/Shared/Options/DelegatingOptionsFactory.cs b/src/Shared/Options/DelegatingOptionsFactory.cs index 1b8fe62188..3e9b2914e3 100644 --- a/src/Shared/Options/DelegatingOptionsFactory.cs +++ b/src/Shared/Options/DelegatingOptionsFactory.cs @@ -16,7 +16,7 @@ example of how that works. #nullable enable using System.Diagnostics; -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using Microsoft.Extensions.Configuration; @@ -27,7 +27,7 @@ namespace Microsoft.Extensions.Options; /// Implementation of . /// /// The type of options being requested. -#if NET6_0_OR_GREATER +#if NET internal sealed class DelegatingOptionsFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> : #else internal sealed class DelegatingOptionsFactory : diff --git a/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs b/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs index 69c7b6c3b6..b3b9736277 100644 --- a/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs +++ b/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs @@ -4,7 +4,7 @@ #nullable enable using System.Diagnostics; -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif using Microsoft.Extensions.Configuration; @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection; internal static class DelegatingOptionsFactoryServiceCollectionExtensions { -#if NET6_0_OR_GREATER +#if NET public static IServiceCollection RegisterOptionsFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( #else public static IServiceCollection RegisterOptionsFactory( @@ -40,7 +40,7 @@ public static IServiceCollection RegisterOptionsFactory( return services!; } -#if NET6_0_OR_GREATER +#if NET public static IServiceCollection RegisterOptionsFactory<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( #else public static IServiceCollection RegisterOptionsFactory( @@ -65,7 +65,7 @@ public static IServiceCollection RegisterOptionsFactory( return services!; } -#if NET6_0_OR_GREATER +#if NET public static IServiceCollection DisableOptionsReloading<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>( #else public static IServiceCollection DisableOptionsReloading( diff --git a/src/Shared/Options/SingletonOptionsManager.cs b/src/Shared/Options/SingletonOptionsManager.cs index c1807183e3..4c7718e78c 100644 --- a/src/Shared/Options/SingletonOptionsManager.cs +++ b/src/Shared/Options/SingletonOptionsManager.cs @@ -3,13 +3,13 @@ #nullable enable -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics.CodeAnalysis; #endif namespace Microsoft.Extensions.Options; -#if NET6_0_OR_GREATER +#if NET internal sealed class SingletonOptionsManager<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TOptions> : IOptionsMonitor, IOptionsSnapshot #else internal sealed class SingletonOptionsManager : IOptionsMonitor, IOptionsSnapshot diff --git a/src/Shared/PropertyFetcher.AOT.cs b/src/Shared/PropertyFetcher.AOT.cs index d15193a40a..003f4a4ee8 100644 --- a/src/Shared/PropertyFetcher.AOT.cs +++ b/src/Shared/PropertyFetcher.AOT.cs @@ -8,7 +8,7 @@ #nullable enable #pragma warning disable IDE0005 // Using directive is unnecessary. -#if NETSTANDARD2_1_0_OR_GREATER || NET6_0_OR_GREATER +#if NETSTANDARD2_1_0_OR_GREATER || NET using System.Diagnostics.CodeAnalysis; #endif using System; @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation; /// The type of the property being fetched. internal sealed class PropertyFetcher { -#if NET6_0_OR_GREATER +#if NET private const string TrimCompatibilityMessage = "PropertyFetcher is used to access properties on objects dynamically by design and cannot be made trim compatible."; #endif private readonly string propertyName; @@ -49,11 +49,11 @@ public PropertyFetcher(string propertyName) /// Object to be fetched. /// Fetched value. /// if the property was fetched. -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(TrimCompatibilityMessage)] #endif public bool TryFetch( -#if NETSTANDARD2_1_0_OR_GREATER || NET6_0_OR_GREATER +#if NETSTANDARD2_1_0_OR_GREATER || NET [NotNullWhen(true)] #endif object? obj, @@ -68,7 +68,7 @@ public bool TryFetch( return innerFetcher.TryFetch(obj, out value); } -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(TrimCompatibilityMessage)] #endif private static bool TryFetchRare(object? obj, string propertyName, ref PropertyFetch? destination, out T? value) @@ -93,7 +93,7 @@ private static bool TryFetchRare(object? obj, string propertyName, ref PropertyF } // see https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(TrimCompatibilityMessage)] #endif private abstract class PropertyFetch @@ -138,7 +138,7 @@ private abstract class PropertyFetch // IL3050 was generated here because of the call to MakeGenericType, which is problematic in AOT if one of the type parameters is a value type; // because the compiler might need to generate code specific to that type. // If the type parameter is a reference type, there will be no problem; because the generated code can be shared among all reference type instantiations. -#if NET6_0_OR_GREATER +#if NET [UnconditionalSuppressMessage("AOT", "IL3050", Justification = "The code guarantees that all the generic parameters are reference types.")] #endif static PropertyFetch? DynamicInstantiationHelper(Type declaringType, PropertyInfo propertyInfo) @@ -152,7 +152,7 @@ private abstract class PropertyFetch } public abstract bool TryFetch( -#if NETSTANDARD2_1_0_OR_GREATER || NET6_0_OR_GREATER +#if NETSTANDARD2_1_0_OR_GREATER || NET [NotNullWhen(true)] #endif object? obj, @@ -180,7 +180,7 @@ private static PropertyFetchInstantiated CreateInstantiated new PropertyFetchInstantiated(propertyInfo); -#if NET6_0_OR_GREATER +#if NET [RequiresUnreferencedCode(TrimCompatibilityMessage)] #endif private sealed class PropertyFetchInstantiated : PropertyFetch @@ -201,7 +201,7 @@ public PropertyFetchInstantiated(PropertyInfo property) : 1 + this.innerFetcher.NumberOfInnerFetchers; public override bool TryFetch( -#if NETSTANDARD2_1_0_OR_GREATER || NET6_0_OR_GREATER +#if NETSTANDARD2_1_0_OR_GREATER || NET [NotNullWhen(true)] #endif object? obj, diff --git a/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationHelperTests.cs b/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationHelperTests.cs index 8e93368f0b..da78729fad 100644 --- a/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationHelperTests.cs +++ b/test/OpenTelemetry.Exporter.OneCollector.Tests/CommonSchemaJsonSerializationHelperTests.cs @@ -93,7 +93,7 @@ public void SerializeComplexValueToJsonTest() var version = new Version("1.4.0"); this.SerializeValueToJsonTest(version, "\"1.4.0\""); -#if NET6_0_OR_GREATER +#if NET var typeWithISpanFormattable = new TypeWithISpanFormattable(overflow: false); this.SerializeValueToJsonTest(typeWithISpanFormattable, "\"hello\""); @@ -139,7 +139,7 @@ private sealed class TypeWithThrowingToString public override string ToString() => throw new NotImplementedException(); } -#if NET6_0_OR_GREATER +#if NET private sealed class TypeWithISpanFormattable : ISpanFormattable { private readonly bool overflow; diff --git a/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTestHelpers/ClientTestHelpers.cs b/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTestHelpers/ClientTestHelpers.cs index 6475ae7c2b..7835d3e7dd 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTestHelpers/ClientTestHelpers.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTestHelpers/ClientTestHelpers.cs @@ -52,7 +52,7 @@ public static async Task WriteResponseAsync(Stream ms, TResponse resp } await ResponseUtils.WriteHeaderAsync(ms, data.Length, compress, CancellationToken.None); -#if NET5_0_OR_GREATER +#if NET await ms.WriteAsync(data); #else await ms.WriteAsync(data, 0, data.Length); diff --git a/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.client.cs b/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.client.cs index 82fc403153..1d2e9f6129 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.client.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.client.cs @@ -114,7 +114,7 @@ public void GrpcClientCallsAreCollectedSuccessfully(string baseAddress, bool sho } } -#if NET6_0_OR_GREATER +#if NET [Theory] [InlineData(true)] [InlineData(false)] diff --git a/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.server.cs b/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.server.cs index 8ff452d8e3..0052403748 100644 --- a/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.server.cs +++ b/test/OpenTelemetry.Instrumentation.GrpcNetClient.Tests/GrpcTests.server.cs @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#if NET6_0_OR_GREATER +#if NET using System.Diagnostics; using System.Net; using Greet; @@ -95,7 +95,7 @@ public void GrpcAspNetCoreInstrumentationAddsCorrectAttributes(string? enableGrp Assert.StartsWith("grpc-dotnet", activity.GetTagValue(SemanticConventions.AttributeUserAgentOriginal) as string); } -#if NET6_0_OR_GREATER +#if NET [Theory(Skip = "Skipping for .NET 6 and higher due to bug #3023")] #endif [InlineData(null)] diff --git a/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeInstrumentationOptionsTests.cs b/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeInstrumentationOptionsTests.cs index 8b0ab4311f..39d8faff0d 100644 --- a/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeInstrumentationOptionsTests.cs +++ b/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeInstrumentationOptionsTests.cs @@ -12,7 +12,7 @@ public void Enable_All_If_Nothing_Was_Defined() var options = new RuntimeInstrumentationOptions(); Assert.True(options.IsGcEnabled); - #if NET6_0_OR_GREATER + #if NET Assert.True(options.IsJitEnabled); Assert.True(options.IsThreadingEnabled); #endif @@ -26,7 +26,7 @@ public void Enable_Gc_Only() var options = new RuntimeInstrumentationOptions { GcEnabled = true }; Assert.True(options.IsGcEnabled); - #if NET6_0_OR_GREATER + #if NET Assert.False(options.IsJitEnabled); Assert.False(options.IsThreadingEnabled); #endif @@ -34,7 +34,7 @@ public void Enable_Gc_Only() Assert.False(options.IsAllEnabled); } - #if NET6_0_OR_GREATER + #if NET [Fact] public void Enable_Jit_Only() { @@ -48,7 +48,7 @@ public void Enable_Jit_Only() } #endif - #if NET6_0_OR_GREATER + #if NET [Fact] public void Enable_Threading_Only() { @@ -68,7 +68,7 @@ public void Enable_Assemblies_Only() var options = new RuntimeInstrumentationOptions { AssembliesEnabled = true }; Assert.False(options.IsGcEnabled); - #if NET6_0_OR_GREATER + #if NET Assert.False(options.IsJitEnabled); Assert.False(options.IsThreadingEnabled); #endif @@ -82,7 +82,7 @@ public void Enable_Multiple() var options = new RuntimeInstrumentationOptions { GcEnabled = true, AssembliesEnabled = true }; Assert.True(options.IsGcEnabled); - #if NET6_0_OR_GREATER + #if NET Assert.False(options.IsJitEnabled); Assert.False(options.IsThreadingEnabled); #endif diff --git a/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs b/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs index f0b23686e7..5b6666a971 100644 --- a/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs +++ b/test/OpenTelemetry.Instrumentation.Runtime.Tests/RuntimeMetricsTests.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; -#if NET6_0_OR_GREATER +#if NET using System.Threading; using System.Threading.Tasks; #endif @@ -66,7 +66,7 @@ public void GcMetricsTest() var totalObjectsSize = exportedItems.FirstOrDefault(i => i.Name == "process.runtime.dotnet.gc.objects.size"); Assert.NotNull(totalObjectsSize); -#if NET6_0_OR_GREATER +#if NET var gcAllocationSizeMetric = exportedItems.FirstOrDefault(i => i.Name == "process.runtime.dotnet.gc.allocations.size"); Assert.NotNull(gcAllocationSizeMetric); @@ -88,7 +88,7 @@ public void GcMetricsTest() #endif } -#if NET6_0_OR_GREATER +#if NET [Fact] public void JitRelatedMetricsTest() { diff --git a/test/Shared/TestHttpServer.cs b/test/Shared/TestHttpServer.cs index f5924c57e8..63f120c4c4 100644 --- a/test/Shared/TestHttpServer.cs +++ b/test/Shared/TestHttpServer.cs @@ -17,7 +17,7 @@ namespace OpenTelemetry.Tests; internal static class TestHttpServer { -#if !NET6_0_OR_GREATER +#if !NET private static readonly Random GlobalRandom = new(); #endif @@ -32,7 +32,7 @@ public static IDisposable RunServer(Action action, out stri { try { -#if NET6_0_OR_GREATER +#if NET port = RandomNumberGenerator.GetInt32(2000, 5000); #else #pragma warning disable CA5394 // Do not use insecure randomness