From 48bf6a2963ad82b65057d936cc8ddb9b3dd2aa37 Mon Sep 17 00:00:00 2001 From: Desu Sai Venkat Date: Wed, 27 Mar 2024 17:28:04 +0530 Subject: [PATCH] fix: initializing MetricsReporter and CrashReporter only if it's enabled for a customer --- Sources/Classes/RSMetricsReporter.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/Classes/RSMetricsReporter.m b/Sources/Classes/RSMetricsReporter.m index 045e76f3..ccf3778e 100644 --- a/Sources/Classes/RSMetricsReporter.m +++ b/Sources/Classes/RSMetricsReporter.m @@ -30,11 +30,15 @@ + (instancetype)initiateWithWriteKey:(NSString *)writeKey preferenceManager:(RSP - (instancetype)initWithWriteKey:(NSString *)writeKey preferenceManager:(RSPreferenceManager *)preferenceManager andConfig:(RSConfig *)config { self = [super init]; if (self) { - RSMetricConfiguration *configuration = [[RSMetricConfiguration alloc] initWithLogLevel:config.logLevel writeKey:writeKey sdkVersion:RS_VERSION]; - [configuration dbCountThreshold:config.dbCountThreshold]; - _metricsClient = [[RSMetricsClient alloc] initWithConfiguration:configuration]; - _metricsClient.isMetricsCollectionEnabled = preferenceManager.isMetricsCollectionEnabled; - _metricsClient.isErrorsCollectionEnabled = preferenceManager.isErrorsCollectionEnabled; + if (preferenceManager.isMetricsCollectionEnabled || preferenceManager.isErrorsCollectionEnabled) { + RSMetricConfiguration *configuration = [[RSMetricConfiguration alloc] initWithLogLevel:config.logLevel writeKey:writeKey sdkVersion:RS_VERSION]; + [configuration dbCountThreshold:config.dbCountThreshold]; + _metricsClient = [[RSMetricsClient alloc] initWithConfiguration:configuration]; + _metricsClient.isMetricsCollectionEnabled = preferenceManager.isMetricsCollectionEnabled; + _metricsClient.isErrorsCollectionEnabled = preferenceManager.isErrorsCollectionEnabled; + } else { + [RSLogger logWarn:@"RSMetricsReporter: Metrics and Errors collection is disabled."]; + } } return self; }