Simplify conditional compilation (#3865)

This commit is contained in:
Piotr Kiełkowicz 2024-12-06 20:58:34 +01:00 committed by GitHub
parent f33e9302c0
commit 723c4d0ea1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
68 changed files with 103 additions and 105 deletions

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NETCOREAPP
#if NET
using System.Reflection;
using System.Runtime.InteropServices;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NETCOREAPP
#if NET
using System.Reflection;
using System.Runtime.Loader;

View File

@ -15,7 +15,7 @@ internal class ContinuationGenerator<TTarget, TReturn>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected static TReturn ToTReturn<TFrom>(TFrom returnValue)
{
#if NET8_0_OR_GREATER
#if NET
return Unsafe.As<TFrom, TReturn>(ref returnValue);
#else
return ContinuationsHelper.Convert<TFrom, TReturn>(returnValue);
@ -25,7 +25,7 @@ internal class ContinuationGenerator<TTarget, TReturn>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected static TTo FromTReturn<TTo>(TReturn? returnValue)
{
#if NET8_0_OR_GREATER
#if NET
return Unsafe.As<TReturn?, TTo>(ref returnValue);
#else
return ContinuationsHelper.Convert<TReturn?, TTo>(returnValue);

View File

@ -3,7 +3,7 @@
namespace OpenTelemetry.AutoInstrumentation.CallTarget.Handlers.Continuations;
#if NET8_0_OR_GREATER
#if NET
internal class ValueTaskContinuationGenerator<TIntegration, TTarget, TReturn> : ContinuationGenerator<TTarget, TReturn>
{
private static readonly ContinuationMethodDelegate? _continuation;

View File

@ -5,7 +5,7 @@
namespace OpenTelemetry.AutoInstrumentation.CallTarget.Handlers.Continuations;
#if NET8_0_OR_GREATER
#if NET
internal class ValueTaskContinuationGenerator<TIntegration, TTarget, TReturn, TResult> : ContinuationGenerator<TTarget, TReturn>
{
private static readonly ContinuationMethodDelegate? _continuation;

View File

@ -39,7 +39,7 @@ internal static class EndMethodHandler<TIntegration, TTarget, TReturn>
// The type is a Task<>
_continuationGenerator = (ContinuationGenerator<TTarget, TReturn>?)Activator.CreateInstance(typeof(TaskContinuationGenerator<,,,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType, ContinuationsHelper.GetResultType(returnType)));
}
#if NET8_0_OR_GREATER
#if NET
else if (genericReturnType == typeof(ValueTask<>))
{
// The type is a ValueTask<>
@ -54,7 +54,7 @@ internal static class EndMethodHandler<TIntegration, TTarget, TReturn>
// The type is a Task
_continuationGenerator = new TaskContinuationGenerator<TIntegration, TTarget, TReturn>();
}
#if NET8_0_OR_GREATER
#if NET
else if (returnType == typeof(ValueTask))
{
// The type is a ValueTask

View File

@ -109,7 +109,7 @@ internal partial class ConfigurationKeys
public const string AspNetInstrumentationCaptureResponseHeaders = "OTEL_DOTNET_AUTO_TRACES_ASPNET_INSTRUMENTATION_CAPTURE_RESPONSE_HEADERS";
#endif
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// Configuration key for ASP.NET Core instrumentation to enable capturing HTTP request headers as span tags.
/// </summary>

View File

@ -46,7 +46,7 @@ internal static class DelayedInitialization
new SqlClientInitializer(lazyInstrumentationLoader, pluginManager, tracerSettings);
}
#if NET8_0_OR_GREATER
#if NET
[MethodImpl(MethodImplOptions.NoInlining)]
public static void AddEntityFrameworkCore(LazyInstrumentationLoader lazyInstrumentationLoader, PluginManager pluginManager, TracerSettings tracerSettings)

View File

@ -30,12 +30,12 @@ internal static class EnvironmentConfigurationMetricHelper
MetricInstrumentation.NetRuntime => Wrappers.AddRuntimeInstrumentation(builder, pluginManager),
MetricInstrumentation.Process => Wrappers.AddProcessInstrumentation(builder),
MetricInstrumentation.NServiceBus => builder
#if NET8_0_OR_GREATER
#if NET
.AddMeter("NServiceBus.Core.Pipeline.Incoming") // NServiceBus 9.1.0+
#endif
.AddMeter("NServiceBus.Core"), // NServiceBus [8,0.0, 9.1.0)
#if NET8_0_OR_GREATER
#if NET
MetricInstrumentation.AspNetCore => builder
.AddMeter("Microsoft.AspNetCore.Hosting")
.AddMeter("Microsoft.AspNetCore.Server.Kestrel")
@ -92,7 +92,7 @@ internal static class EnvironmentConfigurationMetricHelper
[MethodImpl(MethodImplOptions.NoInlining)]
public static MeterProviderBuilder AddHttpClientInstrumentation(MeterProviderBuilder builder, LazyInstrumentationLoader lazyInstrumentationLoader)
{
#if NET8_0_OR_GREATER
#if NET
// HTTP has build in support for metrics in .NET8. Executing OpenTelemetry.Instrumentation.Http in this case leads to duplicated metrics.
return builder
.AddMeter("System.Net.Http")

View File

@ -41,7 +41,7 @@ internal static class EnvironmentConfigurationTracerHelper
TracerInstrumentation.WcfClient => AddWcfIfNeeded(builder, ref wcfInstrumentationAdded),
TracerInstrumentation.OracleMda => Wrappers.AddOracleMdaInstrumentation(builder, lazyInstrumentationLoader, settings),
TracerInstrumentation.RabbitMq => builder.AddSource("RabbitMQ.Client.Publisher").AddSource("RabbitMQ.Client.Subscriber"),
#if NET8_0_OR_GREATER
#if NET
TracerInstrumentation.AspNetCore => Wrappers.AddAspNetCoreInstrumentation(builder, pluginManager, lazyInstrumentationLoader, settings),
TracerInstrumentation.MassTransit => builder.AddSource("MassTransit"),
TracerInstrumentation.MySqlData => builder.AddSource("connector-net"),
@ -136,7 +136,7 @@ internal static class EnvironmentConfigurationTracerHelper
}
#endif
#if NET8_0_OR_GREATER
#if NET
[MethodImpl(MethodImplOptions.NoInlining)]
public static TracerProviderBuilder AddAspNetCoreInstrumentation(TracerProviderBuilder builder, PluginManager pluginManager, LazyInstrumentationLoader lazyInstrumentationLoader, TracerSettings tracerSettings)
{
@ -200,7 +200,7 @@ internal static class EnvironmentConfigurationTracerHelper
.AddLegacySource("Quartz.Job.Veto");
}
#if NET8_0_OR_GREATER
#if NET
[MethodImpl(MethodImplOptions.NoInlining)]
public static TracerProviderBuilder AddEntityFrameworkCoreInstrumentation(TracerProviderBuilder builder, PluginManager pluginManager, LazyInstrumentationLoader lazyInstrumentationLoader, TracerSettings tracerSettings)
{

View File

@ -16,7 +16,7 @@ internal class InstrumentationOptions
AspNetInstrumentationCaptureRequestHeaders = configuration.ParseHeaders(ConfigurationKeys.Traces.InstrumentationOptions.AspNetInstrumentationCaptureRequestHeaders, AdditionalTag.CreateHttpRequestCache);
AspNetInstrumentationCaptureResponseHeaders = configuration.ParseHeaders(ConfigurationKeys.Traces.InstrumentationOptions.AspNetInstrumentationCaptureResponseHeaders, AdditionalTag.CreateHttpResponseCache);
#endif
#if NET8_0_OR_GREATER
#if NET
AspNetCoreInstrumentationCaptureRequestHeaders = configuration.ParseHeaders(ConfigurationKeys.Traces.InstrumentationOptions.AspNetCoreInstrumentationCaptureRequestHeaders, AdditionalTag.CreateHttpRequestCache);
AspNetCoreInstrumentationCaptureResponseHeaders = configuration.ParseHeaders(ConfigurationKeys.Traces.InstrumentationOptions.AspNetCoreInstrumentationCaptureResponseHeaders, AdditionalTag.CreateHttpResponseCache);
EntityFrameworkCoreSetDbStatementForText = configuration.GetBool(ConfigurationKeys.Traces.InstrumentationOptions.EntityFrameworkCoreSetDbStatementForText) ?? false;
@ -43,7 +43,7 @@ internal class InstrumentationOptions
public IReadOnlyList<AdditionalTag> AspNetInstrumentationCaptureResponseHeaders { get; }
#endif
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// Gets the list of HTTP request headers to be captured as the span tags by ASP.NET Core instrumentation.
/// </summary>

View File

@ -35,7 +35,7 @@ internal enum MetricInstrumentation
/// </summary>
NServiceBus = 5,
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// ASP.NET Core instrumentation.
/// </summary>

View File

@ -26,7 +26,7 @@ internal static class ResourceConfigurator
{
resourceBuilder = enabledResourceDetector switch
{
#if NET8_0_OR_GREATER
#if NET
ResourceDetector.Container => Wrappers.AddContainerResourceDetector(resourceBuilder),
#endif
ResourceDetector.AzureAppService => Wrappers.AddAzureAppServiceResourceDetector(resourceBuilder),
@ -56,7 +56,7 @@ internal static class ResourceConfigurator
private static class Wrappers
{
#if NET8_0_OR_GREATER
#if NET
[MethodImpl(MethodImplOptions.NoInlining)]
public static ResourceBuilder AddContainerResourceDetector(ResourceBuilder resourceBuilder)
{

View File

@ -8,7 +8,7 @@ namespace OpenTelemetry.AutoInstrumentation.Configurations;
/// </summary>
internal enum ResourceDetector
{
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// Container resource detector.
/// </summary>

View File

@ -25,7 +25,7 @@ internal enum TracerInstrumentation
/// </summary>
SqlClient = 2,
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// GraphQL instrumentation.
/// </summary>
@ -42,7 +42,7 @@ internal enum TracerInstrumentation
/// </summary>
Npgsql = 5,
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// MySqlData instrumentation.
/// </summary>
@ -65,7 +65,7 @@ internal enum TracerInstrumentation
WcfService = 9,
#endif
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// MassTransit instrumentation.
/// </summary>
@ -87,7 +87,7 @@ internal enum TracerInstrumentation
/// </summary>
Quartz = 13,
#if NET8_0_OR_GREATER
#if NET
/// <summary>
/// Entity Framework Core instrumentation.
/// </summary>

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using OpenTelemetry.AutoInstrumentation.Logging;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Diagnostics;
using System.Globalization;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Runtime.InteropServices;
namespace OpenTelemetry.AutoInstrumentation;

View File

@ -4,7 +4,7 @@
using System.Collections.Specialized;
using System.Diagnostics;
using System.Net.Http.Headers;
#if NET8_0_OR_GREATER
#if NET
using Microsoft.AspNetCore.Http;
#endif
@ -40,7 +40,7 @@ internal static class ActivityExtensions
}
}
#if NET8_0_OR_GREATER
#if NET
public static void AddHeadersAsTags(this Activity activity, IReadOnlyList<AdditionalTag> additionalTags, IHeaderDictionary headers)
{
if (!activity.IsAllDataRequested)

View File

@ -1,11 +1,11 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Diagnostics;
#endif
using OpenTelemetry.AutoInstrumentation.Configurations;
#if NET8_0_OR_GREATER
#if NET
using OpenTelemetry.AutoInstrumentation.ContinuousProfiler;
#endif
using OpenTelemetry.AutoInstrumentation.Diagnostics;
@ -33,7 +33,7 @@ internal static class Instrumentation
private static MeterProvider? _meterProvider;
private static PluginManager? _pluginManager;
#if NET8_0_OR_GREATER
#if NET
private static ContinuousProfilerProcessor? _profilerProcessor;
#endif
@ -89,7 +89,7 @@ internal static class Instrumentation
_pluginManager = new PluginManager(GeneralSettings.Value);
_pluginManager.Initializing();
#if NET8_0_OR_GREATER
#if NET
var profilerEnabled = GeneralSettings.Value.ProfilerEnabled;
if (profilerEnabled)
@ -217,7 +217,7 @@ internal static class Instrumentation
}
}
#if NET8_0_OR_GREATER
#if NET
private static void InitializeContinuousProfiling(
object continuousProfilerExporter,
bool threadSamplingEnabled,
@ -335,7 +335,7 @@ internal static class Instrumentation
break;
case TracerInstrumentation.WcfClient:
break;
#if NET8_0_OR_GREATER
#if NET
case TracerInstrumentation.AspNetCore:
DelayedInitialization.Traces.AddAspNetCore(lazyInstrumentationLoader, pluginManager, tracerSettings);
break;
@ -394,7 +394,7 @@ internal static class Instrumentation
try
{
#if NET8_0_OR_GREATER
#if NET
LazyInstrumentationLoader?.Dispose();
if (_profilerProcessor != null)
{

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using OpenTelemetry.AutoInstrumentation.CallTarget;
namespace OpenTelemetry.AutoInstrumentation.Instrumentations.Logger;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
namespace OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
namespace OpenTelemetry.AutoInstrumentation.Instrumentations.StackExchangeRedis;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using OpenTelemetry.AutoInstrumentation.CallTarget;
using OpenTelemetry.AutoInstrumentation.Configurations;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using OpenTelemetry.AutoInstrumentation.CallTarget;

View File

@ -38,7 +38,7 @@ namespace OpenTelemetry.AutoInstrumentation.Instrumentations.Wcf.Client;
maximumVersion: WcfCommonConstants.Max4Version,
integrationName: WcfClientConstants.IntegrationName,
type: InstrumentationType.Trace)]
#if NET8_0_OR_GREATER
#if NET
[InstrumentMethod(
assemblyName: WcfCommonConstants.ServiceModelPrimitivesAssemblyName,
typeName: WcfClientConstants.ChannelFactoryTypeName,

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using OpenTelemetry.AutoInstrumentation.Configurations;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using OpenTelemetry.AutoInstrumentation.Configurations;
using OpenTelemetry.AutoInstrumentation.Plugins;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

View File

@ -43,7 +43,7 @@ internal static class NativeMethods
}
}
#if NET8_0_OR_GREATER
#if NET
public static void ConfigureNativeContinuousProfiler(bool threadSamplingEnabled, uint threadSamplingInterval, bool allocationSamplingEnabled, uint maxMemorySamplesPerMinute)
{
if (IsWindows)
@ -92,7 +92,7 @@ internal static class NativeMethods
[DllImport("OpenTelemetry.AutoInstrumentation.Native.dll")]
public static extern void ConfigureContinuousProfiler(bool threadSamplingEnabled, uint threadSamplingInterval, bool allocationSamplingEnabled, uint maxMemorySamplesPerMinute);
#if NET8_0_OR_GREATER
#if NET
[DllImport("OpenTelemetry.AutoInstrumentation.Native.dll")]
public static extern int ContinuousProfilerReadThreadSamples(int len, byte[] buf);
@ -117,7 +117,7 @@ internal static class NativeMethods
[DllImport("OpenTelemetry.AutoInstrumentation.Native")]
public static extern void ConfigureContinuousProfiler(bool threadSamplingEnabled, uint threadSamplingInterval, bool allocationSamplingEnabled, uint maxMemorySamplesPerMinute);
#if NET8_0_OR_GREATER
#if NET
[DllImport("OpenTelemetry.AutoInstrumentation.Native")]
public static extern int ContinuousProfilerReadThreadSamples(int len, byte[] buf);

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
namespace OpenTelemetry.AutoInstrumentation.Plugins;

View File

@ -6,7 +6,7 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly: InternalsVisibleTo("IntegrationTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001008db7c66f4ebdc6aac4196be5ce1ff4b59b020028e6dbd6e46f15aa40b3215975b92d0a8e45aba5f36114a8cb56241fbfa49f4c017e6c62197857e4e9f62451bc23d3a660e20861f95a57f23e20c77d413ad216ff1bb55f94104d4c501e32b03219d8603fb6fa73401c6ae6808c8daa61b9eaee5d2377d3c23c9ca6016c6582d8")]
[assembly: InternalsVisibleTo("NuGetPackagesTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001008db7c66f4ebdc6aac4196be5ce1ff4b59b020028e6dbd6e46f15aa40b3215975b92d0a8e45aba5f36114a8cb56241fbfa49f4c017e6c62197857e4e9f62451bc23d3a660e20861f95a57f23e20c77d413ad216ff1bb55f94104d4c501e32b03219d8603fb6fa73401c6ae6808c8daa61b9eaee5d2377d3c23c9ca6016c6582d8")]
#if NET8_0_OR_GREATER
#if NET
[assembly: InternalsVisibleTo("OpenTelemetry.AutoInstrumentation.AspNetCoreBootstrapper, PublicKey=00240000048000009400000006020000002400005253413100040000010001008db7c66f4ebdc6aac4196be5ce1ff4b59b020028e6dbd6e46f15aa40b3215975b92d0a8e45aba5f36114a8cb56241fbfa49f4c017e6c62197857e4e9f62451bc23d3a660e20861f95a57f23e20c77d413ad216ff1bb55f94104d4c501e32b03219d8603fb6fa73401c6ae6808c8daa61b9eaee5d2377d3c23c9ca6016c6582d8")]
#endif
[assembly: InternalsVisibleTo("OpenTelemetry.AutoInstrumentation.Bootstrapping.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001008db7c66f4ebdc6aac4196be5ce1ff4b59b020028e6dbd6e46f15aa40b3215975b92d0a8e45aba5f36114a8cb56241fbfa49f4c017e6c62197857e4e9f62451bc23d3a660e20861f95a57f23e20c77d413ad216ff1bb55f94104d4c501e32b03219d8603fb6fa73401c6ae6808c8daa61b9eaee5d2377d3c23c9ca6016c6582d8")]

View File

@ -17,7 +17,7 @@
// ReSharper disable once CheckNamespace
namespace System.Diagnostics.CodeAnalysis;
#if !NETCOREAPP3_0_OR_GREATER
#if NETFRAMEWORK
/// <summary>Specifies that null is allowed as an input even if the corresponding type disallows it.</summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property)]
internal sealed class AllowNullAttribute : Attribute
@ -124,8 +124,6 @@ internal sealed class MemberNotNullAttribute : Attribute
/// <summary>Gets field or property member names.</summary>
public string[] Members { get; }
}
#endif
#if !NET5_0_OR_GREATER
/// <summary>Specifies that the method or property will ensure that the listed field and property members have not-null values when returning with the specified return value condition.</summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]

View File

@ -29,7 +29,7 @@ public class AzureTests : TestHelper
collector.Expect("Azure.Core.Http");
collector.Expect("Azure.Storage.Blobs.BlobContainerClient");
#if NET8_0_OR_GREATER
#if NET
collector.Expect("System.Net.Http");
#elif NETFRAMEWORK
// On .NET Framework the "OpenTelemetry.Instrumentation.Http.HttpWebRequest"

View File

@ -31,7 +31,7 @@ public class BuildTests
.DisableDiff();
}
#if NET8_0_OR_GREATER
#if NET
[Fact]
public void NetFolderDoesNotContainAnyLibraryFromAdditionalStore()
{

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Text.Json;
using FluentAssertions;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Profiles.V1Experimental;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using Google.Protobuf;
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Trace.V1;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if !NETFRAMEWORK
#if NET
using FluentAssertions;
using IntegrationTests.Helpers;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using Xunit.Abstractions;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using Xunit.Abstractions;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Net;
using System.Text;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using Microsoft.AspNetCore.Http;
namespace IntegrationTests.Helpers;

View File

@ -7,7 +7,7 @@ using System.Text;
#endif
using Google.Protobuf;
#if NET8_0_OR_GREATER
#if NET
using Microsoft.AspNetCore.Http;
#endif
@ -41,7 +41,7 @@ internal static class CollectorResponseHelper
}
#endif
#if NET8_0_OR_GREATER
#if NET
public static async Task GenerateEmptyProtobufResponseAsync<T>(this HttpContext ctx)
where T : IMessage, new()
{

View File

@ -7,7 +7,7 @@ internal static class DirectoryHelpers
{
public static DirectoryInfo CreateTempDirectory()
{
#if NET8_0_OR_GREATER
#if NET
return Directory.CreateTempSubdirectory("native_logs");
#else
var tempDir = Path.Combine(Path.GetTempPath(), "native_logs_" + Path.GetRandomFileName());

View File

@ -1,6 +1,6 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Collections.Concurrent;
using System.Diagnostics;
using FluentAssertions;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Collections.Concurrent;
using System.Text;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using Microsoft.AspNetCore.Http;
namespace IntegrationTests.Helpers;

View File

@ -72,7 +72,7 @@ public abstract class TestHelper
SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", $"http://localhost:{collector.Port}");
}
#if NET8_0_OR_GREATER
#if NET
public void SetExporter(MockProfilesCollector collector)
{
SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", $"http://localhost:{collector.Port}");

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using System.Net;
using Microsoft.AspNetCore.Builder;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using FluentAssertions;
using FluentAssertions.Execution;
using IntegrationTests.Helpers;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Logs.V1;
using Xunit.Abstractions;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using Xunit.Abstractions;
using static OpenTelemetry.Proto.Trace.V1.Span.Types;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Logs.V1;

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using Xunit.Abstractions;

View File

@ -44,7 +44,7 @@ public class NServiceBusTests : TestHelper
using var collector = new MockMetricsCollector(Output);
SetExporter(collector);
#if NET8_0_OR_GREATER
#if NET
if (string.IsNullOrEmpty(packageVersion) || Version.Parse(packageVersion) >= new Version(9, 1))
{
collector.Expect("NServiceBus.Core.Pipeline.Incoming");

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;

View File

@ -151,7 +151,7 @@ public class SmokeTests : TestHelper
collector.ResourceExpector.AssertExpectations();
}
#if NET8_0_OR_GREATER // The feature is not supported on .NET Framework
#if NET // The feature is not supported on .NET Framework
[Fact]
[Trait("Category", "EndToEnd")]
public void LogsResource()
@ -360,7 +360,7 @@ public class SmokeTests : TestHelper
}
#endif
#if NET8_0_OR_GREATER // The feature is not supported on .NET Framework
#if NET // The feature is not supported on .NET Framework
[Fact]
[Trait("Category", "EndToEnd")]
public void SubmitLogs()

View File

@ -23,7 +23,7 @@ public class SqlClientSystemTests : TestHelper
foreach (var version in LibraryVersion.SqlClientSystem)
{
#if NET8_0_OR_GREATER
#if NET
theoryData.Add(version, true);
#endif
theoryData.Add(version, false);

View File

@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET8_0_OR_GREATER
#if NET
using IntegrationTests.Helpers;
using Xunit.Abstractions;

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
// This test won't work outside of windows as it need the server side which is .NET Framework only.
#if NET8_0_OR_GREATER && _WINDOWS
#if NET && _WINDOWS
using Xunit.Abstractions;
namespace IntegrationTests;

View File

@ -1,12 +1,12 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#if NET
using IntegrationTests.Helpers;
using OpenTelemetry.Proto.Logs.V1;
using Xunit.Abstractions;
#if NET8_0_OR_GREATER
namespace IntegrationTests;
public class WorkerTests : TestHelper

View File

@ -20,7 +20,7 @@ public sealed class InstrumentationTargetTests : TestHelper
{
}
#if !NETFRAMEWORK
#if NET
[Fact]
public void PublishApplication()
{
@ -120,7 +120,7 @@ public sealed class InstrumentationTargetTests : TestHelper
}
}
#if !NETFRAMEWORK
#if NET
private void RunDotnetPublish(string arguments, bool expectWarning)
{
const string warningMessage = "RuntimeIdentifier (RID) is not set." +

View File

@ -35,7 +35,7 @@ public sealed class NugetSampleTests : TestHelper
InstrumentExecutable(_ridSpecificAppDir);
}
#if !NETFRAMEWORK
#if NET
[Fact]
public void InstrumentExecutableFromBaseDir()
{
@ -90,7 +90,7 @@ public sealed class NugetSampleTests : TestHelper
#endif
}
#if !NETFRAMEWORK
#if NET
private void InstrumentDll(string appDir)
{
RunAndAssertHttpSpans(() =>
@ -148,7 +148,7 @@ public sealed class NugetSampleTests : TestHelper
#if NETFRAMEWORK
collector.Expect("OpenTelemetry.Instrumentation.Http.HttpWebRequest");
#elif NET8_0_OR_GREATER
#elif NET
collector.Expect("System.Net.Http");
#endif

View File

@ -58,7 +58,7 @@ public class SettingsTests : IDisposable
settings.InstrumentationOptions.AspNetInstrumentationCaptureRequestHeaders.Should().BeEmpty();
settings.InstrumentationOptions.AspNetInstrumentationCaptureResponseHeaders.Should().BeEmpty();
#endif
#if NET8_0_OR_GREATER
#if NET
settings.InstrumentationOptions.AspNetCoreInstrumentationCaptureRequestHeaders.Should().BeEmpty();
settings.InstrumentationOptions.AspNetCoreInstrumentationCaptureResponseHeaders.Should().BeEmpty();
settings.InstrumentationOptions.EntityFrameworkCoreSetDbStatementForText.Should().BeFalse();
@ -292,12 +292,12 @@ public class SettingsTests : IDisposable
#if NETFRAMEWORK
[InlineData("ASPNET", TracerInstrumentation.AspNet)]
#endif
#if NET8_0_OR_GREATER
#if NET
[InlineData("GRAPHQL", TracerInstrumentation.GraphQL)]
#endif
[InlineData("HTTPCLIENT", TracerInstrumentation.HttpClient)]
[InlineData("MONGODB", TracerInstrumentation.MongoDB)]
#if NET8_0_OR_GREATER
#if NET
[InlineData("MYSQLDATA", TracerInstrumentation.MySqlData)]
[InlineData("STACKEXCHANGEREDIS", TracerInstrumentation.StackExchangeRedis)]
#endif
@ -307,13 +307,13 @@ public class SettingsTests : IDisposable
#if NETFRAMEWORK
[InlineData("WCFSERVICE", TracerInstrumentation.WcfService)]
#endif
#if NET8_0_OR_GREATER
#if NET
[InlineData("MASSTRANSIT", TracerInstrumentation.MassTransit)]
#endif
[InlineData("NSERVICEBUS", TracerInstrumentation.NServiceBus)]
[InlineData("ELASTICSEARCH", TracerInstrumentation.Elasticsearch)]
[InlineData("QUARTZ", TracerInstrumentation.Quartz)]
#if NET8_0_OR_GREATER
#if NET
[InlineData("ENTITYFRAMEWORKCORE", TracerInstrumentation.EntityFrameworkCore)]
[InlineData("ASPNETCORE", TracerInstrumentation.AspNetCore)]
#endif
@ -342,7 +342,7 @@ public class SettingsTests : IDisposable
[InlineData("HTTPCLIENT", MetricInstrumentation.HttpClient)]
[InlineData("PROCESS", MetricInstrumentation.Process)]
[InlineData("NSERVICEBUS", MetricInstrumentation.NServiceBus)]
#if NET8_0_OR_GREATER
#if NET
[InlineData("ASPNETCORE", MetricInstrumentation.AspNetCore)]
#endif
internal void MeterSettings_Instrumentations_SupportedValues(string meterInstrumentation, MetricInstrumentation expectedMetricInstrumentation)
@ -410,7 +410,7 @@ public class SettingsTests : IDisposable
}
[Theory]
#if NET8_0_OR_GREATER
#if NET
[InlineData("CONTAINER", ResourceDetector.Container)]
#endif
[InlineData("AZUREAPPSERVICE", ResourceDetector.AzureAppService)]
@ -470,7 +470,7 @@ public class SettingsTests : IDisposable
Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.InstrumentationOptions.AspNetInstrumentationCaptureResponseHeaders, null);
#endif
#if NET8_0_OR_GREATER
#if NET
Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.InstrumentationOptions.AspNetCoreInstrumentationCaptureRequestHeaders, null);
Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.InstrumentationOptions.AspNetCoreInstrumentationCaptureResponseHeaders, null);
Environment.SetEnvironmentVariable(ConfigurationKeys.Traces.InstrumentationOptions.GraphQLSetDocument, null);

View File

@ -7,7 +7,7 @@ internal static class DirectoryHelpers
{
public static DirectoryInfo CreateTempDirectory()
{
#if NET8_0_OR_GREATER
#if NET
return Directory.CreateTempSubdirectory("managed_logs");
#else
var tempDir = Path.Combine(Path.GetTempPath(), "managed_logs_" + Path.GetRandomFileName());

View File

@ -121,7 +121,7 @@ public static class Program
// lazily-loaded metric instrumentation
.AddMeter("OpenTelemetry.Instrumentation.*")
// bytecode metric instrumentation
#if NET8_0_OR_GREATER
#if NET
.AddMeter("NServiceBus.Core.Pipeline.Incoming")
#else
.AddMeter("NServiceBus.Core")

View File

@ -7,7 +7,7 @@ using Greet;
using Grpc.Core;
using Grpc.Net.Client;
using IntegrationTests.Helpers;
#if !NETFRAMEWORK
#if NET
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
@ -23,7 +23,7 @@ ConsoleHelper.WriteSplashScreen(args);
var port = TcpPortProvider.GetOpenPort();
#if !NETFRAMEWORK
#if NET
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(serverOptions =>
@ -73,6 +73,6 @@ catch (RpcException e)
Console.WriteLine(e);
}
#if !NETFRAMEWORK
#if NET
app.Lifetime.StopApplication();
#endif