Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci-visibility] Link CI Visibility and RUM #1706

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/datadog-plugin-cypress/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
TEST_SUITE,
TEST_STATUS,
TEST_FRAMEWORK_VERSION,
TEST_IS_RUM_ACTIVE,
getTestEnvironmentMetadata,
CI_APP_ORIGIN,
getTestParentSpan
Expand Down Expand Up @@ -66,15 +67,18 @@ module.exports = (on, config) => {
}
})
}
return null
return activeSpan ? activeSpan._spanContext._traceId.toString(10) : null
},
'dd:afterEach': (test) => {
const { state, error } = test
const { state, error, isRUMActive } = test
if (activeSpan) {
activeSpan.setTag(TEST_STATUS, CYPRESS_STATUS_TO_TEST_STATUS[state])
if (error) {
activeSpan.setTag('error', error)
}
if (isRUMActive) {
activeSpan.setTag(TEST_IS_RUM_ACTIVE, true)
}
activeSpan.finish()
}
activeSpan = null
Expand Down
27 changes: 21 additions & 6 deletions packages/datadog-plugin-cypress/src/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@ beforeEach(() => {
cy.task('dd:beforeEach', {
testName: Cypress.mocha.getRunner().suite.ctx.currentTest.fullTitle(),
testSuite: Cypress.mocha.getRootSuite().file
}).then(traceId => {
Cypress.env('traceId', traceId)
})
})

after(() => {
cy.window().then(win => {
win.dispatchEvent(new Event('beforeunload'))
})
})


afterEach(() => {
const currentTest = Cypress.mocha.getRunner().suite.ctx.currentTest
cy.task('dd:afterEach', {
testName: currentTest.fullTitle(),
testSuite: Cypress.mocha.getRootSuite().file,
state: currentTest.state,
error: currentTest.err
cy.window().then(win => {
const currentTest = Cypress.mocha.getRunner().suite.ctx.currentTest
const testInfo = {
testName: currentTest.fullTitle(),
testSuite: Cypress.mocha.getRootSuite().file,
state: currentTest.state,
error: currentTest.err,
}
if (win.DD_RUM) {
testInfo.isRUMActive = true
}
cy.task('dd:afterEach', testInfo)
})
})
14 changes: 13 additions & 1 deletion packages/datadog-plugin-cypress/test/app/app-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,17 @@ const http = require('http')
module.exports = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html')
res.writeHead(200)
res.end(`<html><body><div class="hello-world">Hello World</div></body></html>`)
res.end(`
<!DOCTYPE html>
<html>
<head>
<script>
window.DD_RUM=true
</script>
</head>
<body>
<div class="hello-world">Hello World</div>
</body>
</html>
`)
})
7 changes: 5 additions & 2 deletions packages/datadog-plugin-cypress/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
TEST_NAME,
TEST_SUITE,
TEST_STATUS,
TEST_IS_RUM_ACTIVE,
CI_APP_ORIGIN,
ERROR_TYPE,
ERROR_MESSAGE,
Expand Down Expand Up @@ -62,7 +63,8 @@ describe('Plugin', () => {
[TEST_STATUS]: 'pass',
[TEST_SUITE]: 'cypress/integration/integration-test.js',
[TEST_TYPE]: 'test',
[ORIGIN_KEY]: CI_APP_ORIGIN
[ORIGIN_KEY]: CI_APP_ORIGIN,
[TEST_IS_RUM_ACTIVE]: 'true'
})
expect(testSpan.meta[TEST_FRAMEWORK_VERSION]).not.to.be.undefined
})
Expand All @@ -82,7 +84,8 @@ describe('Plugin', () => {
[TEST_SUITE]: 'cypress/integration/integration-test.js',
[TEST_TYPE]: 'test',
[ORIGIN_KEY]: CI_APP_ORIGIN,
[ERROR_TYPE]: 'AssertionError'
[ERROR_TYPE]: 'AssertionError',
[TEST_IS_RUM_ACTIVE]: 'true'
})
expect(testSpan.meta[ERROR_MESSAGE]).to.contain(
"expected '<div.hello-world>' to have text 'Bye World', but the text was 'Hello World'"
Expand Down
2 changes: 2 additions & 0 deletions packages/dd-trace/src/plugins/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TEST_SUITE = 'test.suite'
const TEST_STATUS = 'test.status'
const TEST_PARAMETERS = 'test.parameters'
const TEST_SKIP_REASON = 'test.skip_reason'
const TEST_IS_RUM_ACTIVE = 'test.is_rum_active'

const ERROR_TYPE = 'error.type'
const ERROR_MESSAGE = 'error.msg'
Expand All @@ -43,6 +44,7 @@ module.exports = {
TEST_STATUS,
TEST_PARAMETERS,
TEST_SKIP_REASON,
TEST_IS_RUM_ACTIVE,
ERROR_TYPE,
ERROR_MESSAGE,
ERROR_STACK,
Expand Down