This library add open telemetry configuration extensions for .NET Core Api
- Install
Gainsway.Observabilitypackage in the target project
dotnet add package Gainsway.Observability- Register the Observability services in the Infrastructure project:
# InfrastructureServiceExtensions.cs
var appMetadata = builder.Configuration.GetApplicationMetadata();
builder.AddObservability(serviceName: appMetadata.ServiceName, commitShortSha: appMetadata.CommitShortSha);-
OPTIONAL To create tracing span for each method execution of a class, using .NET DI framework, the class's interface needs to be decorated by using one of the following extensions:
- Enable tracing for all services within a namespace
// Program.cs builder.Services.TraceAllServicesInNamespace("Gainsway");
- Enable tracing for services' interfaces decorated with Traceable attribute
// Program.cs builder.Services.TraceDecoratedServices();
// IMyService.cs [Traceable] public interface IMyService { // ... }
- Enable tracing for services explicitly defined in the config
// Program.cs builder.Services.TraceServices([typeof(IMyService), typeof(IOtherService)]);
-
OPTIONAL To create tracing span for each method execution of a class without using .NET DI framework:
using Gainsway.Observability // ... IMyService domainServiceInstance = new MyService(); IMyService decoratedInstance = TraceDecorator<IMyService>.Create(domainServiceInstance);
Note
In OpenTelemetry .NET environment variable keys are retrieved using
IConfiguration which means they may be set using other mechanisms such as
defined in appSettings.json or specified on the command-line.
The OpenTelemetry Specification defines environment variables which can be used to configure the OTLP exporter and its associated processor (logs & traces) or reader (metrics).
-
All signals
The following environment variables can be used to override the default values of the
OtlpExporterOptions:Environment variable OtlpExporterOptionspropertyOTEL_EXPORTER_OTLP_ENDPOINTEndpointOTEL_EXPORTER_OTLP_HEADERSHeadersOTEL_EXPORTER_OTLP_TIMEOUTTimeoutMillisecondsOTEL_EXPORTER_OTLP_PROTOCOLProtocol(grpcorhttp/protobuf) -
Logs:
The following environment variables can be used to override the default values for the batch processor configured for logging:
Environment variable BatchExportLogRecordProcessorOptionspropertyOTEL_BLRP_SCHEDULE_DELAYScheduledDelayMillisecondsOTEL_BLRP_EXPORT_TIMEOUTExporterTimeoutMillisecondsOTEL_BLRP_MAX_QUEUE_SIZEMaxQueueSizeOTEL_BLRP_MAX_EXPORT_BATCH_SIZEMaxExportBatchSizeThe following environment variables can be used to override the default values of the
OtlpExporterOptionsused for logging when using the UseOtlpExporter extension:Environment variable OtlpExporterOptionspropertyUseOtlpExporter AddOtlpExporter OTEL_EXPORTER_OTLP_LOGS_ENDPOINTEndpointSupported Not supported OTEL_EXPORTER_OTLP_LOGS_HEADERSHeadersSupported Not supported OTEL_EXPORTER_OTLP_LOGS_TIMEOUTTimeoutMillisecondsSupported Not supported OTEL_EXPORTER_OTLP_LOGS_PROTOCOLProtocol(grpcorhttp/protobuf)Supported Not supported -
Metrics:
The following environment variables can be used to override the default value of the
TemporalityPreferencesetting for the reader configured for metrics when using OTLP exporter:Environment variable MetricReaderOptionspropertyOTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCETemporalityPreferenceThe following environment variables can be used to override the default values of the periodic exporting metric reader configured for metrics:
Environment variable PeriodicExportingMetricReaderOptionspropertyOTEL_METRIC_EXPORT_INTERVALExportIntervalMillisecondsOTEL_METRIC_EXPORT_TIMEOUTExportTimeoutMillisecondsThe following environment variables can be used to override the default values of the
OtlpExporterOptionsused for metrics when using the UseOtlpExporter extension:Environment variable OtlpExporterOptionspropertyUseOtlpExporter AddOtlpExporter OTEL_EXPORTER_OTLP_METRICS_ENDPOINTEndpointSupported Not supported OTEL_EXPORTER_OTLP_METRICS_HEADERSHeadersSupported Not supported OTEL_EXPORTER_OTLP_METRICS_TIMEOUTTimeoutMillisecondsSupported Not supported OTEL_EXPORTER_OTLP_METRICS_PROTOCOLProtocol(grpcorhttp/protobuf)Supported Not supported -
Tracing:
The following environment variables can be used to override the default values for the batch processor configured for tracing:
Environment variable BatchExportActivityProcessorOptionspropertyOTEL_BSP_SCHEDULE_DELAYScheduledDelayMillisecondsOTEL_BSP_EXPORT_TIMEOUTExporterTimeoutMillisecondsOTEL_BSP_MAX_QUEUE_SIZEMaxQueueSizeOTEL_BSP_MAX_EXPORT_BATCH_SIZEMaxExportBatchSizeThe following environment variables can be used to override the default values of the
OtlpExporterOptionsused for tracing when using the UseOtlpExporter extension:Environment variable OtlpExporterOptionspropertyUseOtlpExporter AddOtlpExporter OTEL_EXPORTER_OTLP_TRACES_ENDPOINTEndpointSupported Not supported OTEL_EXPORTER_OTLP_TRACES_HEADERSHeadersSupported Not supported OTEL_EXPORTER_OTLP_TRACES_TIMEOUTTimeoutMillisecondsSupported Not supported OTEL_EXPORTER_OTLP_TRACES_PROTOCOLProtocol(grpcorhttp/protobuf)Supported Not supported
The OpenTelemetry Specification defines environment variables which can be used to configure attribute limits.
The following environment variables can be used to configure default attribute limits:
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMITOTEL_ATTRIBUTE_COUNT_LIMIT
The following environment variables can be used to configure span limits used for tracing:
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMITOTEL_SPAN_ATTRIBUTE_COUNT_LIMITOTEL_SPAN_EVENT_COUNT_LIMITOTEL_SPAN_LINK_COUNT_LIMITOTEL_EVENT_ATTRIBUTE_COUNT_LIMITOTEL_LINK_ATTRIBUTE_COUNT_LIMIT
The following environment variables can be used to configure log record limits used for logging:
OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMITOTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT