-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hoist activity fields to the logging scope (#11211)
- Expose SpanId, TraceId and ParentId to logging scope properties - Added tests to verify the Hierarchical ID format - Store the activity and lazily compute the various properties
- Loading branch information
Showing
4 changed files
with
101 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace Microsoft.AspNetCore.Hosting.Internal | ||
{ | ||
/// <summary> | ||
/// Helpers for getting the right values from Activity no matter the format (w3c or hierarchical) | ||
/// </summary> | ||
internal static class ActivityExtensions | ||
{ | ||
public static string GetSpanId(this Activity activity) | ||
{ | ||
return activity.IdFormat switch | ||
{ | ||
ActivityIdFormat.Hierarchical => activity.Id, | ||
ActivityIdFormat.W3C => activity.SpanId.ToHexString(), | ||
_ => null, | ||
} ?? string.Empty; | ||
} | ||
|
||
public static string GetTraceId(this Activity activity) | ||
{ | ||
return activity.IdFormat switch | ||
{ | ||
ActivityIdFormat.Hierarchical => activity.RootId, | ||
ActivityIdFormat.W3C => activity.TraceId.ToHexString(), | ||
_ => null, | ||
} ?? string.Empty; | ||
} | ||
|
||
public static string GetParentId(this Activity activity) | ||
{ | ||
return activity.IdFormat switch | ||
{ | ||
ActivityIdFormat.Hierarchical => activity.ParentId, | ||
ActivityIdFormat.W3C => activity.ParentSpanId.ToHexString(), | ||
_ => null, | ||
} ?? string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters