Skip to content

Commit

Permalink
RUM-2127 Add synthetics info to RUM Views
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Nov 16, 2023
1 parent a366d7e commit e553692
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,23 @@ internal open class RumViewScope(
currentViewId
)
val replayStats = ViewEvent.ReplayStats(recordsCount = sessionReplayRecordsCount)
val syntheticsAttribute = if (
rumContext.syntheticsTestId.isNullOrBlank() ||
rumContext.syntheticsResultId.isNullOrBlank()
) {
null
} else {
ViewEvent.Synthetics(
testId = rumContext.syntheticsTestId,
resultId = rumContext.syntheticsResultId
)
}
val sessionType = if (syntheticsAttribute == null) {
ViewEvent.ViewEventSessionType.USER
} else {
ViewEvent.ViewEventSessionType.SYNTHETICS
}

val viewEvent = ViewEvent(
date = eventTimestamp,
featureFlags = ViewEvent.Context(additionalProperties = featureFlags),
Expand Down Expand Up @@ -742,10 +759,11 @@ internal open class RumViewScope(
application = ViewEvent.Application(rumContext.applicationId),
session = ViewEvent.ViewEventSession(
id = rumContext.sessionId,
type = ViewEvent.ViewEventSessionType.USER,
type = sessionType,
hasReplay = hasReplay,
isActive = rumContext.isSessionActive
),
synthetics = syntheticsAttribute,
source = ViewEvent.Source.tryFromSource(
datadogContext.source,
sdkCore.internalLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ internal class ViewEventAssert(actual: ViewEvent) :
fun hasApplicationId(expected: String): ViewEventAssert {
assertThat(actual.application.id)
.overridingErrorMessage(
"Expected context to have application.id $expected but was ${actual.application.id}"
"Expected event to have application.id $expected but was ${actual.application.id}"
)
.isEqualTo(expected)
return this
Expand All @@ -186,7 +186,7 @@ internal class ViewEventAssert(actual: ViewEvent) :
fun hasSessionId(expected: String): ViewEventAssert {
assertThat(actual.session.id)
.overridingErrorMessage(
"Expected context to have session.id $expected but was ${actual.session.id}"
"Expected event to have session.id $expected but was ${actual.session.id}"
)
.isEqualTo(expected)
return this
Expand All @@ -195,11 +195,51 @@ internal class ViewEventAssert(actual: ViewEvent) :
fun hasSessionActive(expected: Boolean): ViewEventAssert {
assertThat(actual.session.isActive)
.overridingErrorMessage(
"Expected context to have session.isActive $expected but was ${actual.session.isActive}"
"Expected event to have session.isActive $expected but was ${actual.session.isActive}"
).isEqualTo(expected)
return this
}

fun hasUserSession(): ViewEventAssert {
assertThat(actual.session.type)
.overridingErrorMessage(
"Expected event to have session.type:user but was ${actual.session.type}"
).isEqualTo(ViewEvent.ViewEventSessionType.USER)
return this
}

fun hasSyntheticsSession(): ViewEventAssert {
assertThat(actual.session.type)
.overridingErrorMessage(
"Expected event to have session.type:synthetics but was ${actual.session.type}"
).isEqualTo(ViewEvent.ViewEventSessionType.SYNTHETICS)
return this
}

fun hasNoSyntheticsTest(): ViewEventAssert {
assertThat(actual.synthetics?.testId)
.overridingErrorMessage(
"Expected event to have no synthetics.testId but was ${actual.synthetics?.testId}"
).isNull()
assertThat(actual.synthetics?.resultId)
.overridingErrorMessage(
"Expected event to have no synthetics.resultId but was ${actual.synthetics?.resultId}"
).isNull()
return this
}

fun hasSyntheticsTest(testId: String, resultId: String): ViewEventAssert {
assertThat(actual.synthetics?.testId)
.overridingErrorMessage(
"Expected event to have synthetics.testId $testId but was ${actual.synthetics?.testId}"
).isEqualTo(testId)
assertThat(actual.synthetics?.resultId)
.overridingErrorMessage(
"Expected event to have synthetics.resultId $resultId but was ${actual.synthetics?.resultId}"
).isEqualTo(resultId)
return this
}

fun hasLoadingTime(
expected: Long?
): ViewEventAssert {
Expand Down

0 comments on commit e553692

Please sign in to comment.