Skip to content

Commit cbd0224

Browse files
NR-357941-in-progress: Sync NRMASupportMetricHelper
1 parent 87338c4 commit cbd0224

File tree

1 file changed

+120
-94
lines changed

1 file changed

+120
-94
lines changed

Agent/Measurements/NRMASupportMetricHelper.m

Lines changed: 120 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -17,149 +17,175 @@ @implementation NRMASupportMetricHelper
1717

1818
// The value _additionalValue being non-nil means that this is a Data Usage Supportability Metric.
1919
+ (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+
}
2729
}
2830

2931
+ (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]];
3645
}
37-
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:featureFlagString
38-
value:[NSNumber numberWithLongLong:1]
39-
scope:@""
40-
produceUnscoped:YES
41-
additionalValue:nil]];
4246
}
4347
}
4448

4549
+ (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]];
4857
}
49-
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppInstallMetric
50-
value:@1
51-
scope:nil]];
5258
}
5359

5460
+ (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+
}
6068
}
6169

6270
+ (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+
}
6878
}
6979

7080
+ (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]];
7388
}
74-
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:kNRMAAppUpgradeMetric
75-
value:@1
76-
scope:nil]];
7789
}
7890

7991
+ (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]];
82100
}
83-
NSString* metricString = [NSString stringWithFormat:kNRMAStopAgentMetricFormatString, [NewRelicInternalUtils osName], kPlatformPlaceholder];
84-
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:metricString
85-
value:@1
86-
scope:nil]];
87101
}
88102

89103
+ (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+
92115
}
93-
NSString* metricString = [NSString stringWithFormat:kNRMAConfigurationUpdated, [NewRelicInternalUtils osName], kPlatformPlaceholder];
94-
[deferredMetrics addObject:[[NRMAMetric alloc] initWithName:metricString
95-
value:@1
96-
scope:nil]];
97116
}
98117

99118
// Logging
100119

101120
+ (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+
}
109130
}
110131

111132
+ (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+
}
117140

118141
}
119142

120143
// End Logging
121144

122145
+ (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+
}
132157

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+
}
141166

142-
// Handle any deferred supportability metrics.
143-
if (deferredMetrics == nil) { return; }
167+
// Handle any deferred supportability metrics.
168+
if (deferredMetrics == nil) { return; }
144169

145-
for (NRMAMetric *metric in deferredMetrics) {
170+
for (NRMAMetric *metric in deferredMetrics) {
146171

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+
}
149178

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]];
152184
}
153185

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;
159188
}
160-
161-
[deferredMetrics removeAllObjects];
162-
deferredMetrics = nil;
163189
}
164190

165191
@end

0 commit comments

Comments
 (0)