-
-
Notifications
You must be signed in to change notification settings - Fork 230
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
base: main
Are you sure you want to change the base?
Changes from all commits
d116dd9
e6a9743
009f94c
a65b5f1
7efc8f6
0e25afd
093fba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,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> | ||
|
|
@@ -162,7 +162,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); | ||
|
|
@@ -181,6 +186,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); | ||
| } | ||
| } | ||
|
Comment on lines
+195
to
+201
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. note: Could alternatively get from But I guess reading it via the |
||
|
|
||
| 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
+203
to
+214
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) | ||
|
|
||
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.
todo: instead, have something like a per-Platform "Enricher"