Skip to main content

arolariu.Backend.Common.Telemetry

arolariu.Backend.Common​

arolariu.Backend.Common.Telemetry Namespace​

Classes​

HealthTelemetryPolicy Class​

Central policy deciding whether OpenTelemetry signals should be suppressed for a request path.

public static class HealthTelemetryPolicy

Inheritance System.Object 🡒 HealthTelemetryPolicy

Remarks​

Health and connectivity probes dominate request volume without carrying diagnostic value. This policy is consulted by trace filters, the suppression middleware, and log filtering so that the suppressed path list is defined exactly once for this service.

Constructors​

HealthTelemetryPolicy() Constructor​

static HealthTelemetryPolicy();

Fields​

HealthTelemetryPolicy.SuppressedPaths Field​

private static readonly string[] SuppressedPaths;

Field Value​

System.String[]

HealthTelemetryPolicy.SuppressionEnvVar Field​

The environment variable controlling whether health telemetry suppression is active.

public const string SuppressionEnvVar = "OTEL_SUPPRESS_HEALTH_TELEMETRY";

Field Value​

System.String

Remarks​

Defaults to enabled. Only the literal value false disables suppression.

Properties​

HealthTelemetryPolicy.IsSuppressionEnabled Property​

Gets a value indicating whether suppression is enabled for the current process.

public static bool IsSuppressionEnabled { get; }

Property Value​

System.Boolean
true unless SuppressionEnvVar is set to false.

Methods​

HealthTelemetryPolicy.IsSuppressedPath(string) Method​

Determines whether the supplied path is one of the suppressed health endpoints.

public static bool IsSuppressedPath(string? path);

Parameters​

path System.String

The request path, with or without a query string.

Returns​

System.Boolean
true when the path matches a suppressed endpoint.

Remarks​

Matching is exact on the normalized path, never prefix-based.

HealthTelemetryPolicy.Normalize(string) Method​

private static string Normalize(string path);

Parameters​

path System.String

Returns​

System.String

HealthTelemetryPolicy.ParseSuppressionFlag(string) Method​

Parses the raw suppression environment variable value.

public static bool ParseSuppressionFlag(string? rawValue);

Parameters​

rawValue System.String

The raw environment variable value, possibly null or malformed.

Returns​

System.Boolean
false only when rawValue parses as false.

Remarks​

Unset and unparseable values resolve to the safe default of enabled suppression.

HealthTelemetryPolicy.ShouldRecordHttpContext(HttpContext) Method​

Returns true when the request represented by context should be included in distributed traces.

public static bool ShouldRecordHttpContext(Microsoft.AspNetCore.Http.HttpContext context);

Parameters​

context Microsoft.AspNetCore.Http.HttpContext

The incoming ASP.NET Core HTTP context.

Returns​

System.Boolean
false when the request targets a suppressed health probe path; true otherwise.

Remarks​

Intended for use as the AspNetCoreTraceInstrumentationOptions.Filter method group. Fails open: a null context resolves to true (record the activity).

HealthTelemetryPolicy.ShouldRecordHttpRequestMessage(HttpRequestMessage) Method​

Returns true when the outbound request represented by request should be included in distributed traces.

public static bool ShouldRecordHttpRequestMessage(System.Net.Http.HttpRequestMessage request);

Parameters​

request System.Net.Http.HttpRequestMessage

The outbound System.Net.Http.HttpRequestMessage.

Returns​

System.Boolean
false when the request targets a suppressed health probe path; true otherwise.

Remarks​

Intended for use as the HttpClientTraceInstrumentationOptions.FilterHttpRequestMessage method group. Fails open: a null request resolves to true (record the activity).

HealthTelemetryPolicy.ShouldSuppress(string) Method​

Determines whether telemetry should be suppressed for the supplied path.

public static bool ShouldSuppress(string? path);

Parameters​

path System.String

The request path, with or without a query string.

Returns​

System.Boolean
true when telemetry must be suppressed.

Remarks​

Fails safe toward suppression: an unset or unparseable SuppressionEnvVar leaves suppression enabled, so cost control holds even when the environment is misconfigured. Only the literal value false re-enables health telemetry.

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.name — ServiceName
  • service.version — Git commit SHA (from COMMIT_SHA env var), assembly version, or 1.0.0
  • service.instance.id — Machine name
  • deployment.environment — ASPNETCORE_ENVIRONMENT or Development
  • service.namespace — ServiceNamespace
  • cloud.role — CloudRole
  • cloud.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.

// was this page useful?