fix: populate Default attributes on structured logs from current scope - #5216
Merged
Conversation
Fixes #5209 — user.id, user.name, and user.email were missing from structured logs even when user info was set on the scope. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5216 +/- ##
==========================================
+ Coverage 74.16% 74.17% +0.01%
==========================================
Files 508 508
Lines 18353 18368 +15
Branches 3586 3592 +6
==========================================
+ Hits 13612 13625 +13
- Misses 3869 3870 +1
- Partials 872 873 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jamescrosswell
commented
May 11, 2026
jamescrosswell
commented
May 11, 2026
- Replace redundant SdkVersion parameter with Scope (SDK is on scope) - Add server.address attribute (from options.ServerName or Environment.MachineName when SendDefaultPii is enabled) - Integrations (Serilog, Extensions.Logging) now mirror their SDK identity onto the scope before logging Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
jamescrosswell
marked this pull request as ready for review
May 11, 2026 04:09
Flash0ver
approved these changes
Jul 6, 2026
Contributor
There was a problem hiding this comment.
I merged from main and resolved merge conflicts.
@jamescrosswell please review if I applied the changes correctly:
src/Sentry/SentryLog.cs: all into existingAttributes.SetDefaultAttributes(options, sdk);- tests: use
ShouldContain<T>andShouldNotContain<T>extendingSentryAttributes
Both of these changes come from #4936.
Also, there are two Sentry-Bot comments ... I think one is fine, and the other one might be a follow-up.
Flash0ver
reviewed
Jul 6, 2026
This was referenced Jul 7, 2026
3 tasks
This was referenced Jul 16, 2026
This was referenced Jul 20, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5209
Problem
When a user is set on the current scope via
SentrySdk.ConfigureScope, the user attributes (user.id,user.name,user.email) were not being included on structured logs, despite being documented as automatic.The root cause was in
DefaultSentryStructuredLogger.CaptureLog— the scope was fetched but only used to retrieve the SDK version. The scope's user was never consulted.Although the initial report only called out the missing user attributes, we should ensure all of the expected Default Attributes are set correctly:
Then Message Template Attributes are already handled correctly.
Audit
All three log emission paths set the default attributes per the docs:
DefaultSentryStructuredLogger(direct API)Sentry.Extensions.LoggingSentry.Serilogsentry.environmentSetDefaultAttributessentry.releaseSetDefaultAttributes(when non-null)sentry.sdk.name/sentry.sdk.versionscope.Sdk_sdkoverrideSdkoverrideserver.addressSetDefaultAttributesuser.id/user.name/user.emailSetDefaultAttributessentry.originauto.log.extensions_loggingauto.log.serilogsentry.message.template/sentry.message.parameter.XSentryLog.WriteTosentry.environment— set unconditionally inSentryLog.SetDefaultAttributesviaoptions.SettingLocator.GetEnvironment(). That call always returns a value (defaults to"production"or"debug"when nothing is configured), so this attribute is always present.sentry.release— set inSentryLog.SetDefaultAttributeswhenoptions.SettingLocator.GetRelease()returns non-null (falls back to theSENTRY_RELEASEenv var, thenApplicationVersionLocator).sentry.origin— not set bySetDefaultAttributes. Each integration callslog.SetOrigin(...)itself afterSetDefaultAttributes:Sentry.Extensions.Logging/SentryStructuredLogger.cs→"auto.log.extensions_logging"Sentry.Serilog/SentrySink.Structured.cs→"auto.log.serilog"Direct
SentrySdk.Logger.LogInfo(...)calls (viaDefaultSentryStructuredLogger) do not setsentry.origin, which matches the docs: "added when generated by an SDK integration".Note
Sentry.NLogandSentry.Log4Netdon't have structured-log paths yet.