From 8c9ddd4d1a74a064a3fa2f298a789603c7effd06 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Mon, 25 Mar 2024 11:52:44 +0100 Subject: [PATCH 1/2] Revert "Merge pull request #267 from Automattic/update/release-name-value" This reverts commit a9627a0f0a6fccf9d81d17a776a3c0fc74783eac, reversing changes made to 1d192b24297475c870a61f337f69a2e33dfd0d71. --- Sources/Remote Logging/Crash Logging/CrashLogging.swift | 1 + .../Crash Logging/CrashLoggingDataProvider.swift | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Sources/Remote Logging/Crash Logging/CrashLogging.swift b/Sources/Remote Logging/Crash Logging/CrashLogging.swift index 59962441..20be1862 100644 --- a/Sources/Remote Logging/Crash Logging/CrashLogging.swift +++ b/Sources/Remote Logging/Crash Logging/CrashLogging.swift @@ -56,6 +56,7 @@ public class CrashLogging { options.diagnosticLevel = .error options.environment = self.dataProvider.buildType + options.releaseName = self.dataProvider.releaseName options.enableAutoSessionTracking = self.dataProvider.shouldEnableAutomaticSessionTracking options.enableAppHangTracking = self.dataProvider.enableAppHangTracking options.enableCaptureFailedRequests = self.dataProvider.enableCaptureFailedRequests diff --git a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift index 14987803..860de998 100644 --- a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift +++ b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift @@ -8,6 +8,7 @@ public protocol CrashLoggingDataProvider { var sentryDSN: String { get } var userHasOptedOut: Bool { get } var buildType: String { get } + var releaseName: String { get } var currentUser: TracksUser? { get } var additionalUserData: [String: Any] { get } var errorEventsSamplingRate: Double { get } @@ -22,6 +23,10 @@ public protocol CrashLoggingDataProvider { /// Default implementations of common protocol properties public extension CrashLoggingDataProvider { + var releaseName: String { + return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String + } + var additionalUserData: [String: Any] { return [ : ] } From f8f4b30f8432e27d155e92dc4ad681815fb7a8ca Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Mon, 25 Mar 2024 13:19:18 +0100 Subject: [PATCH 2/2] feat: allow SDK consumers to specify release name --- .../Crash Logging/CrashLogging.swift | 5 ++++- .../CrashLoggingDataProvider.swift | 21 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Sources/Remote Logging/Crash Logging/CrashLogging.swift b/Sources/Remote Logging/Crash Logging/CrashLogging.swift index 20be1862..80716b2d 100644 --- a/Sources/Remote Logging/Crash Logging/CrashLogging.swift +++ b/Sources/Remote Logging/Crash Logging/CrashLogging.swift @@ -56,7 +56,10 @@ public class CrashLogging { options.diagnosticLevel = .error options.environment = self.dataProvider.buildType - options.releaseName = self.dataProvider.releaseName + switch self.dataProvider.releaseName { + case .setByApplication(let name): options.releaseName = name + case .setByTracksLibrary: options.releaseName = nil + } options.enableAutoSessionTracking = self.dataProvider.shouldEnableAutomaticSessionTracking options.enableAppHangTracking = self.dataProvider.enableAppHangTracking options.enableCaptureFailedRequests = self.dataProvider.enableCaptureFailedRequests diff --git a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift index 860de998..be7efb60 100644 --- a/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift +++ b/Sources/Remote Logging/Crash Logging/CrashLoggingDataProvider.swift @@ -8,7 +8,7 @@ public protocol CrashLoggingDataProvider { var sentryDSN: String { get } var userHasOptedOut: Bool { get } var buildType: String { get } - var releaseName: String { get } + var releaseName: ReleaseName { get } var currentUser: TracksUser? { get } var additionalUserData: [String: Any] { get } var errorEventsSamplingRate: Double { get } @@ -20,11 +20,26 @@ public protocol CrashLoggingDataProvider { var enableCaptureFailedRequests: Bool { get } } +public enum ReleaseName { + /** + Sets the release name attached for every event sent to Sentry. It's intended to use in debug. + - Parameter name: The name of the release. + */ + case setByApplication(name: String) + + /** + Delegates setting the release name to the Tracks library. It's intended to use in release + builds. The crash logging framework will single-handedly set the release name based on the + build configuration. + */ + case setByTracksLibrary +} + /// Default implementations of common protocol properties public extension CrashLoggingDataProvider { - var releaseName: String { - return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as! String + var releaseName: ReleaseName { + return ReleaseName.setByTracksLibrary } var additionalUserData: [String: Any] {