Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions FirebasePerformance/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Unreleased
- [fixed] Fixed a race condition crash in `FPRConfigurations` by making
`remoteConfigFlags` atomic and explicitly nullable. (#16144)
- [added] Added a `networkInstrumentationEnabled` opt-out for URLSession and
URLConnection swizzling. Settable via `Info.plist` key
`firebase_performance_network_instrumentation_enabled` or at runtime via
`Performance.sharedInstance().isNetworkInstrumentationEnabled`. Defaults to
true. (#8277)

# 12.13.0
- [fixed] Fixed NSURLSession delegate instrumentation for NSProxy delegates. (#14478)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ FOUNDATION_EXTERN FPRConfigName kFPRConfigDataCollectionEnabled;
/** The config KVC name string for the instrumentationEnabled property. */
FOUNDATION_EXTERN FPRConfigName kFPRConfigInstrumentationEnabled;

/** Enables or disables the URLSession/URLConnection network instrumentation only. Other
* instrumentation (app start, screen rendering, custom traces) is unaffected. Default is YES. */
@property(nonatomic, getter=isNetworkInstrumentationEnabled) BOOL networkInstrumentationEnabled;

/** The config KVC name string for the networkInstrumentationEnabled property. */
FOUNDATION_EXTERN FPRConfigName kFPRConfigNetworkInstrumentationEnabled;

/** Log source against which the Fireperf events are recorded. */
@property(nonatomic, readonly) int logSource;

Expand Down
34 changes: 34 additions & 0 deletions FirebasePerformance/Sources/Configurations/FPRConfigurations.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@

FPRConfigName kFPRConfigInstrumentationEnabled = @"instrumentationEnabled";

FPRConfigName kFPRConfigNetworkInstrumentationEnabled = @"networkInstrumentationEnabled";

NSString *const kFPRConfigInstrumentationUserPreference =
@"com.firebase.performanceInsrumentationEnabled";
NSString *const kFPRConfigInstrumentationPlistKey = @"firebase_performance_instrumentation_enabled";

NSString *const kFPRConfigNetworkInstrumentationUserPreference =
@"com.firebase.performanceNetworkInstrumentationEnabled";
NSString *const kFPRConfigNetworkInstrumentationPlistKey =
@"firebase_performance_network_instrumentation_enabled";

NSString *const kFPRConfigCollectionUserPreference = @"com.firebase.performanceCollectionEnabled";
NSString *const kFPRConfigCollectionPlistKey = @"firebase_performance_collection_enabled";

Expand Down Expand Up @@ -62,6 +69,8 @@ + (void)reset {
gSharedInstanceToken = 0;
[[GULUserDefaults standardUserDefaults]
removeObjectForKey:kFPRConfigInstrumentationUserPreference];
[[GULUserDefaults standardUserDefaults]
removeObjectForKey:kFPRConfigNetworkInstrumentationUserPreference];
[[GULUserDefaults standardUserDefaults] removeObjectForKey:kFPRConfigCollectionUserPreference];
}

Expand Down Expand Up @@ -217,6 +226,31 @@ - (BOOL)isInstrumentationEnabled {
return instrumentationPreference;
}

- (void)setNetworkInstrumentationEnabled:(BOOL)networkInstrumentationEnabled {
[self.userDefaults setBool:networkInstrumentationEnabled
forKey:kFPRConfigNetworkInstrumentationUserPreference];
}

- (BOOL)isNetworkInstrumentationEnabled {
// Resolves in order: GULUserDefaults, Info.plist, defaults to YES.
Comment thread
JesusRojass marked this conversation as resolved.
Outdated
BOOL networkInstrumentationPreference = YES;

id networkInstrumentationPreferenceObject =
[self.userDefaults objectForKey:kFPRConfigNetworkInstrumentationUserPreference];

if (networkInstrumentationPreferenceObject) {
networkInstrumentationPreference = [networkInstrumentationPreferenceObject boolValue];
} else {
networkInstrumentationPreferenceObject =
[self objectForInfoDictionaryKey:kFPRConfigNetworkInstrumentationPlistKey];
if (networkInstrumentationPreferenceObject) {
networkInstrumentationPreference = [networkInstrumentationPreferenceObject boolValue];
}
}

return networkInstrumentationPreference;
}

#pragma mark - Fireperf SDK configurations.

- (BOOL)sdkEnabled {
Expand Down
14 changes: 14 additions & 0 deletions FirebasePerformance/Sources/FIRPerformance.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ - (void)setInstrumentationEnabled:(BOOL)instrumentationEnabled {
}
}

- (BOOL)isNetworkInstrumentationEnabled {
return [FPRConfigurations sharedInstance].isNetworkInstrumentationEnabled;
}
Comment thread
JesusRojass marked this conversation as resolved.
Outdated

- (void)setNetworkInstrumentationEnabled:(BOOL)networkInstrumentationEnabled {
[[FPRConfigurations sharedInstance]
setNetworkInstrumentationEnabled:networkInstrumentationEnabled];
if (self.fprClient.isSwizzled) {
FPRLogError(kFPRInstrumentationDisabledAfterConfigure,
@"Network instrumentation preference will only take effect on next app start "
@"because Firebase Performance has already been configured.");
Comment thread
JesusRojass marked this conversation as resolved.
Outdated
}
}

#pragma mark - Custom attributes related methods

- (NSDictionary<NSString *, NSString *> *)attributes {
Expand Down
4 changes: 3 additions & 1 deletion FirebasePerformance/Sources/FPRClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ - (BOOL)startWithConfiguration:(FPRConfiguration *)config error:(NSError *__auto
- (void)checkAndStartInstrumentation {
BOOL instrumentationEnabled = self.configuration.isInstrumentationEnabled;
if (instrumentationEnabled && !self.isSwizzled) {
[self.instrumentation registerInstrumentGroup:kFPRInstrumentationGroupNetworkKey];
if (self.configuration.isNetworkInstrumentationEnabled) {
[self.instrumentation registerInstrumentGroup:kFPRInstrumentationGroupNetworkKey];
}
[self.instrumentation registerInstrumentGroup:kFPRInstrumentationGroupUIKitKey];
self.swizzled = YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ NS_SWIFT_NAME(Performance)
*/
@property(nonatomic, assign, getter=isInstrumentationEnabled) BOOL instrumentationEnabled;

/**
* Controls only the automatic URLSession/URLConnection network instrumentation. Other
* instrumentation (app start, screen rendering, custom traces) is unaffected. Setting this value
* to false has immediate effect only if done before calling FirebaseApp.configure(). Otherwise it
* takes effect on the next app start. Default is true.
*
* This setting is persisted, and is applied on future invocations of your application. Once
* explicitly set, it overrides any settings in your `Info.plist`.
*/
@property(nonatomic, assign, getter=isNetworkInstrumentationEnabled)
BOOL networkInstrumentationEnabled;

/** @return The shared instance. */
+ (nonnull instancetype)sharedInstance NS_SWIFT_NAME(sharedInstance());

Expand Down
Loading