Skip to main content

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

System.String

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

System.String

OTelConstants.CommitShaEnvVar Field

The environment variable name used to resolve the service version (Git commit SHA).

public const string CommitShaEnvVar = "COMMIT_SHA";

Field Value

System.String

OTelConstants.DefaultEnvironment Field

The fallback deployment environment name when the environment variable is not set.

public const string DefaultEnvironment = "Development";

Field Value

System.String

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

System.String

OTelConstants.EnvironmentEnvVar Field

The environment variable name used to resolve the deployment environment.

public const string EnvironmentEnvVar = "ASPNETCORE_ENVIRONMENT";

Field Value

System.String

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

System.String

OTelConstants.ServiceNamespace Field

The service namespace grouping related services. Maps to the service.namespace resource attribute.

public const string ServiceNamespace = "arolariu.ro";

Field Value

System.String

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.nameServiceName
  • service.version — Git commit SHA (from COMMIT_SHA env var), assembly version, or 1.0.0
  • service.instance.id — Machine name
  • deployment.environmentASPNETCORE_ENVIRONMENT or Development
  • service.namespaceServiceNamespace
  • cloud.roleCloudRole
  • cloud.providerCloudProvider

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.

// was this page useful?