-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2325 from DataDog/mconstantin/fix-regression-on-t…
…elemetry-with-throwable-event Fix the regression for the TelemetryErrorEvent with throwable
- Loading branch information
Showing
36 changed files
with
532 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
dd-sdk-android-internal/src/test/java/com/datadog/internal/forge/Configurator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.internal.forge | ||
|
||
import com.datadog.android.internal.tests.elmyr.InternalTelemetryErrorLogForgeryFactory | ||
import com.datadog.tools.unit.forge.BaseConfigurator | ||
import fr.xgouchet.elmyr.Forge | ||
|
||
internal class Configurator : | ||
BaseConfigurator() { | ||
override fun configure(forge: Forge) { | ||
super.configure(forge) | ||
forge.addFactory(InternalTelemetryErrorLogForgeryFactory()) | ||
} | ||
} |
198 changes: 198 additions & 0 deletions
198
...-internal/src/test/java/com/datadog/internal/telemetry/InternalTelemetryErrorEventTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/* | ||
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. | ||
* This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
* Copyright 2016-Present Datadog, Inc. | ||
*/ | ||
|
||
package com.datadog.internal.telemetry | ||
|
||
import com.datadog.android.internal.telemetry.InternalTelemetryEvent | ||
import com.datadog.android.internal.utils.loggableStackTrace | ||
import com.datadog.tools.unit.forge.aThrowable | ||
import fr.xgouchet.elmyr.Forge | ||
import fr.xgouchet.elmyr.junit5.ForgeExtension | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.api.extension.Extensions | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.junit.jupiter.MockitoSettings | ||
import org.mockito.quality.Strictness | ||
|
||
@Extensions( | ||
ExtendWith(MockitoExtension::class), | ||
ExtendWith(ForgeExtension::class) | ||
) | ||
@MockitoSettings(strictness = Strictness.LENIENT) | ||
internal class InternalTelemetryErrorEventTest { | ||
|
||
@Test | ||
fun `M resolve the given stacktrace W resolveStacktrace { stacktrace explicitly provided }`(forge: Forge) { | ||
// Given | ||
val expectedStackTrace = forge.aString() | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = null, | ||
stacktrace = expectedStackTrace, | ||
kind = forge.aNullable { aString() } | ||
) | ||
|
||
// When | ||
val resolvedStackTrace = errorEvent.resolveStacktrace() | ||
assertThat(resolvedStackTrace).isEqualTo(expectedStackTrace) | ||
} | ||
|
||
@Test | ||
fun `M resolve the given stacktrace W resolveStacktrace { stacktrace and throwable explicitly provided }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val expectedStackTrace = forge.aString() | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = forge.aThrowable(), | ||
stacktrace = expectedStackTrace, | ||
kind = forge.aNullable { aString() } | ||
) | ||
|
||
// When | ||
val resolvedStackTrace = errorEvent.resolveStacktrace() | ||
assertThat(resolvedStackTrace).isEqualTo(expectedStackTrace) | ||
} | ||
|
||
@Test | ||
fun `M resolve throwable stacktrace W resolveStacktrace { only throwable explicitly provided }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val fakeThrowable = forge.aThrowable() | ||
val expectedStackTrace = fakeThrowable.loggableStackTrace() | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = fakeThrowable, | ||
stacktrace = null, | ||
kind = forge.aNullable { aString() } | ||
) | ||
|
||
// When | ||
val resolvedStackTrace = errorEvent.resolveStacktrace() | ||
assertThat(resolvedStackTrace).isEqualTo(expectedStackTrace) | ||
} | ||
|
||
@Test | ||
fun `M resolve null W resolveStacktrace { stacktrace nor throwable provided }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = null, | ||
stacktrace = null, | ||
kind = forge.aNullable { aString() } | ||
) | ||
|
||
// When | ||
val resolvedStackTrace = errorEvent.resolveStacktrace() | ||
assertThat(resolvedStackTrace).isNull() | ||
} | ||
|
||
@Test | ||
fun `M resolve the given kind W resolveKind { kind explicitly provided }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val expectedKind = forge.aString() | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = null, | ||
stacktrace = forge.aNullable { aString() }, | ||
kind = expectedKind | ||
) | ||
|
||
// When | ||
val resolvedKind = errorEvent.resolveKind() | ||
assertThat(resolvedKind).isEqualTo(expectedKind) | ||
} | ||
|
||
@Test | ||
fun `M resolve the given kind W resolveKind { kind and throwable explicitly provided }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val expectedKind = forge.aString() | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = forge.aThrowable(), | ||
stacktrace = forge.aNullable { aString() }, | ||
kind = expectedKind | ||
) | ||
|
||
// When | ||
val resolvedKind = errorEvent.resolveKind() | ||
assertThat(resolvedKind).isEqualTo(expectedKind) | ||
} | ||
|
||
@Test | ||
fun `M resolve throwable kind W resolveKind { only throwable explicitly provided }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val fakeThrowable = forge.aThrowable() | ||
val expectedKind = fakeThrowable.javaClass.canonicalName | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = fakeThrowable, | ||
stacktrace = forge.aNullable { aString() }, | ||
kind = null | ||
) | ||
|
||
// When | ||
val resolvedKind = errorEvent.resolveKind() | ||
assertThat(resolvedKind).isEqualTo(expectedKind) | ||
} | ||
|
||
@Test | ||
fun `M resolve throwable kind W resolveKind { only throwable explicitly provided, anonymous class }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val fakeThrowable = object : Throwable() {} | ||
val expectedKind = fakeThrowable.javaClass.simpleName | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = fakeThrowable, | ||
stacktrace = forge.aNullable { aString() }, | ||
kind = null | ||
) | ||
|
||
// When | ||
val resolvedKind = errorEvent.resolveKind() | ||
assertThat(resolvedKind).isEqualTo(expectedKind) | ||
} | ||
|
||
@Test | ||
fun `M resolve null W resolveKind { kind nor throwable provided }`( | ||
forge: Forge | ||
) { | ||
// Given | ||
val errorEvent = InternalTelemetryEvent.Log.Error( | ||
message = forge.aString(), | ||
additionalProperties = forge.aMap { aString() to aString() }, | ||
error = null, | ||
stacktrace = forge.aNullable { aString() }, | ||
kind = null | ||
) | ||
|
||
// When | ||
val resolvedKind = errorEvent.resolveKind() | ||
assertThat(resolvedKind).isNull() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.