Skip to content
Draft
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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();
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 @@ -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);
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