-
-
Notifications
You must be signed in to change notification settings - Fork 421
refactor: Add attributable protocol for typed attribute values #7077
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
df295cf
refactor: Add attributable protocol for typed attribute values
philprime 7aecbe3
Update Sources/Swift/Tools/SentryLogger.swift
philprime 4a4dc20
add fallback method
philprime afd1f46
fix mapping of SentryAttribute to SentryAttributeValue
philprime b57d616
add missing array support
philprime 6a1093d
fix integer array check
philprime 8b7c319
fix array handling
philprime 67494c1
Implement handling of SentryAttribute in SentryAttributeValue and add…
philprime ee2b24a
WIP
philprime ad003d9
Rename asAttributableValue to asSentryAttributableValue; add docs to …
philprime 4409125
Merge remote-tracking branch 'origin/main' into philprime/attributable
philprime d68b098
remove typed attributes from Logs public API
philprime 618e487
Use SentryAttribute in SentryAttributeTests
philprime b586a7f
add more docs
philprime e39f278
Implement safe fallback for empty arrays in SentryAttributeValuable; …
philprime 4a56efe
apply feedback from pull request review
philprime 9b46d45
fix missing usecases
philprime bc47a48
add more docs
philprime 6f1ba10
add casting optimization
philprime 7e7a11c
rename files to match types
philprime 099d616
apply feedback from pull request review
philprime 1ab05b4
Merge branch 'main' into philprime/attributable
philprime 8121614
fix: optimize BatcherScope.applyToItem to avoid repeated computed pro…
philprime 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| public protocol SentryAttributeValuable { | ||
| var asAttributeValue: SentryAttributeValue { get } | ||
| } | ||
|
|
||
| extension String: SentryAttributeValuable { | ||
| public var asAttributeValue: SentryAttributeValue { | ||
| return .string(self) | ||
| } | ||
| } | ||
|
|
||
| extension Bool: SentryAttributeValuable { | ||
| public var asAttributeValue: SentryAttributeValue { | ||
| return .boolean(self) | ||
| } | ||
| } | ||
|
|
||
| extension Int: SentryAttributeValuable { | ||
| public var asAttributeValue: SentryAttributeValue { | ||
| return .integer(self) | ||
| } | ||
| } | ||
|
|
||
| extension Double: SentryAttributeValuable { | ||
| public var asAttributeValue: SentryAttributeValue { | ||
| return .double(self) | ||
| } | ||
| } | ||
|
|
||
| extension Float: SentryAttributeValuable { | ||
| public var asAttributeValue: SentryAttributeValue { | ||
| return .double(Double(self)) | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| public enum SentryAttributeValue: Equatable, Hashable { | ||
| case string(String) | ||
| case boolean(Bool) | ||
| case integer(Int) | ||
| case double(Double) | ||
| case stringArray([String]) | ||
| case booleanArray([Bool]) | ||
| case integerArray([Int]) | ||
| case doubleArray([Double]) | ||
|
|
||
| var type: String { | ||
| switch self { | ||
| case .string: | ||
| return "string" | ||
| case .boolean: | ||
| return "boolean" | ||
| case .integer: | ||
| return "integer" | ||
| case .double: | ||
| return "double" | ||
| case .stringArray: | ||
| return "string[]" | ||
| case .booleanArray: | ||
| return "boolean[]" | ||
| case .integerArray: | ||
| return "integer[]" | ||
| case .doubleArray: | ||
| return "double[]" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension SentryAttributeValue: Encodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case type | ||
| case value | ||
| } | ||
|
|
||
| public func encode(to encoder: any Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
| try container.encode(type, forKey: .type) | ||
|
|
||
| switch self { | ||
| case .string(let value): | ||
| try container.encode(value, forKey: .value) | ||
| case .boolean(let value): | ||
| try container.encode(value, forKey: .value) | ||
| case .integer(let value): | ||
| try container.encode(value, forKey: .value) | ||
| case .double(let value): | ||
| try container.encode(value, forKey: .value) | ||
| case .stringArray(let value): | ||
| try container.encode(value, forKey: .value) | ||
| case .booleanArray(let value): | ||
| try container.encode(value, forKey: .value) | ||
| case .integerArray(let value): | ||
| try container.encode(value, forKey: .value) | ||
| case .doubleArray(let value): | ||
| try container.encode(value, forKey: .value) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension SentryAttributeValue { | ||
| static func from(anyValue value: Any) -> Self { | ||
| if let val = value as? String { | ||
| return .string(val) | ||
| } | ||
| if let val = value as? Bool { | ||
| return .boolean(val) | ||
| } | ||
| if let val = value as? Int { | ||
| return .integer(val) | ||
| } | ||
| if let val = value as? Double { | ||
| return .double(val) | ||
| } | ||
| if let val = value as? Float { | ||
| return .double(Double(val)) | ||
| } | ||
| if let val = value as? SentryAttributeValue { | ||
| return val | ||
| } | ||
| return .string(String(describing: value)) | ||
| } | ||
|
philprime marked this conversation as resolved.
|
||
|
|
||
| var anyValue: Any { | ||
| switch self { | ||
| case .string(let value): | ||
| return value | ||
| case .boolean(let value): | ||
| return value | ||
| case .integer(let value): | ||
| return value | ||
| case .double(let value): | ||
| return value | ||
| case .stringArray(let value): | ||
| return value | ||
| case .booleanArray(let value): | ||
| return value | ||
| case .integerArray(let value): | ||
| return value | ||
| case .doubleArray(let value): | ||
| return value | ||
| } | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| protocol BatcherItem: Encodable { | ||
| var attributes: [String: SentryAttribute] { get set } | ||
| var attributesMap: [String: SentryAttributeValue] { get set } | ||
|
philprime marked this conversation as resolved.
Outdated
|
||
| var traceId: SentryId { get set } | ||
| var body: String { get } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.