@@ -17,149 +17,175 @@ @implementation NRMASupportMetricHelper
17
17
18
18
// The value _additionalValue being non-nil means that this is a Data Usage Supportability Metric.
19
19
+ (void ) enqueueDataUseMetric : (NSString *)subDestination size : (long )size received : (long )received {
20
- NSString * nativePlatform = [NewRelicInternalUtils osName ];
21
- NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
22
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMABytesOutSupportabilityFormatString , nativePlatform, platform, kNRMACollectorDest , subDestination]
23
- value: [NSNumber numberWithLongLong: size]
24
- scope: @" "
25
- produceUnscoped: YES
26
- additionalValue: [NSNumber numberWithLongLong: received]]];
20
+ @synchronized (self) {
21
+ NSString * nativePlatform = [NewRelicInternalUtils osName ];
22
+ NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
23
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMABytesOutSupportabilityFormatString , nativePlatform, platform, kNRMACollectorDest , subDestination]
24
+ value: [NSNumber numberWithLongLong: size]
25
+ scope: @" "
26
+ produceUnscoped: YES
27
+ additionalValue: [NSNumber numberWithLongLong: received]]];
28
+ }
27
29
}
28
30
29
31
+ (void ) enqueueFeatureFlagMetric : (BOOL )enabled features : (NRMAFeatureFlags)features {
30
- NSString * nativePlatform = [NewRelicInternalUtils osName ];
31
- for (NSString *name in [NRMAFlags namesForFlags: features]) {
32
- NSString * featureFlagString = [NSString stringWithFormat: @" Supportability/Mobile/%@ /%@ /API/%@ /%@ " ,
33
- nativePlatform, kPlatformPlaceholder , enabled ? @" enableFeature" : @" disableFeature" , name];
34
- if (deferredMetrics == nil ) {
35
- deferredMetrics = [NSMutableArray array ];
32
+ @synchronized (self) {
33
+ NSString * nativePlatform = [NewRelicInternalUtils osName ];
34
+ for (NSString *name in [NRMAFlags namesForFlags: features]) {
35
+ NSString * featureFlagString = [NSString stringWithFormat: @" Supportability/Mobile/%@ /%@ /API/%@ /%@ " ,
36
+ nativePlatform, kPlatformPlaceholder , enabled ? @" enableFeature" : @" disableFeature" , name];
37
+ if (deferredMetrics == nil ) {
38
+ deferredMetrics = [NSMutableArray array ];
39
+ }
40
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: featureFlagString
41
+ value: [NSNumber numberWithLongLong: 1 ]
42
+ scope: @" "
43
+ produceUnscoped: YES
44
+ additionalValue: nil ]];
36
45
}
37
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: featureFlagString
38
- value: [NSNumber numberWithLongLong: 1 ]
39
- scope: @" "
40
- produceUnscoped: YES
41
- additionalValue: nil ]];
42
46
}
43
47
}
44
48
45
49
+ (void ) enqueueInstallMetric {
46
- if (deferredMetrics == nil ) {
47
- deferredMetrics = [NSMutableArray array ];
50
+ @synchronized (self) {
51
+ if (deferredMetrics == nil ) {
52
+ deferredMetrics = [NSMutableArray array ];
53
+ }
54
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppInstallMetric
55
+ value: @1
56
+ scope: nil ]];
48
57
}
49
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppInstallMetric
50
- value: @1
51
- scope: nil ]];
52
58
}
53
59
54
60
+ (void ) enqueueMaxPayloadSizeLimitMetric : (NSString *)endpoint {
55
- NSString * nativePlatform = [NewRelicInternalUtils osName ];
56
- NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
57
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMAMaxPayloadSizeLimitSupportabilityFormatString , nativePlatform, platform, kNRMACollectorDest , endpoint]
58
- value: @1
59
- scope: nil ]];
61
+ @synchronized (self) {
62
+ NSString * nativePlatform = [NewRelicInternalUtils osName ];
63
+ NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
64
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMAMaxPayloadSizeLimitSupportabilityFormatString , nativePlatform, platform, kNRMACollectorDest , endpoint]
65
+ value: @1
66
+ scope: nil ]];
67
+ }
60
68
}
61
69
62
70
+ (void ) enqueueOfflinePayloadMetric : (long )size {
63
- NSString * nativePlatform = [NewRelicInternalUtils osName ];
64
- NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
65
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMAOfflineSupportabilityFormatString , nativePlatform, platform, kNRMACollectorDest ]
66
- value: [NSNumber numberWithLongLong: size]
67
- scope: nil ]];
71
+ @synchronized (self) {
72
+ NSString * nativePlatform = [NewRelicInternalUtils osName ];
73
+ NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
74
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMAOfflineSupportabilityFormatString , nativePlatform, platform, kNRMACollectorDest ]
75
+ value: [NSNumber numberWithLongLong: size]
76
+ scope: nil ]];
77
+ }
68
78
}
69
79
70
80
+ (void ) enqueueUpgradeMetric {
71
- if (deferredMetrics == nil ) {
72
- deferredMetrics = [NSMutableArray array ];
81
+ @synchronized (self) {
82
+ if (deferredMetrics == nil ) {
83
+ deferredMetrics = [NSMutableArray array ];
84
+ }
85
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppUpgradeMetric
86
+ value: @1
87
+ scope: nil ]];
73
88
}
74
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: kNRMAAppUpgradeMetric
75
- value: @1
76
- scope: nil ]];
77
89
}
78
90
79
91
+ (void ) enqueueStopAgentMetric {
80
- if (deferredMetrics == nil ) {
81
- deferredMetrics = [NSMutableArray array ];
92
+ @synchronized (self) {
93
+ if (deferredMetrics == nil ) {
94
+ deferredMetrics = [NSMutableArray array ];
95
+ }
96
+ NSString * metricString = [NSString stringWithFormat: kNRMAStopAgentMetricFormatString , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
97
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
98
+ value: @1
99
+ scope: nil ]];
82
100
}
83
- NSString * metricString = [NSString stringWithFormat: kNRMAStopAgentMetricFormatString , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
84
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
85
- value: @1
86
- scope: nil ]];
87
101
}
88
102
89
103
+ (void ) enqueueConfigurationUpdateMetric {
90
- if (deferredMetrics == nil ) {
91
- deferredMetrics = [NSMutableArray array ];
104
+
105
+ @synchronized (self) {
106
+
107
+ if (deferredMetrics == nil ) {
108
+ deferredMetrics = [NSMutableArray array ];
109
+ }
110
+ NSString * metricString = [NSString stringWithFormat: kNRMAConfigurationUpdated , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
111
+ [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
112
+ value: @1
113
+ scope: nil ]];
114
+
92
115
}
93
- NSString * metricString = [NSString stringWithFormat: kNRMAConfigurationUpdated , [NewRelicInternalUtils osName ], kPlatformPlaceholder ];
94
- [deferredMetrics addObject: [[NRMAMetric alloc ] initWithName: metricString
95
- value: @1
96
- scope: nil ]];
97
116
}
98
117
99
118
// Logging
100
119
101
120
+ (void ) enqueueLogSuccessMetric : (long )size {
102
- NSString * nativePlatform = [NewRelicInternalUtils osName ];
103
- NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
104
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMALoggingMetricSuccessfulSize , nativePlatform, platform]
105
- value: [NSNumber numberWithLongLong: size]
106
- scope: @" "
107
- produceUnscoped: YES
108
- additionalValue: nil ]];
121
+ @synchronized (self) {
122
+ NSString * nativePlatform = [NewRelicInternalUtils osName ];
123
+ NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
124
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMALoggingMetricSuccessfulSize , nativePlatform, platform]
125
+ value: [NSNumber numberWithLongLong: size]
126
+ scope: @" "
127
+ produceUnscoped: YES
128
+ additionalValue: nil ]];
129
+ }
109
130
}
110
131
111
132
+ (void ) enqueueLogFailedMetric {
112
- NSString * nativePlatform = [NewRelicInternalUtils osName ];
113
- NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
114
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMALoggingMetricFailedUpload , nativePlatform, platform]
115
- value: @1
116
- scope: nil ]];
133
+ @synchronized (self) {
134
+ NSString * nativePlatform = [NewRelicInternalUtils osName ];
135
+ NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
136
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: [NSString stringWithFormat: kNRMALoggingMetricFailedUpload , nativePlatform, platform]
137
+ value: @1
138
+ scope: nil ]];
139
+ }
117
140
118
141
}
119
142
120
143
// End Logging
121
144
122
145
+ (void ) processDeferredMetrics {
123
- // Handle any deferred app start metrics
124
- if ([[NRMAStartTimer sharedInstance ] appLaunchDuration ] != 0 ) {
125
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: NRMA_METRIC_APP_LAUNCH_COLD
126
- value: [NSNumber numberWithDouble: [[NRMAStartTimer sharedInstance ] appLaunchDuration ]]
127
- scope: @" "
128
- produceUnscoped: YES
129
- additionalValue: nil ]];
130
- [NRMAStartTimer sharedInstance ].appLaunchDuration = 0 ;
131
- }
146
+ @synchronized (self) {
147
+
148
+ // Handle any deferred app start metrics
149
+ if ([[NRMAStartTimer sharedInstance ] appLaunchDuration ] != 0 ) {
150
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: NRMA_METRIC_APP_LAUNCH_COLD
151
+ value: [NSNumber numberWithDouble: [[NRMAStartTimer sharedInstance ] appLaunchDuration ]]
152
+ scope: @" "
153
+ produceUnscoped: YES
154
+ additionalValue: nil ]];
155
+ [NRMAStartTimer sharedInstance ].appLaunchDuration = 0 ;
156
+ }
132
157
133
- if ([[NRMAStartTimer sharedInstance ] appResumeDuration ] != 0 ) {
134
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: NRMA_METRIC_APP_LAUNCH_RESUME
135
- value: [NSNumber numberWithDouble: [[NRMAStartTimer sharedInstance ] appResumeDuration ]]
136
- scope: @" "
137
- produceUnscoped: YES
138
- additionalValue: nil ]];
139
- [NRMAStartTimer sharedInstance ].appResumeDuration = 0 ;
140
- }
158
+ if ([[NRMAStartTimer sharedInstance ] appResumeDuration ] != 0 ) {
159
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: NRMA_METRIC_APP_LAUNCH_RESUME
160
+ value: [NSNumber numberWithDouble: [[NRMAStartTimer sharedInstance ] appResumeDuration ]]
161
+ scope: @" "
162
+ produceUnscoped: YES
163
+ additionalValue: nil ]];
164
+ [NRMAStartTimer sharedInstance ].appResumeDuration = 0 ;
165
+ }
141
166
142
- // Handle any deferred supportability metrics.
143
- if (deferredMetrics == nil ) { return ; }
167
+ // Handle any deferred supportability metrics.
168
+ if (deferredMetrics == nil ) { return ; }
144
169
145
- for (NRMAMetric *metric in deferredMetrics) {
170
+ for (NRMAMetric *metric in deferredMetrics) {
146
171
147
- NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
148
- NSString *deferredMetricName = metric.name ;
172
+ NSString * platform = [NewRelicInternalUtils stringFromNRMAApplicationPlatform: [NRMAAgentConfiguration connectionInformation ].deviceInformation.platform];
173
+ NSString *deferredMetricName = metric.name ;
174
+
175
+ if ([metric.name containsString: kPlatformPlaceholder ]) {
176
+ deferredMetricName = [metric.name stringByReplacingOccurrencesOfString: kPlatformPlaceholder withString: platform];
177
+ }
149
178
150
- if ([metric.name containsString: kPlatformPlaceholder ]) {
151
- deferredMetricName = [metric.name stringByReplacingOccurrencesOfString: kPlatformPlaceholder withString: platform];
179
+ [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: deferredMetricName
180
+ value: [NSNumber numberWithLongLong: 1 ]
181
+ scope: @" "
182
+ produceUnscoped: YES
183
+ additionalValue: nil ]];
152
184
}
153
185
154
- [NRMATaskQueue queue: [[NRMAMetric alloc ] initWithName: deferredMetricName
155
- value: [NSNumber numberWithLongLong: 1 ]
156
- scope: @" "
157
- produceUnscoped: YES
158
- additionalValue: nil ]];
186
+ [deferredMetrics removeAllObjects ];
187
+ deferredMetrics = nil ;
159
188
}
160
-
161
- [deferredMetrics removeAllObjects ];
162
- deferredMetrics = nil ;
163
189
}
164
190
165
191
@end
0 commit comments