Files
speckle-sharp-connectors/Sdk/Speckle.Connectors.Logging/Internal/ResourceCreator.cs
T
Adam Hathcock 4f04e9e1b5 Use Metrics in Connectors (#296)
* add metrics to host apps

* merge fixes and compiles

* Use ME.Console and OTel for logging to correlate

* clean up

* clean up for metrics

* fix self-review comments

* fix seq initialization

* clean up for http traces and rhino 8

* use latest SDK

* formatting
2024-10-14 13:36:07 +00:00

44 lines
1.2 KiB
C#

using System.Runtime.InteropServices;
using OpenTelemetry.Resources;
namespace Speckle.Connectors.Logging.Internal;
internal static class ResourceCreator
{
internal static ResourceBuilder Create(string applicationAndVersion, string slug, string connectorVersion) =>
ResourceBuilder
.CreateEmpty()
.AddService(serviceName: Consts.TRACING_SOURCE, serviceVersion: connectorVersion)
.AddAttributes(
new List<KeyValuePair<string, object>>
{
new(Consts.SERVICE_NAME, applicationAndVersion),
new(Consts.SERVICE_SLUG, slug),
new(Consts.OS_NAME, Environment.OSVersion.ToString()),
new(Consts.OS_TYPE, RuntimeInformation.ProcessArchitecture.ToString()),
new(Consts.OS_SLUG, DetermineHostOsSlug()),
new(Consts.RUNTIME_NAME, RuntimeInformation.FrameworkDescription)
}
);
private static string DetermineHostOsSlug()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "Windows";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return "MacOS";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "Linux";
}
return RuntimeInformation.OSDescription;
}
}