BlogDoFT.Libs.Api.OpenTelemetry
1.12.0
See the version list below for details.
dotnet add package BlogDoFT.Libs.Api.OpenTelemetry --version 1.12.0
NuGet\Install-Package BlogDoFT.Libs.Api.OpenTelemetry -Version 1.12.0
<PackageReference Include="BlogDoFT.Libs.Api.OpenTelemetry" Version="1.12.0" />
<PackageVersion Include="BlogDoFT.Libs.Api.OpenTelemetry" Version="1.12.0" />
<PackageReference Include="BlogDoFT.Libs.Api.OpenTelemetry" />
paket add BlogDoFT.Libs.Api.OpenTelemetry --version 1.12.0
#r "nuget: BlogDoFT.Libs.Api.OpenTelemetry, 1.12.0"
#:package BlogDoFT.Libs.Api.OpenTelemetry@1.12.0
#addin nuget:?package=BlogDoFT.Libs.Api.OpenTelemetry&version=1.12.0
#tool nuget:?package=BlogDoFT.Libs.Api.OpenTelemetry&version=1.12.0
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.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.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.