From c47f4af9a0dbdd779abef8aa96346ff6e95571c5 Mon Sep 17 00:00:00 2001 From: Flash0ver <38893694+Flash0ver@users.noreply.github.com> Date: Fri, 15 Aug 2025 11:09:54 +0200 Subject: [PATCH 1/3] ref: shorten Microsoft.Extensions.Logging attribute names --- .../SentryStructuredLogger.cs | 6 +++--- ...AspNetCoreStructuredLoggerProviderTests.cs | 2 +- .../SentryStructuredLoggerProviderTests.cs | 2 +- .../SentryStructuredLoggerTests.cs | 20 +++++++++---------- ...SentryMauiStructuredLoggerProviderTests.cs | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs b/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs index 87a0daae49..36e68454a6 100644 --- a/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs +++ b/src/Sentry.Extensions.Logging/SentryStructuredLogger.cs @@ -92,15 +92,15 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except if (_categoryName is not null) { - log.SetAttribute("microsoft.extensions.logging.category_name", _categoryName); + log.SetAttribute("category.name", _categoryName); } if (eventId.Name is not null || eventId.Id != 0) { - log.SetAttribute("microsoft.extensions.logging.event.id", eventId.Id); + log.SetAttribute("event.id", eventId.Id); } if (eventId.Name is not null) { - log.SetAttribute("microsoft.extensions.logging.event.name", eventId.Name); + log.SetAttribute("event.name", eventId.Name); } _hub.Logger.CaptureLog(log); diff --git a/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs b/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs index 9edf8363ac..797aedf435 100644 --- a/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs +++ b/test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs @@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog() logger.LogInformation("message"); Assert.NotNull(capturedLog); - capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue(); + capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue(); categoryName.Should().Be(typeof(SentryAspNetCoreStructuredLoggerProviderTests).FullName); capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue(); diff --git a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs index bd43dfc668..cb48224c51 100644 --- a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs +++ b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs @@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog() logger.LogInformation("message"); Assert.NotNull(capturedLog); - capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue(); + capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue(); categoryName.Should().Be(typeof(SentryStructuredLoggerProviderTests).FullName); capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue(); diff --git a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs index 65878cdf93..dcf7e0a4c5 100644 --- a/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs +++ b/test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs @@ -111,9 +111,9 @@ public void Log_LogLevel_CaptureLog(LogLevel logLevel, SentryLogLevel expectedLe log.AssertAttribute("sentry.release", "my-release"); log.AssertAttribute("sentry.sdk.name", "SDK Name"); log.AssertAttribute("sentry.sdk.version", "SDK Version"); - log.AssertAttribute("microsoft.extensions.logging.category_name", "CategoryName"); - log.AssertAttribute("microsoft.extensions.logging.event.id", 123); - log.AssertAttribute("microsoft.extensions.logging.event.name", "EventName"); + log.AssertAttribute("category.name", _fixture.CategoryName); + log.AssertAttribute("event.id", eventId.Id); + log.AssertAttribute("event.name", eventId.Name!); } [Fact] @@ -192,7 +192,7 @@ public void Log_WithoutCategoryName_CaptureLog() logger.Log(LogLevel.Information, new EventId(123, "EventName"), new InvalidOperationException("message"), "Message with {Argument}.", "argument"); var log = _fixture.CapturedLogs.Dequeue(); - log.TryGetAttribute("microsoft.extensions.logging.category_name", out object? _).Should().BeFalse(); + log.TryGetAttribute("category.name", out object? _).Should().BeFalse(); } [Fact] @@ -216,8 +216,8 @@ public void Log_WithoutEvent_CaptureLog() logger.Log(LogLevel.Information, new InvalidOperationException("message"), "Message with {Argument}.", "argument"); var log = _fixture.CapturedLogs.Dequeue(); - log.TryGetAttribute("microsoft.extensions.logging.event.id", out object? _).Should().BeFalse(); - log.TryGetAttribute("microsoft.extensions.logging.event.name", out object? _).Should().BeFalse(); + log.TryGetAttribute("event.id", out object? _).Should().BeFalse(); + log.TryGetAttribute("event.name", out object? _).Should().BeFalse(); } [Fact] @@ -228,8 +228,8 @@ public void Log_WithoutEventId_CaptureLog() logger.Log(LogLevel.Information, new EventId(0, "EventName"), new InvalidOperationException("message"), "Message with {Argument}.", "argument"); var log = _fixture.CapturedLogs.Dequeue(); - log.AssertAttribute("microsoft.extensions.logging.event.id", 0); - log.AssertAttribute("microsoft.extensions.logging.event.name", "EventName"); + log.AssertAttribute("event.id", 0); + log.AssertAttribute("event.name", "EventName"); } [Fact] @@ -240,8 +240,8 @@ public void Log_WithoutEventName_CaptureLog() logger.Log(LogLevel.Information, new EventId(123), new InvalidOperationException("message"), "Message with {Argument}.", "argument"); var log = _fixture.CapturedLogs.Dequeue(); - log.AssertAttribute("microsoft.extensions.logging.event.id", 123); - log.TryGetAttribute("microsoft.extensions.logging.event.name", out object? _).Should().BeFalse(); + log.AssertAttribute("event.id", 123); + log.TryGetAttribute("event.name", out object? _).Should().BeFalse(); } [Theory] diff --git a/test/Sentry.Maui.Tests/Internal/SentryMauiStructuredLoggerProviderTests.cs b/test/Sentry.Maui.Tests/Internal/SentryMauiStructuredLoggerProviderTests.cs index 1715498a5b..425ced9bbe 100644 --- a/test/Sentry.Maui.Tests/Internal/SentryMauiStructuredLoggerProviderTests.cs +++ b/test/Sentry.Maui.Tests/Internal/SentryMauiStructuredLoggerProviderTests.cs @@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog() logger.LogInformation("message"); Assert.NotNull(capturedLog); - capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue(); + capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue(); categoryName.Should().Be(typeof(SentryMauiStructuredLoggerProviderTests).FullName); capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue(); From 35ed9e900cf00251df03f5c3dec7985ffaf2990c Mon Sep 17 00:00:00 2001 From: Flash0ver <38893694+Flash0ver@users.noreply.github.com> Date: Fri, 15 Aug 2025 11:15:03 +0200 Subject: [PATCH 2/3] docs: add CHANGELOG --- CHANGELOG.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bcfa31848..1955981dbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,16 @@ ## Unreleased +### Features + +- Experimental _Structured Logs_: + - Shorten the `key` names of `Microsoft.Extensions.Logging` attributes ([#4450](https://github.com/getsentry/sentry-dotnet/pull/4450)) + ### Fixes - Experimental _Structured Logs_: - - Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424)) - - Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly. ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425)) + - Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424)) + - Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425)) ### Dependencies From b891e54fb0ee82bee6dd1b684bac4a823d47e89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6lz?= <38893694+Flash0ver@users.noreply.github.com> Date: Fri, 15 Aug 2025 22:25:06 +0200 Subject: [PATCH 3/3] docs: fix bad merge --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d5d5a08ff..3e1c1ba100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,6 @@ - Experimental _Structured Logs_: - Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424)) - Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425)) - - Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424)) - - Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly. ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425)) - `InvalidOperationException` potentially thrown during a race condition, especially in concurrent high-volume logging scenarios ([#4428](https://github.com/getsentry/sentry-dotnet/pull/4428)) ### Dependencies