getsentry / getsentry/sentry-dotnet

Add Serilog log's properties as Breadcrumb data

Open
#4,152 7 comments 1 reaction 0 assignees View on GitHub
.NET Improvement Serilog
Dominant language
C#
Stars
770
Forks
248
Avg merge
3d 4h
Merged PRs (30d)
49

Description

[This line](https://github.com/getsentry/sentry-dotnet/blob/1bf37620fe5955defb7eca8aa1218e3a969d9413/src/Sentry.Serilog/SentrySink.cs#L114C27-L114C52) shows that a serilog log's properties are set as 'extra' for *the event*, but once I log an event and add properties, it is nowhere to be found.
This does not fit so much with the behavior in other sinks I have seen so far.

Is there a reason for this?
Perhaps a function in the style of `ExtractBreadCrumbDataFromLogEvent` below would be better?

```cs
class SentrySink : ILogEventSink
{
public void Emit(LogEvent logEvent)
{
Dictionary breadcrumbData = ExtractBreadCrumbDataFromLogEvent(logEvent);

SentrySdk.AddBreadcrumb(
message: logEvent.RenderMessage(),
category: "Log",
type: "Default",
data: breadcrumbData,
level: MapLevel(logEvent.Level)
);
}

private static Dictionary ExtractBreadCrumbDataFromLogEvent(LogEvent logEvent)
{
var breadcrumbData = new Dictionary();

if (logEvent.Exception is not null)
breadcrumbData["Exception"] = logEvent.Exception.ToString().Trim('"');

foreach (var prop in logEvent.Properties)
breadcrumbData[prop.Key] = prop.Value.ToString().Trim('"');

return breadcrumbData;
}

private static BreadcrumbLevel MapLevel(LogEventLevel level) =>
level switch
{
LogEventLevel.Verbose => BreadcrumbLevel.Debug,
LogEventLevel.Debug => BreadcrumbLevel.Debug,
LogEventLevel.Information => BreadcrumbLevel.Info,
LogEventLevel.Warning => BreadcrumbLevel.Warning,
LogEventLevel.Error => BreadcrumbLevel.Error,
LogEventLevel.Fatal => BreadcrumbLevel.Critical,
_ => BreadcrumbLevel.Info
};
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.