Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ target 'WordPress' do

# Production

pod 'Automattic-Tracks-iOS', '~> 0.7.0'
pod 'Automattic-Tracks-iOS', '~> 0.8.0'
# While in PR
# pod 'Automattic-Tracks-iOS', :git => 'https://github.com/Automattic/Automattic-Tracks-iOS.git', :branch => ''
# Local Development
Expand Down
18 changes: 9 additions & 9 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ PODS:
- AppCenter/Core
- AppCenter/Distribute (2.5.1):
- AppCenter/Core
- Automattic-Tracks-iOS (0.7.1):
- Automattic-Tracks-iOS (0.8.1):
- CocoaLumberjack (~> 3)
- Reachability (~> 3)
- Sentry (~> 4)
- Sentry (~> 6)
- Sodium (>= 0.9.1)
- UIDeviceIdentifier (~> 1)
- boost-for-react-native (1.63.0)
Expand Down Expand Up @@ -384,9 +384,9 @@ PODS:
- RNTAztecView (1.45.0):
- React-Core
- WordPress-Aztec-iOS (~> 1.19.3)
- Sentry (4.5.0):
- Sentry/Core (= 4.5.0)
- Sentry/Core (4.5.0)
- Sentry (6.1.4):
- Sentry/Core (= 6.1.4)
- Sentry/Core (6.1.4)
- Sodium (0.9.1)
- Starscream (3.0.6)
- SVProgressHUD (2.2.5)
Expand Down Expand Up @@ -443,7 +443,7 @@ DEPENDENCIES:
- AMScrollingNavbar (= 5.6.0)
- AppCenter (= 2.5.1)
- AppCenter/Distribute (= 2.5.1)
- Automattic-Tracks-iOS (~> 0.7.0)
- Automattic-Tracks-iOS (~> 0.8.0)
- Charts (~> 3.2.2)
- CocoaLumberjack (~> 3.0)
- CropViewController (= 2.5.3)
Expand Down Expand Up @@ -678,7 +678,7 @@ SPEC CHECKSUMS:
AMScrollingNavbar: cf0ec5a5ee659d76ba2509f630bf14fba7e16dc3
AppAuth: 31bcec809a638d7bd2f86ea8a52bd45f6e81e7c7
AppCenter: fddcbac6e4baae3d93a196ceb0bfe0e4ce407dec
Automattic-Tracks-iOS: fe148d48abc7125f5cb389ba7f6595f3ffec1a46
Automattic-Tracks-iOS: b942ca6067f089660c75c96fd189599fd065f979
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
Charts: f69cf0518b6d1d62608ca504248f1bbe0b6ae77e
CocoaLumberjack: e8955b9d337ac307103b0a34fd141c32f27e53c5
Expand Down Expand Up @@ -741,7 +741,7 @@ SPEC CHECKSUMS:
RNScreens: 6833ac5c29cf2f03eed12103140530bbd75b6aea
RNSVG: 68a534a5db06dcbdaebfd5079349191598caef7b
RNTAztecView: 0f33f2895c7a6cb54f364ae5aa1917bcd7b24e57
Sentry: ab6c209f23700d1460691dbc90e19ed0a05d496b
Sentry: 9d055e2de30a77685e86b219acf02e59b82091fc
Sodium: 23d11554ecd556196d313cf6130d406dfe7ac6da
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
Expand All @@ -765,6 +765,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: dcb2596ad05a63d662e8c7924357babbf327b421
ZIPFoundation: b1f0de4eed33e74a676f76e12559ab6b75990197

PODFILE CHECKSUM: aceaecff075beee85fa463cb7f39ab112f52e2e0
PODFILE CHECKSUM: 51fad485974e8f9c2651378787ada36aefe69cb2

COCOAPODS: 1.10.0
6 changes: 3 additions & 3 deletions WordPress/Classes/Extensions/UIImageView+SiteIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension UIImageView {
if case .requestCancelled = (error as? AFIError) {
// Do not log intentionally cancelled requests as errors.
} else {
CrashLogging.logError(error)
WordPressAppDelegate.crashLogging?.logError(error)
}
}
})
Expand Down Expand Up @@ -122,7 +122,7 @@ extension UIImageView {

let host = MediaHost(with: blog) { error in
// We'll log the error, so we know it's there, but we won't halt execution.
CrashLogging.logError(error)
WordPressAppDelegate.crashLogging?.logError(error)
}

let mediaRequestAuthenticator = MediaRequestAuthenticator()
Expand All @@ -132,7 +132,7 @@ extension UIImageView {
onComplete: { [weak self] request in
self?.downloadSiteIcon(with: request, placeholderImage: placeholderImage)
}) { error in
CrashLogging.logError(error)
WordPressAppDelegate.crashLogging?.logError(error)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Extensions/WKWebView+UserAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension WKWebView {
func userAgent() -> String {
guard let userAgent = value(forKey: WKWebView.userAgentKey) as? String,
userAgent.count > 0 else {
CrashLogging.logMessage(
WordPressAppDelegate.crashLogging?.logMessage(
"This method for retrieveing the user agent seems to be no longer working. We need to figure out an alternative.",
properties: [:],
level: .error)
Expand Down
33 changes: 33 additions & 0 deletions WordPress/Classes/Models/UserSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation

class UserSettings {

@objc
@UserDefault("crashlytics_opt_out", defaultValue: false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏻

static var userHasOptedOutOfCrashLogging: Bool

@objc
@UserDefault("force-crash-logging", defaultValue: false)
static var userHasForcedCrashLoggingEnabled: Bool
}

/// A property wrapper for UserDefaults access
@propertyWrapper
struct UserDefault<T> {
let key: String
let defaultValue: T

init(_ key: String, defaultValue: T) {
self.key = key
self.defaultValue = defaultValue
}

var wrappedValue: T {
get {
return UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
}
set {
UserDefaults.standard.set(newValue, forKey: key)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AtomicAuthenticationService {
}
}) { error in
// Make sure this error scenario isn't silently ignored.
CrashLogging.logError(error)
WordPressAppDelegate.crashLogging?.logError(error)

// Even if getting the auth cookies fail, we'll still try to load the URL
// so that the user sees a reasonable error situation on screen.
Expand Down
4 changes: 2 additions & 2 deletions WordPress/Classes/Services/AuthenticationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AuthenticationService {
}
}) { error in
// Make sure this error scenario isn't silently ignored.
CrashLogging.logError(error)
WordPressAppDelegate.crashLogging?.logError(error)

// Even if getting the auth cookies fail, we'll still try to load the URL
// so that the user sees a reasonable error situation on screen.
Expand Down Expand Up @@ -107,7 +107,7 @@ class AuthenticationService {
}
}) { error in
// Make sure this error scenario isn't silently ignored.
CrashLogging.logError(error)
WordPressAppDelegate.crashLogging?.logError(error)

// Even if getting the auth cookies fail, we'll still try to load the URL
// so that the user sees a reasonable error situation on screen.
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/MediaCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ extension MediaCoordinator {
}

self.cancelUploadAndDeleteMedia(media)
CrashLogging.logError(mediaError,
WordPressAppDelegate.crashLogging?.logError(mediaError,
userInfo: ["description": "Deleting a media object that's failed to upload because of a missing local file."])

}, for: nil)
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Services/SiteVerticalsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class SiteCreationVerticalsService: LocalCoreDataService, SiteVerticalsSer
switch result {
case .success(let verticals):
guard let vertical = verticals.first else {
CrashLogging.logMessage("The verticals service should always return at least 1 match for the precise term queried.", level: .error)
WordPressAppDelegate.crashLogging?.logMessage("The verticals service should always return at least 1 match for the precise term queried.", level: .error)
completion(.failure(.serviceFailure))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import AutomatticTracks
}

if debugKey == ApiCredentials.debuggingKey(), debugType == "force_crash" {
CrashLogging.crash()
WordPressAppDelegate.crashLogging?.crash()
}

return true
Expand Down
19 changes: 13 additions & 6 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
}()

var analytics: WPAppAnalytics?
private lazy var crashLoggingProvider: WPCrashLoggingProvider = {
return WPCrashLoggingProvider()
}()

@objc var internetReachability: Reachability?
@objc var connectionAvailable: Bool = true
Expand Down Expand Up @@ -67,6 +64,18 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
return UploadsManager(uploaders: uploaders)
}()

private let loggingStack = WPLoggingStack()

/// Access the crash logging type
class var crashLogging: CrashLogging? {
shared?.loggingStack.crashLogging
}

/// Access the event logging type
class var eventLogging: EventLogging? {
shared?.loggingStack.eventLogging
}

@objc class var shared: WordPressAppDelegate? {
return UIApplication.shared.delegate as? WordPressAppDelegate
}
Expand All @@ -82,9 +91,7 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
}

// Start CrashLogging as soon as possible (in case a crash happens during startup)
let dataSource = EventLoggingDataProvider.fromDDFileLogger(WPLogger.shared().fileLogger)
let eventLogging = EventLogging(dataSource: dataSource, delegate: crashLoggingProvider.loggingUploadDelegate)
CrashLogging.start(withDataProvider: crashLoggingProvider, eventLogging: eventLogging)
try? loggingStack.start()

// Configure WPCom API overrides
configureWordPressComApi()
Expand Down
14 changes: 7 additions & 7 deletions WordPress/Classes/Utility/Logging/EventLoggingDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ struct EventLoggingDelegate: AutomatticTracks.EventLoggingDelegate {
var shouldUploadLogFiles: Bool {
return
!ProcessInfo.processInfo.isLowPowerModeEnabled
&& !WPCrashLoggingProvider.userHasOptedOut
&& !UserSettings.userHasOptedOutOfCrashLogging
}

func didQueueLogForUpload(_ log: LogFile) {
NotificationCenter.default.post(name: WPCrashLoggingProvider.QueuedLogsDidChangeNotification, object: log)
NotificationCenter.default.post(name: WPLoggingStack.QueuedLogsDidChangeNotification, object: log)
DDLogDebug("📜 Added log to queue: \(log.uuid)")

if let eventLogging = CrashLogging.eventLogging {
if let eventLogging = WordPressAppDelegate.eventLogging {
DDLogDebug("📜\t There are \(eventLogging.queuedLogFiles.count) logs in the queue.")
}
}

func didStartUploadingLog(_ log: LogFile) {
NotificationCenter.default.post(name: WPCrashLoggingProvider.QueuedLogsDidChangeNotification, object: log)
NotificationCenter.default.post(name: WPLoggingStack.QueuedLogsDidChangeNotification, object: log)
DDLogDebug("📜 Started uploading encrypted log: \(log.uuid)")
}

func didFinishUploadingLog(_ log: LogFile) {
NotificationCenter.default.post(name: WPCrashLoggingProvider.QueuedLogsDidChangeNotification, object: log)
NotificationCenter.default.post(name: WPLoggingStack.QueuedLogsDidChangeNotification, object: log)
DDLogDebug("📜 Finished uploading encrypted log: \(log.uuid)")
if let eventLogging = CrashLogging.eventLogging {
if let eventLogging = WordPressAppDelegate.eventLogging {
DDLogDebug("📜\t There are \(eventLogging.queuedLogFiles.count) logs remaining in the queue.")
}
}

func uploadFailed(withError error: Error, forLog log: LogFile) {
NotificationCenter.default.post(name: WPCrashLoggingProvider.QueuedLogsDidChangeNotification, object: log)
NotificationCenter.default.post(name: WPLoggingStack.QueuedLogsDidChangeNotification, object: log)
DDLogError("📜 Error uploading encrypted log: \(log.uuid)")
DDLogError("📜\t\(error.localizedDescription)")

Expand Down
39 changes: 6 additions & 33 deletions WordPress/Classes/Utility/Logging/SentryStartupEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,12 @@ startup time. This will block the thread. Do not use unless you're sure.
]
})

CrashLogging.logErrorAndWait(NSError(domain: title, code: -1, userInfo: [NSLocalizedDescriptionKey: title]), userInfo: userInfo)
}
}

extension CrashLogging {
/**
Writes the error to the Crash Logging system, and includes a stack trace. This method will block the thread until the event is fired.

- Parameters:
- error: The error object
- userInfo: A dictionary containing additional data about this error.
- level: The level of severity to report in Sentry (`.error` by default)
*/
static func logErrorAndWait(_ error: Error, userInfo: [String: Any]? = nil, level: SentrySeverity = .error) {
let event = Event(level: .error)
event.message = error.localizedDescription
event.extra = userInfo ?? (error as NSError).userInfo
event.timestamp = Date()

Client.shared?.snapshotStacktrace {
Client.shared?.appendStacktrace(to: event)
let error = NSError(domain: title, code: -1, userInfo: [NSLocalizedDescriptionKey: title])
do {
try WordPressAppDelegate.crashLogging?.logErrorAndWait(error, userInfo: userInfo, level: SentryLevel.fatal)
} catch let err {
DDLogError("⛔️ Unable to send startup error message to Sentry:")
DDLogError(err.localizedDescription)
}

guard let client = Client.shared else {
return
}

let semaphore = DispatchSemaphore(value: 0)

client.send(event: event) { _ in
semaphore.signal()
}

semaphore.wait()
}
}
Loading