Skip to content

Commit fb7325e

Browse files
authored
Add performance monitoring configuration – Off by default (#7831)
2 parents 7bf500c + 02d928c commit fb7325e

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

Experiments/Experiments/DefaultFeatureFlagService.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
5151
return buildConfig == .localDeveloper || buildConfig == .alpha
5252
case .productsOnboarding:
5353
return buildConfig == .localDeveloper || buildConfig == .alpha
54+
case .performanceMonitoring,
55+
.performanceMonitoringCoreData,
56+
.performanceMonitoringFileIO,
57+
.performanceMonitoringNetworking,
58+
.performanceMonitoringViewController,
59+
.performanceMonitoringUserInteraction:
60+
// Disabled by default to avoid costs spikes, unless in internal testing builds.
61+
return buildConfig == .alpha
5462
default:
5563
return true
5664
}

Experiments/Experiments/FeatureFlag.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,39 @@ public enum FeatureFlag: Int {
9898
/// Hides products onboarding development.
9999
///
100100
case productsOnboarding
101+
102+
// MARK: - Performance Monitoring
103+
//
104+
// These flags are not transient. That is, they are not here to help us rollout a feature,
105+
// but to serve a safety switches to granularly turn off performance monitoring if it looks
106+
// like we are consuming too many events.
107+
108+
/// Whether to enable performance monitoring.
109+
///
110+
case performanceMonitoring
111+
112+
/// Whether to enable performance monitoring for Core Data operations.
113+
///
114+
/// - Note: The app will ignore this if `performanceMonitoring` is `false`
115+
case performanceMonitoringCoreData
116+
117+
/// Whether to enable performance monitoring for file IO operations.
118+
///
119+
/// - Note: The app will ignore this if `performanceMonitoring` is `false`
120+
case performanceMonitoringFileIO
121+
122+
/// Whether to enable performance monitoring for networking operations.
123+
///
124+
/// - Note: The app will ignore this if `performanceMonitoring` is `false`
125+
case performanceMonitoringNetworking
126+
127+
/// Whether to enable performance monitoring for user interaction events.
128+
///
129+
/// - Note: The app will ignore this if `performanceMonitoring` is `false`
130+
case performanceMonitoringUserInteraction
131+
132+
/// Whether to enable performance monitoring for `UIViewController` life-cycle events.
133+
///
134+
/// - Note: The app will ignore this if `performanceMonitoring` is `false`.
135+
case performanceMonitoringViewController
101136
}

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
11.0
88
-----
9+
- [internal] Add support for controlling performance monitoring via Sentry. **Off by default**. [https://github.com/woocommerce/woocommerce-ios/pull/7831]
910

1011

1112
10.9

WooCommerce/Classes/ServiceLocator/ServiceLocator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ final class ServiceLocator {
6666

6767
/// Crash Logging Stack
6868
///
69-
private static var _crashLogging: CrashLoggingStack = WooCrashLoggingStack()
69+
private static var _crashLogging: CrashLoggingStack = WooCrashLoggingStack(
70+
featureFlagService: featureFlagService
71+
)
7072

7173
/// Support for external Card Readers
7274
///

WooCommerce/Classes/Tools/Logging/WooCrashLoggingStack.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ struct WooCrashLoggingStack: CrashLoggingStack {
1212
let crashLogging: AutomatticTracks.CrashLogging
1313
let eventLogging: EventLogging
1414

15-
private let crashLoggingDataProvider = WCCrashLoggingDataProvider()
15+
private let crashLoggingDataProvider: WCCrashLoggingDataProvider
1616
private let eventLoggingDataProvider = WCEventLoggingDataSource()
1717
private let eventLoggingDelegate = WCEventLoggingDelegate()
1818

19-
init() {
19+
init(featureFlagService: FeatureFlagService) {
2020
let eventLogging = EventLogging(dataSource: eventLoggingDataProvider, delegate: eventLoggingDelegate)
2121

2222
self.eventLogging = eventLogging
23+
self.crashLoggingDataProvider = WCCrashLoggingDataProvider(featureFlagService: featureFlagService)
2324
self.crashLogging = AutomatticTracks.CrashLogging(dataProvider: crashLoggingDataProvider, eventLogging: eventLogging)
2425

2526
/// Upload any remaining files any time the app becomes active
@@ -87,7 +88,11 @@ class WCCrashLoggingDataProvider: CrashLoggingDataProvider {
8788
/// Indicates that app is in an inconsistent state and we don't want to start asking it for metadata
8889
fileprivate var appIsCrashing = false
8990

90-
init() {
91+
let featureFlagService: FeatureFlagService
92+
93+
init(featureFlagService: FeatureFlagService) {
94+
self.featureFlagService = featureFlagService
95+
9196
NotificationCenter.default.addObserver(self, selector: #selector(updateCrashLoggingSystem(_:)), name: .defaultAccountWasUpdated, object: nil)
9297
NotificationCenter.default.addObserver(self, selector: #selector(updateCrashLoggingSystem(_:)), name: .logOutEventReceived, object: nil)
9398
NotificationCenter.default.addObserver(self, selector: #selector(updateCrashLoggingSystem(_:)), name: .StoresManagerDidUpdateDefaultSite, object: nil)
@@ -129,6 +134,26 @@ class WCCrashLoggingDataProvider: CrashLoggingDataProvider {
129134
ServiceLocator.crashLogging.setNeedsDataRefresh()
130135
}
131136
}
137+
138+
// MARK: – Performance Monitoring
139+
140+
var performanceTracking: PerformanceTracking {
141+
guard featureFlagService.isFeatureFlagEnabled(.performanceMonitoring) else {
142+
return .disabled
143+
}
144+
145+
return .enabled(
146+
.init(
147+
// FIXME: Is there a way to control this via feature flags?
148+
sampler: { 0.1 },
149+
trackCoreData: featureFlagService.isFeatureFlagEnabled(.performanceMonitoringCoreData),
150+
trackFileIO: featureFlagService.isFeatureFlagEnabled(.performanceMonitoringFileIO),
151+
trackNetwork: featureFlagService.isFeatureFlagEnabled(.performanceMonitoringNetworking),
152+
trackUserInteraction: featureFlagService.isFeatureFlagEnabled(.performanceMonitoringUserInteraction),
153+
trackViewControllers: featureFlagService.isFeatureFlagEnabled(.performanceMonitoringViewController)
154+
)
155+
)
156+
}
132157
}
133158

134159
struct CrashLoggingSettings {

0 commit comments

Comments
 (0)