BlogDoFT.Libs.Api.OpenTelemetry
10.1.1
dotnet add package BlogDoFT.Libs.Api.OpenTelemetry --version 10.1.1
NuGet\Install-Package BlogDoFT.Libs.Api.OpenTelemetry -Version 10.1.1
<PackageReference Include="BlogDoFT.Libs.Api.OpenTelemetry" Version="10.1.1" />
<PackageVersion Include="BlogDoFT.Libs.Api.OpenTelemetry" Version="10.1.1" />
<PackageReference Include="BlogDoFT.Libs.Api.OpenTelemetry" />
paket add BlogDoFT.Libs.Api.OpenTelemetry --version 10.1.1
#r "nuget: BlogDoFT.Libs.Api.OpenTelemetry, 10.1.1"
#:package BlogDoFT.Libs.Api.OpenTelemetry@10.1.1
#addin nuget:?package=BlogDoFT.Libs.Api.OpenTelemetry&version=10.1.1
#tool nuget:?package=BlogDoFT.Libs.Api.OpenTelemetry&version=10.1.1
BlogDoFT.Libs.Api.OpenTelemetry
Helpers to integrate OpenTelemetry tracing, metrics and logs into ASP.NET Core APIs.
This library provides opinionated wiring and small helpers to capture common HTTP server telemetry, plus configuration mapping from IConfiguration so you can control exporters and instrumentations from appsettings.json.
Features
- Easy registration of OpenTelemetry tracing, metrics and logs via a single
AddOtelextension method - Configuration object model that maps to
IConfiguration(see sampleappsettings.jsonbelow) - Automatic registration of exporters (Console / Zipkin / OTLP / Prometheus) based on configuration
Quick start
- Reference the package in your Web API project.
- In
Program.csorStartup.cs, call the extension methods:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOtel(builder.Configuration);
var app = builder.Build();
app.UseOpenTelemetry();
app.Run();
Configuration (appsettings.json)
The library reads an Observability section from IConfiguration. Minimal example enabling console tracing and metrics:
{
"ApplicationName": "MyWebApi",
"Observability": {
"OpenTelemetry": {
"IncludeFormattedMessage": true,
"IncludeScopes": true,
"ParseStateValues": true,
"UseTracingExporter": "Console",
"UseMetricsExporter": "Console",
"UseLogExporter": "Console",
"HistogramAggregation": "ExplicitBounds"
}
}
}
Enabling Zipkin exporter:
{
"Observability": {
"OpenTelemetry": {
"UseTracingExporter": "Zipkin"
},
"ZipkinExporterOptions": {
"Endpoint": "http://localhost:9411/api/v2/spans"
}
}
}
Enabling OTLP exporter (gRPC):
{
"Observability": {
"OpenTelemetry": {
"UseTracingExporter": "Otlp",
"UseMetricsExporter": "Otlp"
},
"OtlpExporterOptions": {
"Endpoint": "http://otel-collector:4317",
"Protocol": "Grpc"
}
}
}
Prometheus metrics
To enable Prometheus scraping endpoint set the metrics exporter to Prometheus and (optionally) configure PrometheusAspNetCoreOptions.
Notes
- The library maps configuration into the
Observabilityobject model. See theObservabilityand nested classes for all available fields and defaults. - When using OTLP, the default endpoint is
http://localhost:4317and default protocol is gRPC.
Versioning
Starting with v10.0.0, this library's version numbering follows the major version of the .NET runtime it targets. For example, this version is compatible with .NET 10, so the major version is 10 — this explains the jump from the previous 1.x version series.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- OpenTelemetry.Exporter.Console (>= 1.18.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.18.0)
- OpenTelemetry.Exporter.Prometheus.AspNetCore (>= 1.18.0-beta.1)
- OpenTelemetry.Exporter.Zipkin (>= 1.18.0)
- OpenTelemetry.Extensions.Hosting (>= 1.18.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.18.0)
- OpenTelemetry.Instrumentation.Http (>= 1.18.0)
- OpenTelemetry.Instrumentation.Runtime (>= 1.18.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.