Enriching and filtering telemetry
Traces and metrics coming from auto-instrumentation describe the technical side of an operation. While we can always add more spans with custom context (and we’ll learn how to do it in Chapter 6, Tracing Your Code), it could be more practical to add custom context to auto-collected telemetry.
Application-specific context is necessary to track usage and contains essential information that helps to detect and investigate issues.
For example, if we take our meme service, it would be very helpful to have the meme name and size on spans. With this, we’d be able to find the most popular memes, correlate meme upload and download requests, plan capacity, make cache optimizations, or reason about partitioning.
The easiest way to add a meme name is via the Activity.SetTag
method. For example, we can the following code on the Meme
page:
Meme.cshtml.cs
public async Task<IActionResult> OnGet([FromQuery] string name...