A production-ready shared OpenTelemetry configuration library for .NET 8 and .NET 9 applications with runtime configuration, multi-exporter support, and extensibility.
- ✅ Multi-targeting for .NET 8 and .NET 9
- ✅ Configuration via
appsettings.jsonwithIOptionsMonitorsupport - ✅ Runtime toggling of tracing and metrics
- ✅ Multiple exporters: OTLP, Prometheus, Console
- ✅ Extensible API for custom instrumentation
- ✅ Environment variable overrides (OTEL standard)
- ✅ Built-in instrumentation for ASP.NET Core, HTTP, SQL, Runtime, Process
- ✅ Custom metrics support
- ✅ Configurable sampling, resource attributes, and service naming
- ✅ Defensive coding with validation and logging
- ✅ Source Link and symbols for debugging
| Key | Type | Default | Description |
|---|---|---|---|
| EnableTracing | bool | false | Enable distributed tracing |
| EnableMetrics | bool | true | Enable metrics collection |
| OtlpEndpoint | string | http://otlp.kavenegar.io:4317 | OTLP collector endpoint |
| OtlpProtocol | string | Grpc | Protocol: Grpc or HttpProtobuf |
| ServiceName | string | (assembly name) | Service name for telemetry |
| ServiceVersion | string | 1.0.0 | Service version |
| ResourceAttributes | dict | {} | Additional resource attributes |
| EnablePrometheusExporter | bool | false | Enable Prometheus /metrics endpoint |
| EnableConsoleExporter | bool | false | Enable console output (debug) |
| EnableAspNetCoreInstrumentation | bool | true | ASP.NET Core auto-instrumentation |
| EnableHttpClientInstrumentation | bool | true | HTTP client auto-instrumentation |
| EnableSqlClientInstrumentation | bool | true | SQL client auto-instrumentation |
| EnableRuntimeInstrumentation | bool | true | .NET runtime metrics |
| EnableProcessInstrumentation | bool | true | Process metrics (CPU, memory) |
| CustomMeters | string[] | [] | Additional meter names to collect |
| SamplingRatio | double | 1.0 | Trace sampling (0.0-1.0) |
| IncludeMachineNameInServiceName | bool | true | Add machine name to service name |
| IncludeInstanceIdInServiceName | bool | true | Add instance GUID to service name |
| RecordSqlStatements | bool | false | Record SQL text (may contain PII) |
| RecordExceptions | bool | true | Record exceptions in traces |
# list tag
git tag -l
# Delete locally
git tag -d v1.0.0
# Delete from remote
git push origin --delete v1.0.0
# Create annotated tag with message
git tag -a v1.0.0 -m "Release version 1.0.0 - Production ready"
# Push it
git push origin v1.0.0dotnet add package Kavenegar.OpenTelemetry.Shared
dotnet nuget push OpenTelemetry.Shared.1.0.1-beta.1.nupkg -s https://nexus.kavenegar.io/repository/nuget-hosted/ -k 03677d61-5807-3dc0-a02b-eda5f6e5430e- Add to your appsettings.json
{
"OpenTelemetry": {
"ServiceName": "Your Service Name",
"ServiceVersion": "1.0.0",
"EnablePrometheusExporter": true
}
}-
Add Package From Nexus
USE PACKAGE WITH "-RC-" POSTFIX
dotnet add package Kavenegar.OpenTelemetry.Shared - Configure in Program.cs
builder.Services.AddOpenTelemetryService(builder.Configuration);
var app = builder.Build();
// Enable Prometheus endpoint if configured
if (app.Configuration.GetValue<bool>("OpenTelemetry:EnablePrometheusExporter"))
{
app.MapPrometheusScrapingEndpoint();
}