Skip to content

Commit

Permalink
add missing musl check
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshnj committed Mar 4, 2025
1 parent ef0eda3 commit 73e34b1
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tracer/src/Datadog.Trace/LibDatadog/TraceExporterNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ private static string GetRuntimeIdentifier()
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
bool isMusl = IsAlpine();
return RuntimeInformation.ProcessArchitecture switch
{
Architecture.X64 => "linux-x64",
Architecture.Arm64 => "linux-arm64",
Architecture.X64 => isMusl ? "linux-musl-x64" : "linux-x64",
Architecture.Arm64 => isMusl ? "linux-musl-arm64" : "linux-arm64",
_ => throw new PlatformNotSupportedException($"Architecture {RuntimeInformation.ProcessArchitecture} is not supported")
};
}
Expand Down Expand Up @@ -130,6 +131,33 @@ private static string GetRuntimeIdentifier()
#endif
}

/// <summary>
/// Check if the current OS is Alpine Linux.
/// </summary>
public static bool IsAlpine()
{
try
{
if (File.Exists("/etc/os-release"))
{
var strArray = File.ReadAllLines("/etc/os-release");
foreach (var str in strArray)
{
if (str.StartsWith("ID=", StringComparison.Ordinal))
{
return str.Substring(3).Trim('"', '\'') == "alpine";
}
}
}
}
catch
{
// ignore error checking if the file doesn't exist or we can't read it
}

return false;
}

[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern ErrorHandle ddog_trace_exporter_new(out IntPtr outHandle, SafeHandle config);

Expand Down

0 comments on commit 73e34b1

Please sign in to comment.