https://github.com/coronabytes/observability
Easy ASP.NET Core OpenTelemetry Setup
https://github.com/coronabytes/observability
csharp grafana opentelemetry
Last synced: 5 months ago
JSON representation
Easy ASP.NET Core OpenTelemetry Setup
- Host: GitHub
- URL: https://github.com/coronabytes/observability
- Owner: coronabytes
- License: mit
- Created: 2024-07-18T20:09:57.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-12-25T18:41:15.000Z (6 months ago)
- Last Synced: 2025-01-31T21:52:43.235Z (5 months ago)
- Topics: csharp, grafana, opentelemetry
- Language: C#
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/Core.Observability)
[](https://www.nuget.org/packages/Core.Observability)```
dotnet add package Core.Observability
```
# 3-Line OpenTelemetry ASP.NET Core Integration
- 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## Initialization in ASP.NET Core
```csharp
builder.AddObservability();builder.Services.Configure(options =>
{
options.TraceIdHeader = "x-trace-id";
options.Augment = (context, tags) =>
{
tags.Add("TenantId", "extrakt from http context");
return ValueTask.CompletedTask;
};
});
``````csharp
// optional
app.MapObservabilityHealthChecks();app.UseAuthorization();
// required
app.UseObservability();app.MapControllers();
app.Run();
```## More Instrumentation
```csharp
builder.AddObservability(configureTracing: tracer =>
{
tracer.AddEntityFrameworkCoreInstrumentation();
tracer.AddRedisInstrumentation();
});
```## Environment Variables
```
"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"
```