From 5acf5e6bb6c4c9304a9f4a5536a010b8716be15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 18:49:15 +0100 Subject: [PATCH 1/3] [repo] Remove #nullable enable (#2290) --- src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs | 2 -- src/Shared/ActivityHelperExtensions.cs | 2 -- src/Shared/ActivityInstrumentationHelper.cs | 2 -- src/Shared/AssemblyVersionExtensions.cs | 2 -- src/Shared/Configuration/IConfigurationExtensionsLogger.cs | 2 -- .../Configuration/OpenTelemetryConfigurationExtensions.cs | 2 -- src/Shared/DatabaseSemanticConventionHelper.cs | 2 -- src/Shared/DiagnosticSourceListener.cs | 2 -- src/Shared/DiagnosticSourceSubscriber.cs | 2 -- src/Shared/ExceptionExtensions.cs | 2 -- src/Shared/GrpcStatusCanonicalCode.cs | 2 -- src/Shared/GrpcTagHelper.cs | 2 -- src/Shared/Guard.cs | 2 -- src/Shared/ListenerHandler.cs | 2 -- src/Shared/MultiTypePropertyFetcher.cs | 2 -- .../DelegatingOptionsFactoryServiceCollectionExtensions.cs | 2 -- src/Shared/Options/SingletonOptionsManager.cs | 2 -- src/Shared/PropertyFetcher.AOT.cs | 2 -- src/Shared/RedactionHelper.cs | 2 -- src/Shared/RequestDataHelper.cs | 2 -- .../GenevaLogExporterTests.cs | 2 ++ .../GenevaMetricExporterOptionsTests.cs | 2 ++ .../GenevaMetricExporterTests.cs | 2 ++ .../GenevaTraceExporterTests.cs | 2 ++ test/OpenTelemetry.Exporter.Geneva.Tests/JsonSerializerTests.cs | 2 ++ .../LogSerializationTests.cs | 2 ++ .../MessagePackSerializerTests.cs | 2 ++ .../OpenTelemetry.Exporter.Geneva.Tests.csproj | 1 - .../OtlpProtobufMetricExporterTests.cs | 2 ++ .../TableNameSerializerTests.cs | 2 ++ .../UnixDomainSocketDataTransportTests.cs | 2 ++ .../UnixDomainSocketEndPointTests.cs | 2 ++ .../UnixUserEventsDataTransportTests.cs | 2 -- .../Processors/EventsActivityProcessorTests.cs | 2 -- .../RouteTests/RoutingTestCases.cs | 2 -- .../RouteTests/RoutingTestFixture.cs | 2 -- .../RouteTests/RoutingTestResult.cs | 2 -- .../RouteTests/RoutingTests.cs | 2 -- .../RouteTests/TestApplication/ActionDescriptorInfo.cs | 1 - .../TestApplication/ControllerActionDescriptorInfo.cs | 1 - .../RouteTests/TestApplication/PageActionDescriptorInfo.cs | 1 - .../RouteTests/TestApplication/RouteInfo.cs | 2 -- .../RouteTests/TestApplication/RouteInfoDiagnosticObserver.cs | 2 -- .../RouteTests/TestApplication/TestApplicationFactory.cs | 2 -- .../RouteTests/TestCase.cs | 1 - test/Shared/CustomTextMapPropagator.cs | 2 -- test/Shared/EventSourceTestHelper.cs | 2 -- test/Shared/InMemoryEventListener.cs | 2 -- test/Shared/PlatformHelpers.cs | 2 -- test/Shared/SkipUnlessEnvVarFoundFactAttribute.cs | 2 -- test/Shared/SkipUnlessEnvVarFoundTheoryAttribute.cs | 2 -- test/Shared/TestActivityExportProcessor.cs | 2 -- test/Shared/TestActivityProcessor.cs | 2 -- test/Shared/TestEventListener.cs | 2 -- test/Shared/TestHttpServer.cs | 2 -- test/Shared/TestSampler.cs | 2 -- test/Shared/TestTextMapPropagator.cs | 2 -- 57 files changed, 22 insertions(+), 87 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs index 15fab0e0fa..abf8f996bf 100644 --- a/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs +++ b/src/OpenTelemetry.Instrumentation.Process/ProcessMetrics.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics.Metrics; using System.Reflection; using OpenTelemetry.Internal; diff --git a/src/Shared/ActivityHelperExtensions.cs b/src/Shared/ActivityHelperExtensions.cs index 7425c97edc..2e5430ead6 100644 --- a/src/Shared/ActivityHelperExtensions.cs +++ b/src/Shared/ActivityHelperExtensions.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/src/Shared/ActivityInstrumentationHelper.cs b/src/Shared/ActivityInstrumentationHelper.cs index 02a0d83e16..0f7ec41d1a 100644 --- a/src/Shared/ActivityInstrumentationHelper.cs +++ b/src/Shared/ActivityInstrumentationHelper.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; namespace OpenTelemetry.Instrumentation; diff --git a/src/Shared/AssemblyVersionExtensions.cs b/src/Shared/AssemblyVersionExtensions.cs index 4c71ae3598..953de906cc 100644 --- a/src/Shared/AssemblyVersionExtensions.cs +++ b/src/Shared/AssemblyVersionExtensions.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using System.Reflection; diff --git a/src/Shared/Configuration/IConfigurationExtensionsLogger.cs b/src/Shared/Configuration/IConfigurationExtensionsLogger.cs index 0835cf6ff8..196a485bf3 100644 --- a/src/Shared/Configuration/IConfigurationExtensionsLogger.cs +++ b/src/Shared/Configuration/IConfigurationExtensionsLogger.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - namespace Microsoft.Extensions.Configuration; internal interface IConfigurationExtensionsLogger diff --git a/src/Shared/Configuration/OpenTelemetryConfigurationExtensions.cs b/src/Shared/Configuration/OpenTelemetryConfigurationExtensions.cs index e663c53a67..3637927de2 100644 --- a/src/Shared/Configuration/OpenTelemetryConfigurationExtensions.cs +++ b/src/Shared/Configuration/OpenTelemetryConfigurationExtensions.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; #if NET || NETSTANDARD2_1 using System.Diagnostics.CodeAnalysis; diff --git a/src/Shared/DatabaseSemanticConventionHelper.cs b/src/Shared/DatabaseSemanticConventionHelper.cs index a3bc4b5e98..1225e43069 100644 --- a/src/Shared/DatabaseSemanticConventionHelper.cs +++ b/src/Shared/DatabaseSemanticConventionHelper.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Configuration; diff --git a/src/Shared/DiagnosticSourceListener.cs b/src/Shared/DiagnosticSourceListener.cs index 3ffad9bf33..9b0b07b3c8 100644 --- a/src/Shared/DiagnosticSourceListener.cs +++ b/src/Shared/DiagnosticSourceListener.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using OpenTelemetry.Internal; diff --git a/src/Shared/DiagnosticSourceSubscriber.cs b/src/Shared/DiagnosticSourceSubscriber.cs index 3318216db0..87863b2193 100644 --- a/src/Shared/DiagnosticSourceSubscriber.cs +++ b/src/Shared/DiagnosticSourceSubscriber.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using OpenTelemetry.Internal; diff --git a/src/Shared/ExceptionExtensions.cs b/src/Shared/ExceptionExtensions.cs index 9070b59c20..5071a8feeb 100644 --- a/src/Shared/ExceptionExtensions.cs +++ b/src/Shared/ExceptionExtensions.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Globalization; namespace OpenTelemetry.Internal; diff --git a/src/Shared/GrpcStatusCanonicalCode.cs b/src/Shared/GrpcStatusCanonicalCode.cs index d4ec2cf7fb..8abad05f25 100644 --- a/src/Shared/GrpcStatusCanonicalCode.cs +++ b/src/Shared/GrpcStatusCanonicalCode.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - namespace OpenTelemetry.Instrumentation; /// diff --git a/src/Shared/GrpcTagHelper.cs b/src/Shared/GrpcTagHelper.cs index d7c22b1c63..7911cc5c7d 100644 --- a/src/Shared/GrpcTagHelper.cs +++ b/src/Shared/GrpcTagHelper.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using System.Text.RegularExpressions; using OpenTelemetry.Trace; diff --git a/src/Shared/Guard.cs b/src/Shared/Guard.cs index a00cfafb09..d8b88d6a07 100644 --- a/src/Shared/Guard.cs +++ b/src/Shared/Guard.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - // Note: For some targets this file will contain more than one type/namespace. #pragma warning disable IDE0161 // Convert to file-scoped namespace diff --git a/src/Shared/ListenerHandler.cs b/src/Shared/ListenerHandler.cs index a7c6f9049d..d711aab6b0 100644 --- a/src/Shared/ListenerHandler.cs +++ b/src/Shared/ListenerHandler.cs @@ -3,8 +3,6 @@ using System.Diagnostics; -#nullable enable - namespace OpenTelemetry.Instrumentation; /// diff --git a/src/Shared/MultiTypePropertyFetcher.cs b/src/Shared/MultiTypePropertyFetcher.cs index 1370094a58..b5f82fd86d 100644 --- a/src/Shared/MultiTypePropertyFetcher.cs +++ b/src/Shared/MultiTypePropertyFetcher.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Collections.Concurrent; using System.Reflection; diff --git a/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs b/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs index b3b9736277..81e9ac0a66 100644 --- a/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs +++ b/src/Shared/Options/DelegatingOptionsFactoryServiceCollectionExtensions.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; #if NET using System.Diagnostics.CodeAnalysis; diff --git a/src/Shared/Options/SingletonOptionsManager.cs b/src/Shared/Options/SingletonOptionsManager.cs index 4c7718e78c..d3b1928d55 100644 --- a/src/Shared/Options/SingletonOptionsManager.cs +++ b/src/Shared/Options/SingletonOptionsManager.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - #if NET using System.Diagnostics.CodeAnalysis; #endif diff --git a/src/Shared/PropertyFetcher.AOT.cs b/src/Shared/PropertyFetcher.AOT.cs index 209f91cada..19b3153814 100644 --- a/src/Shared/PropertyFetcher.AOT.cs +++ b/src/Shared/PropertyFetcher.AOT.cs @@ -5,8 +5,6 @@ // Usages of the non-AOT-compatible version can be moved over to this one when they need to support AOT/trimming. // Copied from https://github.com/open-telemetry/opentelemetry-dotnet/blob/86a6ba0b7f7ed1f5e84e5a6610e640989cd3ae9f/src/Shared/DiagnosticSourceInstrumentation/PropertyFetcher.cs#L30 -#nullable enable - #if NETSTANDARD2_1_0_OR_GREATER || NET using System.Diagnostics.CodeAnalysis; #endif diff --git a/src/Shared/RedactionHelper.cs b/src/Shared/RedactionHelper.cs index 045d99cad2..ed34bb3e4f 100644 --- a/src/Shared/RedactionHelper.cs +++ b/src/Shared/RedactionHelper.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Text; namespace OpenTelemetry.Internal; diff --git a/src/Shared/RequestDataHelper.cs b/src/Shared/RequestDataHelper.cs index 6acce7fe40..edd9532569 100644 --- a/src/Shared/RequestDataHelper.cs +++ b/src/Shared/RequestDataHelper.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - #if NET using System.Collections.Frozen; #endif diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs index e5065cc143..eaa566ed9d 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaLogExporterTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Diagnostics; using System.Globalization; using System.Net.Sockets; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterOptionsTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterOptionsTests.cs index e711d89757..5ccc866188 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterOptionsTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterOptionsTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using Xunit; namespace OpenTelemetry.Exporter.Geneva.Tests; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs index 62d1176481..d7f189a0e6 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaMetricExporterTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Diagnostics; using System.Diagnostics.Metrics; using System.Globalization; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs index c4d8d21205..6bf12ca320 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/GenevaTraceExporterTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Diagnostics; using System.Net.Sockets; using System.Reflection; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/JsonSerializerTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/JsonSerializerTests.cs index c49a58b40c..783e3524cf 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/JsonSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/JsonSerializerTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Text; using OpenTelemetry.Exporter.Geneva.Tld; using Xunit; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/LogSerializationTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/LogSerializationTests.cs index dd311dcff1..d71cbb2cb7 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/LogSerializationTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/LogSerializationTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Net.Sockets; using System.Runtime.InteropServices; using Microsoft.Extensions.Logging; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/MessagePackSerializerTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/MessagePackSerializerTests.cs index 997a6afd87..640f78f0c0 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/MessagePackSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/MessagePackSerializerTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Globalization; using System.Text; using OpenTelemetry.Exporter.Geneva.MsgPack; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/OpenTelemetry.Exporter.Geneva.Tests.csproj b/test/OpenTelemetry.Exporter.Geneva.Tests/OpenTelemetry.Exporter.Geneva.Tests.csproj index 4cc8b83b36..31ae1a4442 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/OpenTelemetry.Exporter.Geneva.Tests.csproj +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/OpenTelemetry.Exporter.Geneva.Tests.csproj @@ -8,7 +8,6 @@ $(TargetFrameworks);net48;net472;net471;net47;net462 Unit test project for Geneva Exporters for OpenTelemetry. $(NoWarn);SA1311;SA1312;SA1313;SA1123;SA1202;OTEL1002 - disable diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/OtlpProtobufMetricExporterTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/OtlpProtobufMetricExporterTests.cs index 4870b6aee1..5ac0832ba0 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/OtlpProtobufMetricExporterTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/OtlpProtobufMetricExporterTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Diagnostics; using System.Diagnostics.Metrics; using Google.Protobuf; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/TableNameSerializerTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/TableNameSerializerTests.cs index b4b01ab8f4..636676c55c 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/TableNameSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/TableNameSerializerTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Text; using Xunit; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketDataTransportTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketDataTransportTests.cs index 753de5c7e0..0fb9e2302c 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketDataTransportTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketDataTransportTests.cs @@ -1,6 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#nullable disable + using System.Net.Sockets; using System.Reflection; using OpenTelemetry.Exporter.Geneva.Transports; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketEndPointTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketEndPointTests.cs index d0d922ca2b..85351d141c 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketEndPointTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/UnixDomainSocketEndPointTests.cs @@ -3,6 +3,8 @@ #if !NET +#nullable disable + using System.Net; using System.Net.Sockets; using System.Text; diff --git a/test/OpenTelemetry.Exporter.Geneva.Tests/UnixUserEventsDataTransportTests.cs b/test/OpenTelemetry.Exporter.Geneva.Tests/UnixUserEventsDataTransportTests.cs index 6cc7956eb9..4af7484581 100644 --- a/test/OpenTelemetry.Exporter.Geneva.Tests/UnixUserEventsDataTransportTests.cs +++ b/test/OpenTelemetry.Exporter.Geneva.Tests/UnixUserEventsDataTransportTests.cs @@ -3,8 +3,6 @@ #if NET6_0_OR_GREATER -#nullable enable - using System.Diagnostics; using System.Globalization; using System.Text.RegularExpressions; diff --git a/test/OpenTelemetry.Exporter.Instana.Tests/Processors/EventsActivityProcessorTests.cs b/test/OpenTelemetry.Exporter.Instana.Tests/Processors/EventsActivityProcessorTests.cs index 35452ace15..7b46ec5013 100644 --- a/test/OpenTelemetry.Exporter.Instana.Tests/Processors/EventsActivityProcessorTests.cs +++ b/test/OpenTelemetry.Exporter.Instana.Tests/Processors/EventsActivityProcessorTests.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using OpenTelemetry.Exporter.Instana.Implementation; using OpenTelemetry.Exporter.Instana.Implementation.Processors; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestCases.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestCases.cs index e14243fbbe..f02b4203fe 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestCases.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestCases.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestFixture.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestFixture.cs index fdb42af421..a49503722b 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestFixture.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestFixture.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Globalization; using System.Text; using Microsoft.AspNetCore.Builder; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestResult.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestResult.cs index f1df77ba10..affa074c20 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestResult.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestResult.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Text.Json; using System.Text.Json.Serialization; using RouteTests.TestApplication; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTests.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTests.cs index c6cbc6fba4..93199709ea 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTests.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTests.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using OpenTelemetry; using OpenTelemetry.Metrics; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ActionDescriptorInfo.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ActionDescriptorInfo.cs index 98c15a18ba..e0df2673e8 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ActionDescriptorInfo.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ActionDescriptorInfo.cs @@ -1,7 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable using System.Text.Json.Serialization; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Controllers; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ControllerActionDescriptorInfo.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ControllerActionDescriptorInfo.cs index ae5ef6b907..34260c4889 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ControllerActionDescriptorInfo.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/ControllerActionDescriptorInfo.cs @@ -1,7 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable using System.Text.Json.Serialization; namespace RouteTests.TestApplication; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/PageActionDescriptorInfo.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/PageActionDescriptorInfo.cs index dda48ae462..bdaf96851a 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/PageActionDescriptorInfo.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/PageActionDescriptorInfo.cs @@ -1,7 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable using System.Text.Json.Serialization; namespace RouteTests.TestApplication; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfo.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfo.cs index 0d8d2e9668..2754617e78 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfo.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfo.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Text.Json.Serialization; using Microsoft.AspNetCore.Http; #if NET diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfoDiagnosticObserver.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfoDiagnosticObserver.cs index e5e4025ec4..a144f56b58 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfoDiagnosticObserver.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/RouteInfoDiagnosticObserver.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Diagnostics; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs index cc9d682db6..c50fe412f2 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestApplication/TestApplicationFactory.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics; diff --git a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestCase.cs b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestCase.cs index 36710fe4a9..f4e07d2388 100644 --- a/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestCase.cs +++ b/test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/TestCase.cs @@ -1,7 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable using RouteTests.TestApplication; namespace RouteTests; diff --git a/test/Shared/CustomTextMapPropagator.cs b/test/Shared/CustomTextMapPropagator.cs index 8d3404e816..436879e8b5 100644 --- a/test/Shared/CustomTextMapPropagator.cs +++ b/test/Shared/CustomTextMapPropagator.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; using OpenTelemetry.Context.Propagation; diff --git a/test/Shared/EventSourceTestHelper.cs b/test/Shared/EventSourceTestHelper.cs index 02de7a2a76..837f3cd569 100644 --- a/test/Shared/EventSourceTestHelper.cs +++ b/test/Shared/EventSourceTestHelper.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics.Tracing; using System.Globalization; using System.Reflection; diff --git a/test/Shared/InMemoryEventListener.cs b/test/Shared/InMemoryEventListener.cs index bf3d3fd567..4ddb42bb52 100644 --- a/test/Shared/InMemoryEventListener.cs +++ b/test/Shared/InMemoryEventListener.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Collections.Concurrent; using System.Diagnostics.Tracing; diff --git a/test/Shared/PlatformHelpers.cs b/test/Shared/PlatformHelpers.cs index a737fa49f3..22b9c3a570 100644 --- a/test/Shared/PlatformHelpers.cs +++ b/test/Shared/PlatformHelpers.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - #pragma warning disable SA1649 // File name should match first type name #pragma warning disable SA1402 // File may only contain a single type diff --git a/test/Shared/SkipUnlessEnvVarFoundFactAttribute.cs b/test/Shared/SkipUnlessEnvVarFoundFactAttribute.cs index d6e4f02518..88bedacb31 100644 --- a/test/Shared/SkipUnlessEnvVarFoundFactAttribute.cs +++ b/test/Shared/SkipUnlessEnvVarFoundFactAttribute.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using Xunit; namespace OpenTelemetry.Tests; diff --git a/test/Shared/SkipUnlessEnvVarFoundTheoryAttribute.cs b/test/Shared/SkipUnlessEnvVarFoundTheoryAttribute.cs index 5820d36bef..2e43f8cb19 100644 --- a/test/Shared/SkipUnlessEnvVarFoundTheoryAttribute.cs +++ b/test/Shared/SkipUnlessEnvVarFoundTheoryAttribute.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using Xunit; namespace OpenTelemetry.Tests; diff --git a/test/Shared/TestActivityExportProcessor.cs b/test/Shared/TestActivityExportProcessor.cs index 0c4dadfb16..b882af8f8e 100644 --- a/test/Shared/TestActivityExportProcessor.cs +++ b/test/Shared/TestActivityExportProcessor.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; namespace OpenTelemetry.Tests; diff --git a/test/Shared/TestActivityProcessor.cs b/test/Shared/TestActivityProcessor.cs index b788c5fa7c..e0319da15a 100644 --- a/test/Shared/TestActivityProcessor.cs +++ b/test/Shared/TestActivityProcessor.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics; namespace OpenTelemetry.Tests; diff --git a/test/Shared/TestEventListener.cs b/test/Shared/TestEventListener.cs index 424ba512a6..29cb03d6bc 100644 --- a/test/Shared/TestEventListener.cs +++ b/test/Shared/TestEventListener.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using System.Diagnostics.Tracing; namespace OpenTelemetry.Tests; diff --git a/test/Shared/TestHttpServer.cs b/test/Shared/TestHttpServer.cs index c567606649..d294ff24eb 100644 --- a/test/Shared/TestHttpServer.cs +++ b/test/Shared/TestHttpServer.cs @@ -4,8 +4,6 @@ // Note: When implicit usings are enabled in a project this file will generate // warnings/errors without this suppression. -#nullable enable - using System.Net; #if !NETFRAMEWORK using System.Security.Cryptography; diff --git a/test/Shared/TestSampler.cs b/test/Shared/TestSampler.cs index c23bf68ed1..972985bfad 100644 --- a/test/Shared/TestSampler.cs +++ b/test/Shared/TestSampler.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using OpenTelemetry.Trace; namespace OpenTelemetry.Tests; diff --git a/test/Shared/TestTextMapPropagator.cs b/test/Shared/TestTextMapPropagator.cs index ba58606acf..5ce7fd9bd3 100644 --- a/test/Shared/TestTextMapPropagator.cs +++ b/test/Shared/TestTextMapPropagator.cs @@ -1,8 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#nullable enable - using OpenTelemetry.Context.Propagation; namespace OpenTelemetry.Tests; From cd8f08aa9328badf79273bb7d8874fff79816734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 18:58:06 +0100 Subject: [PATCH 2/3] [repo/OWIN] Prepare to .NET9 (#2291) --- .../Implementation/DiagnosticsMiddleware.cs | 27 +++-------- .../DiagnosticsMiddlewareTests.cs | 45 +++++++++---------- 2 files changed, 27 insertions(+), 45 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Owin/Implementation/DiagnosticsMiddleware.cs b/src/OpenTelemetry.Instrumentation.Owin/Implementation/DiagnosticsMiddleware.cs index cf029720c0..56092245f4 100644 --- a/src/OpenTelemetry.Instrumentation.Owin/Implementation/DiagnosticsMiddleware.cs +++ b/src/OpenTelemetry.Instrumentation.Owin/Implementation/DiagnosticsMiddleware.cs @@ -77,7 +77,7 @@ private static void BeginRequest(IOwinContext owinContext) var textMapPropagator = Propagators.DefaultTextMapPropagator; var ctx = textMapPropagator.Extract(default, owinContext.Request, OwinRequestHeaderValuesGetter); - Activity? activity = OwinInstrumentationActivitySource.ActivitySource.StartActivity( + var activity = OwinInstrumentationActivitySource.ActivitySource.StartActivity( OwinInstrumentationActivitySource.IncomingRequestActivityName, ActivityKind.Server, ctx.ActivityContext); @@ -103,7 +103,7 @@ private static void BeginRequest(IOwinContext owinContext) activity.SetTag(SemanticConventions.AttributeUrlQuery, request.Query); activity.SetTag(SemanticConventions.AttributeUrlScheme, owinContext.Request.Scheme); - if (request.Headers.TryGetValue("User-Agent", out string[] userAgent) && userAgent.Length > 0) + if (request.Headers.TryGetValue("User-Agent", out var userAgent) && userAgent.Length > 0) { activity.SetTag(SemanticConventions.AttributeUserAgentOriginal, userAgent[0]); } @@ -124,7 +124,7 @@ private static void BeginRequest(IOwinContext owinContext) } } - if (!(textMapPropagator is TraceContextPropagator)) + if (textMapPropagator is not TraceContextPropagator) { Baggage.Current = ctx.Baggage; } @@ -136,7 +136,7 @@ private static void BeginRequest(IOwinContext owinContext) [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void RequestEnd(IOwinContext owinContext, Exception? exception, long startTimestamp) { - if (owinContext.Environment.TryGetValue(ContextKey, out object context) + if (owinContext.Environment.TryGetValue(ContextKey, out var context) && context is Activity activity) { if (Activity.Current != activity) @@ -191,7 +191,7 @@ private static void RequestEnd(IOwinContext owinContext, Exception? exception, l new(SemanticConventions.AttributeHttpResponseStatusCode, owinContext.Response.StatusCode)); } - if (!(Propagators.DefaultTextMapPropagator is TraceContextPropagator)) + if (Propagators.DefaultTextMapPropagator is not TraceContextPropagator) { Baggage.Current = default; } @@ -209,21 +209,4 @@ private static void RequestEnd(IOwinContext owinContext, Exception? exception, l new(SemanticConventions.AttributeHttpResponseStatusCode, owinContext.Response.StatusCode)); } } - - /// - /// Gets the OpenTelemetry standard uri tag value for a span based on its request . - /// - /// . - /// Span uri value. - private static string GetUriTagValueFromRequestUri(Uri uri, bool disableQueryRedaction) - { - if (string.IsNullOrEmpty(uri.UserInfo) && disableQueryRedaction) - { - return uri.OriginalString; - } - - var query = disableQueryRedaction ? uri.Query : RedactionHelper.GetRedactedQueryString(uri.Query); - - return string.Concat(uri.Scheme, Uri.SchemeDelimiter, uri.Authority, uri.AbsolutePath, query, uri.Fragment); - } } diff --git a/test/OpenTelemetry.Instrumentation.Owin.Tests/DiagnosticsMiddlewareTests.cs b/test/OpenTelemetry.Instrumentation.Owin.Tests/DiagnosticsMiddlewareTests.cs index 445818e461..849b30f0c3 100644 --- a/test/OpenTelemetry.Instrumentation.Owin.Tests/DiagnosticsMiddlewareTests.cs +++ b/test/OpenTelemetry.Instrumentation.Owin.Tests/DiagnosticsMiddlewareTests.cs @@ -24,7 +24,7 @@ public class DiagnosticsMiddlewareTests : IDisposable public DiagnosticsMiddlewareTests() { - Random random = new Random(); + var random = new Random(); var retryCount = 5; do { @@ -60,7 +60,7 @@ public DiagnosticsMiddlewareTests() return next(); }); - HttpConfiguration config = new HttpConfiguration(); + var config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", @@ -120,8 +120,8 @@ public async Task OutgoingRequestInstrumentationTest( bool generateRemoteException = false, bool recordException = false) { - List stoppedActivities = new List(); - List exportedMetrics = new List(); + List stoppedActivities = []; + List exportedMetrics = []; var builder = Sdk.CreateTracerProviderBuilder() .AddInMemoryExporter(stoppedActivities); @@ -135,9 +135,9 @@ public async Task OutgoingRequestInstrumentationTest( { if (enrich) { - if (!enrichmentException) - { - options.Enrich = (activity, eventName, context, exception) => + options.Enrich = enrichmentException + ? (_, _, _, _) => throw new Exception("Error while enriching activity") + : (activity, eventName, _, _) => { switch (eventName) { @@ -147,13 +147,10 @@ public async Task OutgoingRequestInstrumentationTest( case OwinEnrichEventType.EndRequest: activity.SetTag("client.endrequest", nameof(OwinEnrichEventType.EndRequest)); break; + default: + break; } }; - } - else - { - options.Enrich = (activity, eventName, context, exception) => throw new Exception("Error while enriching activity"); - } } options.Filter = _ => !filter; @@ -166,12 +163,12 @@ public async Task OutgoingRequestInstrumentationTest( meterBuilder.AddOwinInstrumentation(); } - using TracerProvider tracerProvider = builder.Build(); - using MeterProvider meterProvider = meterBuilder.Build(); + using var tracerProvider = builder.Build(); + using var meterProvider = meterBuilder.Build(); - using HttpClient client = new HttpClient(); + using var client = new HttpClient(); - Uri requestUri = generateRemoteException + var requestUri = generateRemoteException ? new Uri($"{this.serviceBaseUri}exception") : new Uri($"{this.serviceBaseUri}api/test"); @@ -192,7 +189,7 @@ Owin has finished to inspect the activity status. */ Assert.NotEmpty(stoppedActivities); Assert.Single(stoppedActivities); - Activity activity = stoppedActivities[0]; + var activity = stoppedActivities[0]; Assert.Equal(OwinInstrumentationActivitySource.IncomingRequestActivityName, activity.OperationName); Assert.Equal(requestUri.Host, activity.TagObjects.FirstOrDefault(t => t.Key == SemanticConventions.AttributeServerAddress).Value); @@ -257,6 +254,8 @@ Owin has finished to inspect the activity status. */ case SemanticConventions.AttributeHttpResponseStatusCode: Assert.Equal(generateRemoteException ? 500 : 200, tag.Value); break; + default: + break; } } } @@ -295,7 +294,7 @@ public async Task QueryParametersAreRedacted( Environment.SetEnvironmentVariable("OTEL_DOTNET_EXPERIMENTAL_OWIN_DISABLE_URL_QUERY_REDACTION", "true"); } - List stoppedActivities = new List(); + List stoppedActivities = []; var builder = Sdk.CreateTracerProviderBuilder() .ConfigureServices(services => @@ -316,10 +315,10 @@ public async Task QueryParametersAreRedacted( .AddOwinInstrumentation() .Build(); - using HttpClient client = new HttpClient(); + using var client = new HttpClient(); - Uri requestUri = new Uri($"{this.serviceBaseUri}{actualPath}"); - Uri expectedRequestUri = new Uri($"{this.serviceBaseUri}{expectedPath}"); + var requestUri = new Uri($"{this.serviceBaseUri}{actualPath}"); + var expectedRequestUri = new Uri($"{this.serviceBaseUri}{expectedPath}"); this.requestCompleteHandle.Reset(); @@ -340,7 +339,7 @@ Owin has finished to inspect the activity status. */ Assert.NotEmpty(stoppedActivities); Assert.Single(stoppedActivities); - Activity activity = stoppedActivities[0]; + var activity = stoppedActivities[0]; Assert.Equal(OwinInstrumentationActivitySource.IncomingRequestActivityName, activity.OperationName); Assert.Equal(requestUri.Host, activity.TagObjects.FirstOrDefault(t => t.Key == SemanticConventions.AttributeServerAddress).Value); @@ -356,7 +355,7 @@ Owin has finished to inspect the activity status. */ private List GetMetricPoints(Metric metric) { - List metricPoints = new(); + List metricPoints = []; foreach (var metricPoint in metric.GetMetricPoints()) { From a1edda618d56f3c3a5746f84bac13e834b7e0412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Mon, 4 Nov 2024 19:10:01 +0100 Subject: [PATCH 3/3] [repo/Quartz] Prepare to .NET9 (#2293) --- .../QuartzDiagnosticListener.cs | 7 ++-- .../QuartzDiagnosticListenerTests.cs | 38 +++++++++---------- .../TestJob.cs | 6 +-- .../TestJobExecutionExceptionJob.cs | 2 +- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs index bb6e68b523..9f390287d9 100644 --- a/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs +++ b/src/OpenTelemetry.Instrumentation.Quartz/Implementation/QuartzDiagnosticListener.cs @@ -28,7 +28,7 @@ public QuartzDiagnosticListener(string sourceName, QuartzInstrumentationOptions public override void OnEventWritten(string name, object? payload) { - Activity? activity = Activity.Current; + var activity = Activity.Current; Guard.ThrowIfNull(activity); switch (name) { @@ -44,6 +44,8 @@ public override void OnEventWritten(string name, object? payload) case "Quartz.Job.Veto.Exception": this.OnException(activity, payload); break; + default: + break; } } @@ -127,8 +129,7 @@ private void OnException(Activity activity, object? payload) { if (activity.IsAllDataRequested) { - var exc = payload as Exception; - if (exc == null) + if (payload is not Exception exc) { QuartzInstrumentationEventSource.Log.NullPayload(nameof(QuartzDiagnosticListener), nameof(this.OnStopActivity)); return; diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs index b2faa5ea71..09289ecf17 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/QuartzDiagnosticListenerTests.cs @@ -21,8 +21,8 @@ public QuartzDiagnosticListenerTests() public async Task Should_Create_Activity() { // Arrange - Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + var barrier = new Barrier(2); + List jobExecTimestamps = []; var exportedItems = new List(); using var tel = Sdk.CreateTracerProviderBuilder() @@ -38,7 +38,7 @@ public async Task Should_Create_Activity() scheduler.Context.Put("DATESTAMPS", jobExecTimestamps); await scheduler.Start(); - JobDataMap jobDataMap = new JobDataMap { { "A", "B" } }; + var jobDataMap = new JobDataMap { { "A", "B" } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -74,8 +74,8 @@ public async Task Should_Create_Activity() public async Task Should_Create_Activity_And_Enrich_When_Enrich() { // Arrange - Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + var barrier = new Barrier(2); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -105,7 +105,7 @@ public async Task Should_Create_Activity_And_Enrich_When_Enrich() await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -141,8 +141,8 @@ public async Task Should_Create_Activity_And_Enrich_When_Enrich() public async Task Should_Record_Exception_When_Record_Exception_Enabled() { // Arrange - Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + var barrier = new Barrier(2); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -162,7 +162,7 @@ public async Task Should_Record_Exception_When_Record_Exception_Enabled() await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -195,8 +195,8 @@ public async Task Should_Record_Exception_When_Record_Exception_Enabled() public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enrich() { // Arrange - Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + var barrier = new Barrier(2); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -229,7 +229,7 @@ public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enri await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -262,8 +262,8 @@ public async Task Should_Enrich_Exception_When_Record_Exception_Enabled_And_Enri public async Task Should_Creates_Activity_Event_On_Job_Execution_Exception() { // Arrange - Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + var barrier = new Barrier(2); + List jobExecTimestamps = []; var exportedItems = new List(); using var tel = Sdk.CreateTracerProviderBuilder() @@ -291,7 +291,7 @@ public async Task Should_Creates_Activity_Event_On_Job_Execution_Exception() await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() @@ -323,8 +323,8 @@ public async Task Should_Creates_Activity_Event_On_Job_Execution_Exception() public async Task Should_Not_Record_Activity_When_Trace_Operation_Is_Not_Present() { // Arrange - Barrier barrier = new Barrier(2); - List jobExecTimestamps = new List(); + var barrier = new Barrier(2); + List jobExecTimestamps = []; var exportedItems = new List(); @@ -332,7 +332,7 @@ public async Task Should_Not_Record_Activity_When_Trace_Operation_Is_Not_Present .SetSampler(new AlwaysOnSampler()) .AddQuartzInstrumentation(q => { - q.TracedOperations = new HashSet(); + q.TracedOperations = []; }) .AddInMemoryExporter(exportedItems) .Build(); @@ -346,7 +346,7 @@ public async Task Should_Not_Record_Activity_When_Trace_Operation_Is_Not_Present await scheduler.Start(); var testId = Guid.NewGuid().ToString(); - JobDataMap jobDataMap = new JobDataMap { { "TestId", testId } }; + var jobDataMap = new JobDataMap { { "TestId", testId } }; var name = Guid.NewGuid().ToString(); var job = JobBuilder.Create() diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs index 7be379f91c..e1fbee1e48 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJob.cs @@ -5,14 +5,14 @@ namespace OpenTelemetry.Instrumentation.Quartz.Tests; -public class TestJob : IJob +internal class TestJob : IJob { public Task Execute(IJobExecutionContext context) { try { - List jobExecTimestamps = (List)context.Scheduler.Context.Get("DATESTAMPS"); - Barrier barrier = (Barrier)context.Scheduler.Context.Get("BARRIER"); + var jobExecTimestamps = (List)context.Scheduler.Context.Get("DATESTAMPS"); + var barrier = (Barrier)context.Scheduler.Context.Get("BARRIER"); jobExecTimestamps.Add(DateTime.UtcNow); diff --git a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs index 6ebed283b5..bb81998837 100644 --- a/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs +++ b/test/OpenTelemetry.Instrumentation.Quartz.Tests/TestJobExecutionExceptionJob.cs @@ -5,7 +5,7 @@ namespace OpenTelemetry.Instrumentation.Quartz.Tests; -public class TestJobExecutionExceptionJob : IJob +internal class TestJobExecutionExceptionJob : IJob { public Task Execute(IJobExecutionContext context) {