-
-
Notifications
You must be signed in to change notification settings - Fork 226
feat(logs): apply default attributes from Scope #4784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Flash0ver
wants to merge
6
commits into
main
Choose a base branch
from
logs/default-attributes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+262
−14
Draft
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d116dd9
feat(logs): add more default attributes
Flash0ver e6a9743
ref(logs): apply default attributes from scope
Flash0ver 009f94c
fix(logs): SDK-Logger sets sdk-name and sdk-version attributes
Flash0ver a65b5f1
Merge branch 'main' into logs/default-attributes
Flash0ver 7efc8f6
merge
Flash0ver 0e25afd
assert "sentry.origin"
Flash0ver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,8 +24,8 @@ internal SentryLog(DateTimeOffset timestamp, SentryId traceId, SentryLogLevel le | |
| TraceId = traceId; | ||
| Level = level; | ||
| Message = message; | ||
| // 7 is the number of built-in attributes, so we start with that. | ||
| _attributes = new Dictionary<string, SentryAttribute>(7); | ||
| // we currently set up to 18 default attributes, the next prime number is 23 | ||
| _attributes = new Dictionary<string, SentryAttribute>(23); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -163,7 +163,12 @@ internal void SetAttribute(string key, int value) | |
| _attributes[key] = new SentryAttribute(value, "integer"); | ||
| } | ||
|
|
||
| internal void SetDefaultAttributes(SentryOptions options, SdkVersion sdk) | ||
| internal void SetDefaultAttributes(SentryOptions options, Scope scope) | ||
| { | ||
| SetDefaultAttributes(options, scope, scope.Sdk); | ||
| } | ||
|
|
||
| internal void SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersion sdk) | ||
| { | ||
| var environment = options.SettingLocator.GetEnvironment(); | ||
| SetAttribute("sentry.environment", environment); | ||
|
|
@@ -182,6 +187,72 @@ internal void SetDefaultAttributes(SentryOptions options, SdkVersion sdk) | |
| { | ||
| SetAttribute("sentry.sdk.version", version); | ||
| } | ||
|
|
||
| if (scope is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (scope.PropagationContext._dynamicSamplingContext is { } dynamicSamplingContext) | ||
| { | ||
| if (dynamicSamplingContext.Items.TryGetValue("replay_id", out var replayId)) | ||
| { | ||
| SetAttribute("sentry.replay_id", replayId); | ||
| } | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
Comment on lines
+204
to
+215
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: PII Do we need to check |
||
|
|
||
| if (scope.Contexts.Browser.Name is { } browserName) | ||
| { | ||
| SetAttribute("browser.name", browserName); | ||
| } | ||
| if (scope.Contexts.Browser.Version is { } browserVersion) | ||
| { | ||
| SetAttribute("browser.version", browserVersion); | ||
| } | ||
|
|
||
| var serverAddress = options.ServerName; | ||
| if (!string.IsNullOrEmpty(serverAddress)) | ||
| { | ||
| SetAttribute("server.address", serverAddress); | ||
| } | ||
| else if (options.SendDefaultPii) | ||
| { | ||
| SetAttribute("server.address", Environment.MachineName); | ||
| } | ||
|
|
||
| if (scope.Contexts.OperatingSystem.Name is { } osName) | ||
| { | ||
| SetAttribute("os.name", osName); | ||
| } | ||
| if (scope.Contexts.OperatingSystem.Version is { } osVersion) | ||
| { | ||
| SetAttribute("os.version", osVersion); | ||
| } | ||
| if (scope.Contexts.Device.Brand is { } deviceBrand) | ||
| { | ||
| SetAttribute("device.brand", deviceBrand); | ||
| } | ||
| if (scope.Contexts.Device.Model is { } deviceModel) | ||
| { | ||
| SetAttribute("device.model", deviceModel); | ||
| } | ||
| if (scope.Contexts.Device.Family is { } deviceFamily) | ||
| { | ||
| SetAttribute("device.family", deviceFamily); | ||
| } | ||
| } | ||
|
|
||
| internal void SetOrigin(string origin) | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Could alternatively get from
IReplaySession.ActiveReplayId.But I guess reading it via the
Scopeunifies the source, and avoid a dependency toIReplaySession.