From c1846ca7682c0c7eb6870ff9d951834fafaeca7b Mon Sep 17 00:00:00 2001 From: Geoff Pado Date: Fri, 2 Aug 2024 20:35:46 -0700 Subject: [PATCH 1/3] Use new TelemetryDeck error logging --- .../ErrorHandling/Sources/ErrorHandler.swift | 18 +++++++++++++----- .../Tests/ErrorHandlerTests.swift | 11 +++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift b/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift index bdffe2cd..9356d3b2 100644 --- a/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift +++ b/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift @@ -27,15 +27,18 @@ public struct ErrorHandler: ErrorHandling { } public func log(_ error: Error) { - let errorDescription: String + let errorID: String if type(of: error) is NSError.Type { let nsError = error as NSError - errorDescription = "\(nsError.domain) - \(nsError.code): \(nsError.localizedDescription)" + errorID = "\(nsError.domain) - \(nsError.code)" } else { - errorDescription = String(describing: error) + errorID = String(describing: error) } - logger.log(Event(name: Self.logError, info: ["errorDescription": errorDescription])) + logger.log(Event(name: Self.logError, info: [ + Self.telemetryErrorIDKey: errorID, + Self.errorDescriptionKey: error.localizedDescription + ])) } public func crash(_ message: String) -> Never { @@ -50,9 +53,14 @@ public struct ErrorHandler: ErrorHandling { // MARK: Event Names - private static let logError = Event.Name("logError") + private static let logError = Event.Name("TelemetryDeck.Error.occurred") private static let crash = Event.Name("crash") private static let notImplemented = Event.Name("notImplemented") + + // MARK: Event Keys + + private static let errorDescriptionKey = "errorDescription" + private static let telemetryErrorIDKey = "TelemetryDeck.Error.id" } @objc(ErrorHandling) diff --git a/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift b/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift index 3c18b1b6..6f46a728 100644 --- a/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift +++ b/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift @@ -15,8 +15,8 @@ final class ErrorHandlerTests: XCTestCase { handler.log(SampleError.sample) let event = try XCTUnwrap(logger.loggedEvents.first) - XCTAssertEqual(event.value, "logError") - XCTAssertEqual(event.info, ["errorDescription": "sample"]) + XCTAssertEqual(event.value, "TelemetryDeck.Error.occurred") + XCTAssertEqual(event.info["TelemetryDeck.Error.id"], "sample") } func testLoggingNSErrorLogsInformation() throws { @@ -27,8 +27,11 @@ final class ErrorHandlerTests: XCTestCase { handler.log(error) let event = try XCTUnwrap(logger.loggedEvents.first) - XCTAssertEqual(event.value, "logError") - XCTAssertEqual(event.info, ["errorDescription": "sample - 19: The operation couldn’t be completed. (sample error 19.)"]) + XCTAssertEqual(event.value, "TelemetryDeck.Error.occurred") + XCTAssertEqual(event.info, [ + "TelemetryDeck.Error.id": "sample - 19", + "errorDescription": "The operation couldn’t be completed. (sample error 19.)" + ]) } func testCrashingLogsMessage() throws { From 825edbcb41ff2fae1ff4392b66238ff30806afea Mon Sep 17 00:00:00 2001 From: Geoff Pado Date: Fri, 2 Aug 2024 20:42:16 -0700 Subject: [PATCH 2/3] Fix app ratings prompter tests --- .../AppRatings/Tests/AppRatingsPrompterTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Capabilities/AppRatings/Tests/AppRatingsPrompterTests.swift b/Modules/Capabilities/AppRatings/Tests/AppRatingsPrompterTests.swift index e71cbc97..0d6ae8f3 100644 --- a/Modules/Capabilities/AppRatings/Tests/AppRatingsPrompterTests.swift +++ b/Modules/Capabilities/AppRatings/Tests/AppRatingsPrompterTests.swift @@ -58,8 +58,8 @@ class AppRatingsPrompterTests: XCTestCase { prompter.displayRatingsPrompt(in: nil) let event = try XCTUnwrap(spy.loggedEvents.first) - XCTAssertEqual(event.value, "logError") - XCTAssertEqual(event.info, ["errorDescription": "missingWindowScene"]) + XCTAssertEqual(event.value, "TelemetryDeck.Error.occurred") + XCTAssertEqual(event.info["TelemetryDeck.Error.id"], "missingWindowScene") } func testDisplayingPromptLogsEvent() throws { From d6593aaf187eea24c9748f7d6d86e4c2b4727c13 Mon Sep 17 00:00:00 2001 From: Geoff Pado Date: Fri, 2 Aug 2024 20:44:07 -0700 Subject: [PATCH 3/3] Fix linting issues --- Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift | 2 +- .../Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift b/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift index 9356d3b2..888d1705 100644 --- a/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift +++ b/Modules/Capabilities/ErrorHandling/Sources/ErrorHandler.swift @@ -37,7 +37,7 @@ public struct ErrorHandler: ErrorHandling { logger.log(Event(name: Self.logError, info: [ Self.telemetryErrorIDKey: errorID, - Self.errorDescriptionKey: error.localizedDescription + Self.errorDescriptionKey: error.localizedDescription, ])) } diff --git a/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift b/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift index 6f46a728..b5e9c1a8 100644 --- a/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift +++ b/Modules/Capabilities/ErrorHandling/Tests/ErrorHandlerTests.swift @@ -30,7 +30,7 @@ final class ErrorHandlerTests: XCTestCase { XCTAssertEqual(event.value, "TelemetryDeck.Error.occurred") XCTAssertEqual(event.info, [ "TelemetryDeck.Error.id": "sample - 19", - "errorDescription": "The operation couldn’t be completed. (sample error 19.)" + "errorDescription": "The operation couldn’t be completed. (sample error 19.)", ]) }