Skip to content

Commit b42b57f

Browse files
authored
Merge pull request #334 from Countly/logging_unsupported
feat: add detailed logs to removing unsupported data types
2 parents b956455 + 1a7d8fa commit b42b57f

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

sdk/src/androidTest/java/ly/count/android/sdk/UtilsInternalLimitsTests.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.junit.runner.RunWith;
1313
import org.mockito.Mockito;
1414

15-
import static org.mockito.Mockito.mock;
16-
1715
@RunWith(AndroidJUnit4.class)
1816
public class UtilsInternalLimitsTests {
1917

@@ -160,7 +158,7 @@ public void truncateSegmentationKeys_inconsistentKeys() {
160158
*/
161159
@Test(expected = AssertionError.class)
162160
public void truncateSegmentationValues_null() {
163-
UtilsInternalLimits.truncateSegmentationValues(null, 10, "someTag", mock(ModuleLog.class));
161+
UtilsInternalLimits.truncateSegmentationValues(null, 10, "someTag", Mockito.mock(ModuleLog.class));
164162
Assert.assertTrue(true);
165163
}
166164

@@ -170,7 +168,7 @@ public void truncateSegmentationValues_null() {
170168
@Test
171169
public void truncateSegmentationValues_empty() {
172170
Map<String, Object> values = new HashMap<>();
173-
UtilsInternalLimits.truncateSegmentationValues(values, 10, "someTag", mock(ModuleLog.class));
171+
UtilsInternalLimits.truncateSegmentationValues(values, 10, "someTag", Mockito.mock(ModuleLog.class));
174172
Assert.assertTrue(true);
175173
}
176174

@@ -184,7 +182,7 @@ public void truncateSegmentationValues_underLimit() {
184182
values.put("a2", "2");
185183
values.put("a3", "3");
186184
values.put("a4", "4");
187-
UtilsInternalLimits.truncateSegmentationValues(values, 6, "someTag", mock(ModuleLog.class));
185+
UtilsInternalLimits.truncateSegmentationValues(values, 6, "someTag", Mockito.mock(ModuleLog.class));
188186

189187
Assert.assertEquals(4, values.size());
190188
Assert.assertEquals("1", values.get("a1"));
@@ -203,7 +201,7 @@ public void truncateSegmentationValues_aboveLimit() {
203201
values.put("a2", "2");
204202
values.put("a3", "3");
205203
values.put("a4", "4");
206-
UtilsInternalLimits.truncateSegmentationValues(values, 2, "someTag", mock(ModuleLog.class));
204+
UtilsInternalLimits.truncateSegmentationValues(values, 2, "someTag", Mockito.mock(ModuleLog.class));
207205

208206
Assert.assertEquals(2, values.size());
209207
//after inspecting what is returned in the debugger, it should have the values of "a2" and "a4"
@@ -215,36 +213,36 @@ public void truncateSegmentationValues_aboveLimit() {
215213
public void removeReservedKeysFromSegmentation() {
216214
Map<String, Object> values = new HashMap<>();
217215

218-
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] {}, "", mock(ModuleLog.class));
216+
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] {}, "", Mockito.mock(ModuleLog.class));
219217
Assert.assertEquals(0, values.size());
220218

221-
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "", null }, "", mock(ModuleLog.class));
219+
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "", null }, "", Mockito.mock(ModuleLog.class));
222220
Assert.assertEquals(0, values.size());
223221

224222
values.put("b", 1);
225223
Assert.assertEquals(1, values.size());
226-
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "a1", "", null }, "", mock(ModuleLog.class));
224+
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "a1", "", null }, "", Mockito.mock(ModuleLog.class));
227225
Assert.assertEquals(1, values.size());
228226
Assert.assertTrue(values.containsKey("b"));
229227

