Skip to content

Commit 76d5732

Browse files
authored
Ship managed profiler for net8.0 (#2745)
Fixes #2744 This ensures some optimisations on newer runtimes are available when using the profiler installation mechanism.
1 parent d421aae commit 76d5732

8 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/profiler/Elastic.Apm.Profiler.Managed.Loader/Startup.NetCore.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ public partial class Startup
2222
private static string ResolveDirectory()
2323
{
2424
var version = Environment.Version;
25-
// use netcoreapp3.1 for netcoreapp3.1 and later
26-
var framework = version.Major == 3 && version.Minor >= 1 || version.Major >= 6
27-
? "netstandard2.1"
28-
: "netstandard2.0";
25+
string framework;
26+
if (version.Major >= 8)
27+
framework = "net8.0";
28+
else if ((version.Major == 3 && version.Minor >= 1) || version.Major >= 5)
29+
framework = "netstandard2.1";
30+
else
31+
framework = "netstandard2.0";
2932

3033
var directory = ReadEnvironmentVariable("ELASTIC_APM_PROFILER_HOME") ?? string.Empty;
3134
Logger.Log(LogLevel.Debug, "Resolving assemblies from {0}", directory);

src/profiler/Elastic.Apm.Profiler.Managed/CallTarget/Handlers/Continuations/ContinuationGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class ContinuationGenerator<TTarget, TReturn>
2020
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2121
protected static TReturn ToTReturn<TFrom>(TFrom returnValue)
2222
{
23-
#if NETSTANDARD2_1_OR_GREATER
23+
#if NETSTANDARD2_1_OR_GREATER || NET
2424
return Unsafe.As<TFrom, TReturn>(ref returnValue);
2525
#else
2626
return ContinuationsHelper.Convert<TFrom, TReturn>(returnValue);
@@ -30,7 +30,7 @@ protected static TReturn ToTReturn<TFrom>(TFrom returnValue)
3030
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3131
protected static TTo FromTReturn<TTo>(TReturn returnValue)
3232
{
33-
#if NETSTANDARD2_1_OR_GREATER
33+
#if NETSTANDARD2_1_OR_GREATER || NET
3434
return Unsafe.As<TReturn, TTo>(ref returnValue);
3535
#else
3636
return ContinuationsHelper.Convert<TReturn, TTo>(returnValue);

src/profiler/Elastic.Apm.Profiler.Managed/CallTarget/Handlers/Continuations/ContinuationsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal static Type GetResultType(Type parentType)
3939
return typeof(object);
4040
}
4141

42-
#if NETSTANDARD2_1_OR_GREATER
42+
#if NETSTANDARD2_1_OR_GREATER || NET
4343
#else
4444
internal static TTo Convert<TFrom, TTo>(TFrom value) => Converter<TFrom, TTo>.Convert(value);
4545

src/profiler/Elastic.Apm.Profiler.Managed/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Elastic.Apm.Profiler.Managed.CallTarget.Handlers.Continuations
1414
{
15-
#if NETSTANDARD2_1_OR_GREATER
15+
#if NETSTANDARD2_1_OR_GREATER || NET
1616
internal class ValueTaskContinuationGenerator<TIntegration, TTarget, TReturn> : ContinuationGenerator<TTarget, TReturn>
1717
{
1818
private static readonly Func<TTarget, object, Exception, CallTargetState, object> _continuation;

src/profiler/Elastic.Apm.Profiler.Managed/CallTarget/Handlers/Continuations/ValueTaskContinuationGenerator`1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Elastic.Apm.Profiler.Managed.CallTarget.Handlers.Continuations
1616
{
17-
#if NETSTANDARD2_1_OR_GREATER
17+
#if NETSTANDARD2_1_OR_GREATER || NET
1818
internal class ValueTaskContinuationGenerator<TIntegration, TTarget, TReturn, TResult> : ContinuationGenerator<TTarget, TReturn>
1919
{
2020
private static readonly Func<TTarget, TResult, Exception, CallTargetState, TResult> _continuation;

src/profiler/Elastic.Apm.Profiler.Managed/CallTarget/Handlers/EndMethodHandler`1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static EndMethodHandler()
4646
typeof(TaskContinuationGenerator<,,,>).MakeGenericType(typeof(TIntegration), typeof(TTarget), returnType,
4747
ContinuationsHelper.GetResultType(returnType)));
4848
}
49-
#if NETSTANDARD2_1_OR_GREATER
49+
#if NETSTANDARD2_1_OR_GREATER || NET
5050
else if (genericReturnType == typeof(ValueTask<>))
5151
{
5252
// The type is a ValueTask<>
@@ -63,7 +63,7 @@ static EndMethodHandler()
6363
// The type is a Task
6464
_continuationGenerator = new TaskContinuationGenerator<TIntegration, TTarget, TReturn>();
6565
}
66-
#if NETSTANDARD2_1_OR_GREATER
66+
#if NETSTANDARD2_1_OR_GREATER || NET
6767
else if (returnType == typeof(ValueTask))
6868
{
6969
// The type is a ValueTask

src/profiler/Elastic.Apm.Profiler.Managed/DuckTyping/DuckType.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ private static CreateTypeResult CreateProxyType(Type proxyDefinitionType, Type t
114114
// If the proxy type definition is an interface we create an struct proxy
115115
// If the proxy type definition is an struct then we use that struct to copy the values from the target type
116116
parentType = typeof(ValueType);
117+
#pragma warning disable SYSLIB0050
117118
typeAttributes = TypeAttributes.Public | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit
118119
| TypeAttributes.SequentialLayout | TypeAttributes.Sealed | TypeAttributes.Serializable;
120+
#pragma warning restore SYSLIB0050
119121
if (proxyDefinitionType.IsInterface)
120122
interfaceTypes = new[] { proxyDefinitionType, typeof(IDuckType) };
121123
else

src/profiler/Elastic.Apm.Profiler.Managed/Elastic.Apm.Profiler.Managed.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net462;netstandard2.0;netstandard2.1</TargetFrameworks>
4+
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<DefineConstants>$(DefineConstants);PROFILER_MANAGED</DefineConstants>
77
</PropertyGroup>

0 commit comments

Comments
 (0)