Skip to content

Commit

Permalink
[Resources.Host] Replace .NET 6 target with .NET 8 and add .NET Stand…
Browse files Browse the repository at this point in the history
…ard 2.0 target (#2168)
  • Loading branch information
joegoldman2 authored Oct 4, 2024
1 parent 9400d5c commit 7f91d74
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Resources.Host/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Drop support for .NET 6 as this target is no longer supported
and add .NET 8/.NET Standard 2.0 targets.
([#2168](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2168))

## 0.1.0-beta.3

Released 2024-Aug-30
Expand Down
20 changes: 10 additions & 10 deletions src/OpenTelemetry.Resources.Host/HostDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
#if NET
#if !NETFRAMEWORK
using System.Runtime.InteropServices;
#endif
using System.Text;
Expand All @@ -18,7 +18,7 @@ internal sealed class HostDetector : IResourceDetector
{
private const string ETCMACHINEID = "/etc/machine-id";
private const string ETCVARDBUSMACHINEID = "/var/lib/dbus/machine-id";
#if NET
#if !NETFRAMEWORK
private readonly Func<OSPlatform, bool> isOsPlatform;
#endif
private readonly Func<IEnumerable<string>> getFilePaths;
Expand All @@ -30,7 +30,7 @@ internal sealed class HostDetector : IResourceDetector
/// </summary>
public HostDetector()
: this(
#if NET
#if !NETFRAMEWORK
RuntimeInformation.IsOSPlatform,
#endif
GetFilePaths,
Expand All @@ -39,7 +39,7 @@ public HostDetector()
{
}

#if NET
#if !NETFRAMEWORK
public HostDetector(
Func<IEnumerable<string>> getFilePaths,
Func<string?> getMacOsMachineId,
Expand All @@ -54,21 +54,21 @@ public HostDetector(
#endif

internal HostDetector(
#if NET
#if !NETFRAMEWORK
Func<OSPlatform, bool> isOsPlatform,
#endif
Func<IEnumerable<string>> getFilePaths,
Func<string?> getMacOsMachineId,
Func<string?> getWindowsMachineId)
{
#if NET
#if !NETFRAMEWORK
Guard.ThrowIfNull(isOsPlatform);
#endif
Guard.ThrowIfNull(getFilePaths);
Guard.ThrowIfNull(getMacOsMachineId);
Guard.ThrowIfNull(getWindowsMachineId);

#if NET
#if !NETFRAMEWORK
this.isOsPlatform = isOsPlatform;
#endif
this.getFilePaths = getFilePaths;
Expand Down Expand Up @@ -117,10 +117,10 @@ public Resource Detect()

foreach (var line in lines)
{
#if NETFRAMEWORK
if (line.IndexOf("IOPlatformUUID", StringComparison.OrdinalIgnoreCase) >= 0)
#else
#if NET
if (line.Contains("IOPlatformUUID", StringComparison.OrdinalIgnoreCase))
#else
if (line.IndexOf("IOPlatformUUID", StringComparison.OrdinalIgnoreCase) >= 0)
#endif
{
var parts = line.Split('"');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;$(NetStandardMinimumSupportedVersion)</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Description>OpenTelemetry Extensions - Host Resource Detector.</Description>
<Description>OpenTelemetry Resource Detectors for Host.</Description>
<MinVerTagPrefix>Resources.Host-</MinVerTagPrefix>
</PropertyGroup>

<!--Do not run Package Baseline Validation as this package has never released a stable version.
Remove this property once we have released a stable version and add PackageValidationBaselineVersion property.-->
<!-- Do not run Package Baseline Validation as this package has never released a stable version.
Remove this property once we have released a stable version and add PackageValidationBaselineVersion property. -->
<PropertyGroup>
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\Shared\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Unit test project for Host Detector for OpenTelemetry</Description>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
<TargetFrameworks>$(SupportedNetTargets)</TargetFrameworks>
<TargetFrameworks>$(SupportedNetTargetsWithoutNet6)</TargetFrameworks>
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Description>Unit test project for Host Detector for OpenTelemetry.</Description>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 7f91d74

Please sign in to comment.