forked from RehanSaeed/Serilog.Enrichers.Span
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
63 additions
and
89 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
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,31 @@ | ||
namespace Serilog.Enrichers.Span | ||
{ | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
/// <summary> | ||
/// A log event enricher which adds tags from the current <see cref="Activity"/>. | ||
/// </summary> | ||
public class ActivityTagEnricher : ILogEventEnricher | ||
{ | ||
private const string ActivityTags = "Attributes"; | ||
|
||
/// <summary> | ||
/// Enrich the log event. | ||
/// </summary> | ||
/// <param name="logEvent">The log event to enrich.</param> | ||
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param> | ||
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) | ||
{ | ||
var activity = Activity.Current; | ||
|
||
if (activity is not null) | ||
{ | ||
var tags = activity.Tags.Select(tag => new LogEventProperty(tag.Key, new ScalarValue(tag.Value))); | ||
logEvent.AddPropertyIfAbsent(new LogEventProperty(ActivityTags, new StructureValue(tags))); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Serilog.Enrichers.Span | ||
{ | ||
/// <summary> | ||
/// Options. | ||
/// </summary> | ||
public class SpanOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets a value indicating whether to include tags in log or not. Default is false. | ||
/// </summary> | ||
public bool IncludeTags { get; set; } | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.