Class OpenTelemetryExtensions
- Namespace
- Microsoft.Extensions.Hosting
- Assembly
- Stratara.ServiceDefaults.dll
OpenTelemetry wiring used by every Stratara host. Configures logging + metrics + tracing with HTTP,
EF Core, RabbitMQ, and runtime instrumentation, and registers an OTLP exporter automatically when
the OTEL_EXPORTER_OTLP_ENDPOINT configuration value is non-empty.
public static class OpenTelemetryExtensions
- Inheritance
-
OpenTelemetryExtensions
- Inherited Members
Remarks
When the OTLP exporter is enabled, the export timeout (OTEL_EXPORTER_OTLP_TIMEOUT) defaults
to 5000 ms instead of the OTel spec default of 10 000 ms to keep host shutdown / metric flush
reactive when the collector is unreachable. Consumers can override either default via the same
environment variable or configuration key.
HTTP-client instrumentation registers an enrichment callback that overwrites any
http.request.header.authorization / http.request.header.cookie /
http.response.header.set-cookie tags with "REDACTED". This defends against bearer
tokens or session cookies leaking into trace exporters when a consumer opts into header capture
(via OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS or the SDK's own options). The default OTel
behaviour without that opt-in is already to omit headers, so for most consumers this is a
belt-and-braces safeguard.
Methods
ConfigureOpenTelemetry<TBuilder>(TBuilder, Action<MeterProviderBuilder>?, Action<TracerProviderBuilder>?)
Configures OpenTelemetry logging + metrics + tracing on the given host builder.
Adds default instrumentation (HTTP client, EF Core, RabbitMQ, runtime) and wires the OTLP exporter
when OTEL_EXPORTER_OTLP_ENDPOINT is set.
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder, Action<MeterProviderBuilder>? configureMetrics = null, Action<TracerProviderBuilder>? configureTracing = null) where TBuilder : IHostApplicationBuilder
Parameters
builderTBuilderThe host application builder.
configureMetricsAction<MeterProviderBuilder>Optional callback to extend the metrics pipeline with host-specific meters/exporters.
configureTracingAction<TracerProviderBuilder>Optional callback to extend the tracing pipeline with host-specific sources/exporters.
Returns
- TBuilder
The same builder for chaining.
Type Parameters
TBuilderThe host-builder type.
Examples
Exports over OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is set, and stays local when it is not:
builder.ConfigureOpenTelemetry();