-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip ActivityData capture for NLog, since doing Layout capture (#379)
* Skip ActivityData capture for NLog, since doing Layout capture * address formatting --------- Co-authored-by: Martijn Laarman <[email protected]>
- Loading branch information
Showing
5 changed files
with
74 additions
and
3 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,51 @@ | ||
using System.Diagnostics; | ||
|
||
namespace Elastic.CommonSchema.NLog | ||
{ | ||
/// <summary> | ||
/// Helpers for getting the right values from Activity no matter the format (w3c or hierarchical) | ||
/// </summary> | ||
internal static class ActivityExtensions | ||
{ | ||
private static readonly ActivitySpanId EmptySpanId = default; | ||
private static readonly ActivityTraceId EmptyTraceId = default; | ||
|
||
public static string GetSpanId(this Activity activity) => | ||
activity.IdFormat == ActivityIdFormat.W3C ? | ||
SpanIdToHexString(activity.SpanId) : | ||
activity.Id; | ||
|
||
public static string GetTraceId(this Activity activity) => | ||
activity.IdFormat == ActivityIdFormat.W3C ? | ||
TraceIdToHexString(activity.TraceId) : | ||
activity.RootId; | ||
|
||
public static string GetParentId(this Activity activity) => | ||
activity.IdFormat == ActivityIdFormat.W3C ? | ||
SpanIdToHexString(activity.ParentSpanId) : | ||
activity.ParentId; | ||
|
||
private static string SpanIdToHexString(ActivitySpanId spanId) | ||
{ | ||
if (EmptySpanId.Equals(spanId)) | ||
return string.Empty; | ||
|
||
var spanHexString = spanId.ToHexString(); | ||
if (ReferenceEquals(spanHexString, EmptySpanId.ToHexString())) | ||
return string.Empty; | ||
|
||
return spanHexString; | ||
} | ||
|
||
private static string TraceIdToHexString(ActivityTraceId traceId) | ||
{ | ||
if (EmptyTraceId.Equals(traceId)) | ||
return string.Empty; | ||
|
||
var traceHexString = traceId.ToHexString(); | ||
return ReferenceEquals(traceHexString, EmptyTraceId.ToHexString()) | ||
? string.Empty | ||
: traceHexString; | ||
} | ||
} | ||
} |
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
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