-
-
Notifications
You must be signed in to change notification settings - Fork 372
refactor(logs): Add generic internal item batcher #7017
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 all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3ca02d7
refactor(refactor): Add generic internal item batcher
philprime 193c27b
Add SentryItemBatcherTests to enhance item batching functionality
philprime b1891d3
fixed tests and added more protocols
philprime e89eab0
Merge remote-tracking branch 'origin/main' into philprime/log-batcher…
philprime eb09954
refactor item batcher
philprime cc065bb
refactor item batcher into protocols
philprime 8be32e7
cleanup
philprime 21d4e61
Update Sources/Swift/Protocol/SentryAttribute.swift
philprime c17ef37
Enhance Batcher and TestCurrentDateProvider functionality
philprime a217014
Merge branch 'main' into philprime/log-batcher-abstraction
philprime 59c136b
apply feedback from PR review
philprime 821311a
change batcher capture items guard to check for item count
philprime 38a71dc
rename storage flush to clear
philprime 51aae95
rename batch storage to batch buffer
philprime b81f760
change getInstallationId to fixed value
philprime 7913996
split config into metadata
philprime 02b92cf
fix date encoding with tests
philprime 44c52ff
fix tests
philprime fcd211a
move installationid to metadata
philprime d824fa6
add json encoder to inmemory buffer
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
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,106 @@ | ||
| /// A typed attribute that can be attached to structured item entries used by Logs | ||
| /// | ||
| /// `Attribute` provides a type-safe way to store structured data alongside item messages. | ||
| /// Supports String, Bool, Int, and Double types. | ||
| @objcMembers | ||
| public final class SentryAttribute: NSObject { | ||
| /// The type identifier for this attribute ("string", "boolean", "integer", "double") | ||
| public let type: String | ||
| /// The actual value stored in this attribute | ||
| public let value: Any | ||
|
|
||
| public init(string value: String) { | ||
| self.type = "string" | ||
| self.value = value | ||
| super.init() | ||
| } | ||
|
|
||
| public init(boolean value: Bool) { | ||
| self.type = "boolean" | ||
| self.value = value | ||
| super.init() | ||
| } | ||
|
|
||
| public init(integer value: Int) { | ||
| self.type = "integer" | ||
| self.value = value | ||
| super.init() | ||
| } | ||
|
|
||
| public init(double value: Double) { | ||
| self.type = "double" | ||
| self.value = value | ||
| super.init() | ||
| } | ||
|
|
||
| /// Creates a double attribute from a float value | ||
| public init(float value: Float) { | ||
| self.type = "double" | ||
| self.value = Double(value) | ||
| super.init() | ||
| } | ||
|
|
||
| internal init(value: Any) { | ||
| switch value { | ||
| case let stringValue as String: | ||
| self.type = "string" | ||
| self.value = stringValue | ||
| case let boolValue as Bool: | ||
| self.type = "boolean" | ||
| self.value = boolValue | ||
| case let intValue as Int: | ||
| self.type = "integer" | ||
| self.value = intValue | ||
| case let doubleValue as Double: | ||
| self.type = "double" | ||
| self.value = doubleValue | ||
| case let floatValue as Float: | ||
| self.type = "double" | ||
| self.value = Double(floatValue) | ||
| default: | ||
| // For any other type, convert to string representation | ||
| self.type = "string" | ||
| self.value = String(describing: value) | ||
| } | ||
| super.init() | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Internal Encodable Support | ||
| @_spi(Private) extension SentryAttribute: Encodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case value | ||
| case type | ||
| } | ||
|
|
||
| @_spi(Private) public func encode(to encoder: any Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
|
||
| try container.encode(type, forKey: .type) | ||
|
|
||
| switch type { | ||
| case "string": | ||
| guard let stringValue = value as? String else { | ||
| throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: encoder.codingPath, debugDescription: "Expected String but got \(Swift.type(of: value))")) | ||
| } | ||
| try container.encode(stringValue, forKey: .value) | ||
| case "boolean": | ||
| guard let boolValue = value as? Bool else { | ||
| throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: encoder.codingPath, debugDescription: "Expected Bool but got \(Swift.type(of: value))")) | ||
| } | ||
| try container.encode(boolValue, forKey: .value) | ||
| case "integer": | ||
| guard let intValue = value as? Int else { | ||
| throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: encoder.codingPath, debugDescription: "Expected Int but got \(Swift.type(of: value))")) | ||
| } | ||
| try container.encode(intValue, forKey: .value) | ||
| case "double": | ||
| guard let doubleValue = value as? Double else { | ||
| throw EncodingError.invalidValue(value, EncodingError.Context(codingPath: encoder.codingPath, debugDescription: "Expected Double but got \(Swift.type(of: value))")) | ||
| } | ||
| try container.encode(doubleValue, forKey: .value) | ||
| default: | ||
| try container.encode(String(describing: value), forKey: .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
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.