End-to-End .NET Observability with OpenTelemetry
When one user request crosses an API gateway, an application service, a cache, and a database, one server log is not enough. Observability is the ability to infer internal system state from traces, metrics, and logs. OpenTelemetry provides vendor-neutral APIs and protocols for producing those signals and sending them to different monitoring backends.
Different jobs for three signals
Metrics show how often and how severely a system is failing, such as error rate and p95 latency. A trace explains the path and timing of one request across services. Logs contain detailed events. When TraceId and SpanId are included in structured logs, an engineer can move from an alert to a problematic request and then to the exact related events.
ASP.NET Core configuration
This baseline instruments incoming HTTP requests, HttpClient calls, and EF Core activity. The exporter can target an OTLP collector, console output, or another backend depending on the environment.
builder.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddEntityFrameworkCoreInstrumentation()
.AddOtlpExporter())
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddRuntimeInstrumentation()
.AddOtlpExporter());Avoid high-cardinality or sensitive attributes such as email addresses, raw queries, and tokens. Prefer route names, status values, dependency types, and safe business identifiers. Tune sampling to traffic volume and prioritize retaining failed and unusually slow traces.
Implementation steps
- Define user-centered service indicators such as availability, error rate, and latency.
- Apply consistent service names and environment resource attributes.
- Add HTTP, database, and messaging instrumentation deliberately.
- Include TraceId in structured logging fields.
- Build dashboards and alert thresholds from measured baseline behavior.
What to avoid
- Sampling every request at high traffic and allowing telemetry cost to grow without limits.
- Exporting personal data or authentication tokens as span attributes.
- Creating many charts without a small set of reliable alerts tied to user impact.
Conclusion
OpenTelemetry does not create observability by itself. Teams still need meaningful signals, safe attributes, and useful alert design. Instrument one critical user journey end to end before expanding coverage. The objective is not to collect more data, but to answer production questions faster with evidence.
0 Yorumlar