Skip to content

Commit

Permalink
Remove net 6.0 targets and update accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejgordon committed Nov 25, 2024
1 parent c5abef6 commit 0eeaf50
Show file tree
Hide file tree
Showing 50 changed files with 108 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bootstrap/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ runs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x
- id: dotnet
shell: bash
run: |
dotnet --list-sdks
dotnet --version
dotnet tool restore
AGENT_VERSION=$(dotnet minver -t=v -p=canary.0 -v=e)
echo "Version Number: ${AGENT_VERSION}"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/install-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
if: "${{ inputs.azure == 'true' && runner.os == 'Linux' }}"
shell: bash
run: |
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
wget -q https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install azure-functions-core-tools-4
sudo apt-get install azure-functions-core-tools-4=4.0.6280-1
- name: 'Windows: Azure functions core tools'
if: "${{ inputs.azure == 'true' && runner.os == 'Windows' }}"
shell: cmd
run: choco install azure-functions-core-tools -y --no-progress -r --version 4.0.4829
run: choco install azure-functions-core-tools -y --no-progress -r --version 4.0.6280

# TEST CONTAINERS CLOUD
# If no PR event or if a PR event that's caused by a non-fork and non dependabot actor
Expand Down
16 changes: 8 additions & 8 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />

<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.1" />

<PackageVersion Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
<PackageVersion Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Microsoft.Owin.Host.SystemWeb" Version="4.1.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
Expand Down
8 changes: 3 additions & 5 deletions build/scripts/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,14 @@ module Build =
ToolRestore()
DotNet.Exec ["restore" ; Paths.Solution; "-v"; "q"]
if isWindows then DotNet.Exec ["restore" ; aspNetFullFramework; "-v"; "q"]

let Format () =
DotNet.Exec ["dotnet"; "format"; "--verbosity"; "quiet"; "--exclude"; "src/Elastic.Apm/Libraries/"]

DotNet.Exec ["format"; "--verbosity"; "quiet"; "--verify-no-changes"; "--exclude"; "src/Elastic.Apm/Libraries/"]
let private copyDllsAndPdbs (destination: DirectoryInfo) (source: DirectoryInfo) =
source.GetFiles()
|> Seq.filter (fun file -> file.Extension = ".dll" || file.Extension = ".pdb")
|> Seq.iter (fun file -> file.CopyTo(Path.combine destination.FullName file.Name, true) |> ignore)

/// Creates versioned ElasticApmAgent.zip file
/// Creates versioned ElasticApmAgent.zip file
let AgentZip () =
let name = "ElasticApmAgent"
let currentAssemblyVersion = Versioning.CurrentVersion.FileVersion
Expand Down Expand Up @@ -277,7 +275,7 @@ module Build =

