Skip to content

Commit 679eebd

Browse files
authored
ref(logs): shorten Microsoft.Extensions.Logging attribute names (#4450)
1 parent cbd289b commit 679eebd

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Experimental _Structured Logs_:
8+
- Shorten the `key` names of `Microsoft.Extensions.Logging` attributes ([#4450](https://github.com/getsentry/sentry-dotnet/pull/4450))
9+
510
### Fixes
611

712
- Experimental _Structured Logs_:
8-
- Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance. ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424))
9-
- Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly. ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425))
13+
- Remove `IDisposable` from `SentryStructuredLogger`. Disposal is intended through the owning `IHub` instance ([#4424](https://github.com/getsentry/sentry-dotnet/pull/4424))
14+
- Ensure all buffered logs are sent to Sentry when the application terminates unexpectedly ([#4425](https://github.com/getsentry/sentry-dotnet/pull/4425))
1015
- `InvalidOperationException` potentially thrown during a race condition, especially in concurrent high-volume logging scenarios ([#4428](https://github.com/getsentry/sentry-dotnet/pull/4428))
1116

1217
### Dependencies

src/Sentry.Extensions.Logging/SentryStructuredLogger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
9292

9393
if (_categoryName is not null)
9494
{
95-
log.SetAttribute("microsoft.extensions.logging.category_name", _categoryName);
95+
log.SetAttribute("category.name", _categoryName);
9696
}
9797
if (eventId.Name is not null || eventId.Id != 0)
9898
{
99-
log.SetAttribute("microsoft.extensions.logging.event.id", eventId.Id);
99+
log.SetAttribute("event.id", eventId.Id);
100100
}
101101
if (eventId.Name is not null)
102102
{
103-
log.SetAttribute("microsoft.extensions.logging.event.name", eventId.Name);
103+
log.SetAttribute("event.name", eventId.Name);
104104
}
105105

106106
_hub.Logger.CaptureLog(log);

test/Sentry.AspNetCore.Tests/SentryAspNetCoreStructuredLoggerProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog()
8383
logger.LogInformation("message");
8484

8585
Assert.NotNull(capturedLog);
86-
capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue();
86+
capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue();
8787
categoryName.Should().Be(typeof(SentryAspNetCoreStructuredLoggerProviderTests).FullName);
8888

8989
capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue();

test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog()
8383
logger.LogInformation("message");
8484

8585
Assert.NotNull(capturedLog);
86-
capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue();
86+
capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue();
8787
categoryName.Should().Be(typeof(SentryStructuredLoggerProviderTests).FullName);
8888

8989
capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue();

test/Sentry.Extensions.Logging.Tests/SentryStructuredLoggerTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ public void Log_LogLevel_CaptureLog(LogLevel logLevel, SentryLogLevel expectedLe
111111
log.AssertAttribute("sentry.release", "my-release");
112112
log.AssertAttribute("sentry.sdk.name", "SDK Name");
113113
log.AssertAttribute("sentry.sdk.version", "SDK Version");
114-
log.AssertAttribute("microsoft.extensions.logging.category_name", "CategoryName");
115-
log.AssertAttribute("microsoft.extensions.logging.event.id", 123);
116-
log.AssertAttribute("microsoft.extensions.logging.event.name", "EventName");
114+
log.AssertAttribute("category.name", _fixture.CategoryName);
115+
log.AssertAttribute("event.id", eventId.Id);
116+
log.AssertAttribute("event.name", eventId.Name!);
117117
}
118118

119119
[Fact]
@@ -192,7 +192,7 @@ public void Log_WithoutCategoryName_CaptureLog()
192192
logger.Log(LogLevel.Information, new EventId(123, "EventName"), new InvalidOperationException("message"), "Message with {Argument}.", "argument");
193193

194194
var log = _fixture.CapturedLogs.Dequeue();
195-
log.TryGetAttribute("microsoft.extensions.logging.category_name", out object? _).Should().BeFalse();
195+
log.TryGetAttribute("category.name", out object? _).Should().BeFalse();
196196
}
197197

198198
[Fact]
@@ -216,8 +216,8 @@ public void Log_WithoutEvent_CaptureLog()
216216
logger.Log(LogLevel.Information, new InvalidOperationException("message"), "Message with {Argument}.", "argument");
217217

218218
var log = _fixture.CapturedLogs.Dequeue();
219-
log.TryGetAttribute("microsoft.extensions.logging.event.id", out object? _).Should().BeFalse();
220-
log.TryGetAttribute("microsoft.extensions.logging.event.name", out object? _).Should().BeFalse();
219+
log.TryGetAttribute("event.id", out object? _).Should().BeFalse();
220+
log.TryGetAttribute("event.name", out object? _).Should().BeFalse();
221221
}
222222

223223
[Fact]
@@ -228,8 +228,8 @@ public void Log_WithoutEventId_CaptureLog()
228228
logger.Log(LogLevel.Information, new EventId(0, "EventName"), new InvalidOperationException("message"), "Message with {Argument}.", "argument");
229229

230230
var log = _fixture.CapturedLogs.Dequeue();
231-
log.AssertAttribute("microsoft.extensions.logging.event.id", 0);
232-
log.AssertAttribute("microsoft.extensions.logging.event.name", "EventName");
231+
log.AssertAttribute("event.id", 0);
232+
log.AssertAttribute("event.name", "EventName");
233233
}
234234

235235
[Fact]
@@ -240,8 +240,8 @@ public void Log_WithoutEventName_CaptureLog()
240240
logger.Log(LogLevel.Information, new EventId(123), new InvalidOperationException("message"), "Message with {Argument}.", "argument");
241241

242242
var log = _fixture.CapturedLogs.Dequeue();
243-
log.AssertAttribute("microsoft.extensions.logging.event.id", 123);
244-
log.TryGetAttribute("microsoft.extensions.logging.event.name", out object? _).Should().BeFalse();
243+
log.AssertAttribute("event.id", 123);
244+
log.TryGetAttribute("event.name", out object? _).Should().BeFalse();
245245
}
246246

247247
[Theory]

test/Sentry.Maui.Tests/Internal/SentryMauiStructuredLoggerProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void CreateLogger_DependencyInjection_CanLog()
8383
logger.LogInformation("message");
8484

8585
Assert.NotNull(capturedLog);
86-
capturedLog.TryGetAttribute("microsoft.extensions.logging.category_name", out object? categoryName).Should().BeTrue();
86+
capturedLog.TryGetAttribute("category.name", out object? categoryName).Should().BeTrue();
8787
categoryName.Should().Be(typeof(SentryMauiStructuredLoggerProviderTests).FullName);
8888

8989
capturedLog.TryGetAttribute("sentry.sdk.name", out object? name).Should().BeTrue();

0 commit comments

Comments
 (0)