Skip to content

Commit 875dfc8

Browse files
authored
Merge pull request #3073 from DataDog/nogorodnikov/add-ids-to-errors-long-tasks
Add IDs to errors and long tasks
2 parents 5a0ff29 + 5931c42 commit 875dfc8

File tree

8 files changed

+75
-4
lines changed

8 files changed

+75
-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/assertj/LongTaskEventAssert.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,17 @@ internal class LongTaskEventAssert(actual: LongTaskEvent) :
401401
return this
402402
}
403403

404+
fun hasLongTaskId(): LongTaskEventAssert {
405+
assertThat(actual.longTask.id)
406+
.overridingErrorMessage(
407+
"Expected RUM event to have long_task.id" +
408+
" but instead it was ${if (actual.longTask.id == null) "null" else "blank"}"
409+
)
410+
.isNotNull
411+
.isNotBlank
412+
return this
413+
}
414+
404415
companion object {
405416
internal const val TIMESTAMP_THRESHOLD_MS = 50L
406417
internal fun assertThat(actual: LongTaskEvent): LongTaskEventAssert =

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)

0 commit comments

Comments
 (0)