15
15
16
16
@implementation NRMASupportMetricHelper
17
17
18
+ static NSMutableArray <NRMAMetric *> *deferredMetrics;
19
+
20
+ + (void ) initialize {
21
+ deferredMetrics = [NSMutableArray array ];
22
+ }
23
+
18
24
// The value _additionalValue being non-nil means that this is a Data Usage Supportability Metric.
19
25
+ (void ) enqueueDataUseMetric : (NSString *)subDestination size : (long )size received : (long )received {
20
26
NSString * nativePlatform = [NewRelicInternalUtils osName ];
@@ -31,24 +37,22 @@ + (void) enqueueFeatureFlagMetric:(BOOL)enabled features:(NRMAFeatureFlags)featu
31
37
for (NSString *name in [NRMAFlags namesForFlags: features]) {
32
38
NSString * featureFlagString = [NSString stringWithFormat: @" Supportability/Mobile/%@ /%@ /API/%@ /%@ " ,
33
39
nativePlatform, kPlatformPlaceholder , enabled ? @" enableFeature" : @" disableFeature" , name];
34
- if (deferredMetrics == nil ) {
35
- deferredMetrics = [NSMutableArray array ];
40
+ @synchronized (deferredMetrics) {
41
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: featureFlagString
42
+ value: [NSNumber numberWithLongLong: 1 ]
43
+ scope: @" "
44
+ produceUnscoped: YES
45
+ additionalValue: nil ]];
36
46
}
37
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: featureFlagString
38
- value: [NSNumber numberWithLongLong: 1 ]
39
- scope: @" "
40
- produceUnscoped: YES
41
- additionalValue: nil ]];
42
47
}
43
48
}
44
49
45
50
+ (void ) enqueueInstallMetric {
46
- if (deferredMetrics == nil ) {
47
- deferredMetrics = [NSMutableArray array ];
51
+ @synchronized (deferredMetrics) {
52
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppInstallMetric
53
+ value: @1
54
+ scope: nil ]];
48
55
}
49
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppInstallMetric
50
- value: @1
51
- scope: nil ]];
52
56
}
53
57
54
58
+ (void ) enqueueMaxPayloadSizeLimitMetric : (NSString *)endpoint {
@@ -68,32 +72,29 @@ + (void) enqueueOfflinePayloadMetric:(long)size {
68
72
}
69
73
70
74
+ (void ) enqueueUpgradeMetric {
71
- if (deferredMetrics == nil ) {
72
- deferredMetrics = [NSMutableArray array ];
75
+ @synchronized (deferredMetrics) {
76
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppUpgradeMetric
77
+ value: @1
78
+ scope: nil ]];
73
79
}
74
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppUpgradeMetric
75
- value: @1
76
- scope: nil ]];
77
80
}
78
81
79
82
+ (void ) enqueueStopAgentMetric {
80
- if (deferredMetrics == nil ) {
81
- deferredMetrics = [NSMutableArray array ];
83
+ @synchronized (deferredMetrics) {
84
+ NSString * metricString = [NSString stringWithFormat: kNRMAStopAgentMetricFormatString , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
85
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
86
+ value: @1
87
+ scope: nil ]];
82
88
}
83
- NSString * metricString = [NSString stringWithFormat: kNRMAStopAgentMetricFormatString , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
84
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
85
- value: @1
86
- scope: nil ]];
87
89
}
88
90
89
91
+ (void ) enqueueConfigurationUpdateMetric {
90
- if (deferredMetrics == nil ) {
91
- deferredMetrics = [NSMutableArray array ];
92
+ @synchronized (deferredMetrics) {
93
+ NSString * metricString = [NSString stringWithFormat: kNRMAConfigurationUpdated , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
94
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
95
+ value: @1
96
+ scope: nil ]];
92
97
}
93
- NSString * metricString = [NSString stringWithFormat: kNRMAConfigurationUpdated , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
94
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
95
- value: @1
96
- scope: nil ]];
97
98
}
98
99
99
100
// Logging
@@ -140,26 +141,24 @@ + (void) processDeferredMetrics {
140
141
}
141
142
142
143
// Handle any deferred supportability metrics.
143
- if (deferredMetrics == nil ) { return ; }
144
-
145
- for (NRMAMetric *metric in deferredMetrics) {
146
-
147
- NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
148
- NSString *deferredMetricName = metric.name ;
149
-
150
- if ([metric.name containsString: kPlatformPlaceholder ]) {
151
- deferredMetricName = [metric.name stringByReplacingOccurrencesOfString: kPlatformPlaceholder withString: platform];
144
+ @synchronized (deferredMetrics) {
145
+ for (NRMAMetric *metric in deferredMetrics) {
146
+ NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
147
+ NSString *deferredMetricName = metric.name ;
148
+
149
+ if ([metric.name containsString: kPlatformPlaceholder ]) {
150
+ deferredMetricName = [metric.name stringByReplacingOccurrencesOfString: kPlatformPlaceholder withString: platform];
151
+ }
152
+
153
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: deferredMetricName
154
+ value: [NSNumber numberWithLongLong: 1 ]
155
+ scope: @" "
156
+ produceUnscoped: YES
157
+ additionalValue: nil ]];
152
158
}
153
159
154
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: deferredMetricName
155
- value: [NSNumber numberWithLongLong: 1 ]
156
- scope: @" "
157
- produceUnscoped: YES
158
- additionalValue: nil ]];
160
+ [deferredMetrics removeAllObjects ];
159
161
}
160
-
161
- [deferredMetrics removeAllObjects ];
162
- deferredMetrics = nil ;
163
162
}
164
163
165
164
@end
0 commit comments