.NET Integration
Auto-instrument .NET applications with OpenTelemetry
Installation
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
dotnet add package OpenTelemetry.Instrumentation.Http
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
ASP.NET Core Setup
// Program.cs
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenTelemetry()
.WithTracing(tracerProviderBuilder =>
tracerProviderBuilder
.AddSource("MyApp")
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService("my-dotnet-service"))
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri("https://api.qorrelate.io/v1/otlp");
options.Headers = $"X-API-Key={builder.Configuration["Qorrelate:ApiKey"]}";
}));
var app = builder.Build();
app.Run();
Configuration
// appsettings.json
{
"Qorrelate": {
"ApiKey": "your_api_key_here"
},
"OpenTelemetry": {
"ServiceName": "my-dotnet-service",
"Environment": "production"
}
}
Docker Example
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY bin/Release/net8.0/publish/ .
ENV OTEL_SERVICE_NAME=my-dotnet-service
ENV OTEL_EXPORTER_OTLP_ENDPOINT=https://api.qorrelate.io/v1/otlp
ENTRYPOINT ["dotnet", "MyApp.dll"]