diff --git a/.cspell/dot-net.txt b/.cspell/dot-net.txt
index dcdd2541f6..f0221a4f9e 100644
--- a/.cspell/dot-net.txt
+++ b/.cspell/dot-net.txt
@@ -1,35 +1,36 @@
-CORECLR
-netcoreapp
-NGEN
+aspnet
+ASPNETCORE
+ASSERTE
+Bootstrapper
+callq
CLSID
-MSVC
+CONTRACTL
+CORECLR
+corelib
corerun
-lldb
-SIGUSR
-callq
-movq
-movl
+corprof
+cref
dlerror
-popq
-libcoreclr
+dlopen
eetoprofinterfaceimpl
+HOSTINGSTARTUPASSEMBLIES
+idls
+iisreset
+ILREWRITE
+libcoreclr
+lldb
LPCSTR
-ASSERTE
-CONTRACTL
+midl
+movl
+movq
+MSVC
+netcoreapp
+NETFX
+NGEN
nullptr
-dlopen
-ILREWRITE
-aspnet
+popq
+pwsh
+SIGUSR
+stdlibc
struct
typeof
-cref
-corprof
-idls
-midl
-stdlibc
-corelib
-ASPNETCORE
-HOSTINGSTARTUPASSEMBLIES
-Bootstrapper
-NETFX
-iisreset
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad069eb046..e0d333eb62 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,10 @@ This beta release is built on top of [OpenTelemetry .NET](https://github.com/ope
- `OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_LOGS_INSTRUMENTATION_ENABLED`,
- `OTEL_DOTNET_AUTO_LOGS_{0}_INSTRUMENTATION_ENABLED`.
+- Set the default of `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES` to
+ `dotnet,dotnet.exe,powershell.exe,pwsh,pwsh.exe`.
+- Unset, in the StartupHook, the `DOTNET_ADDITIONAL_DEPS`, `DOTNET_SHARED_STORE`,
+ and `DOTNET_STARTUP_HOOKS` environment variables, for processes in `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES`.
### Deprecated
diff --git a/docs/config.md b/docs/config.md
index 2a10c151f5..04c90cd607 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -44,10 +44,10 @@ However, if given setting supports it, then:
## Global settings
-| Environment variable | Description | Default value |
-|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
-| `OTEL_DOTNET_AUTO_HOME` | Installation location. | |
-| `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES` | Names of the executable files that the profiler cannot instrument. Supports multiple comma-separated values, for example: `ReservedProcess.exe,powershell.exe`. If unset, the profiler attaches to all processes by default. | |
+| Environment variable | Description | Default value |
+|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------|
+| `OTEL_DOTNET_AUTO_HOME` | Installation location. | |
+| `OTEL_DOTNET_AUTO_EXCLUDE_PROCESSES` | Names of the executable files that the profiler cannot instrument. Supports multiple comma-separated values, for example: `ReservedProcess.exe,powershell.exe`. | dotnet,dotnet.exe,powershell.exe,pwsh,pwsh.exe |
## Resources
diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props
index 91b37107df..832ac06c70 100644
--- a/src/Directory.Packages.props
+++ b/src/Directory.Packages.props
@@ -40,7 +40,7 @@
-
+
@@ -68,4 +68,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Build.props b/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Build.props
index 4659de022b..830a5b162f 100644
--- a/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Build.props
+++ b/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Build.props
@@ -3,7 +3,9 @@
+
+
diff --git a/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Packages.props b/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Packages.props
index e3e4302534..4d0c26ab18 100644
--- a/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Packages.props
+++ b/src/OpenTelemetry.AutoInstrumentation.AdditionalDeps/Directory.Packages.props
@@ -4,9 +4,11 @@
-
-
-
+
+
+
+
+
diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp
index 58814e46c4..83666e5584 100644
--- a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp
+++ b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp
@@ -104,7 +104,14 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
#endif
const auto process_name = GetCurrentProcessName();
- const auto exclude_process_names = GetEnvironmentValues(environment::exclude_process_names);
+ auto exclude_process_names = GetEnvironmentValues(environment::exclude_process_names);
+ if (exclude_process_names.empty())
+ {
+ exclude_process_names = std::vector
+ {
+ WStr("powershell.exe"), WStr("pwsh"), WStr("pwsh.exe")
+ };
+ }
// attach profiler only if this process's name is NOT on the list
if (!exclude_process_names.empty() && Contains(exclude_process_names, process_name))
@@ -114,6 +121,9 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
return E_FAIL;
}
+ Logger::Info("Profiler NOT disabled: ", process_name, " NOT found in ",
+ environment::exclude_process_names, ".");
+
if (runtime_information_.is_core())
{
// .NET Core applications should use the dotnet startup hook to bootstrap OpenTelemetry so that the
diff --git a/src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs b/src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs
index 5697877c00..6eb942b04e 100644
--- a/src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs
+++ b/src/OpenTelemetry.AutoInstrumentation.StartupHook/StartupHook.cs
@@ -53,6 +53,12 @@ public static void Initialize()
if (IsApplicationInExcludeList(applicationName))
{
Logger.LogInformation("Application is in the exclusion list. Skipping initialization.");
+
+ // TODO: Non-destructive clean-up: remove only OTel .NET AutoInstrumentaion related paths.
+ Environment.SetEnvironmentVariable("DOTNET_ADDITIONAL_DEPS", null);
+ Environment.SetEnvironmentVariable("DOTNET_SHARED_STORE", null);
+ Environment.SetEnvironmentVariable("DOTNET_STARTUP_HOOKS", null);
+
return;
}
@@ -138,7 +144,10 @@ private static List GetExcludedApplicationNames()
if (environmentValue == null)
{
- return excludedProcesses;
+ return new List
+ {
+ "powershell.exe", "pwsh", "pwsh.exe"
+ };
}
foreach (var processName in environmentValue.Split(Constants.ConfigurationValues.Separator))
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs
index f42066e470..b1381a2cb6 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs
@@ -14,11 +14,6 @@
// limitations under the License.
//
-using System.Diagnostics;
-using System.Diagnostics.Metrics;
-using OpenTelemetry.AutoInstrumentation.Instrumentations.GraphQL;
-using OpenTelemetry.Logs;
-
namespace OpenTelemetry.AutoInstrumentation.Configurations;
///
@@ -97,7 +92,7 @@ public static class Traces
public const string EnabledTracesInstrumentationTemplate = "OTEL_DOTNET_AUTO_TRACES_{0}_INSTRUMENTATION_ENABLED";
///
- /// Configuration key for additional names to be added to the tracer at the startup.
+ /// Configuration key for additional ActivitySource names to be added to the tracer at the startup.
///
public const string AdditionalSources = "OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES";
@@ -123,7 +118,6 @@ public static class InstrumentationOptions
{
///
/// Configuration key for GraphQL instrumentation to enable passing query as a document attribute.
- /// See .
///
public const string GraphQLSetDocument = "OTEL_DOTNET_AUTO_GRAPHQL_SET_DOCUMENT";
}
@@ -161,7 +155,7 @@ public static class Metrics
public const string EnabledMetricsInstrumentationTemplate = "OTEL_DOTNET_AUTO_METRICS_{0}_INSTRUMENTATION_ENABLED";
///
- /// Configuration key for additional names to be added to the meter at the startup.
+ /// Configuration key for additional "Meter" names to be added to the meter at the startup.
///
public const string AdditionalSources = "OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES";
}
@@ -189,7 +183,7 @@ public static class Logs
///
/// Configuration key for whether or not formatted log message
- /// should be included on generated s.
+ /// should be included on generated.
///
public const string IncludeFormattedMessage = "OTEL_DOTNET_AUTO_LOGS_INCLUDE_FORMATTED_MESSAGE";
diff --git a/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs b/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs
index a429c7dcfb..75d77e72ed 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Configurations/DelayedInitialization.cs
@@ -87,7 +87,7 @@ public static void AddAspNet(LazyInstrumentationLoader lazyInstrumentationLoader
{
#if NET462
new AspNetMetricsInitializer(lazyInstrumentationLoader);
-#elif NET6_0_OR_GREATER
+#elif NET6_0_OR_GREATER && _INCLUDE_ASP_NET_CORE_
lazyInstrumentationLoader.Add(new AspNetCoreMetricsInitializer());
#endif
}
diff --git a/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreInitializer.cs b/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreInitializer.cs
index eea286360e..bf0cc0a996 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreInitializer.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreInitializer.cs
@@ -34,10 +34,10 @@ public override void Initialize(ILifespanManager lifespanManager)
var instrumentationType = Type.GetType("OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentation, OpenTelemetry.Instrumentation.AspNetCore")!;
var httpInListenerType = Type.GetType("OpenTelemetry.Instrumentation.AspNetCore.Implementation.HttpInListener, OpenTelemetry.Instrumentation.AspNetCore")!;
- var options = new OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions();
- _pluginManager.ConfigureTracesOptions(options);
+ // var options = new OpenTelemetry.Instrumentation.AspNetCore.AspNetCoreInstrumentationOptions();
+ // _pluginManager.ConfigureTracesOptions(options);
- var httpInListener = Activator.CreateInstance(httpInListenerType, args: options);
+ var httpInListener = Activator.CreateInstance(httpInListenerType);
var instrumentation = Activator.CreateInstance(instrumentationType, args: httpInListener)!;
lifespanManager.Track(instrumentation);
diff --git a/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreMetricsInitializer.cs b/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreMetricsInitializer.cs
index c27c77cfe2..1863094434 100644
--- a/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreMetricsInitializer.cs
+++ b/src/OpenTelemetry.AutoInstrumentation/Loading/Initializers/AspNetCoreMetricsInitializer.cs
@@ -14,7 +14,7 @@
// limitations under the License.
//
-#if NET6_0_OR_GREATER
+#if NET6_0_OR_GREATER && _INCLUDE_ASP_NET_CORE_
using System.Reflection;
using OpenTelemetry.Instrumentation.AspNetCore;
diff --git a/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj b/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj
index f9199badeb..c4d5ade486 100644
--- a/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj
+++ b/src/OpenTelemetry.AutoInstrumentation/OpenTelemetry.AutoInstrumentation.csproj
@@ -33,7 +33,6 @@
-
@@ -69,4 +68,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/IntegrationTests/DotNetCliTests.cs b/test/IntegrationTests/DotNetCliTests.cs
new file mode 100644
index 0000000000..545679ac87
--- /dev/null
+++ b/test/IntegrationTests/DotNetCliTests.cs
@@ -0,0 +1,115 @@
+//
+// Copyright The OpenTelemetry Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#if !NETFRAMEWORK
+
+using System.Runtime.InteropServices;
+using FluentAssertions;
+using IntegrationTests.Helpers;
+using Org.BouncyCastle.Asn1.X509;
+using Xunit.Abstractions;
+using Timeout = IntegrationTests.Helpers.Timeout;
+
+namespace IntegrationTests;
+
+[Trait("Category", "EndToEnd")]
+public sealed class DotNetCliTests : TestHelper, IDisposable
+{
+ private const string DotNetCli = "dotnet";
+ private const string TargetAppName = "OTelDotNetCliTest";
+
+ private readonly string _prevWorkingDir = Directory.GetCurrentDirectory();
+ private readonly DirectoryInfo _tempWorkingDir;
+
+ public DotNetCliTests(ITestOutputHelper output)
+ : base(DotNetCli, output)
+ {
+ var tempDirName = Path.Combine(
+ Path.GetTempPath(),
+ $"otel-dotnet-test-{Guid.NewGuid():N}",
+ TargetAppName);
+ _tempWorkingDir = Directory.CreateDirectory(tempDirName);
+
+ Directory.SetCurrentDirectory(_tempWorkingDir.FullName);
+ }
+
+ [Fact]
+ public void ExecuteDotNetCliWorkFlow()
+ {
+ var tfm = $"net{Environment.Version.Major}.0";
+ RunDotNetCli($"new console --framework {tfm}");
+
+ ChangeDefaultProgramToHttpClient();
+
+ RunDotNetCli("build");
+
+ using var collector = new MockSpansCollector(Output);
+ SetExporter(collector);
+
+#if NET7_0_OR_GREATER
+ collector.Expect("System.Net.Http");
+#else
+ collector.Expect("OpenTelemetry.Instrumentation.Http.HttpClient");
+#endif
+
+ // "dotnet run" is not supported, however, "dotnet " is expected to work.
+ var targetAppDllPath = Path.Combine(".", "bin", "Debug", tfm, TargetAppName + ".dll");
+ RunDotNetCli(targetAppDllPath);
+
+ collector.AssertExpectations();
+ }
+
+ public void Dispose()
+ {
+ Directory.SetCurrentDirectory(_prevWorkingDir);
+ _tempWorkingDir.Delete(recursive: true);
+ }
+
+ private static void ChangeDefaultProgramToHttpClient()
+ {
+ const string ProgramContent = @"
+using var httpClient = new HttpClient();
+using var response = await httpClient.GetAsync(""http://example.com"");
+Console.WriteLine(response.StatusCode);
+";
+
+ File.WriteAllText("Program.cs", ProgramContent);
+ }
+
+ private void RunDotNetCli(string arguments)
+ {
+ Output.WriteLine($"Running: {DotNetCli} {arguments}");
+
+ using var process = InstrumentedProcessHelper.Start(DotNetCli, arguments, EnvironmentHelper);
+ using var helper = new ProcessHelper(process);
+
+ process.Should().NotBeNull();
+
+ bool processTimeout = !process!.WaitForExit((int)Timeout.ProcessExit.TotalMilliseconds);
+ if (processTimeout)
+ {
+ process.Kill();
+ }
+
+ Output.WriteLine("ProcessId: " + process.Id);
+ Output.WriteLine("Exit Code: " + process.ExitCode);
+ Output.WriteResult(helper);
+
+ processTimeout.Should().BeFalse("Test application timed out");
+ process.ExitCode.Should().Be(0, "Test application exited with non-zero exit code");
+ }
+}
+#endif
diff --git a/test/IntegrationTests/Helpers/CollectorResponseHelper.cs b/test/IntegrationTests/Helpers/CollectorResponseHelper.cs
index 27c1b5aea5..4e43f802c0 100644
--- a/test/IntegrationTests/Helpers/CollectorResponseHelper.cs
+++ b/test/IntegrationTests/Helpers/CollectorResponseHelper.cs
@@ -28,7 +28,6 @@ namespace IntegrationTests.Helpers;
internal static class CollectorResponseHelper
{
-#if NETFRAMEWORK
public static void GenerateEmptyProtobufResponse(this HttpListenerContext ctx)
where T : IMessage, new()
{
@@ -52,28 +51,4 @@ public static void GenerateEmptyJsonResponse(this HttpListenerContext ctx)
ctx.Response.OutputStream.Write(buffer, 0, buffer.Length);
ctx.Response.Close();
}
-#endif
-
-#if NET6_0_OR_GREATER
- public static async Task GenerateEmptyProtobufResponseAsync(this HttpContext ctx)
- where T : IMessage, new()
- {
- ctx.Response.ContentType = "application/x-protobuf";
- ctx.Response.StatusCode = (int)HttpStatusCode.OK;
- var responseMessage = new T();
- ctx.Response.ContentLength = responseMessage.CalculateSize();
-
- using var outMemory = new MemoryStream();
- responseMessage.WriteTo(outMemory);
-
- await ctx.Response.Body.WriteAsync(outMemory.GetBuffer(), 0, (int)outMemory.Length);
- await ctx.Response.CompleteAsync();
- }
-
- public static async Task GenerateEmptyJsonResponseAsync(this HttpContext ctx)
- {
- ctx.Response.ContentType = "application/json";
- await ctx.Response.WriteAsync("{}");
- }
-#endif
}
diff --git a/test/IntegrationTests/Helpers/MockLogsCollector.cs b/test/IntegrationTests/Helpers/MockLogsCollector.cs
index 1eb52f6750..75dad9cf85 100644
--- a/test/IntegrationTests/Helpers/MockLogsCollector.cs
+++ b/test/IntegrationTests/Helpers/MockLogsCollector.cs
@@ -15,17 +15,12 @@
//
using System.Collections.Concurrent;
+using System.Net;
using System.Text;
using OpenTelemetry.Proto.Collector.Logs.V1;
using OpenTelemetry.Proto.Logs.V1;
using Xunit.Abstractions;
-#if NETFRAMEWORK
-using System.Net;
-#else
-using Microsoft.AspNetCore.Http;
-#endif
-
namespace IntegrationTests.Helpers;
public class MockLogsCollector : IDisposable
@@ -39,11 +34,7 @@ public MockLogsCollector(ITestOutputHelper output, string host = "localhost")
{
_output = output;
-#if NETFRAMEWORK
_listener = new(output, HandleHttpRequests, host, "/v1/logs/");
-#else
- _listener = new(output, HandleHttpRequests, "/v1/logs");
-#endif
}
///
@@ -163,7 +154,6 @@ private static void FailExpectations(
Assert.Fail(message.ToString());
}
-#if NETFRAMEWORK
private void HandleHttpRequests(HttpListenerContext ctx)
{
var logsMessage = ExportLogsServiceRequest.Parser.ParseFrom(ctx.Request.InputStream);
@@ -171,16 +161,6 @@ private void HandleHttpRequests(HttpListenerContext ctx)
ctx.GenerateEmptyProtobufResponse();
}
-#else
- private async Task HandleHttpRequests(HttpContext ctx)
- {
- using var bodyStream = await ctx.ReadBodyToMemoryAsync();
- var metricsMessage = ExportLogsServiceRequest.Parser.ParseFrom(bodyStream);
- HandleLogsMessage(metricsMessage);
-
- await ctx.GenerateEmptyProtobufResponseAsync();
- }
-#endif
private void HandleLogsMessage(ExportLogsServiceRequest logsMessage)
{
diff --git a/test/IntegrationTests/Helpers/MockMetricsCollector.cs b/test/IntegrationTests/Helpers/MockMetricsCollector.cs
index 252cfba96e..42f0dc32a3 100644
--- a/test/IntegrationTests/Helpers/MockMetricsCollector.cs
+++ b/test/IntegrationTests/Helpers/MockMetricsCollector.cs
@@ -15,17 +15,12 @@
//
using System.Collections.Concurrent;
+using System.Net;
using System.Text;
using OpenTelemetry.Proto.Collector.Metrics.V1;
using OpenTelemetry.Proto.Metrics.V1;
using Xunit.Abstractions;
-#if NETFRAMEWORK
-using System.Net;
-#else
-using Microsoft.AspNetCore.Http;
-#endif
-
namespace IntegrationTests.Helpers;
public class MockMetricsCollector : IDisposable
@@ -39,11 +34,7 @@ public class MockMetricsCollector : IDisposable
public MockMetricsCollector(ITestOutputHelper output, string host = "localhost")
{
_output = output;
-#if NETFRAMEWORK
_listener = new(output, HandleHttpRequests, host, "/v1/metrics/");
-#else
- _listener = new(output, HandleHttpRequests, "/v1/metrics");
-#endif
}
///
@@ -178,7 +169,6 @@ private static void FailMetrics(
Assert.Fail(message.ToString());
}
-#if NETFRAMEWORK
private void HandleHttpRequests(HttpListenerContext ctx)
{
var metricsMessage = ExportMetricsServiceRequest.Parser.ParseFrom(ctx.Request.InputStream);
@@ -186,16 +176,6 @@ private void HandleHttpRequests(HttpListenerContext ctx)
ctx.GenerateEmptyProtobufResponse();
}
-#else
- private async Task HandleHttpRequests(HttpContext ctx)
- {
- using var bodyStream = await ctx.ReadBodyToMemoryAsync();
- var metricsMessage = ExportMetricsServiceRequest.Parser.ParseFrom(bodyStream);
- HandleMetricsMessage(metricsMessage);
-
- await ctx.GenerateEmptyProtobufResponseAsync();
- }
-#endif
private void HandleMetricsMessage(ExportMetricsServiceRequest metricsMessage)
{
diff --git a/test/IntegrationTests/Helpers/MockSpansCollector.cs b/test/IntegrationTests/Helpers/MockSpansCollector.cs
index b61519d4fe..a84e6f0f6f 100644
--- a/test/IntegrationTests/Helpers/MockSpansCollector.cs
+++ b/test/IntegrationTests/Helpers/MockSpansCollector.cs
@@ -15,17 +15,12 @@
//
using System.Collections.Concurrent;
+using System.Net;
using System.Text;
using OpenTelemetry.Proto.Collector.Trace.V1;
using OpenTelemetry.Proto.Trace.V1;
using Xunit.Abstractions;
-#if NETFRAMEWORK
-using System.Net;
-#else
-using Microsoft.AspNetCore.Http;
-#endif
-
namespace IntegrationTests.Helpers;
public class MockSpansCollector : IDisposable
@@ -40,11 +35,7 @@ public MockSpansCollector(ITestOutputHelper output, string host = "localhost")
{
_output = output;
-#if NETFRAMEWORK
_listener = new TestHttpServer(output, HandleHttpRequests, host, "/v1/traces/");
-#else
- _listener = new TestHttpServer(output, HandleHttpRequests, "/v1/traces");
-#endif
}
///
@@ -170,7 +161,6 @@ private static void FailExpectations(
Assert.Fail(message.ToString());
}
-#if NETFRAMEWORK
private void HandleHttpRequests(HttpListenerContext ctx)
{
var traceMessage = ExportTraceServiceRequest.Parser.ParseFrom(ctx.Request.InputStream);
@@ -178,16 +168,6 @@ private void HandleHttpRequests(HttpListenerContext ctx)
ctx.GenerateEmptyProtobufResponse();
}
-#else
- private async Task HandleHttpRequests(HttpContext ctx)
- {
- using var bodyStream = await ctx.ReadBodyToMemoryAsync();
- var traceMessage = ExportTraceServiceRequest.Parser.ParseFrom(bodyStream);
- HandleTraceMessage(traceMessage);
-
- await ctx.GenerateEmptyProtobufResponseAsync();
- }
-#endif
private void HandleTraceMessage(ExportTraceServiceRequest traceMessage)
{
diff --git a/test/IntegrationTests/Helpers/MockZipkinCollector.cs b/test/IntegrationTests/Helpers/MockZipkinCollector.cs
index 4e9f14dfa4..7b864f93c0 100644
--- a/test/IntegrationTests/Helpers/MockZipkinCollector.cs
+++ b/test/IntegrationTests/Helpers/MockZipkinCollector.cs
@@ -16,19 +16,13 @@
using System.Collections.Concurrent;
using System.Diagnostics;
+using System.Net;
using System.Runtime.Serialization;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit.Abstractions;
-#if NETFRAMEWORK
-using System.Net;
-using IntegrationTests.Helpers.Compatibility;
-#else
-using Microsoft.AspNetCore.Http;
-#endif
-
namespace IntegrationTests.Helpers;
public class MockZipkinCollector : IDisposable
@@ -42,11 +36,7 @@ public class MockZipkinCollector : IDisposable
public MockZipkinCollector(ITestOutputHelper output, string host = "localhost")
{
_output = output;
-#if NETFRAMEWORK
_listener = new TestHttpServer(output, HandleHttpRequests, host, "/api/v2/spans/");
-#else
- _listener = new TestHttpServer(output, HandleHttpRequests, "/api/v2/spans");
-#endif
}
///
@@ -155,22 +145,12 @@ private static void FailExpectations(
Assert.Fail(message.ToString());
}
-#if NETFRAMEWORK
private void HandleHttpRequests(HttpListenerContext ctx)
{
HandleJsonStream(ctx.Request.InputStream);
ctx.GenerateEmptyJsonResponse();
}
-#else
- private async Task HandleHttpRequests(HttpContext ctx)
- {
- using var bodyStream = await ctx.ReadBodyToMemoryAsync();
- HandleJsonStream(bodyStream);
-
- await ctx.GenerateEmptyJsonResponseAsync();
- }
-#endif
private void HandleJsonStream(Stream bodyStream)
{
@@ -218,19 +198,6 @@ public string? Service
public string? Library { get; set; }
- public ActivityKind Kind
- {
- get
- {
- if (_zipkinData.TryGetValue("kind", out var value))
- {
- return (ActivityKind)Enum.Parse(typeof(ActivityKind), value.ToString(), true);
- }
-
- return ActivityKind.Internal;
- }
- }
-
public long Start
{
get => Convert.ToInt64(_zipkinData["timestamp"].ToString());
@@ -286,7 +253,6 @@ public override string ToString()
sb.AppendLine($"Service: {Service}");
sb.AppendLine($"Name: {Name}");
sb.AppendLine($"Library: {Library}");
- sb.AppendLine($"Kind: {Kind}");
sb.AppendLine($"Start: {Start}");
sb.AppendLine($"Duration: {Duration}");
sb.AppendLine($"Error: {Error}");
@@ -321,12 +287,12 @@ private void OnDeserialized(StreamingContext context)
return;
}
- Library = Tags.GetValueOrDefault("otel.library.name");
+ Library = Tags.TryGetValue("otel.library.name", out var library) ? library : default;
- var error = Tags.GetValueOrDefault("error") ?? "false";
+ var error = Tags.TryGetValue("error", out var errorValue) ? errorValue : "false";
Error = (byte)(error.ToLowerInvariant().Equals("true") ? 1 : 0);
- var spanKind = _zipkinData.GetValueOrDefault("kind")?.ToString();
+ var spanKind = _zipkinData.TryGetValue("kind", out var spanKindValue) ? spanKindValue.ToString() : default;
if (spanKind != null)
{
Tags["span.kind"] = spanKind.ToLowerInvariant();
diff --git a/test/IntegrationTests/Helpers/TestHttpServer.AspNetCore.cs b/test/IntegrationTests/Helpers/TestHttpServer.AspNetCore.cs
deleted file mode 100644
index fa2cc604a0..0000000000
--- a/test/IntegrationTests/Helpers/TestHttpServer.AspNetCore.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-//
-// Copyright The OpenTelemetry Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-#if NET6_0_OR_GREATER
-
-using System.Net;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Hosting.Server.Features;
-using Microsoft.AspNetCore.Http;
-using Xunit.Abstractions;
-
-namespace IntegrationTests.Helpers;
-
-public class TestHttpServer : IDisposable
-{
- private readonly ITestOutputHelper _output;
- private readonly RequestDelegate _requestHandler;
- private readonly IWebHost _listener;
-
- public TestHttpServer(ITestOutputHelper output, RequestDelegate requestHandler, string path)
- {
- _output = output;
- _requestHandler = requestHandler;
-
- _listener = new WebHostBuilder()
- .UseKestrel(options =>
- options.Listen(IPAddress.Loopback, 0)) // dynamic port
- .Configure(x => x.Map(path, x =>
- {
- x.Run(requestHandler);
- }))
- .Build();
-
- _listener.Start();
-
- var address = _listener.ServerFeatures!
- .Get()!
- .Addresses
- .First();
- Port = int.Parse(address.Split(':').Last());
- WriteOutput($"Listening on '{address}/{path}'");
- }
-
- ///
- /// Gets the TCP port that this listener is listening on.
- ///
- public int Port { get; }
-
- public void Dispose()
- {
- WriteOutput($"Shutting down");
- _listener.Dispose();
- }
-
- private void WriteOutput(string msg)
- {
- const string name = nameof(TestHttpServer);
- _output.WriteLine($"[{name}]: {msg}");
- }
-}
-
-#endif
diff --git a/test/IntegrationTests/Helpers/TestHttpServer.NetFramework.cs b/test/IntegrationTests/Helpers/TestHttpServer.NetFramework.cs
index 8070042cfa..40bbd49d56 100644
--- a/test/IntegrationTests/Helpers/TestHttpServer.NetFramework.cs
+++ b/test/IntegrationTests/Helpers/TestHttpServer.NetFramework.cs
@@ -14,8 +14,6 @@
// limitations under the License.
//
-#if NETFRAMEWORK
-
using System.Net;
using Xunit.Abstractions;
@@ -99,4 +97,3 @@ private void WriteOutput(string msg)
_output.WriteLine($"[{name}]: {msg}");
}
}
-#endif
diff --git a/test/IntegrationTests/IntegrationTests.csproj b/test/IntegrationTests/IntegrationTests.csproj
index 2289c131db..252afc163d 100644
--- a/test/IntegrationTests/IntegrationTests.csproj
+++ b/test/IntegrationTests/IntegrationTests.csproj
@@ -14,6 +14,11 @@
+
+
+
+
+
@@ -37,10 +42,6 @@
-
-
-
-
diff --git a/test/IntegrationTests/SmokeTests.cs b/test/IntegrationTests/SmokeTests.cs
index ee5898a710..7f56fef491 100644
--- a/test/IntegrationTests/SmokeTests.cs
+++ b/test/IntegrationTests/SmokeTests.cs
@@ -115,8 +115,8 @@ public void TracesResource()
#endif
collector.ResourceExpector.Expect("telemetry.sdk.name", "opentelemetry");
collector.ResourceExpector.Expect("telemetry.sdk.language", "dotnet");
- collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version);
- collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version);
+ // collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version);
+ // collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version);
EnableOnlyHttpClientTraceInstrumentation();
SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary");
@@ -134,8 +134,8 @@ public void MetricsResource()
collector.ResourceExpector.Expect("service.name", ServiceName);
collector.ResourceExpector.Expect("telemetry.sdk.name", "opentelemetry");
collector.ResourceExpector.Expect("telemetry.sdk.language", "dotnet");
- collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version);
- collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version);
+ // collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version);
+ // collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version);
EnableOnlyHttpClientTraceInstrumentation();
SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ADDITIONAL_SOURCES", "MyCompany.MyProduct.MyLibrary");
@@ -154,8 +154,8 @@ public void LogsResource()
collector.ResourceExpector.Expect("service.name", ServiceName);
collector.ResourceExpector.Expect("telemetry.sdk.name", "opentelemetry");
collector.ResourceExpector.Expect("telemetry.sdk.language", "dotnet");
- collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version);
- collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version);
+ // collector.ResourceExpector.Expect("telemetry.sdk.version", typeof(OpenTelemetry.Resources.Resource).Assembly.GetCustomAttribute()!.Version);
+ // collector.ResourceExpector.Expect("telemetry.auto.version", OpenTelemetry.AutoInstrumentation.Constants.Tracer.Version);
EnableOnlyHttpClientTraceInstrumentation();
EnableBytecodeInstrumentation();