fix: populate Default attributes on structured logs from current scope#5216
Open
jamescrosswell wants to merge 5 commits into
Open
fix: populate Default attributes on structured logs from current scope#5216jamescrosswell wants to merge 5 commits into
jamescrosswell wants to merge 5 commits into
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.13% 74.16% +0.03%
==========================================
Files 506 506
Lines 18292 18306 +14
Branches 3576 3582 +6
==========================================
+ Hits 13560 13576 +16
+ Misses 3860 3859 -1
+ Partials 872 871 -1 ☔ View full report in Codecov by Sentry. 🚀 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>
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.