Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Structured Logs now have a `sentry.origin` attribute to so it's clearer where these come from ([#4566](https://github.com/getsentry/sentry-dotnet/pull/4566))

### Dependencies

- Bump Java SDK from v8.22.0 to v8.23.0 ([#4586](https://github.com/getsentry/sentry-dotnet/pull/4586))
Expand Down
1 change: 1 addition & 0 deletions src/Sentry.Extensions.Logging/SentryStructuredLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
};

log.SetDefaultAttributes(_options, _sdk);
log.SetOrigin("auto.log.extensions_logging");

if (_categoryName is not null)
{
Expand Down
1 change: 1 addition & 0 deletions src/Sentry.Serilog/SentrySink.Structured.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private static void CaptureStructuredLog(IHub hub, SentryOptions options, LogEve
};

log.SetDefaultAttributes(options, Sdk);
log.SetOrigin("auto.log.serilog");

foreach (var attribute in attributes)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Sentry/SentryLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ internal void SetDefaultAttributes(SentryOptions options, SdkVersion sdk)
}
}

internal void SetOrigin(string origin)
{
SetAttribute("sentry.origin", origin);
}

internal void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
{
writer.WriteStartObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public void CreateLogger_DependencyInjection_CanLog()

capturedLog.TryGetAttribute("sentry.sdk.version", out object? version).Should().BeTrue();
version.Should().Be(SentryMiddleware.NameAndVersion.Version);

capturedLog.TryGetAttribute("sentry.origin", out object? origin).Should().BeTrue();
origin.Should().Be("auto.log.extensions_logging");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public void CreateLogger_DependencyInjection_CanLog()

capturedLog.TryGetAttribute("sentry.sdk.version", out object? version).Should().BeTrue();
version.Should().Be(SentryLoggerProvider.NameAndVersion.Version);

capturedLog.TryGetAttribute("sentry.origin", out object? origin).Should().BeTrue();
origin.Should().Be("auto.log.extensions_logging");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void Log_LogLevel_CaptureLog(LogLevel logLevel, SentryLogLevel expectedLe
log.ParentSpanId.Should().Be(parentSpanId);
log.AssertAttribute("sentry.environment", "my-environment");
log.AssertAttribute("sentry.release", "my-release");
log.AssertAttribute("sentry.origin", "auto.log.extensions_logging");
log.AssertAttribute("sentry.sdk.name", "SDK Name");
log.AssertAttribute("sentry.sdk.version", "SDK Version");
log.AssertAttribute("category.name", _fixture.CategoryName);
Expand Down
2 changes: 2 additions & 0 deletions test/Sentry.Serilog.Tests/SentrySinkTests.Structured.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public void Emit_StructuredLogging_LogEvent(bool withActiveSpan)
environment.Should().Be("test-environment");
log.TryGetAttribute("sentry.release", out object? release).Should().BeTrue();
release.Should().Be("test-release");
log.TryGetAttribute("sentry.origin", out object? origin).Should().BeTrue();
origin.Should().Be("auto.log.serilog");
log.TryGetAttribute("sentry.sdk.name", out object? sdkName).Should().BeTrue();
sdkName.Should().Be(SentrySink.SdkName);
log.TryGetAttribute("sentry.sdk.version", out object? sdkVersion).Should().BeTrue();
Expand Down
3 changes: 3 additions & 0 deletions test/Sentry.Tests/SentryLogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public void Protocol_Default_VerifyAttributes()
log.Parameters.Should().BeEquivalentTo(new KeyValuePair<string, object>[] { new("param", "params"), });
log.ParentSpanId.Should().Be(ParentSpanId);

// should only show up in sdk integrations
log.TryGetAttribute("sentry.origin", out object origin).Should().BeFalse();

log.TryGetAttribute("attribute", out object attribute).Should().BeTrue();
attribute.Should().Be("value");
log.TryGetAttribute("sentry.environment", out string environment).Should().BeTrue();
Expand Down
Loading