OpenTelemetry is the backbone of observability in TaskHub.Shared, unifying Traces, Metrics, and Logs.
Tracing allows you to follow a single request across multiple microservices.
TaskHub.Shared automatically instrument:
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
}
Data is exported using the OTLP protocol, typically to an OpenTelemetry Collector.
"OpenTelemetry": {
"OtlpEndpoint": "http://otel-collector:4317",
"SamplingRatio": 1.0
}
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.
builder.Services.AddAppOpenTelemetry(o => {
o.ServiceName = "MyService";
o.OtlpEndpoint = "http://otel-collector:4317";
});