feat(logs): apply default attributes from Scope#4784
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- apply default attributes from Scope ([#4784](https://github.com/getsentry/sentry-dotnet/pull/4784))If none of the above apply, you can opt out of this check by adding |
| if (scope.PropagationContext._dynamicSamplingContext is { } dynamicSamplingContext) | ||
| { | ||
| if (dynamicSamplingContext.Items.TryGetValue("replay_id", out var replayId)) | ||
| { | ||
| SetAttribute("sentry.replay_id", replayId); | ||
| } | ||
| } |
There was a problem hiding this comment.
note: Could alternatively get from IReplaySession.ActiveReplayId.
But I guess reading it via the Scope unifies the source, and avoid a dependency to IReplaySession.
| if (scope.User.Id is { } userId) | ||
| { | ||
| SetAttribute("user.id", userId); | ||
| } | ||
| if (scope.User.Username is { } userName) | ||
| { | ||
| SetAttribute("user.name", userName); | ||
| } | ||
| if (scope.User.Email is { } userEmail) | ||
| { | ||
| SetAttribute("user.email", userEmail); | ||
| } |
There was a problem hiding this comment.
question: PII
Do we need to check SentryOptions.SendDefaultPii?
Or do/can/should we assume that the data is set only when enabled already, or explicitly set by user code.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4784 +/- ##
==========================================
+ Coverage 73.85% 73.93% +0.07%
==========================================
Files 494 494
Lines 17868 17903 +35
Branches 3509 3525 +16
==========================================
+ Hits 13197 13237 +40
+ Misses 3815 3807 -8
- Partials 856 859 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@Flash0ver Do we have an ETA on when this will be released? We have another customer who is looking to add user scope context to logs. |
|
@InterstellarStella TL;DR: January 2026 ... Scope-Attributes a bit afterwards We are lacking some info on the Scope, a fix we could neatly combine with Scope-Attributes. Similarly, as an intermediate workaround, user code could attach this/any information via options.SetBeforeSendLog(static (SentryLog log) =>
{
log.SetAttribute("attribute-name", "attribute-value");
return log;
});Once we ship this changeset and apply these in-box, it will be (ever so slightly) more efficient, but functionally equivalent. |
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Features ✨
Dependencies ⬆️Deps
Other
🤖 This preview updates automatically when you update the PR. |
fixes #4493
closes #4733
See docs: https://develop.sentry.dev/sdk/telemetry/logs/#default-attributes
Changes
Scope.internalAPIs for thatHowever, it seems that we're missing a lot of the Contexts on the
Scope,where we currently mostly apply them to
Events.TODO
Scopewith the data neededCHANGELOG.mdentry