Skip to content

Commit 15f59af

Browse files
authored
Include internal keys even if no custom keys were set. (#3261)
This will fix the issue with Unity metadata being excluded in some cases.
1 parent 589de6a commit 15f59af

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinatorTest.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public void testNonFatalEvent_addsNoKeysToEventWhenNoneAvailable() {
267267
}
268268

269269
@Test
270-
public void testFatalEvent_addsSortedKeysToEvent() {
270+
public void testFatalEvent_addsSortedCustomKeysToEvent() {
271271
final long timestamp = System.currentTimeMillis();
272272

273273
mockEventInteractions();
@@ -292,12 +292,47 @@ public void testFatalEvent_addsSortedKeysToEvent() {
292292
ImmutableList.from(customAttribute1, customAttribute2);
293293

294294
when(reportMetadata.getCustomKeys()).thenReturn(attributes);
295-
when(reportMetadata.getInternalKeys()).thenReturn(attributes);
296295

297296
reportingCoordinator.onBeginSession(sessionId, timestamp);
298297
reportingCoordinator.persistFatalEvent(mockException, mockThread, sessionId, timestamp);
299298

300299
verify(mockEventAppBuilder).setCustomAttributes(expectedCustomAttributes);
300+
verify(mockEventAppBuilder).build();
301+
verify(mockEventBuilder).setApp(mockEventApp);
302+
verify(mockEventBuilder).build();
303+
verify(logFileManager, never()).clearLog();
304+
}
305+
306+
@Test
307+
public void testFatalEvent_addsSortedInternalKeysToEvent() {
308+
final long timestamp = System.currentTimeMillis();
309+
310+
mockEventInteractions();
311+
312+
final String sessionId = "testSessionId";
313+
314+
final String testKey1 = "testKey1";
315+
final String testValue1 = "testValue1";
316+
final String testKey2 = "testKey2";
317+
final String testValue2 = "testValue2";
318+
319+
final Map<String, String> attributes = new HashMap<>();
320+
attributes.put(testKey1, testValue1);
321+
attributes.put(testKey2, testValue2);
322+
323+
final CustomAttribute customAttribute1 =
324+
CustomAttribute.builder().setKey(testKey1).setValue(testValue1).build();
325+
final CustomAttribute customAttribute2 =
326+
CustomAttribute.builder().setKey(testKey2).setValue(testValue2).build();
327+
328+
final ImmutableList<CustomAttribute> expectedCustomAttributes =
329+
ImmutableList.from(customAttribute1, customAttribute2);
330+
331+
when(reportMetadata.getInternalKeys()).thenReturn(attributes);
332+
333+
reportingCoordinator.onBeginSession(sessionId, timestamp);
334+
reportingCoordinator.persistFatalEvent(mockException, mockThread, sessionId, timestamp);
335+
301336
verify(mockEventAppBuilder).setInternalKeys(expectedCustomAttributes);
302337
verify(mockEventAppBuilder).build();
303338
verify(mockEventBuilder).setApp(mockEventApp);

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private CrashlyticsReport.Session.Event addLogsAndCustomKeysToEvent(
241241
final List<CustomAttribute> sortedInternalKeys =
242242
getSortedCustomAttributes(reportMetadata.getInternalKeys());
243243

244-
if (!sortedCustomAttributes.isEmpty()) {
244+
if (!sortedCustomAttributes.isEmpty() || !sortedInternalKeys.isEmpty()) {
245245
eventBuilder.setApp(
246246
capturedEvent.getApp().toBuilder()
247247
.setCustomAttributes(ImmutableList.from(sortedCustomAttributes))

0 commit comments

Comments
 (0)