Making Traces Useful
To support monitoring and diagnostics, high-quality spans should have:
- a descriptive name
- a low-cardinality name
- attached attributes (tags) that can be used for filtering, grouping and analyzing events
Descriptive span names help you to interpret traces and understand the flow of control. The span names generated by instrumented libraries do not always carry enough context to clearly communicate what is happening within the application.
Make span names low-cardinality by interpolating variables. For example, all spans representing a currency conversion should have the same name, so that Seq will consider them to have the same event type.
DO
Include placeholders in span event messages and attach corresponding properties:
// SerilogTracing syntax logger.StartActivity("Converting {SourceCurrency} to {TargetCurrency}", "AUD", "GBP"); // OpenTelemetry .NET SDK syntax var activity = tracingSource.StartActivity("Converting {SourceCurrency} to {TargetCurrency}"); activity?.SetTag("SourceCurrency", "AUD"); activity?.SetTag("TargetCurrency", "GBP");
DON'T
Freeze variables in span event messages:
// SerilogTracing syntax logger.StartActivity("Converting GBP to AUD"); logger.StartActivity("Converting USD to DKK"); // OpenTelemetry .NET SDK syntax tracingSource.StartActivity("Converting GBP to AUD"); tracingSource.StartActivity("Converting USD to DKK");
Updated 10 months ago