Skip to content

Commit 0caef34

Browse files
authored
Fix to ensure that the installation ID is right set for sending events. (#8578)
1 parent 77dae88 commit 0caef34

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

FirebasePerformance/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Version 8.6.1
2+
* Fix the case where the event were dropped for missing a critical field in the event.
3+
14
# Version 8.6.0
25
* Add Firebase Performance support for Swift Package Manager. (#6528)
36
* Fix a crash due to a race condition. (#8485)

FirebasePerformance/Sources/FPRClient.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,16 @@ - (void)processAndLogEvent:(firebase_perf_v1_PerfMetric)event {
271271
});
272272

273273
// Attempts to dispatch events if successfully retrieve installation ID.
274-
__block firebase_perf_v1_PerfMetric curEvent = event;
275274
[self.installations
276275
installationIDWithCompletion:^(NSString *_Nullable identifier, NSError *_Nullable error) {
277276
if (error) {
278277
FPRLogError(kFPRClientInstanceIDNotAvailable, @"FIRInstallations error: %@",
279278
error.description);
280279
} else {
281280
dispatch_group_async(self.eventsQueueGroup, self.eventsQueue, ^{
282-
curEvent.application_info.app_instance_id = FPREncodeString(identifier);
283-
[self.gdtLogger logEvent:event];
281+
firebase_perf_v1_PerfMetric updatedEvent = event;
282+
updatedEvent.application_info.app_instance_id = FPREncodeString(identifier);
283+
[self.gdtLogger logEvent:updatedEvent];
284284
});
285285
}
286286
}];

FirebasePerformance/Tests/Unit/FPRClientTest.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "FirebasePerformance/Sources/Configurations/FPRConfigurations+Private.h"
1818
#import "FirebasePerformance/Sources/FPRClient+Private.h"
1919
#import "FirebasePerformance/Sources/FPRClient.h"
20+
#import "FirebasePerformance/Sources/FPRNanoPbUtils.h"
2021
#import "FirebasePerformance/Sources/Loggers/FPRGDTLogger.h"
2122
#import "FirebasePerformance/Sources/Loggers/FPRGDTLogger_Private.h"
2223

@@ -29,6 +30,8 @@
2930
#import <OCMock/OCMock.h>
3031
#import "SharedTestUtilities/GDTCORTransportFake.h"
3132

33+
NSString *const kFPRMockInstallationId = @"mockId";
34+
3235
@interface FPRClientTest : FPRTestCase
3336

3437
/** Configuration which can be assigned as a fake object for event dispatch control. */
@@ -47,7 +50,7 @@ - (void)setUp {
4750
// Arrange installations object.
4851
FPRFakeInstallations *installations = [FPRFakeInstallations installations];
4952
self.client = [[FPRClient alloc] init];
50-
installations.identifier = @"mockId";
53+
installations.identifier = kFPRMockInstallationId;
5154
self.client.installations = (FIRInstallations *)installations;
5255

5356
// Arrange remote config object.
@@ -73,6 +76,9 @@ - (void)testLogAndProcessEventsForTrace {
7376
// Act on event logging call.
7477
[self.client processAndLogEvent:perfMetric];
7578

79+
firebase_perf_v1_PerfMetric expectedMetric = perfMetric;
80+
expectedMetric.application_info.app_instance_id = FPREncodeString(kFPRMockInstallationId);
81+
7682
// Wait for async job to execute event logging.
7783
dispatch_group_wait(self.client.eventsQueueGroup, DISPATCH_TIME_FOREVER);
7884

@@ -82,8 +88,10 @@ - (void)testLogAndProcessEventsForTrace {
8288
(GDTCORTransportFake *)self.client.gdtLogger.gdtfllTransport;
8389
XCTAssertEqual(fakeGdtTransport.logEvents.count, 1);
8490
GDTCOREvent *event = fakeGdtTransport.logEvents.firstObject;
91+
XCTAssertNotNil(
92+
FPRDecodeString([(FPRGDTEvent *)event.dataObject metric].application_info.app_instance_id));
8593
XCTAssertEqualObjects([event.dataObject transportBytes],
86-
[[FPRGDTEvent gdtEventForPerfMetric:perfMetric] transportBytes]);
94+
[[FPRGDTEvent gdtEventForPerfMetric:expectedMetric] transportBytes]);
8795
});
8896
}
8997

@@ -96,6 +104,9 @@ - (void)testLogAndProcessEventsForNetworkTrace {
96104
// Act on event logging call.
97105
[self.client processAndLogEvent:perfMetric];
98106

107+
firebase_perf_v1_PerfMetric expectedMetric = perfMetric;
108+
expectedMetric.application_info.app_instance_id = FPREncodeString(kFPRMockInstallationId);
109+
99110
// Wait for async job to execute event logging.
100111
dispatch_group_wait(self.client.eventsQueueGroup, DISPATCH_TIME_FOREVER);
101112

@@ -105,8 +116,10 @@ - (void)testLogAndProcessEventsForNetworkTrace {
105116
(GDTCORTransportFake *)self.client.gdtLogger.gdtfllTransport;
106117
XCTAssertEqual(fakeGdtTransport.logEvents.count, 1);
107118
GDTCOREvent *event = fakeGdtTransport.logEvents.firstObject;
119+
XCTAssertNotNil(
120+
FPRDecodeString([(FPRGDTEvent *)event.dataObject metric].application_info.app_instance_id));
108121
XCTAssertEqualObjects([event.dataObject transportBytes],
109-
[[FPRGDTEvent gdtEventForPerfMetric:perfMetric] transportBytes]);
122+
[[FPRGDTEvent gdtEventForPerfMetric:expectedMetric] transportBytes]);
110123
});
111124
}
112125

@@ -118,6 +131,9 @@ - (void)testLogAndProcessEventsForGauge {
118131
// Act on event logging call.
119132
[self.client processAndLogEvent:perfMetric];
120133

134+
firebase_perf_v1_PerfMetric expectedMetric = perfMetric;
135+
expectedMetric.application_info.app_instance_id = FPREncodeString(kFPRMockInstallationId);
136+
121137
// Wait for async job to execute event logging.
122138
dispatch_group_wait(self.client.eventsQueueGroup, DISPATCH_TIME_FOREVER);
123139

@@ -127,8 +143,10 @@ - (void)testLogAndProcessEventsForGauge {
127143
(GDTCORTransportFake *)self.client.gdtLogger.gdtfllTransport;
128144
XCTAssertEqual(fakeGdtTransport.logEvents.count, 1);
129145
GDTCOREvent *event = fakeGdtTransport.logEvents.firstObject;
146+
XCTAssertNotNil(
147+
FPRDecodeString([(FPRGDTEvent *)event.dataObject metric].application_info.app_instance_id));
130148
XCTAssertEqualObjects([event.dataObject transportBytes],
131-
[[FPRGDTEvent gdtEventForPerfMetric:perfMetric] transportBytes]);
149+
[[FPRGDTEvent gdtEventForPerfMetric:expectedMetric] transportBytes]);
132150
});
133151
}
134152

0 commit comments

Comments
 (0)