// assemblies compiled against 6.0 version of System.Diagnostics.DiagnosticSource
!! (Paths.BuildOutput (sprintf "Elastic.Apm.StartupHook.Loader_%i.0.0/netstandard2.0" oldDiagnosticSourceVersion.Major))
++ (Paths.BuildOutput (sprintf "Elastic.Apm_%i.0.0/net6.0" diagnosticSourceVersion6.Major))
++ (Paths.BuildOutput (sprintf "Elastic.Apm_%i.0.0/net8.0" diagnosticSourceVersion6.Major))
|> Seq.filter Path.isDirectory
|> Seq.map DirectoryInfo
|> Seq.iter (copyDllsAndPdbs (agentDir.CreateSubdirectory(sprintf "%i.0.0" diagnosticSourceVersion6.Major)))
Expand Down
2 changes: 1 addition & 1 deletion sample/ApiSamples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public static void SampleSpanWithCustomContextFillAll()
// ReSharper restore ArrangeMethodOrOperatorBody
#pragma warning restore IDE0022

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// Test for https://github.com/elastic/apm-agent-dotnet/issues/884
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Apm/Api/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ static bool CheckForLoadedAssembly(string name)
// Legacy mechanism: if the profiler is loaded add a `p` suffix to Agent.Version
service.Agent.Version += "-p";
// Check if profiler was injected via K8S hook.
var envvars =new EnvironmentVariables(logger);
if (envvars.SafeCheckValue("ELASTIC_APM_ACTIVATION_METHOD", "K8S")
var envvars = new EnvironmentVariables(logger);
if (envvars.SafeCheckValue("ELASTIC_APM_ACTIVATION_METHOD", "K8S")
|| envvars.SafeCheckValue("ELASTIC_APM_ACTIVATION_METHOD", "K8S_ATTACH"))
activationMethod = Consts.ActivationK8SAttach;
else
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Apm/Elastic.Apm.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462;net472;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net462;net472;net8.0</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>
<PropertyGroup>
Expand Down Expand Up @@ -103,7 +103,7 @@
<PackageReference Include="System.Threading.Tasks.Dataflow" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="System.Diagnostics.PerformanceCounter" />
</ItemGroup>

Expand Down
6 changes: 3 additions & 3 deletions src/Elastic.Apm/Filters/CookieHeaderRedactionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Elastic.Apm.Config;
using Elastic.Apm.Helpers;
using Elastic.Apm.Model;
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
using System.Buffers;
#endif

Expand Down Expand Up @@ -45,7 +45,7 @@ internal static void HandleCookieHeader(Dictionary<string, string> headers, IRea
// e.g. Cookies | cookies | COOKIES
const int maxKeys = 4;

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
var matchedKeys = ArrayPool<string>.Shared.Rent(maxKeys);
var matchedValues = ArrayPool<string>.Shared.Rent(maxKeys);
#else
Expand Down Expand Up @@ -81,7 +81,7 @@ internal static void HandleCookieHeader(Dictionary<string, string> headers, IRea
}
}

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
ArrayPool<string>.Shared.Return(matchedKeys);
ArrayPool<string>.Shared.Return(matchedValues);
#endif
Expand Down
8 changes: 5 additions & 3 deletions src/Elastic.Apm/Libraries/Newtonsoft.Json/JsonException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ public JsonException(string message, Exception? innerException)
/// <exception cref="ArgumentNullException">The <paramref name="info"/> parameter is <c>null</c>.</exception>
/// <exception cref="SerializationException">The class name is <c>null</c> or <see cref="Exception.HResult"/> is zero (0).</exception>
public JsonException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#pragma warning disable SYSLIB0051
: base(info, context)
#pragma warning restore SYSLIB0051
{
}
#endif

internal static JsonException Create(IJsonLineInfo lineInfo, string path, string message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region License
#region License

// Copyright (c) 2007 James Newton-King
//
Expand Down Expand Up @@ -35,9 +35,11 @@
#nullable enable
namespace Elastic.Apm.Libraries.Newtonsoft.Json.Serialization
{
internal class JsonFormatterConverter : IFormatterConverter
{
private readonly JsonSerializerInternalReader _reader;
#pragma warning disable SYSLIB0050
internal class JsonFormatterConverter : IFormatterConverter
#pragma warning restore SYSLIB0050
{
private readonly JsonSerializerInternalReader _reader;
private readonly JsonISerializableContract _contract;
private readonly JsonProperty? _member;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region License
#region License

// Copyright (c) 2007 James Newton-King
//
Expand Down Expand Up @@ -183,8 +183,10 @@ internal object GetUninitializedObject()
throw new JsonException("Insufficient permissions. Creating an uninitialized '{0}' type requires full trust.".FormatWith(CultureInfo.InvariantCulture, NonNullableUnderlyingType));
}

return FormatterServices.GetUninitializedObject(NonNullableUnderlyingType);
}
#pragma warning disable SYSLIB0050
return FormatterServices.GetUninitializedObject(NonNullableUnderlyingType);
#pragma warning restore SYSLIB0050
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1552,9 +1552,11 @@ private object CreateISerializable(JsonReader reader, JsonISerializableContract
TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Deserializing {0} using ISerializable constructor.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType)), null);
}

SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new JsonFormatterConverter(this, contract, member));
#pragma warning disable SYSLIB0050
SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new JsonFormatterConverter(this, contract, member));
#pragma warning restore SYSLIB0050

bool finished = false;
bool finished = false;
do
{
switch (reader.TokenType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,12 @@ private void SerializeISerializable(JsonWriter writer, ISerializable value, Json

WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty);

SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());
#pragma warning disable SYSLIB0050
SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());
value.GetObjectData(serializationInfo, Serializer._context);
#pragma warning restore SYSLIB0050

foreach (SerializationEntry serializationEntry in serializationInfo)
foreach (SerializationEntry serializationEntry in serializationInfo)
{
JsonContract? valueContract = GetContractSafe(serializationEntry.Value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static Task<int> ReadAsync(this TextReader reader, char[] buffer, int ind
public static bool IsCompletedSucessfully(this Task task)
{
// IsCompletedSuccessfully is the faster method, but only currently exposed on .NET Core 2.0
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
return task.IsCompletedSuccessfully;
#else
return task.Status == TaskStatus.RanToCompletion;
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Apm/Logging/IApmLoggingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static LogValuesFormatter GetOrAddFormatter(string message, IReadOnlyCol
return formatter;

formatter = new LogValuesFormatter(message, args);
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
Formatters.AddOrUpdate(message, formatter);
return formatter;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Apm/Logging/ScopedLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal LogValuesFormatter GetOrAddFormatter(string message, IReadOnlyCollectio
return formatter;

formatter = new LogValuesFormatter($"{{{{{{Scope}}}}}} {message}", args, Scope);
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
Formatters.AddOrUpdate(message, formatter);
return formatter;
#else
Expand Down
6 changes: 3 additions & 3 deletions src/Elastic.Apm/Metrics/Linux/GlobalMemoryStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Runtime.InteropServices;
using Elastic.Apm.Logging;

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
using System.Buffers;
using System.Buffers.Text;
#endif
Expand All @@ -19,7 +19,7 @@ internal static class GlobalMemoryStatus
{
public const string ProcMemInfo = "/proc/meminfo";

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
private static readonly FileStreamOptions Options = new() { BufferSize = 0, Mode = FileMode.Open, Access = FileAccess.Read };
private static readonly byte Space = (byte)' ';

Expand Down Expand Up @@ -57,7 +57,7 @@ internal static (long totalMemory, long availableMemory) GetTotalAndAvailableSys
}
try
{
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
using var fs = new FileStream(memInfoPath, Options);
var buffer = ArrayPool<byte>.Shared.Rent(8192); // Should easily be large enough for max meminfo file.

Expand Down
10 changes: 5 additions & 5 deletions src/Elastic.Apm/Metrics/MetricsProvider/CgroupMetricsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using Elastic.Apm.Helpers;
using Elastic.Apm.Logging;

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
using System.Buffers.Text;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down Expand Up @@ -46,7 +46,7 @@ internal class CgroupMetricsProvider : IMetricsProvider
internal static readonly Regex Cgroup2MountPoint = new("^\\d+? \\d+? .+? .+? (.*?) .*cgroup2.*cgroup.*");
internal static readonly Regex MemoryCgroup = new("^\\d+:memory:.*");

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
private static readonly FileStreamOptions Options = new() { BufferSize = 0, Mode = FileMode.Open, Access = FileAccess.Read };
#endif

Expand Down Expand Up @@ -316,7 +316,7 @@ private MetricSample GetMemoryMemLimitBytes()
return new MetricSample(SystemProcessCgroupMemoryMemLimitBytes, totalMemory);
}

#if NET6_0_OR_GREATER // Optimised code for newer runtimes
#if NET8_0_OR_GREATER // Optimised code for newer runtimes
return GetLongValueFromFile(_cGroupFiles.MaxMemoryFile, SystemProcessCgroupMemoryMemLimitBytes);
#else
using var reader = new StreamReader(_cGroupFiles.MaxMemoryFile);
Expand All @@ -339,7 +339,7 @@ private MetricSample GetMemoryMemUsageBytes()
{
try
{
#if NET6_0_OR_GREATER // Optimised code for newer runtimes
#if NET8_0_OR_GREATER // Optimised code for newer runtimes
return GetLongValueFromFile(_cGroupFiles.UsedMemoryFile, SystemProcessCgroupMemoryMemUsageBytes);
#else
using var reader = new StreamReader(_cGroupFiles.UsedMemoryFile);
Expand All @@ -356,7 +356,7 @@ private MetricSample GetMemoryMemUsageBytes()
return null;
}

#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private MetricSample GetLongValueFromFile(string path, string sampleName)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.Apm/OpenTelemetry/ElasticActivityListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void CreateSpanForActivity(Activity activity, long timestamp, List<SpanL

// By default we set unknown outcome
transaction.Outcome = Outcome.Unknown;
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
switch (activity.Status)
{
case ActivityStatusCode.Unset:
Expand Down Expand Up @@ -254,7 +254,7 @@ private static void UpdateSpan(Activity activity, Span span)

// By default we set unknown outcome
span.Outcome = Outcome.Unknown;
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
switch (activity.Status)
{
case ActivityStatusCode.Unset:
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Apm/Report/PayloadSenderV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ private void ProcessQueueItems(object[] queueItems)
var message = "Unknown 400 Bad Request";
if (response?.Content != null)
{
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
var intakeResponse = _payloadItemSerializer.Deserialize<IntakeResponse>(response.Content.ReadAsStream());
#else
var intakeResponse = _payloadItemSerializer.Deserialize<IntakeResponse>(response.Content.ReadAsStreamAsync().GetAwaiter().GetResult());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0; net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<AssemblyName>Elastic.Apm.Azure.ServiceBus</AssemblyName>
<RootNamespace>Elastic.Apm.Azure.ServiceBus</RootNamespace>
<PackageId>Elastic.Apm.Azure.ServiceBus</PackageId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<RootNamespace>Elastic.Apm.EntityFrameworkCore</RootNamespace>
<AssemblyName>Elastic.Apm.EntityFrameworkCore</AssemblyName>
<PackageId>Elastic.Apm.EntityFrameworkCore</PackageId>
Expand All @@ -11,7 +11,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" VersionOverride="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ params IDiagnosticsSubscriber[] subscribers
}

private static string GetEnvironmentName(this IServiceProvider serviceProvider) =>
#if NET6_0_OR_GREATER
#if NET8_0_OR_GREATER
(serviceProvider.GetService(typeof(IWebHostEnvironment)) as IWebHostEnvironment)?.EnvironmentName;
#else
#pragma warning disable CS0246
Expand Down
Loading

0 comments on commit 0eeaf50

Please sign in to comment.