230228
values.put("a", 2);
231229
Assert.assertEquals(2, values.size());
232-
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "a1", "", null }, "", mock(ModuleLog.class));
230+
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "a1", "", null }, "", Mockito.mock(ModuleLog.class));
233231
Assert.assertEquals(1, values.size());
234232
Assert.assertTrue(values.containsKey("b"));
235233

236234
values.put("a", 2);
237235
values.put("c", 3);
238236
Assert.assertEquals(3, values.size());
239-
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "a1", "", null }, "", mock(ModuleLog.class));
237+
UtilsInternalLimits.removeReservedKeysFromSegmentation(values, new String[] { "a", "a1", "", null }, "", Mockito.mock(ModuleLog.class));
240238
Assert.assertEquals(2, values.size());
241239
Assert.assertTrue(values.containsKey("b"));
242240
Assert.assertTrue(values.containsKey("c"));
243241
}
244242

245243
@Test(expected = AssertionError.class)
246244
public void removeUnsupportedDataTypesNull() {
247-
Assert.assertFalse(UtilsInternalLimits.removeUnsupportedDataTypes(null));
245+
Assert.assertFalse(UtilsInternalLimits.removeUnsupportedDataTypes(null, Mockito.mock(ModuleLog.class)));
248246
}
249247

250248
@Test
@@ -261,7 +259,7 @@ public void removeUnsupportedDataTypes() {
261259
segm.put("41", new Object());
262260
segm.put("42", new int[] { 1, 2 });
263261

264-
Assert.assertTrue(UtilsInternalLimits.removeUnsupportedDataTypes(segm));
262+
Assert.assertTrue(UtilsInternalLimits.removeUnsupportedDataTypes(segm, Mockito.mock(ModuleLog.class)));
265263

266264
Assert.assertTrue(segm.containsKey("aa"));
267265
Assert.assertTrue(segm.containsKey("aa1"));
@@ -284,7 +282,7 @@ public void removeUnsupportedDataTypes2() {
284282

285283
Assert.assertEquals(3, segm.size());
286284

287-
Assert.assertTrue(UtilsInternalLimits.removeUnsupportedDataTypes(segm));
285+
Assert.assertTrue(UtilsInternalLimits.removeUnsupportedDataTypes(segm, Mockito.mock(ModuleLog.class)));
288286

289287
Assert.assertEquals(0, segm.size());
290288

@@ -298,7 +296,7 @@ public void removeUnsupportedDataTypes2() {
298296

299297
Assert.assertEquals(7, segm.size());
300298

301-
Assert.assertTrue(UtilsInternalLimits.removeUnsupportedDataTypes(segm));
299+
Assert.assertTrue(UtilsInternalLimits.removeUnsupportedDataTypes(segm, Mockito.mock(ModuleLog.class)));
302300

303301
Assert.assertEquals(4, segm.size());
304302
Assert.assertTrue(segm.containsKey("1"));

sdk/src/main/java/ly/count/android/sdk/ModuleCrash.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ boolean crashFilterCheck(@NonNull CrashData crashData) {
256256
UtilsInternalLimits.applySdkInternalLimitsToSegmentation(crashData.getCrashSegmentation(), _cly.config_.sdkInternalLimits, L, "[ModuleCrash] sendCrashReportToQueue");
257257
String truncatedStackTrace = UtilsInternalLimits.applyInternalLimitsToStackTraces(crashData.getStackTrace(), _cly.config_.sdkInternalLimits.maxStackTraceLineLength, "[ModuleCrash] sendCrashReportToQueue", L);
258258
crashData.setStackTrace(truncatedStackTrace);
259-
UtilsInternalLimits.removeUnsupportedDataTypes(crashData.getCrashSegmentation());
260-
UtilsInternalLimits.removeUnsupportedDataTypes(crashData.getCrashMetrics());
259+
UtilsInternalLimits.removeUnsupportedDataTypes(crashData.getCrashSegmentation(), L);
260+
UtilsInternalLimits.removeUnsupportedDataTypes(crashData.getCrashMetrics(), L);
261261

262262
return false;
263263
}

sdk/src/main/java/ly/count/android/sdk/ModuleEvents.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void recordEventInternal(@Nullable final String key, @Nullable Map<String
8888
L.d("[ModuleEvents] recordEventInternal, key:[" + key + "] eventIdOverride:[" + eventIdOverride + "] segmentation:[" + segmentation + "] count:[" + count + "] sum:[" + sum + "] dur:[" + dur + "] instant:[" + instant + "]");
8989

9090
if (segmentation != null) {
91-
UtilsInternalLimits.removeUnsupportedDataTypes(segmentation);
91+
UtilsInternalLimits.removeUnsupportedDataTypes(segmentation, L);
9292
}
9393

9494
//record the current event timestamps
@@ -163,7 +163,7 @@ public void recordEventInternal(@Nullable final String key, @Nullable Map<String
163163
case ACTION_EVENT_KEY:
164164
if (consentProvider.getConsent(Countly.CountlyFeatureNames.clicks) || consentProvider.getConsent(Countly.CountlyFeatureNames.scrolls)) {
165165
if (segmentation != null) {
166-
UtilsInternalLimits.removeUnsupportedDataTypes(segmentation);
166+
UtilsInternalLimits.removeUnsupportedDataTypes(segmentation, L);
167167
}
168168
eventQueueProvider.recordEventToEventQueue(key, segmentation, count, sum, dur, timestamp, hour, dow, eventId, pvid, cvid, null);
169169
_cly.moduleRequestQueue.sendEventsIfNeeded(false);

sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ void reportFeedbackWidgetManuallyInternal(@Nullable CountlyFeedbackWidget widget
447447

448448
if (widgetResult != null) {
449449
//removing broken values first
450-
UtilsInternalLimits.removeUnsupportedDataTypes(widgetResult);
450+
UtilsInternalLimits.removeUnsupportedDataTypes(widgetResult, L);
451451

452452
Iterator<Map.Entry<String, Object>> iter = widgetResult.entrySet().iterator();
453453
while (iter.hasNext()) {

sdk/src/main/java/ly/count/android/sdk/UtilsInternalLimits.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ static void removeReservedKeysFromSegmentation(@NonNull Map<String, Object> segm
292292
* @param data
293293
* @return returns true if any entry had been removed
294294
*/
295-
static boolean removeUnsupportedDataTypes(@NonNull Map<String, Object> data) {
295+
static boolean removeUnsupportedDataTypes(@NonNull Map<String, Object> data, @NonNull ModuleLog L) {
296296
assert data != null;
297297

298-
boolean removed = false;
298+
StringBuilder removedKeys = new StringBuilder();
299299

300300
for (Iterator<Map.Entry<String, Object>> it = data.entrySet().iterator(); it.hasNext(); ) {
301301
Map.Entry<String, Object> entry = it.next();
@@ -305,15 +305,16 @@ static boolean removeUnsupportedDataTypes(@NonNull Map<String, Object> data) {
305305
if (key == null || key.isEmpty() || !(isSupportedDataType(value))) {
306306
//found unsupported data type or null key or value, removing
307307
it.remove();
308-
removed = true;
308+
removedKeys.append("key:[").append(key).append("] value:[").append(value).append("] type:[").append(value == null ? "null" : value.getClass().getSimpleName()).append("] ,");
309309
}
310310
}
311+
String removedKeysStr = removedKeys.toString();
311312

312-
if (removed) {
313-
Countly.sharedInstance().L.w("[Utils] Unsupported data types were removed from provided segmentation");
313+
if (!removedKeysStr.isEmpty()) {
314+
L.w("[UtilsInternalLimits] removeUnsupportedDataTypes, removed " + removedKeysStr + " from the provided data map.");
314315
}
315316

316-
return removed;
317+
return !removedKeysStr.isEmpty();
317318
}
318319

319320
/**

0 commit comments

Comments
 (0)