Skip to content

Commit

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

(6/9) RUM-2127 Add synthetics info to RUM Errors
  • Loading branch information
xgouchet authored Nov 16, 2023
2 parents 436fad3 + a649930 commit 8afdbd6
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,23 @@ internal class RumResourceScope(
attributes.putAll(GlobalRumMonitor.get(sdkCore).getAttributes())

val rumContext = getRumContext()

val syntheticsAttribute = if (
rumContext.syntheticsTestId.isNullOrBlank() ||
rumContext.syntheticsResultId.isNullOrBlank()
) {
null
} else {
ErrorEvent.Synthetics(
testId = rumContext.syntheticsTestId,
resultId = rumContext.syntheticsResultId
)
}
val sessionType = if (syntheticsAttribute == null) {
ErrorEvent.ErrorEventSessionType.USER
} else {
ErrorEvent.ErrorEventSessionType.SYNTHETICS
}
sdkCore.getFeature(Feature.RUM_FEATURE_NAME)
?.withWriteContext { datadogContext, eventBatchWriter ->
val user = datadogContext.userInfo
Expand Down Expand Up @@ -351,9 +368,10 @@ internal class RumResourceScope(
application = ErrorEvent.Application(rumContext.applicationId),
session = ErrorEvent.ErrorEventSession(
id = rumContext.sessionId,
type = ErrorEvent.ErrorEventSessionType.USER,
type = sessionType,
hasReplay = hasReplay
),
synthetics = syntheticsAttribute,
source = ErrorEvent.ErrorEventSource.tryFromSource(
datadogContext.source,
sdkCore.internalLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,22 @@ internal open class RumViewScope(
datadogContext,
rumContext.viewId.orEmpty()
)
val syntheticsAttribute = if (
rumContext.syntheticsTestId.isNullOrBlank() ||
rumContext.syntheticsResultId.isNullOrBlank()
) {
null
} else {
ErrorEvent.Synthetics(
testId = rumContext.syntheticsTestId,
resultId = rumContext.syntheticsResultId
)
}
val sessionType = if (syntheticsAttribute == null) {
ErrorEvent.ErrorEventSessionType.USER
} else {
ErrorEvent.ErrorEventSessionType.SYNTHETICS
}
val errorEvent = ErrorEvent(
date = event.eventTime.timestamp + serverTimeOffsetInMs,
featureFlags = ErrorEvent.Context(featureFlags),
Expand Down Expand Up @@ -412,9 +428,10 @@ internal open class RumViewScope(
application = ErrorEvent.Application(rumContext.applicationId),
session = ErrorEvent.ErrorEventSession(
id = rumContext.sessionId,
type = ErrorEvent.ErrorEventSessionType.USER,
type = sessionType,
hasReplay = hasReplay
),
synthetics = syntheticsAttribute,
source = ErrorEvent.ErrorEventSource.tryFromSource(
datadogContext.source,
sdkCore.internalLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ internal class ErrorEventAssert(actual: ErrorEvent) :
fun hasApplicationId(expected: String): ErrorEventAssert {
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 @@ -261,12 +261,52 @@ internal class ErrorEventAssert(actual: ErrorEvent) :
fun hasSessionId(expected: String): ErrorEventAssert {
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(): ErrorEventAssert {
assertThat(actual.session.type)
.overridingErrorMessage(
"Expected event to have session.type:user but was ${actual.session.type}"
).isEqualTo(ErrorEvent.ErrorEventSessionType.USER)
return this
}

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

fun hasNoSyntheticsTest(): ErrorEventAssert {
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): ErrorEventAssert {
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 hasActionId(expected: String?): ErrorEventAssert {
if (expected != null) {
assertThat(actual.action?.id)
Expand Down
Loading

0 comments on commit 8afdbd6

Please sign in to comment.