arolariu.Backend.Common.Telemetry
arolariu.Backend.Common
arolariu.Backend.Common.Telemetry Namespace
Classes
OTelConstants Class
Centralized constants for OpenTelemetry resource configuration across all signal types (logging, tracing, metrics). These constants ensure consistent service identification in Azure Application Insights and other OTel backends.
public static class OTelConstants
Inheritance System.Object 🡒 OTelConstants
Remarks
All three OTel extensions (LoggingExtensions, TracingExtensions, MeteringExtensions) use these shared constants via ResourceBuilderFactory to eliminate configuration duplication and guarantee attribute alignment across signals.
Fields
OTelConstants.CloudProvider Field
The cloud provider identifier.
Maps to the cloud.provider resource attribute.
public const string CloudProvider = "azure";
Field Value
OTelConstants.CloudRole Field
The cloud role name used by Azure Application Insights for application map grouping.
Maps to the cloud.role resource attribute.
public const string CloudRole = "api";
Field Value
OTelConstants.CommitShaEnvVar Field
The environment variable name used to resolve the service version (Git commit SHA).
public const string CommitShaEnvVar = "COMMIT_SHA";
Field Value
OTelConstants.DefaultEnvironment Field
The fallback deployment environment name when the environment variable is not set.
public const string DefaultEnvironment = "Development";
Field Value
OTelConstants.DefaultServiceVersion Field
The fallback service version when neither the commit SHA nor the assembly version is available.
public const string DefaultServiceVersion = "1.0.0";
Field Value
OTelConstants.EnvironmentEnvVar Field
The environment variable name used to resolve the deployment environment.
public const string EnvironmentEnvVar = "ASPNETCORE_ENVIRONMENT";
Field Value
OTelConstants.ServiceName Field
The logical service name reported to OTel backends.
Maps to the service.name resource attribute.
public const string ServiceName = "arolariu-api";
Field Value
OTelConstants.ServiceNamespace Field
The service namespace grouping related services.
Maps to the service.namespace resource attribute.
public const string ServiceNamespace = "arolariu.ro";
Field Value
ResourceBuilderFactory Class
Factory for creating a shared OpenTelemetry.Resources.ResourceBuilder with consistent service identification attributes. This eliminates the triple duplication of resource configuration across logging, tracing, and metering extensions.
public static class ResourceBuilderFactory
Inheritance System.Object 🡒 ResourceBuilderFactory
Example
// In any OTel extension method:
otelOptions.SetResourceBuilder(ResourceBuilderFactory.Create());
Remarks
The resource builder produced by this factory includes:
service.name— ServiceNameservice.version— Git commit SHA (fromCOMMIT_SHAenv var), assembly version, or1.0.0service.instance.id— Machine namedeployment.environment—ASPNETCORE_ENVIRONMENTorDevelopmentservice.namespace— ServiceNamespacecloud.role— CloudRolecloud.provider— CloudProvider
Methods
ResourceBuilderFactory.Create() Method
Creates a OpenTelemetry.Resources.ResourceBuilder pre-configured with the standard service identification attributes.
public static OpenTelemetry.Resources.ResourceBuilder Create();
Returns
OpenTelemetry.Resources.ResourceBuilder
A configured OpenTelemetry.Resources.ResourceBuilder ready for use in OTel signal providers.