From c8117787812e36b346cac9ba78ffc579c8ce1997 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Fri, 19 Jan 2024 16:39:47 +0100 Subject: [PATCH] Added Activity DisplayName + TraceStateString --- README.md | 2 ++ .../LayoutRenderers/ActivityTraceLayoutRenderer.cs | 2 ++ .../LayoutRenderers/ActivityTraceProperty.cs | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 6952753..be32482 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Example of `NLog.config` file that outputs span-details together with LogEvent b - ParentId : Identifier for the parent activity - TraceId : Identifier for the root activity (Request Trace Identifier) - OperationName : Operation name of the current activity +- DisplayName : Explicit assigned Activity DisplayName (with fallback to OperationName) - StartTimeUtc : Time when the operation started - Duration : Duration of the operation (formatted as TimeSpan) - DurationMs : Duration of the operation (formatted as TimeSpan.TotalMilliseconds) @@ -69,6 +70,7 @@ Example of `NLog.config` file that outputs span-details together with LogEvent b - SourceName : Name of the activity source associated with this activity - SourceVersion : Version of the activity source associated with this activity - ActivityKind : Relationship kind between the activity, its parents, and its children. Can be combined with `format="d"` +- TraceStateString : W3C 'tracestate' header as a string **Formatting** - Format: Format for rendering the property. diff --git a/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceLayoutRenderer.cs b/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceLayoutRenderer.cs index 9c82272..396dfc4 100644 --- a/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceLayoutRenderer.cs +++ b/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceLayoutRenderer.cs @@ -175,6 +175,7 @@ private string GetValue(System.Diagnostics.Activity activity) case ActivityTraceProperty.SpanId: return activity.GetSpanId(); case ActivityTraceProperty.TraceId: return activity.GetTraceId(); case ActivityTraceProperty.OperationName: return activity.OperationName; + case ActivityTraceProperty.DisplayName: return activity.DisplayName; case ActivityTraceProperty.StartTimeUtc: return activity.StartTimeUtc > DateTime.MinValue ? activity.StartTimeUtc.ToString(Format, Culture) : string.Empty; case ActivityTraceProperty.Duration: return GetDuration(activity); case ActivityTraceProperty.ParentId: return activity.GetParentId(); @@ -186,6 +187,7 @@ private string GetValue(System.Diagnostics.Activity activity) case ActivityTraceProperty.SourceName: return activity.Source?.Name; case ActivityTraceProperty.SourceVersion: return activity.Source?.Version; case ActivityTraceProperty.ActivityKind: return ConvertToString(activity.Kind, Format); + case ActivityTraceProperty.TraceStateString: return activity.TraceStateString; default: return string.Empty; } } diff --git a/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceProperty.cs b/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceProperty.cs index 5b27d7b..6274539 100644 --- a/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceProperty.cs +++ b/src/NLog.DiagnosticSource/LayoutRenderers/ActivityTraceProperty.cs @@ -73,5 +73,13 @@ public enum ActivityTraceProperty /// Duration of the operation (formatted as TimeSpan.TotalMilliseconds) /// DurationMs, + /// + /// Explicit assigned Activity DisplayName (with fallback to OperationName) + /// + DisplayName, + /// + /// Holds the W3C 'tracestate' header as a string. See also + /// + TraceStateString, } } \ No newline at end of file