Skip to content

Commit f52cb0b

Browse files
authored
[test optimization] allow overwriting the RUM flush wait time by setting environment variable DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS
* feat(test-optimization): allow overwriting the RUM flush wait time by setting environment variable DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS * chore(test-optimization): add more error and debug logs for rum integrations
1 parent 5856d72 commit f52cb0b

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

packages/datadog-instrumentations/src/playwright.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const {
1111
getIsFaultyEarlyFlakeDetection
1212
} = require('../../dd-trace/src/plugins/util/test')
1313
const log = require('../../dd-trace/src/log')
14+
const {
15+
getEnvironmentVariable
16+
} = require('../../dd-trace/src/config-helper')
1417
const { DD_MAJOR } = require('../../../version')
1518

1619
const testStartCh = channel('ci:playwright:test:start')
@@ -38,7 +41,7 @@ const testSuiteToTestStatuses = new Map()
3841
const testSuiteToErrors = new Map()
3942
const testsToTestStatuses = new Map()
4043

41-
const RUM_FLUSH_WAIT_TIME = 1000
44+
const RUM_FLUSH_WAIT_TIME = Number(getEnvironmentVariable('DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS')) || 1000
4245

4346
let applyRepeatEachIndex = null
4447

@@ -1078,9 +1081,19 @@ addHook({
10781081

10791082
try {
10801083
if (page) {
1081-
const isRumActive = await page.evaluate(() => {
1082-
return window.DD_RUM && window.DD_RUM.getInternalContext ? !!window.DD_RUM.getInternalContext() : false
1084+
const { isRumInstrumented, isRumActive, rumSamplingRate } = await page.evaluate(() => {
1085+
const isRumInstrumented = !!window.DD_RUM
1086+
const isRumActive = window.DD_RUM && window.DD_RUM.getInternalContext
1087+
? !!window.DD_RUM.getInternalContext()
1088+
: false
1089+
const rumSamplingRate = window.DD_RUM && window.DD_RUM.getInitConfiguration
1090+
? window.DD_RUM.getInitConfiguration().sessionSampleRate
1091+
: null
1092+
return { isRumInstrumented, isRumActive, rumSamplingRate }
10831093
})
1094+
if (isRumInstrumented && rumSamplingRate < 100 && !isRumActive) {
1095+
log.debug("RUM was detected on the page, but it isn't active because the sampling rate is below 100%")
1096+
}
10841097

10851098
if (isRumActive) {
10861099
testPageGotoCh.publish({
@@ -1089,8 +1102,9 @@ addHook({
10891102
})
10901103
}
10911104
}
1092-
} catch {
1105+
} catch (e) {
10931106
// ignore errors such as redirects, context destroyed, etc
1107+
log.error('goto hook error', e)
10941108
}
10951109

10961110
return response
@@ -1182,8 +1196,9 @@ addHook({
11821196
}
11831197
}
11841198
}
1185-
} catch {
1199+
} catch (e) {
11861200
// ignore errors
1201+
log.error('afterEach hook error', e)
11871202
}
11881203
},
11891204
title: 'afterEach hook',

packages/datadog-instrumentations/src/selenium.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { addHook, channel } = require('./helpers/instrument')
44
const shimmer = require('../../datadog-shimmer')
5+
const { getEnvironmentVariable } = require('../../dd-trace/src/config-helper')
56

67
const ciSeleniumDriverGetStartCh = channel('ci:selenium:driver:get')
78

@@ -15,7 +16,8 @@ if (window.DD_RUM && window.DD_RUM.stopSession) {
1516
`
1617
const IS_RUM_ACTIVE_SCRIPT = 'return !!window.DD_RUM'
1718

18-
const DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS = 500
19+
const DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS =
20+
Number(getEnvironmentVariable('DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS')) || 500
1921
const DD_CIVISIBILITY_TEST_EXECUTION_ID_COOKIE_NAME = 'datadog-ci-visibility-test-execution-id'
2022

2123
// TODO: can we increase the supported version range?

packages/dd-trace/src/supported-configurations.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"DD_CIVISIBILITY_GIT_UPLOAD_ENABLED": ["A"],
5151
"DD_CIVISIBILITY_IMPACTED_TESTS_DETECTION_ENABLED": ["A"],
5252
"DD_CIVISIBILITY_ITR_ENABLED": ["A"],
53+
"DD_CIVISIBILITY_RUM_FLUSH_WAIT_MILLIS": ["A"],
5354
"DD_CIVISIBILITY_MANUAL_API_ENABLED": ["A"],
5455
"DD_CIVISIBILITY_TEST_COMMAND": ["A"],
5556
"DD_CIVISIBILITY_TEST_MODULE_ID": ["A"],

0 commit comments

Comments
 (0)