diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cdf7c28d0..3aaa3dd144 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Upload linked PDBs to fix non-IL-stripped symbolication for iOS ([#4527](https://github.com/getsentry/sentry-dotnet/pull/4527)) - In MAUI Android apps, generate and inject UUID to APK and upload ProGuard mapping to Sentry with the UUID ([#4532](https://github.com/getsentry/sentry-dotnet/pull/4532)) - Fixed WASM0001 warning when building Blazor WebAssembly projects ([#4519](https://github.com/getsentry/sentry-dotnet/pull/4519)) +- 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 diff --git a/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs b/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs index 36e68454a6..6735cc9d5b 100644 --- a/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs +++ b/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs @@ -89,6 +89,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except }; log.SetDefaultAttributes(_options, _sdk); + log.SetOrigin("auto.log.extensions_logging"); if (_categoryName is not null) { diff --git a/src/Sentry.Serilog/SentrySink.Structured.cs b/src/Sentry.Serilog/SentrySink.Structured.cs index 6584afb934..6054585c7f 100644 --- a/src/Sentry.Serilog/SentrySink.Structured.cs +++ b/src/Sentry.Serilog/SentrySink.Structured.cs @@ -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) { diff --git a/src/Sentry/SentryLog.cs b/src/Sentry/SentryLog.cs index 7e58fec173..334e565875 100644 --- a/src/Sentry/SentryLog.cs +++ b/src/Sentry/SentryLog.cs @@ -199,6 +199,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(); diff --git a/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs b/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs index 797aedf435..d19cdf5cc4 100644 --- a/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs +++ b/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs @@ -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] diff --git a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs index cb48224c51..a8c52f13da 100644 --- a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs +++ b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs @@ -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] diff --git a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs index dcf7e0a4c5..dd86c1327b 100644 --- a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs +++ b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs @@ -109,6 +109,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); diff --git a/test/Sentry.Serilog.Tests/SentrySinkTests.Structured.cs b/test/Sentry.Serilog.Tests/SentrySinkTests.Structured.cs index b7cb36b76f..5a13e94f5d 100644 --- a/test/Sentry.Serilog.Tests/SentrySinkTests.Structured.cs +++ b/test/Sentry.Serilog.Tests/SentrySinkTests.Structured.cs @@ -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(); diff --git a/test/Sentry.Tests/SentryLogTests.cs b/test/Sentry.Tests/SentryLogTests.cs index 3393137b85..89948a847a 100644 --- a/test/Sentry.Tests/SentryLogTests.cs +++ b/test/Sentry.Tests/SentryLogTests.cs @@ -53,6 +53,9 @@ public void Protocol_Default_VerifyAttributes() log.Parameters.Should().BeEquivalentTo(new KeyValuePair[] { 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();