dotnet add package Core.Observability
- trace id in response header
- sends logs, metrics and traces to opentelemetry collector
- enrichment/augmentation of logs and traces even when exceptions occurr
- inject trace id to http requests
- health checks
- best practices from aspire
- servicediscovery
- http resilience handler
builder.AddObservability();
builder.Services.Configure<ObservabilityOptions>(options =>
{
options.TraceIdHeader = "x-trace-id";
options.Augment = (context, tags) =>
{
tags.Add("TenantId", "extrakt from http context");
return ValueTask.CompletedTask;
};
});
// optional
app.MapObservabilityHealthChecks();
app.UseAuthorization();
// required
app.UseObservability();
app.MapControllers();
app.Run();
builder.AddObservability(configureTracing: tracer =>
{
tracer.AddEntityFrameworkCoreInstrumentation();
tracer.AddRedisInstrumentation();
});
"OTEL_SERVICE_NAME": "my-project",
"OTEL_RESOURCE_ATTRIBUTES": "service.namespace=core,environment.name=dev",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317",
or
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://collector:4317",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc"