Skip to content

Commit 4a92245

Browse files
committed
Add IDs to errors and long tasks
1 parent 7606b1a commit 4a92245

File tree

7 files changed

+60
-4
lines changed

7 files changed

+60
-4
lines changed

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/DatadogLateCrashReporter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.datadog.android.rum.internal.utils.buildDDTagsString
2929
import com.datadog.android.rum.model.ErrorEvent
3030
import com.datadog.android.rum.model.ViewEvent
3131
import com.google.gson.JsonObject
32+
import java.util.UUID
3233
import java.util.concurrent.TimeUnit
3334

3435
internal class DatadogLateCrashReporter(
@@ -256,6 +257,7 @@ internal class DatadogLateCrashReporter(
256257
),
257258
context = ErrorEvent.Context(additionalProperties = additionalProperties),
258259
error = ErrorEvent.Error(
260+
id = UUID.randomUUID().toString(),
259261
message = errorLogMessage,
260262
source = ErrorEvent.ErrorSource.SOURCE,
261263
stack = stacktrace,

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ internal class RumResourceScope(
437437
buildId = datadogContext.appBuildId,
438438
date = eventTimestamp,
439439
error = ErrorEvent.Error(
440+
id = UUID.randomUUID().toString(),
440441
message = message,
441442
source = source.toSchemaSource(),
442443
stack = stackTrace,

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ internal open class RumViewScope(
713713
date = event.eventTime.timestamp + serverTimeOffsetInMs,
714714
featureFlags = ErrorEvent.Context(eventFeatureFlags),
715715
error = ErrorEvent.Error(
716+
id = UUID.randomUUID().toString(),
716717
message = message,
717718
source = event.source.toSchemaSource(),
718719
stack = event.stacktrace ?: event.throwable?.loggableStackTrace(),
@@ -1449,6 +1450,7 @@ internal open class RumViewScope(
14491450
LongTaskEvent(
14501451
date = timestamp - TimeUnit.NANOSECONDS.toMillis(event.durationNs),
14511452
longTask = LongTaskEvent.LongTask(
1453+
id = UUID.randomUUID().toString(),
14521454
duration = event.durationNs,
14531455
isFrozenFrame = isFrozenFrame
14541456
),

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/assertj/ErrorEventAssert.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,17 @@ internal class ErrorEventAssert(actual: ErrorEvent) :
649649
return this
650650
}
651651

652+
fun hasErrorId(): ErrorEventAssert {
653+
assertThat(actual.error.id)
654+
.overridingErrorMessage(
655+
"Expected RUM event to have error.id" +
656+
" but instead it was ${if (actual.error.id == null) "null" else "blank"}"
657+
)
658+
.isNotNull
659+
.isNotBlank
660+
return this
661+
}
662+
652663
companion object {
653664
internal const val TIMESTAMP_THRESHOLD_MS = 50L
654665
internal fun assertThat(actual: ErrorEvent): ErrorEventAssert =

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/DatadogLateCrashReporterTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ internal class DatadogLateCrashReporterTest {
174174
verify(mockRumWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
175175

176176
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
177+
.hasErrorId()
177178
.hasApplicationId(fakeViewEvent.application.id)
178179
.hasSessionId(fakeViewEvent.session.id)
179180
.hasView(
@@ -276,6 +277,7 @@ internal class DatadogLateCrashReporterTest {
276277
verify(mockRumWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
277278

278279
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
280+
.hasErrorId()
279281
.hasApplicationId(fakeViewEvent.application.id)
280282
.hasSessionId(fakeViewEvent.session.id)
281283
.hasView(
@@ -378,6 +380,7 @@ internal class DatadogLateCrashReporterTest {
378380
verify(mockRumWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
379381

380382
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
383+
.hasErrorId()
381384
.hasErrorSourceType(ErrorEvent.SourceType.NDK)
382385
}
383386
}
@@ -429,6 +432,7 @@ internal class DatadogLateCrashReporterTest {
429432
verify(mockRumWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
430433

431434
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
435+
.hasErrorId()
432436
.hasApplicationId(fakeViewEvent.application.id)
433437
.hasSessionId(fakeViewEvent.session.id)
434438
.hasView(
@@ -525,6 +529,7 @@ internal class DatadogLateCrashReporterTest {
525529
verify(mockRumWriter, times(1)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
526530

527531
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
532+
.hasErrorId()
528533
.hasApplicationId(fakeViewEvent.application.id)
529534
.hasSessionId(fakeViewEvent.session.id)
530535
.hasBuildId(fakeDatadogContext.appBuildId)
@@ -724,6 +729,7 @@ internal class DatadogLateCrashReporterTest {
724729
verify(mockRumWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
725730

726731
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
732+
.hasErrorId()
727733
.hasApplicationId(fakeViewEvent.application.id)
728734
.hasSessionId(fakeViewEvent.session.id)
729735
.hasView(
@@ -815,6 +821,7 @@ internal class DatadogLateCrashReporterTest {
815821
verify(mockRumWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
816822

817823
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
824+
.hasErrorId()
818825
.hasApplicationId(fakeViewEvent.application.id)
819826
.hasSessionId(fakeViewEvent.session.id)
820827
.hasView(
@@ -904,6 +911,7 @@ internal class DatadogLateCrashReporterTest {
904911
verify(mockRumWriter, times(1)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
905912

906913
ErrorEventAssert.assertThat(firstValue as ErrorEvent)
914+
.hasErrorId()
907915
.hasApplicationId(fakeViewEvent.application.id)
908916
.hasSessionId(fakeViewEvent.session.id)
909917
.hasView(

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScopeTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ internal class RumResourceScopeTest {
12441244
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
12451245
assertThat(lastValue)
12461246
.apply {
1247+
hasErrorId()
12471248
hasMessage(message)
12481249
hasErrorSource(source)
12491250
hasStackTrace(throwable.loggableStackTrace())
@@ -1327,6 +1328,7 @@ internal class RumResourceScopeTest {
13271328
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
13281329
assertThat(lastValue)
13291330
.apply {
1331+
hasErrorId()
13301332
hasMessage(message)
13311333
hasErrorSource(source)
13321334
hasStackTrace(throwable.loggableStackTrace())
@@ -1405,6 +1407,7 @@ internal class RumResourceScopeTest {
14051407
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
14061408
assertThat(lastValue)
14071409
.apply {
1410+
hasErrorId()
14081411
hasMessage(message)
14091412
hasErrorSource(source)
14101413
hasStackTrace(stackTrace)
@@ -1503,6 +1506,7 @@ internal class RumResourceScopeTest {
15031506
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
15041507
assertThat(lastValue)
15051508
.apply {
1509+
hasErrorId()
15061510
hasMessage(message)
15071511
hasErrorSource(source)
15081512
hasStackTrace(throwable.loggableStackTrace())
@@ -1604,6 +1608,7 @@ internal class RumResourceScopeTest {
16041608
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
16051609
assertThat(lastValue)
16061610
.apply {
1611+
hasErrorId()
16071612
hasMessage(message)
16081613
hasErrorSource(source)
16091614
hasStackTrace(stackTrace)
@@ -1698,6 +1703,7 @@ internal class RumResourceScopeTest {
16981703
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
16991704
assertThat(lastValue)
17001705
.apply {
1706+
hasErrorId()
17011707
hasMessage(message)
17021708
hasErrorSource(source)
17031709
hasStackTrace(throwable.loggableStackTrace())
@@ -1797,6 +1803,7 @@ internal class RumResourceScopeTest {
17971803
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
17981804
assertThat(lastValue)
17991805
.apply {
1806+
hasErrorId()
18001807
hasMessage(message)
18011808
hasErrorSource(source)
18021809
hasStackTrace(stackTrace)
@@ -1878,6 +1885,7 @@ internal class RumResourceScopeTest {
18781885
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
18791886
assertThat(lastValue)
18801887
.apply {
1888+
hasErrorId()
18811889
hasMessage(message)
18821890
hasErrorSource(source)
18831891
hasStackTrace(throwable.loggableStackTrace())
@@ -1961,6 +1969,7 @@ internal class RumResourceScopeTest {
19611969
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
19621970
assertThat(lastValue)
19631971
.apply {
1972+
hasErrorId()
19641973
hasMessage(message)
19651974
hasErrorSource(source)
19661975
hasStackTrace(stackTrace)
@@ -2042,6 +2051,7 @@ internal class RumResourceScopeTest {
20422051
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
20432052
assertThat(lastValue)
20442053
.apply {
2054+
hasErrorId()
20452055
hasMessage(message)
20462056
hasErrorSource(source)
20472057
hasStackTrace(throwable.loggableStackTrace())
@@ -2125,6 +2135,7 @@ internal class RumResourceScopeTest {
21252135
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
21262136
assertThat(lastValue)
21272137
.apply {
2138+
hasErrorId()
21282139
hasMessage(message)
21292140
hasErrorSource(source)
21302141
hasStackTrace(stackTrace)
@@ -2210,6 +2221,7 @@ internal class RumResourceScopeTest {
22102221
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
22112222
assertThat(lastValue)
22122223
.apply {
2224+
hasErrorId()
22132225
hasMessage(message)
22142226
hasErrorSource(source)
22152227
hasStackTrace(throwable.loggableStackTrace())
@@ -2298,6 +2310,7 @@ internal class RumResourceScopeTest {
22982310
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
22992311
assertThat(lastValue)
23002312
.apply {
2313+
hasErrorId()
23012314
hasMessage(message)
23022315
hasErrorSource(source)
23032316
hasStackTrace(stackTrace)

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScopeTest.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,6 +3458,7 @@ internal class RumViewScopeTest {
34583458

34593459
assertThat(firstValue)
34603460
.apply {
3461+
hasErrorId()
34613462
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
34623463
hasMessage(expectedMessage)
34633464
hasErrorSource(source)
@@ -3540,6 +3541,7 @@ internal class RumViewScopeTest {
35403541

35413542
assertThat(firstValue)
35423543
.apply {
3544+
hasErrorId()
35433545
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
35443546
hasMessage(expectedMessage)
35453547
hasErrorSource(source)
@@ -3614,6 +3616,7 @@ internal class RumViewScopeTest {
36143616

36153617
assertThat(firstValue)
36163618
.apply {
3619+
hasErrorId()
36173620
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
36183621
hasMessage(message)
36193622
hasErrorSource(source)
@@ -3688,6 +3691,7 @@ internal class RumViewScopeTest {
36883691

36893692
assertThat(firstValue)
36903693
.apply {
3694+
hasErrorId()
36913695
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
36923696
hasMessage(message)
36933697
hasErrorSource(source)
@@ -3764,6 +3768,7 @@ internal class RumViewScopeTest {
37643768

37653769
assertThat(firstValue)
37663770
.apply {
3771+
hasErrorId()
37673772
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
37683773
hasMessage(message)
37693774
hasErrorSource(source)
@@ -3842,6 +3847,7 @@ internal class RumViewScopeTest {
38423847

38433848
assertThat(firstValue)
38443849
.apply {
3850+
hasErrorId()
38453851
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
38463852
hasMessage(throwableMessage)
38473853
hasErrorSource(source)
@@ -3916,6 +3922,7 @@ internal class RumViewScopeTest {
39163922

39173923
assertThat(firstValue)
39183924
.apply {
3925+
hasErrorId()
39193926
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
39203927
hasMessage(message)
39213928
hasErrorSource(source)
@@ -3975,6 +3982,7 @@ internal class RumViewScopeTest {
39753982

39763983
assertThat(firstValue)
39773984
.apply {
3985+
hasErrorId()
39783986
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
39793987
hasMessage(expectedMessage)
39803988
hasErrorSource(source)
@@ -4054,6 +4062,7 @@ internal class RumViewScopeTest {
40544062

40554063
assertThat(firstValue)
40564064
.apply {
4065+
hasErrorId()
40574066
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
40584067
hasMessage(message)
40594068
hasErrorSource(source)
@@ -4135,6 +4144,7 @@ internal class RumViewScopeTest {
41354144
verify(mockWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
41364145
assertThat(firstValue as ErrorEvent)
41374146
.apply {
4147+
hasErrorId()
41384148
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
41394149
hasMessage(message)
41404150
hasErrorSource(source)
@@ -4275,6 +4285,7 @@ internal class RumViewScopeTest {
42754285

42764286
assertThat(firstValue)
42774287
.apply {
4288+
hasErrorId()
42784289
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
42794290
hasMessage(throwableMessage)
42804291
hasErrorSource(source)
@@ -4352,6 +4363,7 @@ internal class RumViewScopeTest {
43524363
verify(mockWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
43534364
assertThat(firstValue as ErrorEvent)
43544365
.apply {
4366+
hasErrorId()
43554367
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
43564368
hasMessage(expectedMessage)
43574369
hasErrorSource(source)
@@ -4504,6 +4516,7 @@ internal class RumViewScopeTest {
45044516
verify(mockWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.CRASH))
45054517
assertThat(firstValue as ErrorEvent)
45064518
.apply {
4519+
hasErrorId()
45074520
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
45084521
hasMessage(expectedMessage)
45094522
hasErrorSource(source)
@@ -4639,6 +4652,7 @@ internal class RumViewScopeTest {
46394652
verify(mockWriter).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
46404653
assertThat(firstValue as ErrorEvent)
46414654
.apply {
4655+
hasErrorId()
46424656
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
46434657
hasMessage(expectedMessage)
46444658
hasErrorSource(source)
@@ -4721,6 +4735,7 @@ internal class RumViewScopeTest {
47214735

47224736
assertThat(firstValue)
47234737
.apply {
4738+
hasErrorId()
47244739
hasTimestamp(resolveExpectedTimestamp(fakeEvent.eventTime.timestamp))
47254740
hasMessage(expectedMessage)
47264741
hasErrorSource(source)
@@ -7574,7 +7589,9 @@ internal class RumViewScopeTest {
75747589
// THEN
75757590
argumentCaptor<Any> {
75767591
verify(mockWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
7577-
assertThat(lastValue as ErrorEvent).hasFeatureFlag(flagName, flagValue)
7592+
assertThat(lastValue as ErrorEvent)
7593+
.hasErrorId()
7594+
.hasFeatureFlag(flagName, flagValue)
75787595
}
75797596
}
75807597

@@ -7747,9 +7764,11 @@ internal class RumViewScopeTest {
77477764
// THEN
77487765
argumentCaptor<Any> {
77497766
verify(mockWriter, times(2)).write(eq(mockEventBatchWriter), capture(), eq(EventType.DEFAULT))
7750-
assertThat(lastValue as ErrorEvent).hasFeatureFlag(flagName1, flagValue1)
7751-
assertThat(lastValue as ErrorEvent).hasFeatureFlag(flagName2, flagValue2)
7752-
assertThat(lastValue as ErrorEvent).hasFeatureFlag(flagName3, flagValue3)
7767+
assertThat(lastValue as ErrorEvent)
7768+
.hasErrorId()
7769+
.hasFeatureFlag(flagName1, flagValue1)
7770+
.hasFeatureFlag(flagName2, flagValue2)
7771+
.hasFeatureFlag(flagName3, flagValue3)
77537772
}
77547773
}
77557774

0 commit comments

Comments
 (0)