-
-
Notifications
You must be signed in to change notification settings - Fork 371
[Structured Logging] Add SentryLog Models
#5441
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
39 commits
Select commit
Hold shift + click to select a range
a64ff19
Move SentryAsyncLogWrapper out of SentryLogC.h. Move `SenryLog.c` dec…
denrase 807cb7e
Update visibility to private
denrase f630a8b
Rename SentryLog to SentryLogSwift
denrase 8749842
Rename file
denrase e668737
remove unused SentryLogLevel in defines
denrase f441b96
Add log models and serialization/deserialization tests
denrase e8851ad
addadd cl entry
denrase 4b2981c
Rename `SentrLogSwift` to SentrySDKLog
denrase 3cd7e3b
remove duplicate imports
denrase d10a5c2
Rename SentryLogLevel to SentryLog.Level and restore previous ObjC Se…
denrase 05a9399
Merge branch 'main' into feat/structured-logs-models
denrase cbb641c
Use new naming
denrase 9b61085
rename files
denrase 238bf17
Add docs link to toSeverityNumber()
denrase 6074420
Rename SentryLogAttribute to SentryLog.Attribute and change it to an …
denrase 39c2e9e
Add encodeToJSONData helper with correct date encoding strategy
denrase 6cd8671
Fix failing SentrySDKLogTests
denrase dddb9dd
run clang format
denrase d36a441
run swiftlint —fix
denrase ad20321
remove new sentry log classes
denrase 1d89693
Revert "remove new sentry log classes"
denrase c5a365e
update cl
denrase 50fa3e3
Merge branch 'main' into feat/structured-logs-models
denrase ddf7abf
fix cl
denrase c461f7f
cleanup
denrase 43f0736
format
denrase 3eeb816
Merge branch 'main' into feat/structured-logs-models
denrase bfe2a69
fix project file
denrase a06a3da
Merge branch 'main' into feat/structured-logs-models
denrase f3a910e
fix cl
denrase 005e3c6
Merge branch 'main' into feat/structured-logs-models
denrase ad54f0b
remove cl entry
denrase 542a919
add sev tests
denrase 0e65135
use XCTUnwrap instead of XCTAssertNotNil
denrase 605f164
make encode funcs internal
denrase 548eb4e
remove separate codable files
denrase 0484a04
dont use forece unwraps in tests
denrase 5a8661a
use double instead of
denrase 124d3e3
run swift lint fix
denrase 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| struct SentryLog: Codable { | ||
| let timestamp: Date | ||
| var traceId: SentryId | ||
| let level: SentryLog.Level | ||
| let body: String | ||
| let attributes: [String: SentryLog.Attribute] | ||
| let severityNumber: Int? | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case timestamp | ||
| case traceId = "trace_id" | ||
| case level | ||
| case body | ||
| case attributes | ||
| case severityNumber = "severity_number" | ||
| } | ||
|
|
||
| /// The traceId is initially an empty default value and is populated during processing; | ||
| /// by the time processing completes, it is guaranteed to be a valid non-empty trace id. | ||
| init( | ||
| timestamp: Date, | ||
| traceId: SentryId? = nil, | ||
| level: SentryLog.Level, | ||
| body: String, | ||
| attributes: [String: SentryLog.Attribute], | ||
| severityNumber: Int? = nil | ||
| ) { | ||
| self.timestamp = timestamp | ||
| self.traceId = traceId ?? SentryId.empty | ||
| self.level = level | ||
| self.body = body | ||
| self.attributes = attributes | ||
| self.severityNumber = severityNumber | ||
| } | ||
|
|
||
| init(from decoder: any Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
|
||
| let timestamp = try container.decode(Date.self, forKey: .timestamp) | ||
| let traceIdString = try container.decode(String.self, forKey: .traceId) | ||
| let traceId = SentryId(uuidString: traceIdString) | ||
| let level = try container.decode(SentryLog.Level.self, forKey: .level) | ||
| let body = try container.decode(String.self, forKey: .body) | ||
| let attributes = try container.decode([String: SentryLog.Attribute].self, forKey: .attributes) | ||
| let severityNumber = try container.decodeIfPresent(Int.self, forKey: .severityNumber) | ||
|
|
||
| self.init( | ||
| timestamp: timestamp, | ||
| traceId: traceId, | ||
| level: level, | ||
| body: body, | ||
| attributes: attributes, | ||
| severityNumber: severityNumber | ||
| ) | ||
| } | ||
|
|
||
| func encode(to encoder: any Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
|
||
| try container.encode(timestamp, forKey: .timestamp) | ||
| try container.encode(traceId.sentryIdString, forKey: .traceId) | ||
| try container.encode(level, forKey: .level) | ||
| try container.encode(body, forKey: .body) | ||
| try container.encode(attributes, forKey: .attributes) | ||
| try container.encodeIfPresent(severityNumber, forKey: .severityNumber) | ||
| } | ||
| } |
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,66 @@ | ||
| extension SentryLog { | ||
| enum Attribute: Codable { | ||
| case string(String) | ||
| case boolean(Bool) | ||
| case integer(Int) | ||
| case double(Double) | ||
|
|
||
| var type: String { | ||
| switch self { | ||
| case .string: return "string" | ||
| case .boolean: return "boolean" | ||
| case .integer: return "integer" | ||
| case .double: return "double" | ||
| } | ||
| } | ||
|
|
||
| var value: 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 | ||
| } | ||
| } | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case value | ||
| case type | ||
| } | ||
|
|
||
| init(from decoder: any Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
|
||
| let type = try container.decode(String.self, forKey: .type) | ||
| switch type { | ||
| case "string": | ||
| self = .string(try container.decode(String.self, forKey: .value)) | ||
| case "boolean": | ||
| self = .boolean(try container.decode(Bool.self, forKey: .value)) | ||
| case "integer": | ||
| self = .integer(try container.decode(Int.self, forKey: .value)) | ||
| case "double": | ||
| self = .double(try container.decode(Double.self, forKey: .value)) | ||
| default: | ||
| throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Unknown type: \(type)") | ||
| } | ||
| } | ||
|
|
||
| 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) | ||
| } | ||
| } | ||
| } | ||
| } |
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,28 @@ | ||
| extension SentryLog { | ||
| enum Level: String, Codable { | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case trace | ||
| case debug | ||
| case info | ||
| case warn | ||
| case error | ||
| case fatal | ||
|
|
||
| // Docs: https://develop.sentry.dev/sdk/telemetry/logs/#log-severity-number | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func toSeverityNumber() -> Int { | ||
denrase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| switch self { | ||
| case .trace: | ||
| return 1 | ||
| case .debug: | ||
| return 5 | ||
| case .info: | ||
| return 9 | ||
| case .warn: | ||
| return 13 | ||
| case .error: | ||
| return 17 | ||
| case .fatal: | ||
| return 21 | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.