Skip to content

Conversation

Flash0ver
Copy link
Member

@Flash0ver Flash0ver commented Aug 21, 2025

Changes

Add Serilog integration to Sentry Structured Logging.

Docs

Dogfooding

  • getsentry/symbol-collector -> SymbolCollector.Server

@Flash0ver Flash0ver self-assigned this Aug 21, 2025
@Flash0ver Flash0ver added Serilog .NET Pull requests that update .net code Logs labels Aug 21, 2025
Copy link
Contributor

github-actions bot commented Aug 21, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against c29c704

@Flash0ver
Copy link
Member Author

@sentry review

@Flash0ver Flash0ver marked this pull request as ready for review August 22, 2025 00:08

private void CaptureStructuredLog(IHub hub, LogEvent logEvent, string formatted, string? template)
{
var traceHeader = hub.GetTraceHeader() ?? SentryTraceHeader.Empty;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the ParentSpanId required in the protocol for StructuredLogging? An empty SpanId probably isn't that useful otherwise eh?

Copy link
Member Author

@Flash0ver Flash0ver Aug 25, 2025

Choose a reason for hiding this comment

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

No ... it's an optional "Default Attribute" ... the trace_id is required.

Oops ... I made this mistake in the Sentry-SDK and Microsoft.Extensions.Logging integrations, too.

I'll create a follow-up PR to fix this issue in all integrations.

@Mike-E-angelo
Copy link

Thank you for your efforts here. 🙏 Is there a preview band we can try this out, perhaps? I have two projects that would really benefit from having this in place. Thank you for your continued efforts.

@jacobsamo
Copy link

Looking forward to when this gets out, would really benefit my team

cursor[bot]

This comment was marked as outdated.

Copy link

codecov bot commented Sep 10, 2025

Codecov Report

❌ Patch coverage is 82.00000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.50%. Comparing base (7061fb9) to head (c29c704).

Files with missing lines Patch % Lines
src/Sentry.Serilog/SentrySink.cs 68.96% 5 Missing and 4 partials ⚠️
src/Sentry.Serilog/SentrySink.Structured.cs 87.50% 4 Missing and 3 partials ⚠️
src/Sentry.Serilog/LogLevelExtensions.cs 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4462      +/-   ##
==========================================
+ Coverage   73.42%   73.50%   +0.08%     
==========================================
  Files         479      480       +1     
  Lines       17506    17587      +81     
  Branches     3480     3505      +25     
==========================================
+ Hits        12853    12928      +75     
+ Misses       3774     3773       -1     
- Partials      879      886       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell jamescrosswell self-requested a review September 17, 2025 08:01

private bool IsEnabled(LogEvent logEvent)
{
var options = _hubAccessor()?.GetSentryOptions();
Copy link
Collaborator

@jamescrosswell jamescrosswell Sep 18, 2025

Choose a reason for hiding this comment

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

Suggested change
var options = _hubAccessor()?.GetSentryOptions();
var options = _hubAccessor().GetSentryOptions();

_hubAccessor() is never null

This also looks unecessary:

var hub = _hubAccessor();
if (hub is null || !hub.IsEnabled)


return logEvent.Level >= _options.MinimumEventLevel
|| logEvent.Level >= _options.MinimumBreadcrumbLevel
|| options?.Experimental.EnableLogs is true;
Copy link
Collaborator

@jamescrosswell jamescrosswell Sep 18, 2025

Choose a reason for hiding this comment

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

I was a bit confused by this... so we don't filter any structured logs by Log Level - everything gets captured (all the way down to SentryLogLevel.Trace)?

Worth adding a code comment explaining why this is the case. I think we inherit the log level filter from MEL so we don't need to implement anything explicitly ourselves right?


Dictionary<string, string>? data = null;
if (exception != null && !string.IsNullOrWhiteSpace(formatted))
var options = hub.GetSentryOptions();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe worth adding a note explaining why we fetch the options from the Hub here (rather than just using _options as we do above). I remember we had a conversation about this but I can't remember what the reason was anymore.

Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

I left a couple of comments, nothing blocking though. LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Logs .NET Pull requests that update .net code Serilog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants