TaskHub.Shared

OpenTelemetry Integration

OpenTelemetry is the backbone of observability in TaskHub.Shared, unifying Traces, Metrics, and Logs.

Tracing

Tracing allows you to follow a single request across multiple microservices.

Automatic Instrumentation

TaskHub.Shared automatically instrument:

Manual Tracing

You can add your own spans using ActivitySource.

private static readonly ActivitySource MySource = new("MyCompany.MyService");

public async Task DoSomething()
{
    using var activity = MySource.StartActivity("CustomOperation");
    activity?.SetTag("custom.property", "value");
    
    // ... logic
}

Exporting Data

Data is exported using the OTLP protocol, typically to an OpenTelemetry Collector.

"OpenTelemetry": {
  "OtlpEndpoint": "http://otel-collector:4317",
  "SamplingRatio": 1.0
}

Correlation

The system ensures that TraceId is propagated across service boundaries via HTTP headers (traceparent). This allows you to see a complete distributed trace in tools like Grafana Tempo.

Registration

builder.Services.AddAppOpenTelemetry(o => {
    o.ServiceName = "MyService";
    o.OtlpEndpoint = "http://otel-collector:4317";
});