TaskHub.Shared

OpenTelemetry (OTEL)

OpenTelemetry is an open-source observability framework for cloud-native software. It provides a vendor-neutral set of APIs and SDKs to collect and export traces, metrics, and logs.

In TaskHub, OTEL is the shared spine that ties together logs (Loki), metrics (Prometheus), and traces (Tempo) into a single observable system.

🎯 Why OTEL Here

🧭 The Three Signals

Signal What it answers TaskHub backend
Traces β€œWhere did this request spend its time, and who did it call?” Grafana Tempo
Metrics β€œHow fast / how many / how big β€” over time?” Prometheus
Logs β€œWhat happened, in human-readable detail?” Grafana Loki

All three are stitched together by TraceId and SpanId, so a slow trace in Tempo links directly to its log lines in Loki.

πŸ“¦ Module

TaskHub.Observability.OpenTelemetry provides:

See OpenTelemetry usage for setup and OpenTelemetry architecture for internals.

βš™οΈ Minimal Configuration

"OpenTelemetry": {
  "ServiceVersion": "1.0",
  "Protocol": "grpc",
  "TracingEndpoint": "http://otel-collector:4317",
  "Environment": "Production",
  "RecordException": true,
  "IsHttpTracesEnabled": true,
  "IsAspNetTracesEnabled": true,
  "IsEFCoreTracesEnabled": true,
  "Ignore": [ "/health", "/metrics", "/swagger" ],
  "Sources": [ "ReaderRepository", "WriterRepository" ],
  "Sampling": { "IsEnabled": true, "Type": "AlwaysOn" }
}

Sources is the list of custom ActivitySource names your service emits β€” list every one, or spans won’t be exported.

πŸ§ͺ Sampling Strategies

Type Behavior When to use
AlwaysOn Every trace exported. Dev, staging, low-traffic services.
AlwaysOff Nothing exported. Trace-only-on-demand setups.
TraceIdRatio Random fraction (e.g. 0.1 = 10%). High-traffic production.
ParentBased Inherit decision from upstream service. Chained microservices.

βœ… Best Practices

πŸ”— See Also