Skip to content

Commit

Permalink
Merge pull request #1718 from DataDog/xgouchet/RUM-2127/5_read_synthe…
Browse files Browse the repository at this point in the history
…tics_info

(5/9) RUM-2127 Add synthetics info to RUM Actions
  • Loading branch information
xgouchet authored Nov 16, 2023
2 parents 4a9ae58 + 69f9cfd commit 436fad3
Show file tree
Hide file tree
Showing 6 changed files with 522 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,23 @@ internal class RumActionScope(
val eventLongTaskCount = longTaskCount
val eventResourceCount = resourceCount

val syntheticsAttribute = if (
rumContext.syntheticsTestId.isNullOrBlank() ||
rumContext.syntheticsResultId.isNullOrBlank()
) {
null
} else {
ActionEvent.Synthetics(
testId = rumContext.syntheticsTestId,
resultId = rumContext.syntheticsResultId
)
}
val sessionType = if (syntheticsAttribute == null) {
ActionEvent.ActionEventSessionType.USER
} else {
ActionEvent.ActionEventSessionType.SYNTHETICS
}

sdkCore.getFeature(Feature.RUM_FEATURE_NAME)
?.withWriteContext { datadogContext, eventBatchWriter ->
val user = datadogContext.userInfo
Expand Down Expand Up @@ -241,9 +258,10 @@ internal class RumActionScope(
application = ActionEvent.Application(rumContext.applicationId),
session = ActionEvent.ActionEventSession(
id = rumContext.sessionId,
type = ActionEvent.ActionEventSessionType.USER,
type = sessionType,
hasReplay = hasReplay
),
synthetics = syntheticsAttribute,
source = ActionEvent.Source.tryFromSource(
datadogContext.source,
sdkCore.internalLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,22 @@ internal open class RumViewScope(
sdkCore.getFeature(Feature.RUM_FEATURE_NAME)
?.withWriteContext { datadogContext, eventBatchWriter ->
val user = datadogContext.userInfo
val syntheticsAttribute = if (
rumContext.syntheticsTestId.isNullOrBlank() ||
rumContext.syntheticsResultId.isNullOrBlank()
) {
null
} else {
ActionEvent.Synthetics(
testId = rumContext.syntheticsTestId,
resultId = rumContext.syntheticsResultId
)
}
val sessionType = if (syntheticsAttribute == null) {
ActionEvent.ActionEventSessionType.USER
} else {
ActionEvent.ActionEventSessionType.SYNTHETICS
}

val actionEvent = ActionEvent(
date = eventTimestamp,
Expand Down Expand Up @@ -878,9 +894,10 @@ internal open class RumViewScope(
application = ActionEvent.Application(rumContext.applicationId),
session = ActionEvent.ActionEventSession(
id = rumContext.sessionId,
type = ActionEvent.ActionEventSessionType.USER,
type = sessionType,
hasReplay = false
),
synthetics = syntheticsAttribute,
source = ActionEvent.Source.tryFromSource(
datadogContext.source,
sdkCore.internalLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ internal class ActionEventAssert(actual: ActionEvent) :
fun hasApplicationId(expected: String): ActionEventAssert {
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 @@ -246,12 +246,52 @@ internal class ActionEventAssert(actual: ActionEvent) :
fun hasSessionId(expected: String): ActionEventAssert {
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
}

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

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

fun hasNoSyntheticsTest(): ActionEventAssert {
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): ActionEventAssert {
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 hasDuration(expected: Long): ActionEventAssert {
assertThat(actual.action.loadingTime)
.overridingErrorMessage(
Expand Down
Loading

0 comments on commit 436fad3

Please sign in to comment.