-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using Microsoft.Win32; | ||
using OpenTelemetry.Resources; | ||
|
@@ -17,7 +16,10 @@ namespace OpenTelemetry.ResourceDetectors.Host; | |
/// </summary> | ||
public sealed class HostDetector : IResourceDetector | ||
{ | ||
private const string ETC_MACHINEID = "/etc/machine-id"; | ||
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net7.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net7.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net8.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net8.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net6.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net6.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
Check failure on line 19 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
|
||
private const string ETC_VAR_DBUS_MACHINEID = "/var/lib/dbus/machine-id"; | ||
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net7.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net7.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net8.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net8.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net6.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net6.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
Check failure on line 20 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
|
||
private readonly PlatformID platformId; | ||
private readonly Func<IEnumerable<string>> getFilePaths; | ||
private readonly Func<string> getMacOsMachineId; | ||
private readonly Func<string> getWindowsMachineId; | ||
|
||
|
@@ -27,6 +29,7 @@ public sealed class HostDetector : IResourceDetector | |
public HostDetector() | ||
: this( | ||
Environment.OSVersion.Platform, | ||
GetFilePaths, | ||
GetMachineIdMacOs, | ||
GetMachineIdWindows) | ||
{ | ||
|
@@ -38,9 +41,10 @@ public HostDetector() | |
/// <param name="platformId">Target platform ID.</param> | ||
/// <param name="getMacOsMachineId">Function to get MacOS machine ID.</param> | ||
/// <param name="getWindowsMachineId">Function to get Windows machine ID.</param> | ||
internal HostDetector(PlatformID platformId, Func<string> getMacOsMachineId, Func<string> getWindowsMachineId) | ||
internal HostDetector(PlatformID platformId, Func<IEnumerable<string>> getFilePaths, Func<string> getMacOsMachineId, Func<string> getWindowsMachineId) | ||
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net7.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net7.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net8.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net8.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net6.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (ubuntu-latest, net6.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net7.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net462)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net6.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
Check failure on line 44 in src/OpenTelemetry.ResourceDetectors.Host/HostDetector.cs GitHub Actions / build-test-host / build-test (windows-latest, net8.0)
|
||
{ | ||
this.platformId = platformId; | ||
this.getFilePaths = getFilePaths ?? throw new ArgumentNullException(nameof(getFilePaths)); | ||
this.getMacOsMachineId = getMacOsMachineId ?? throw new ArgumentNullException(nameof(getMacOsMachineId)); | ||
this.getWindowsMachineId = getWindowsMachineId ?? throw new ArgumentNullException(nameof(getWindowsMachineId)); | ||
} | ||
|
@@ -68,6 +72,12 @@ public Resource Detect() | |
return Resource.Empty; | ||
} | ||
|
||
private static IEnumerable<string> GetFilePaths() | ||
{ | ||
yield return ETC_MACHINEID; | ||
yield return ETC_VAR_DBUS_MACHINEID; | ||
} | ||
|
||
private static string GetMachineIdMacOs() | ||
{ | ||
var startInfo = new ProcessStartInfo | ||
|
@@ -108,7 +118,7 @@ private string GetMachineId() | |
|
||
private string GetMachineIdLinux() | ||
{ | ||
var paths = new[] { "/etc/machine-id", "/var/lib/dbus/machine-id" }; | ||
var paths = this.getFilePaths(); | ||
|
||
foreach (var path in paths) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
etc_machineid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
etc_var_dbus_machineid |