Skip to content

Commit d8bcfe9

Browse files
authored
Merge branch 'version6' into jpnurmi/android-breadcrumbs
2 parents d20933e + 130650d commit d8bcfe9

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
### Fixes
1818

19+
- The `Serilog` integration captures _Structured Logs_ (when enabled) independently of captured Events and added Breadcrumbs ([#4691](https://github.com/getsentry/sentry-dotnet/pull/4691))
1920
- Deliver system breadcrumbs in the main thread on Android ([#4671](https://github.com/getsentry/sentry-dotnet/pull/4671))
2021

2122
## 6.0.0-preview.2

src/Sentry.Serilog/SentrySink.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private void InnerEmit(LogEvent logEvent)
105105
var exception = logEvent.Exception;
106106
var template = logEvent.MessageTemplate.Text;
107107
var formatted = FormatLogEvent(logEvent);
108+
var addedBreadcrumbForException = false;
108109

109110
if (logEvent.Level >= _options.MinimumEventLevel)
110111
{
@@ -137,11 +138,11 @@ private void InnerEmit(LogEvent logEvent)
137138
// Capturing exception events adds a breadcrumb automatically... we don't want to add another one
138139
if (exception != null)
139140
{
140-
return;
141+
addedBreadcrumbForException = true;
141142
}
142143
}
143144

144-
if (logEvent.Level >= _options.MinimumBreadcrumbLevel)
145+
if (!addedBreadcrumbForException && logEvent.Level >= _options.MinimumBreadcrumbLevel)
145146
{
146147
Dictionary<string, string>? data = null;
147148
if (exception != null && !string.IsNullOrWhiteSpace(formatted))

test/Sentry.Serilog.Tests/SentrySinkTests.Structured.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,36 @@ public void Emit_StructuredLogging_LogEvent(bool withActiveSpan)
134134
log.TryGetAttribute("property.Structure-Property", out object? structure).Should().BeTrue();
135135
structure.Should().Be("""[42, "42"]""");
136136
}
137+
138+
[Fact]
139+
public void Emit_StructuredLoggingWithException_NoBreadcrumb()
140+
{
141+
InMemorySentryStructuredLogger capturer = new();
142+
_fixture.Hub.Logger.Returns(capturer);
143+
_fixture.Options.Experimental.EnableLogs = true;
144+
145+
var sut = _fixture.GetSut();
146+
var logger = new LoggerConfiguration().WriteTo.Sink(sut).MinimumLevel.Verbose().CreateLogger();
147+
148+
logger.Write(LogEventLevel.Error, new Exception("expected message"), "Message");
149+
150+
_fixture.Scope.Breadcrumbs.Should().BeEmpty();
151+
capturer.Logs.Should().ContainSingle().Which.Message.Should().Be("Message");
152+
}
153+
154+
[Fact]
155+
public void Emit_StructuredLoggingWithoutException_LeavesBreadcrumb()
156+
{
157+
InMemorySentryStructuredLogger capturer = new();
158+
_fixture.Hub.Logger.Returns(capturer);
159+
_fixture.Options.Experimental.EnableLogs = true;
160+
161+
var sut = _fixture.GetSut();
162+
var logger = new LoggerConfiguration().WriteTo.Sink(sut).MinimumLevel.Verbose().CreateLogger();
163+
164+
logger.Write(LogEventLevel.Error, (Exception?)null, "Message");
165+
166+
_fixture.Scope.Breadcrumbs.Should().ContainSingle().Which.Message.Should().Be("Message");
167+
capturer.Logs.Should().ContainSingle().Which.Message.Should().Be("Message");
168+
}
137169
}

0 commit comments

Comments
 (0)