Skip to content

Commit

Permalink
Merge pull request #435 from DataDog/xgouchet/RUMM-910/keep_all_custo…
Browse files Browse the repository at this point in the history
…m_actions

RUMM-910 Keep all custom actions
  • Loading branch information
xgouchet authored Dec 7, 2020
2 parents c13a0e8 + 15189e9 commit 8a090e8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class RumActionScope(

private val eventTimestamp = eventTime.timestamp
internal val actionId: String = UUID.randomUUID().toString()
private var type: RumActionType = initialType
internal var type: RumActionType = initialType
internal var name: String = initialName
private val startedNanos: Long = eventTime.nanoTime
private var lastInteractionNanos: Long = startedNanos
Expand Down Expand Up @@ -156,7 +156,9 @@ internal class RumActionScope(
) {
if (sent) return

if (resourceCount > 0 || errorCount > 0 || viewTreeChangeCount > 0) {
val actualType = type
val sideEffectsCount = resourceCount + errorCount + viewTreeChangeCount
if (sideEffectsCount > 0 || actualType == RumActionType.CUSTOM) {
attributes.putAll(GlobalRum.globalAttributes)

val context = getRumContext()
Expand All @@ -165,7 +167,7 @@ internal class RumActionScope(
val actionEvent = ActionEvent(
date = eventTimestamp,
action = ActionEvent.Action(
type = type.toSchemaType(),
type = actualType.toSchemaType(),
id = actionId,
target = ActionEvent.Target(name),
error = ActionEvent.Error(errorCount),
Expand Down Expand Up @@ -198,7 +200,7 @@ internal class RumActionScope(
parentScope.handleEvent(RumRawEvent.SentAction(), writer)
} else {
devLogger.i(
"RUM Action $actionId ($type on $name) was dropped " +
"RUM Action $actionId ($actualType on $name) was dropped " +
"(no side effect was registered during its scope)"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ internal class RumActionScopeTest {
@Mock
lateinit var mockWriter: Writer<RumEvent>

@Forgery
lateinit var fakeType: RumActionType

@StringForgery
Expand All @@ -94,6 +93,11 @@ internal class RumActionScopeTest {
fun `set up`(forge: Forge) {
fakeEventTime = Time()

fakeType = forge.aValueFrom(
RumActionType::class.java,
exclude = listOf(RumActionType.CUSTOM)
)

RumFeature::class.java.setStaticValue("userInfoProvider", mockUserInfoProvider)

fakeAttributes = forge.exhaustiveAttributes()
Expand Down Expand Up @@ -1044,6 +1048,42 @@ internal class RumActionScopeTest {
assertThat(result).isNull()
}

@Test
fun `M send custom Action after timeout W handleEvent(any) and no side effect`() {
// When
Thread.sleep(RumActionScope.ACTION_INACTIVITY_MS)
testedScope.type = RumActionType.CUSTOM
val result = testedScope.handleEvent(mockEvent(), mockWriter)

// Then
argumentCaptor<RumEvent> {
verify(mockWriter).write(capture())
assertThat(lastValue)
.hasAttributes(fakeAttributes)
.hasUserExtraAttributes(fakeUserInfo.extraInfo)
.hasActionData {
hasId(testedScope.actionId)
hasTimestamp(fakeEventTime.timestamp)
hasType(RumActionType.CUSTOM)
hasTargetName(fakeName)
hasDuration(1)
hasResourceCount(0)
hasErrorCount(0)
hasCrashCount(0)
hasView(fakeParentContext.viewId, fakeParentContext.viewUrl)
hasUserInfo(fakeUserInfo)
hasApplicationId(fakeParentContext.applicationId)
hasSessionId(fakeParentContext.sessionId)
}
}
verify(mockParentScope).handleEvent(
isA<RumRawEvent.SentAction>(),
same(mockWriter)
)
verifyNoMoreInteractions(mockWriter)
assertThat(result).isNull()
}

@Test
fun `𝕄 send Action after threshold 𝕎 handleEvent(ViewTreeChanged+any)`() {
// When
Expand Down

0 comments on commit 8a090e8

Please sign in to comment.