Skip to content

Commit

Permalink
Few fixes following .NET Standard 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joegoldman2 committed Oct 5, 2024
1 parent b5cc8f6 commit 8f72ae3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/OpenTelemetry.Resources.Container/ContainerDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ static Resource BuildResource(string containerId)
containerId = GetIdFromLineV1(line);
}
#if NET
else if (cgroupVersion == ParseMode.V2 && line.Contains(Hostname, StringComparison.Ordinal))
else if (parseMode == ParseMode.V2 && line.Contains(Hostname, StringComparison.Ordinal))
#else
else if (cgroupVersion == ParseMode.V2 && line.Contains(Hostname))
else if (parseMode == ParseMode.V2 && line.Contains(Hostname))
#endif
{
containerId = GetIdFromLineV2(line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<MinVerTagPrefix>Resources.Container-</MinVerTagPrefix>
</PropertyGroup>

<!-- Disable the nullable warnings when compiling for .NET Standard 2.0 -->
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<NoWarn>$(NoWarn);nullable</NoWarn>
</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. -->
<PropertyGroup>
Expand All @@ -15,6 +20,7 @@

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="$(OpenTelemetryCoreLatestVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonPkgVer)" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 11 additions & 11 deletions src/Shared/ResourceDetectorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#endif
using System.Text;
using System.Text.Json;
#if NET
#if !NETFRAMEWORK
using System.Text.Json.Serialization.Metadata;
#endif

Expand All @@ -17,7 +17,7 @@ namespace OpenTelemetry.Resources;
/// </summary>
internal static class ResourceDetectorUtils
{
#if !NET
#if NETFRAMEWORK
private static readonly JsonSerializerOptions JsonSerializerOptions = new(JsonSerializerDefaults.Web);
#endif

Expand Down Expand Up @@ -47,31 +47,31 @@ internal static async Task<string> SendOutRequestAsync(
}
}

#if NET
internal static T? DeserializeFromFile<T>(string filePath, JsonTypeInfo<T> jsonTypeInfo)
#if NETFRAMEWORK
internal static T? DeserializeFromFile<T>(string filePath)
{
using (var stream = GetStream(filePath))
{
return JsonSerializer.Deserialize(stream, jsonTypeInfo);
return JsonSerializer.Deserialize<T>(stream, JsonSerializerOptions);
}
}

internal static T? DeserializeFromString<T>(string json, JsonTypeInfo<T> jsonTypeInfo)
internal static T? DeserializeFromString<T>(string json)
{
return JsonSerializer.Deserialize(json, jsonTypeInfo);
return JsonSerializer.Deserialize<T>(json, JsonSerializerOptions);
}
#else
internal static T? DeserializeFromFile<T>(string filePath)
internal static T? DeserializeFromFile<T>(string filePath, JsonTypeInfo<T> jsonTypeInfo)
{
using (var stream = GetStream(filePath))
{
return JsonSerializer.Deserialize<T>(stream, JsonSerializerOptions);
return JsonSerializer.Deserialize(stream, jsonTypeInfo);
}
}

internal static T? DeserializeFromString<T>(string json)
internal static T? DeserializeFromString<T>(string json, JsonTypeInfo<T> jsonTypeInfo)
{
return JsonSerializer.Deserialize<T>(json, JsonSerializerOptions);
return JsonSerializer.Deserialize(json, jsonTypeInfo);
}
#endif

Expand Down

0 comments on commit 8f72ae3

Please sign in to comment.