Summary
In this chapter, we explored manual distributed tracing instrumentation using .NET diagnostics primitives. Activity
and ActivitySource
are the default ways to instrument your code – create, start, end, and enrich activities with attributes and events. You can achieve the same functionality with Tracer
and TelemetrySpan
, from the OpenTelemetry API package. They provide a thin wrapper over .NET diagnostics APIs while using OpenTelemetry terminology.
We also looked into the ambient context propagation with Activity.Current
and how it makes multiple instrumentation layers work together. Then, we learned about events and their limitations and used links to correlate different traces.
Finally, we covered testing – since instrumentation can be critical for monitoring, we should validate it as any other feature. We learned how to reliably do this in ASP.NET Core applications.
With this, you should be able to write rich tracing instrumentations and troubleshoot...