Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coronabytes/observability
Easy ASP.NET Core OpenTelemetry Setup
https://github.com/coronabytes/observability
csharp grafana opentelemetry
Last synced: 3 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 (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-10T07:48:55.000Z (5 months ago)
- Last Synced: 2024-09-28T15:40:53.339Z (3 months ago)
- Topics: csharp, grafana, opentelemetry
- Language: C#
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Nuget](https://img.shields.io/nuget/v/Core.Observability)](https://www.nuget.org/packages/Core.Observability)
[![Nuget](https://img.shields.io/nuget/dt/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"
```