Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Serilog integration #118

Merged
merged 7 commits into from
Nov 21, 2018
Merged

Add Serilog integration #118

merged 7 commits into from
Nov 21, 2018

Conversation

Mitch528
Copy link
Contributor

No description provided.

@bruno-garcia
Copy link
Member

bruno-garcia commented Oct 12, 2018

Thanks for this @Mitch528
Serilog was really missing here!

Could you please add a sample project?

Also, I wonder, how does it work when combined with ASP.NET Core?

@Mitch528
Copy link
Contributor Author

Done.

I haven't tested it with ASP.NET Core, but I'm not sure if it would combine well with it since the AspNetCore package uses Sentry.Extensions.Logging and I'm guessing both would attempt to send the same event to Sentry if used together.

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462</TargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bruno-garcia the other test projects, except for the Log4Net one, target netcoreapp2.1;netcoreapp2.0;net462. Should these projects do the same?

@bruno-garcia
Copy link
Member

@Mitch528 now the logEntry interface is part of the Sentry.Protocol.
I've implemented it on the MEL integration: #125

Could you please add it also to the Serilog integration?

@Mitch528
Copy link
Contributor Author

@bruno-garcia Yep, added.

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

I haven't tested it with ASP.NET Core, but I'm not sure if it would combine well with it since the AspNetCore package uses Sentry.Extensions.Logging and I'm guessing both would attempt to send the same event to Sentry if used together.

The SDK has a built in de-duplication processor but it wouldn't be needed in this case. Serilog removes the MEL logging processor when it adds itself.

As I mentioned in another review comment, MEL has 2 levels which configure what is sent as event and what is stored as breadcrumbs. It would be great if the Serilog integration also had this behavior. This mean that when logging Informational messages, by default, that data would only be stored as breadcrumbs and sent with the following events. Sentry is not really a logging tool and simply sending all log messages to Sentry is not the way go to IMO.

src/Sentry.Serilog/SentrySink.cs Outdated Show resolved Hide resolved
src/Sentry.Serilog/SentrySink.cs Outdated Show resolved Hide resolved
test/Sentry.Serilog.Tests/Sentry.Serilog.Tests.csproj Outdated Show resolved Hide resolved
Hub = hubGetter;
}

public void Emit(LogEvent logEvent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Emit is simply raising an event to Sentry with any log message created.
It would be nicer to enable a support like the one done for Microsoft.Extensions.Logging which have 2 log levels switches. One controls what is sent to sentry (creating an event) and one controls what should be added as breadcrumb.

This is great because we can store logs messages like Information as breadcrumbs and in the event of a LogError all the Information from that same scope are sent out with the the error event.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entierly accurate. If you take a look here:

public static LoggerConfiguration Sentry(
this LoggerSinkConfiguration loggerConfiguration,
string dsn = null,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
IFormatProvider formatProvider = null)
{
return loggerConfiguration.Sink(new SentrySink(formatProvider) { Dsn = dsn }, restrictedToMinimumLevel);
}

The restrictedToMinimumLevel option sets the minimum level for which Emit is called by Serilog. I'm not really sure what the best way would be to have a minimum breadcrumb level, since Serilog will not call Emit if the aforementioned option is, for example, set to Error and the miniumum breadcrumb level is set to Info.

We could override restrictedToMinimumLevel and set it to the lowest level and then add our own switch that checks it within Emit, but that seems to be a bit counterintuitive I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restrictedToMinimumLevel is the minimal level to either event or breadcrumb then.

For example: restrictedToMinimumLevel = Info, we would capture breadcrumbs (for Info or higher) and send events (error or higher)

If restrictedToMinimumLevel is Warning, we'd only capture breadcrumbs for Warnings or higher, and send events Error or higher.

Finally if restrictedToMinimumLevel is Error, then breadcrumbs would be tracked only for Error or higher as well as sending events.

A logging integration with Sentry that sends all Log.. to Sentry doesn't make much sense. Sentry is not a logging tool and flooding it with events that are not grouped together create a storm of noise (i.e: Notifications).

Keeping the Info/Warn logs around (breadcrumbs) for a while to be sent in case there's an Error is, in my opinion, the best approach as it gives you the context you need to troubleshoot an issue.

src/Sentry.Serilog/SentrySink.cs Show resolved Hide resolved
Copy link

@rodion-m rodion-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please accept this request. Serilog supporting is really needed feature. Thank you.

@bruno-garcia bruno-garcia merged commit 412e511 into getsentry:master Nov 21, 2018
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants