-
-
Notifications
You must be signed in to change notification settings - Fork 366
ref: Convert ExtraContextProvider to Swift #6445
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
static NSString *const SentryDeviceContextFreeMemoryKey = @"free_memory"; | ||
static NSString *const SentryDeviceContextAppMemoryKey = @"app_memory"; |
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,72 @@ | ||
@_implementationOnly import _SentryPrivate | ||
|
||
@_spi(Private) @objc public final class SentryExtraContextProvider: NSObject { | ||
|
||
private static let kSentryProcessInfoThermalStateNominal = "nominal" | ||
private static let kSentryProcessInfoThermalStateFair = "fair" | ||
private static let kSentryProcessInfoThermalStateSerious = "serious" | ||
private static let kSentryProcessInfoThermalStateCritical = "critical" | ||
|
||
private let crashWrapper: SentryCrashWrapper | ||
private let processInfoWrapper: SentryProcessInfoSource | ||
|
||
#if (os(iOS) || targetEnvironment(macCatalyst)) && !SENTRY_NO_UIKIT | ||
private let deviceWrapper: SentryUIDeviceWrapper | ||
|
||
@objc public init(crashWrapper: SentryCrashWrapper, processInfoWrapper: SentryProcessInfoSource, deviceWrapper: SentryUIDeviceWrapper) { | ||
self.crashWrapper = crashWrapper | ||
self.processInfoWrapper = processInfoWrapper | ||
self.deviceWrapper = deviceWrapper | ||
} | ||
#else | ||
@objc public init(crashWrapper: SentryCrashWrapper, processInfoWrapper: SentryProcessInfoSource) { | ||
self.crashWrapper = crashWrapper | ||
self.processInfoWrapper = processInfoWrapper | ||
} | ||
#endif | ||
noahsmartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@objc public func getExtraContext() -> [String: Any] { | ||
[ | ||
"device": getExtraDeviceContext(), | ||
"app": getExtraAppContext() | ||
] | ||
} | ||
|
||
private func getExtraDeviceContext() -> [String: Any] { | ||
var extraDeviceContext: [String: Any] = [ | ||
SentryDeviceContextFreeMemoryKey: NSNumber(value: crashWrapper.freeMemorySize), | ||
"processor_count": NSNumber(value: processInfoWrapper.processorCount) | ||
] | ||
|
||
let thermalState = processInfoWrapper.thermalState | ||
switch thermalState { | ||
case .nominal: | ||
extraDeviceContext["thermal_state"] = Self.kSentryProcessInfoThermalStateNominal | ||
case .fair: | ||
extraDeviceContext["thermal_state"] = Self.kSentryProcessInfoThermalStateFair | ||
case .serious: | ||
extraDeviceContext["thermal_state"] = Self.kSentryProcessInfoThermalStateSerious | ||
case .critical: | ||
extraDeviceContext["thermal_state"] = Self.kSentryProcessInfoThermalStateCritical | ||
default: | ||
SentrySDKLog.warning("Unexpected thermal state enum value: \(thermalState)") | ||
} | ||
|
||
#if (os(iOS) || targetEnvironment(macCatalyst)) && !SENTRY_NO_UIKIT | ||
if deviceWrapper.orientation != .unknown { | ||
extraDeviceContext["orientation"] | ||
= deviceWrapper.orientation.isPortrait ? "portrait" : "landscape" | ||
} | ||
|
||
if deviceWrapper.isBatteryMonitoringEnabled { | ||
extraDeviceContext["charging"] = NSNumber(value: deviceWrapper.batteryState == .charging) | ||
extraDeviceContext["battery_level"] = NSNumber(value: Int(deviceWrapper.batteryLevel * 100)) | ||
} | ||
#endif | ||
return extraDeviceContext | ||
} | ||
|
||
private func getExtraAppContext() -> [String: Any] { | ||
[ SentryDeviceContextAppMemoryKey: NSNumber(value: self.crashWrapper.appMemorySize) ] | ||
} | ||
} |
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,3 +1,4 @@ | ||
@_spi(Private) import Sentry | ||
@_spi(Private) import SentryTestUtils | ||
import XCTest | ||
|
||
|
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.
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.