\d+))?(\-(?[0-9A-Za-z]+))?$",
RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture);
- private static StartupHookLogger _logger;
+ private static StartupHookLogger Logger;
///
/// The Initialize method called by DOTNET_STARTUP_HOOKS
///
public static void Initialize()
{
+ Logger = StartupHookLogger.Create();
+
+ if (!IsNet8OrHigher())
+ {
+ Logger.WriteLine("The .NET runtime version is lower than .NET 8. The Elastic APM .NET Agent startup " +
+ "hook is only supported on .NET 8 or higher. Some functionality may not work as expected.");
+ }
+
var startupHookEnvVar = Environment.GetEnvironmentVariable("DOTNET_STARTUP_HOOKS");
var startupHookDirectory = Path.GetDirectoryName(startupHookEnvVar);
if (string.IsNullOrEmpty(startupHookEnvVar) || !File.Exists(startupHookEnvVar))
return;
- _logger = StartupHookLogger.Create();
- _logger.WriteLine($"Check if {SystemDiagnosticsDiagnosticsource} is loaded");
-
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
- _logger.WriteLine($"Assemblies loaded:{Environment.NewLine}{string.Join(Environment.NewLine, assemblies.Select(a => a.GetName()))}");
+ Logger.WriteLine($"Assemblies loaded:{Environment.NewLine}{string.Join(Environment.NewLine, assemblies.Select(a => a.GetName()))}");
+
+ Logger.WriteLine($"Check if {SystemDiagnosticsDiagnosticsource} is loaded");
var diagnosticSourceAssemblies = assemblies
.Where(a => a.GetName().Name.Equals(SystemDiagnosticsDiagnosticsource, StringComparison.Ordinal))
@@ -52,16 +62,17 @@ public static void Initialize()
switch (diagnosticSourceAssemblies.Count)
{
case 0:
- _logger.WriteLine($"No {SystemDiagnosticsDiagnosticsource} loaded. Load using AssemblyLoadContext.Default");
-
+ Logger.WriteLine($"No {SystemDiagnosticsDiagnosticsource} loaded. Loading using AssemblyLoadContext.Default");
diagnosticSourceAssembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(SystemDiagnosticsDiagnosticsource));
break;
case 1:
diagnosticSourceAssembly = diagnosticSourceAssemblies[0];
+ Logger.WriteLine($"{SystemDiagnosticsDiagnosticsource} is loaded (Version: {diagnosticSourceAssembly.GetName().Version}). ");
break;
default:
- _logger.WriteLine($"Found {diagnosticSourceAssemblies.Count} {SystemDiagnosticsDiagnosticsource} assemblies loaded in the app domain");
+ Logger.WriteLine($"Found {diagnosticSourceAssemblies.Count} {SystemDiagnosticsDiagnosticsource} assemblies loaded in the app domain");
diagnosticSourceAssembly = diagnosticSourceAssemblies.First();
+ Logger.WriteLine($"{SystemDiagnosticsDiagnosticsource} is loaded (Version: {diagnosticSourceAssembly.GetName().Version}). ");
break;
}
@@ -77,6 +88,9 @@ public static void Initialize()
.First();
loaderDirectory = Path.Combine(startupHookDirectory, highestAvailableAgent);
+
+ Logger.WriteLine($"Loading {LoaderDll} using AssemblyLoadContext.Default from {loaderDirectory}");
+
loaderAssembly = AssemblyLoadContext.Default
.LoadFromAssemblyPath(Path.Combine(loaderDirectory, LoaderDll));
}
@@ -86,37 +100,74 @@ public static void Initialize()
var diagnosticSourcePublicKeyToken = diagnosticSourceAssemblyName.GetPublicKeyToken();
if (!diagnosticSourcePublicKeyToken.SequenceEqual(SystemDiagnosticsDiagnosticSourcePublicKeyToken))
{
- _logger.WriteLine($"{SystemDiagnosticsDiagnosticsource} public key token "
+ Logger.WriteLine($"{SystemDiagnosticsDiagnosticsource} public key token "
+ $"{PublicKeyTokenBytesToString(diagnosticSourcePublicKeyToken)} did not match expected "
+ $"public key token {PublicKeyTokenBytesToString(SystemDiagnosticsDiagnosticSourcePublicKeyToken)}");
return;
}
var diagnosticSourceVersion = diagnosticSourceAssemblyName.Version;
- _logger.WriteLine($"{SystemDiagnosticsDiagnosticsource} {diagnosticSourceVersion} loaded");
- // .NET 7 still uses LoaderDll version 6.
- var majorVersion = Math.Min(6, diagnosticSourceVersion.Major);
- loaderDirectory = Path.Combine(startupHookDirectory, $"{majorVersion}.0.0");
+ Logger.WriteLine($"{SystemDiagnosticsDiagnosticsource} {diagnosticSourceVersion} loaded");
+
+ if (diagnosticSourceVersion.Major < 6)
+ {
+ Logger.WriteLine($"{SystemDiagnosticsDiagnosticsource} version {diagnosticSourceVersion} is not supported. 6.0.0 or higher is required. Agent not loaded.");
+ return;
+ }
+ else if (diagnosticSourceVersion.Major == 6 || diagnosticSourceVersion.Major == 7)
+ {
+ loaderDirectory = Path.Combine(startupHookDirectory, "6.0.0");
+ }
+ else
+ {
+ loaderDirectory = Path.Combine(startupHookDirectory, "8.0.0");
+ }
+
if (Directory.Exists(loaderDirectory))
{
+ Logger.WriteLine($"Loading {LoaderDll} using AssemblyLoadContext.Default from {loaderDirectory}");
+
loaderAssembly = AssemblyLoadContext.Default
.LoadFromAssemblyPath(Path.Combine(loaderDirectory, LoaderDll));
}
else
{
- _logger.WriteLine(
+ Logger.WriteLine(
$"No compatible agent for {SystemDiagnosticsDiagnosticsource} {diagnosticSourceVersion}. Agent not loaded");
}
}
if (loaderAssembly is null)
{
- _logger.WriteLine($"No {LoaderDll} assembly loaded. Agent not loaded");
+ Logger.WriteLine($"No {LoaderDll} assembly loaded. Agent not loaded");
return;
}
LoadAssembliesFromLoaderDirectory(loaderDirectory);
InvokerLoaderMethod(loaderAssembly);
+
+ static bool IsNet8OrHigher()
+ {
+ var desc = RuntimeInformation.FrameworkDescription;
+ if (desc.StartsWith(".NET", StringComparison.OrdinalIgnoreCase))
+ {
+ var parts = desc.Split(' ');
+ if (parts.Length >= 2 && Version.TryParse(parts[1], out var version))
+ {
+ return version.Major >= 8;
+ }
+ }
+ return false;
+ }
+
+ static string PublicKeyTokenBytesToString(byte[] publicKeyToken)
+ {
+ var token = string.Empty;
+ for (var i = 0; i < publicKeyToken.Length; i++)
+ token += $"{publicKeyToken[i]:x2}";
+
+ return token;
+ }
}
///
@@ -150,7 +201,7 @@ private static void LoadAssembliesFromLoaderDirectory(string loaderDirectory)
}
catch (Exception e)
{
- _logger.WriteLine(e.ToString());
+ Logger.WriteLine(e.ToString());
}
}
@@ -158,43 +209,31 @@ private static void LoadAssembliesFromLoaderDirectory(string loaderDirectory)
};
}
- ///
- /// Converts public key token bytes into a string
- ///
- private static string PublicKeyTokenBytesToString(byte[] publicKeyToken)
- {
- var token = string.Empty;
- for (var i = 0; i < publicKeyToken.Length; i++)
- token += $"{publicKeyToken[i]:x2}";
-
- return token;
- }
-
///
/// Invokes the Elastic.Apm.StartupHook.Loader.Loader.Initialize() method from a specific assembly
///
/// The loader assembly
private static void InvokerLoaderMethod(Assembly loaderAssembly)
{
- _logger.WriteLine($"Get {LoaderTypeName} type");
+ Logger.WriteLine($"Get {LoaderTypeName} type");
var loaderType = loaderAssembly.GetType(LoaderTypeName);
if (loaderType is null)
{
- _logger.WriteLine($"{LoaderTypeName} type is null");
+ Logger.WriteLine($"{LoaderTypeName} type is null");
return;
}
- _logger.WriteLine($"Get {LoaderTypeName}.{LoaderTypeMethod} method");
+ Logger.WriteLine($"Get {LoaderTypeName}.{LoaderTypeMethod} method");
var initializeMethod = loaderType.GetMethod(LoaderTypeMethod, BindingFlags.Public | BindingFlags.Static);
if (initializeMethod is null)
{
- _logger.WriteLine($"{LoaderTypeName}.{LoaderTypeMethod} method is null");
+ Logger.WriteLine($"{LoaderTypeName}.{LoaderTypeMethod} method is null");
return;
}
- _logger.WriteLine($"Invoke {LoaderTypeName}.{LoaderTypeMethod} method");
+ Logger.WriteLine($"Invoke {LoaderTypeName}.{LoaderTypeMethod} method");
initializeMethod.Invoke(null, null);
}
}
diff --git a/src/startuphook/ElasticApmAgentStartupHook/StartupHookLogger.cs b/src/startuphook/ElasticApmAgentStartupHook/StartupHookLogger.cs
index 69ea6fd0a..0fbcb5497 100644
--- a/src/startuphook/ElasticApmAgentStartupHook/StartupHookLogger.cs
+++ b/src/startuphook/ElasticApmAgentStartupHook/StartupHookLogger.cs
@@ -51,7 +51,7 @@ public void WriteLine(string message)
var log = $"[{DateTime.Now:u}] {message}";
Console.Out.WriteLine(log);
Console.Out.Flush();
- File.AppendAllLines(_logPath, new[] { log });
+ File.AppendAllLines(_logPath, [log]);
}
catch
{
diff --git a/test/Elastic.Apm.Tests.Utilities/XUnit/FactRequiresMvcTestingFix.cs b/test/Elastic.Apm.Tests.Utilities/XUnit/FactRequiresMvcTestingFix.cs
index 0974a18af..8f654f35b 100644
--- a/test/Elastic.Apm.Tests.Utilities/XUnit/FactRequiresMvcTestingFix.cs
+++ b/test/Elastic.Apm.Tests.Utilities/XUnit/FactRequiresMvcTestingFix.cs
@@ -14,7 +14,7 @@ public FactRequiresMvcTestingFix()
{
if (Environment.Version.Major < 7)
return;
- Skip = $"This test is disabled on .NET 7 until https://github.com/dotnet/aspnetcore/issues/45233";
+ Skip = $"This test is disabled on .NET until https://github.com/dotnet/aspnetcore/issues/45233";
}
}
@@ -24,6 +24,6 @@ public TheoryRequiresMvcTestingFix()
{
if (Environment.Version.Major < 7)
return;
- Skip = $"This test is disabled on .NET 7 until https://github.com/dotnet/aspnetcore/issues/45233";
+ Skip = $"This test is disabled on .NET until https://github.com/dotnet/aspnetcore/issues/45233";
}
}
diff --git a/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs b/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs
index c131d3dae..29f071cc0 100644
--- a/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs
+++ b/test/Elastic.Apm.Tests/HelpersTests/TimeUtilsTests.cs
@@ -27,7 +27,7 @@ public class TimeUtilsTests
{ 5 * 24 * 60 * 60 * 1_000_000L, new DateTime(1970, 1, 6, 0, 0, 0, DateTimeKind.Utc) }
};
-#if NETCOREAPP
+#if NET
[Fact]
public void TimeUtilsUnixEpochDateTimeEqualsDateTimeUnixEpoch() => TimeUtils.UnixEpochDateTime.Should().Be(DateTime.UnixEpoch);
#endif
diff --git a/test/Elastic.Apm.Tests/LoggerTests.cs b/test/Elastic.Apm.Tests/LoggerTests.cs
index 1be429dd6..038114050 100644
--- a/test/Elastic.Apm.Tests/LoggerTests.cs
+++ b/test/Elastic.Apm.Tests/LoggerTests.cs
@@ -156,7 +156,7 @@ public void EnsureFormattersAreShared()
var scopedLogger = consoleLogger.Scoped("MyTestScope");
for (var i = 0; i < 10; i++)
scopedLogger.Warning()?.Log("This is a test log from the test StructuredLogTemplateWith1MissingArgument, args: {arg1}", i);
-#if NET8_0_OR_GREATER
+#if NET
var cachedFormatterCount = scopedLogger.Formatters.Count();
cachedFormatterCount.Should().Be(1);
diff --git a/test/Elastic.Apm.Tests/MetricsTests.cs b/test/Elastic.Apm.Tests/MetricsTests.cs
index 60f0664a0..0ed862de2 100644
--- a/test/Elastic.Apm.Tests/MetricsTests.cs
+++ b/test/Elastic.Apm.Tests/MetricsTests.cs
@@ -306,7 +306,7 @@ public void CollectGcMetrics()
var logger = new TestLogger(LogLevel.Trace);
using (var gcMetricsProvider = new GcMetricsProvider(logger, new List()))
{
-#if NETCOREAPP2_2_OR_GREATER
+#if NET
//EventSource Microsoft-Windows-DotNETRuntime is only 2.2+, no gc metrics on 2.1
//repeat the allocation multiple times and make sure at least 1 GetSamples() call returns value
diff --git a/test/Elastic.Apm.Tests/ServerCertificateTests.cs b/test/Elastic.Apm.Tests/ServerCertificateTests.cs
index f1d20ee92..cb5383458 100644
--- a/test/Elastic.Apm.Tests/ServerCertificateTests.cs
+++ b/test/Elastic.Apm.Tests/ServerCertificateTests.cs
@@ -5,7 +5,7 @@
// depends on Mock APM server project TargetFramework
-#if NET5_0_OR_GREATER
+#if NET
using System;
using System.IO;
@@ -70,6 +70,11 @@ public void ServerCert_Should_Allow_Https_To_Apm_Server()
_server.ReceivedData.Transactions.Should().HaveCount(1);
var transaction = _server.ReceivedData.Transactions.First();
+
+ transaction.Context.Should().NotBeNull();
+ transaction.Context.Labels.Should().NotBeNull();
+ transaction.Context.Labels.MergedDictionary.Should().NotBeNull();
+
transaction.Context.Labels.MergedDictionary.Should().ContainKey("self_signed_cert");
}
diff --git a/test/integrations/Elastic.Apm.AspNetCore.Tests/AspNetCoreBasicTests.cs b/test/integrations/Elastic.Apm.AspNetCore.Tests/AspNetCoreBasicTests.cs
index 137eeb935..72ddabd35 100644
--- a/test/integrations/Elastic.Apm.AspNetCore.Tests/AspNetCoreBasicTests.cs
+++ b/test/integrations/Elastic.Apm.AspNetCore.Tests/AspNetCoreBasicTests.cs
@@ -89,11 +89,8 @@ public async Task HomeSimplePageTransactionTest()
var aspNetCoreVersion = Assembly.Load("Microsoft.AspNetCore").GetName().Version.ToString();
agent.Service.Framework.Version.Should().Be(aspNetCoreVersion);
-#if NET8_0
+
agent.Service.Runtime.Name.Should().Be(Runtime.DotNetName + " 8");
-#else
- agent.Service.Runtime.Name.Should().Be(Runtime.DotNetCoreName);
-#endif
agent.Service.Runtime.Version.Should().StartWith(Directory.GetParent(typeof(object).Assembly.Location).Name);
var transaction = payloadSender.FirstTransaction;
@@ -118,13 +115,7 @@ public async Task HomeSimplePageTransactionTest()
}
//test transaction.context.request
-#if NET5_0_OR_GREATER
- transaction.Context.Request.HttpVersion.Should().Be("1.1");
-#elif NETCOREAPP3_0 || NETCOREAPP3_1
transaction.Context.Request.HttpVersion.Should().Be("2");
-#else
- transaction.Context.Request.HttpVersion.Should().Be("2.0");
-#endif
transaction.Context.Request.Method.Should().Be("GET");
//test transaction.context.request.url
@@ -237,14 +228,7 @@ public async Task HomeSimplePagePostTransactionTest()
var aspNetCoreVersion = Assembly.Load("Microsoft.AspNetCore").GetName().Version.ToString(2);
agent.Service.Framework.Version.Should().StartWith(aspNetCoreVersion);
-#if NET6_0
- agent.Service.Runtime.Name.Should().Be(Runtime.DotNetName + " 6");
-#elif NET7_0
- agent.Service.Runtime.Name.Should().Be(Runtime.DotNetName + " 7");
-#else
agent.Service.Runtime.Name.Should().Be(Runtime.DotNetCoreName);
-#endif
-
agent.Service.Runtime.Version.Should().StartWith(Directory.GetParent(typeof(object).Assembly.Location).Name);
payloadSender.Transactions.Should().ContainSingle();
@@ -272,13 +256,7 @@ public async Task HomeSimplePagePostTransactionTest()
}
//test transaction.context.request
-#if NET5_0_OR_GREATER
- transaction.Context.Request.HttpVersion.Should().Be("1.1");
-#elif NETCOREAPP3_0 || NETCOREAPP3_1
transaction.Context.Request.HttpVersion.Should().Be("2");
-#else
- transaction.Context.Request.HttpVersion.Should().Be("2.0");
-#endif
transaction.Context.Request.Method.Should().Be("POST");
//test transaction.context.request.url
diff --git a/test/integrations/Elastic.Apm.AspNetCore.Tests/Helper.cs b/test/integrations/Elastic.Apm.AspNetCore.Tests/Helper.cs
index 8fed78d03..1218ab961 100644
--- a/test/integrations/Elastic.Apm.AspNetCore.Tests/Helper.cs
+++ b/test/integrations/Elastic.Apm.AspNetCore.Tests/Helper.cs
@@ -2,9 +2,9 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
+using System;
using System.Net.Http;
using System.Reflection;
-using Elastic.Apm.AspNetCore.DiagnosticListener;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.EntityFrameworkCore;
using Microsoft.AspNetCore.Builder;
@@ -27,9 +27,7 @@ WebApplicationFactory factory
#pragma warning disable IDE0022 // Use expression body for methods
client = GetClient(agent, factory);
#pragma warning restore IDE0022 // Use expression body for methods
-#if NETCOREAPP3_0 || NETCOREAPP3_1
client.DefaultRequestVersion = new Version(2, 0);
-#endif
}
else
client = GetClientWithoutExceptionPage(agent, factory);
diff --git a/test/integrations/Elastic.Apm.AspNetCore.Tests/TransactionIgnoreUrlsTest.cs b/test/integrations/Elastic.Apm.AspNetCore.Tests/TransactionIgnoreUrlsTest.cs
index 7cd8c4aab..496cb6fbb 100644
--- a/test/integrations/Elastic.Apm.AspNetCore.Tests/TransactionIgnoreUrlsTest.cs
+++ b/test/integrations/Elastic.Apm.AspNetCore.Tests/TransactionIgnoreUrlsTest.cs
@@ -7,9 +7,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using Elastic.Apm.Extensions.Hosting;
-using Elastic.Apm.Logging;
using Elastic.Apm.Tests.Utilities;
-using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using SampleAspNetCoreApp;
@@ -53,9 +51,7 @@ private void Setup()
#pragma warning disable IDE0022 // Use expression body for methods
_client = Helper.GetClient(_agent, _factory);
#pragma warning restore IDE0022 // Use expression body for methods
-#if NETCOREAPP3_0 || NETCOREAPP3_1
_client.DefaultRequestVersion = new Version(2, 0);
-#endif
}
///
diff --git a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/Continuations/ValueTaskContinuationGeneratorTests.cs b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/Continuations/ValueTaskContinuationGeneratorTests.cs
index 69679eddf..eae3f98f6 100644
--- a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/Continuations/ValueTaskContinuationGeneratorTests.cs
+++ b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/Continuations/ValueTaskContinuationGeneratorTests.cs
@@ -7,7 +7,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
//
-#if NET8_0_OR_GREATER
+#if NET
using System;
using System.Threading;
using System.Threading.Tasks;
diff --git a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/DuckIgnoreTests.cs b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/DuckIgnoreTests.cs
index 621f9132a..9e850003e 100644
--- a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/DuckIgnoreTests.cs
+++ b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/DuckIgnoreTests.cs
@@ -25,7 +25,7 @@ public void NonPublicStructCopyTest()
Assert.Equal(ValuesDuckType.Third.ToString(), ((IGetValue)copy).GetValueProp);
}
-#if NET8_0_OR_GREATER
+#if NET
[Fact]
public void NonPublicStructInterfaceProxyTest()
{
@@ -69,17 +69,17 @@ public struct CopyStruct : IGetValue
public string GetValue() => Value.ToString();
}
-#if NETCOREAPP3_0_OR_GREATER
+#if NET
// Interface with a default implementation
public interface IPrivateStruct
{
ValuesDuckType Value { get; }
[DuckIgnore]
- public string GetValueProp => Value.ToString();
+ string GetValueProp => Value.ToString();
[DuckIgnore]
- public string GetValue() => Value.ToString();
+ string GetValue() => Value.ToString();
}
#endif
diff --git a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/ExceptionsTests.cs b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/ExceptionsTests.cs
index c4a6b656f..97b386549 100644
--- a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/ExceptionsTests.cs
+++ b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/ExceptionsTests.cs
@@ -318,18 +318,18 @@ public void TargetMethodNotFoundException()
public interface ITargetMethodNotFoundException
{
- public void AddTypo(string key, string value);
+ void AddTypo(string key, string value);
}
public interface ITargetMethodNotFound2Exception
{
- public void AddGeneric(object value);
+ void AddGeneric(object value);
}
public interface ITargetMethodNotFound3Exception
{
[Duck(GenericParameterTypeNames = new string[] { "P1", "P2" })]
- public void AddGeneric(object value);
+ void AddGeneric(object value);
}
internal class TargetMethodNotFoundExceptionClass
@@ -355,7 +355,7 @@ public void ProxyMethodParameterIsMissingException()
public interface IProxyMethodParameterIsMissingException
{
[Duck(ParameterTypeNames = new string[] { "System.String", "System.String" })]
- public void Add(string key);
+ void Add(string key);
}
internal class ProxyMethodParameterIsMissingExceptionClass
@@ -384,13 +384,13 @@ public void ProxyAndTargetMethodParameterSignatureMismatchException()
public interface IProxyAndTargetMethodParameterSignatureMismatchException
{
[Duck(ParameterTypeNames = new string[] { "System.String", "System.String" })]
- public void Add(string key, ref string value);
+ void Add(string key, ref string value);
}
public interface IProxyAndTargetMethodParameterSignatureMismatch2Exception
{
[Duck(ParameterTypeNames = new string[] { "System.String", "System.String" })]
- public void Add(string key, out string value);
+ void Add(string key, out string value);
}
internal class ProxyAndTargetMethodParameterSignatureMismatchExceptionClass
@@ -438,9 +438,9 @@ public void TargetMethodAmbiguousMatchException()
public interface ITargetMethodAmbiguousMatchException
{
- public void Add(string key, object value);
+ void Add(string key, object value);
- public void Add(string key, string value);
+ void Add(string key, string value);
}
internal class TargetMethodAmbiguousMatchExceptionClass
diff --git a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/Methods/ProxiesDefinitions/IDictioDuckType.cs b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/Methods/ProxiesDefinitions/IDictioDuckType.cs
index 18773212b..207975adc 100644
--- a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/Methods/ProxiesDefinitions/IDictioDuckType.cs
+++ b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/Methods/ProxiesDefinitions/IDictioDuckType.cs
@@ -15,13 +15,13 @@ namespace Elastic.Apm.Profiler.Managed.Tests.DuckTyping.Methods.ProxiesDefinitio
{
public interface IDictioDuckType
{
- public ICollection Keys { get; }
+ ICollection Keys { get; }
- public ICollection Values { get; }
+ ICollection Values { get; }
int Count { get; }
- public string this[string key] { get; set; }
+ string this[string key] { get; set; }
void Add(string key, string value);
diff --git a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/StructTests.cs b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/StructTests.cs
index 2be73e11a..07f277996 100644
--- a/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/StructTests.cs
+++ b/test/profiler/Elastic.Apm.Profiler.Managed.Tests/DuckTyping/StructTests.cs
@@ -102,7 +102,7 @@ public interface IPrivateDuckChainingTarget
public interface IPrivateTarget
{
[Duck(Kind = DuckKind.Field)]
- public string Name { get; }
+ string Name { get; }
}
private class PrivateDuckChainingTarget
diff --git a/test/startuphook/Elastic.Apm.StartupHook.Sample/Elastic.Apm.StartupHook.Sample.csproj b/test/startuphook/Elastic.Apm.StartupHook.Sample/Elastic.Apm.StartupHook.Sample.csproj
index ccd7e8ece..9d6373c0f 100644
--- a/test/startuphook/Elastic.Apm.StartupHook.Sample/Elastic.Apm.StartupHook.Sample.csproj
+++ b/test/startuphook/Elastic.Apm.StartupHook.Sample/Elastic.Apm.StartupHook.Sample.csproj
@@ -1,7 +1,7 @@
- net8.0
+ net8.0;net9.0
false
diff --git a/test/startuphook/Elastic.Apm.StartupHook.Sample/Startup.cs b/test/startuphook/Elastic.Apm.StartupHook.Sample/Startup.cs
index 251396d9a..df083d930 100644
--- a/test/startuphook/Elastic.Apm.StartupHook.Sample/Startup.cs
+++ b/test/startuphook/Elastic.Apm.StartupHook.Sample/Startup.cs
@@ -13,7 +13,7 @@ public class Startup
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) =>
-#if NET5_0_OR_GREATER
+#if NET
services.AddControllersWithViews();
#else
services.AddMvc();
diff --git a/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs b/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs
index 8e0062aa2..fce6be31f 100644
--- a/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs
+++ b/test/startuphook/Elastic.Apm.StartupHook.Tests/DotnetProject.cs
@@ -5,13 +5,10 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
-using System.Xml.Linq;
using ProcNet;
-using ProcNet.Std;
using Xunit.Abstractions;
namespace Elastic.Apm.StartupHook.Tests
@@ -168,7 +165,7 @@ public static DotnetProject Create(ITestOutputHelper output, string name, string
"new",
"globaljson",
"--sdk-version",
- "8.0.404", // Fixing this specific version, for now
+ "9.0.303", // Fixing this specific version, for now
"--roll-forward",
"LatestPatch"
])
diff --git a/test/startuphook/Elastic.Apm.StartupHook.Tests/Elastic.Apm.StartupHook.Tests.csproj b/test/startuphook/Elastic.Apm.StartupHook.Tests/Elastic.Apm.StartupHook.Tests.csproj
index 809140a35..5c31fc309 100644
--- a/test/startuphook/Elastic.Apm.StartupHook.Tests/Elastic.Apm.StartupHook.Tests.csproj
+++ b/test/startuphook/Elastic.Apm.StartupHook.Tests/Elastic.Apm.StartupHook.Tests.csproj
@@ -1,13 +1,13 @@
-
- net8.0
-
+
+ net8.0
+
+
+
+
+
-
-
-
-
diff --git a/test/startuphook/Elastic.Apm.StartupHook.Tests/StartupHookTests.cs b/test/startuphook/Elastic.Apm.StartupHook.Tests/StartupHookTests.cs
index 8810d7bee..dd8be841b 100644
--- a/test/startuphook/Elastic.Apm.StartupHook.Tests/StartupHookTests.cs
+++ b/test/startuphook/Elastic.Apm.StartupHook.Tests/StartupHookTests.cs
@@ -31,10 +31,21 @@ public partial class StartupHookTests(ITestOutputHelper output)
private static IEnumerable<(string TargetFramework, string RuntimeName, string Version, string ShortVersion)> GetDotNetFrameworkVersionInfos()
{
yield return ("net8.0", ".NET 8", "8.0.0.0", "80");
+ yield return ("net9.0", ".NET 9", "9.0.0.0", "90");
}
+ private static readonly Dictionary CommonEnvVars = new()
+ {
+ [CloudProvider.ToEnvironmentVariable()] = "none",
+ [CentralConfig.ToEnvironmentVariable()] = "false",
+ // We disable the OpenTelemetry bridge here to avoid additional transactions
+ // that may be created. In .NET 9 there are some additional activities for
+ // HttpConnection that result in additional spans and transactions.
+ ["ELASTIC_APM_OPENTELEMETRY_BRIDGE_ENABLED"] = "false"
+ };
+
public static IEnumerable