Skip to content

Commit ac06a0b

Browse files
ericlazjuan-fernandez
authored andcommitted
[ci-visibility] Change test.type in browser tests (#3358)
* Add framework type checking * Improve code readability Co-authored-by: Juan Antonio Fernández de Alba <[email protected]> * Fix imports * Fix styling Co-authored-by: Juan Antonio Fernández de Alba <[email protected]> * Add cypress and playwright tests * Change browser conditions to detect all playwright instances * Fix include string * Fix some suites still being reported as test type --------- Co-authored-by: Juan Antonio Fernández de Alba <[email protected]>
1 parent facc347 commit ac06a0b

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

integration-tests/playwright/playwright.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313
} = require('../helpers')
1414
const { FakeCiVisIntake } = require('../ci-visibility-intake')
1515
const webAppServer = require('../ci-visibility/web-app-server')
16-
const { TEST_STATUS, TEST_SOURCE_START } = require('../../packages/dd-trace/src/plugins/util/test')
16+
const { TEST_STATUS, TEST_SOURCE_START, TEST_TYPE } = require('../../packages/dd-trace/src/plugins/util/test')
1717

1818
// TODO: remove when 2.x support is removed.
1919
// This is done because from playwright@>=1.22.0 node 12 is not supported
@@ -73,7 +73,8 @@ versions.forEach((version) => {
7373
assert.equal(testSessionEvent.content.meta[TEST_STATUS], 'fail')
7474
assert.include(testModuleEvent.content.resource, 'test_module.playwright test')
7575
assert.equal(testModuleEvent.content.meta[TEST_STATUS], 'fail')
76-
76+
assert.equal(testSessionEvent.content.meta[TEST_TYPE], 'browser')
77+
assert.equal(testModuleEvent.content.meta[TEST_TYPE], 'browser')
7778
assert.includeMembers(testSuiteEvents.map(suite => suite.content.resource), [
7879
'test_suite.todo-list-page-test.js',
7980
'test_suite.landing-page-test.js',

packages/datadog-plugin-cypress/src/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const CYPRESS_STATUS_TO_TEST_STATUS = {
3737
function getTestSpanMetadata (tracer, testName, testSuite, cypressConfig) {
3838
const childOf = getTestParentSpan(tracer)
3939

40-
const commonTags = getTestCommonTags(testName, testSuite, cypressConfig.version)
40+
const commonTags = getTestCommonTags(testName, testSuite, cypressConfig.version, TEST_FRAMEWORK_NAME)
4141

4242
return {
4343
childOf,

packages/datadog-plugin-cypress/test/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('Plugin', function () {
7676
[TEST_STATUS]: 'pass',
7777
[TEST_SUITE]: 'cypress/integration/integration-test.js',
7878
[TEST_SOURCE_FILE]: 'cypress/integration/integration-test.js',
79-
[TEST_TYPE]: 'test',
79+
[TEST_TYPE]: 'browser',
8080
[ORIGIN_KEY]: CI_APP_ORIGIN,
8181
[TEST_IS_RUM_ACTIVE]: 'true',
8282
[TEST_CODE_OWNERS]: JSON.stringify(['@datadog']),
@@ -101,7 +101,7 @@ describe('Plugin', function () {
101101
[TEST_STATUS]: 'fail',
102102
[TEST_SUITE]: 'cypress/integration/integration-test.js',
103103
[TEST_SOURCE_FILE]: 'cypress/integration/integration-test.js',
104-
[TEST_TYPE]: 'test',
104+
[TEST_TYPE]: 'browser',
105105
[ORIGIN_KEY]: CI_APP_ORIGIN,
106106
[ERROR_TYPE]: 'AssertionError',
107107
[TEST_IS_RUM_ACTIVE]: 'true',

packages/dd-trace/src/plugins/ci_plugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ module.exports = class CiPlugin extends Plugin {
111111
const childOf = getTestParentSpan(this.tracer)
112112

113113
let testTags = {
114-
...getTestCommonTags(testName, testSuite, this.frameworkVersion),
114+
...getTestCommonTags(
115+
testName,
116+
testSuite,
117+
this.frameworkVersion,
118+
this.constructor.id
119+
),
115120
[COMPONENT]: this.constructor.id,
116121
...extraTags
117122
}

packages/dd-trace/src/plugins/util/test.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ function getTestParametersString (parametersByTestName, testName) {
210210
}
211211
}
212212

213+
function getTestTypeFromFramework (testFramework) {
214+
if (testFramework === 'playwright' || testFramework === 'cypress') {
215+
return 'browser'
216+
}
217+
return 'test'
218+
}
219+
213220
function finishAllTraceSpans (span) {
214221
span.context()._trace.started.forEach(traceSpan => {
215222
if (traceSpan !== span) {
@@ -225,10 +232,10 @@ function getTestParentSpan (tracer) {
225232
})
226233
}
227234

228-
function getTestCommonTags (name, suite, version) {
235+
function getTestCommonTags (name, suite, version, testFramework) {
229236
return {
230237
[SPAN_TYPE]: 'test',
231-
[TEST_TYPE]: 'test',
238+
[TEST_TYPE]: getTestTypeFromFramework(testFramework),
232239
[SAMPLING_RULE_DECISION]: 1,
233240
[SAMPLING_PRIORITY]: AUTO_KEEP,
234241
[TEST_NAME]: name,
@@ -306,12 +313,12 @@ function getCodeOwnersForFilename (filename, entries) {
306313
return null
307314
}
308315

309-
function getTestLevelCommonTags (command, testFrameworkVersion) {
316+
function getTestLevelCommonTags (command, testFrameworkVersion, testFramework) {
310317
return {
311318
[TEST_FRAMEWORK_VERSION]: testFrameworkVersion,
312319
[LIBRARY_VERSION]: ddTraceVersion,
313320
[TEST_COMMAND]: command,
314-
[TEST_TYPE]: 'test'
321+
[TEST_TYPE]: getTestTypeFromFramework(testFramework)
315322
}
316323
}
317324

@@ -321,7 +328,7 @@ function getTestSessionCommonTags (command, testFrameworkVersion, testFramework)
321328
[RESOURCE_NAME]: `test_session.${command}`,
322329
[TEST_MODULE]: testFramework,
323330
[TEST_TOOLCHAIN]: getPkgManager(),
324-
...getTestLevelCommonTags(command, testFrameworkVersion)
331+
...getTestLevelCommonTags(command, testFrameworkVersion, testFramework)
325332
}
326333
}
327334

@@ -330,7 +337,7 @@ function getTestModuleCommonTags (command, testFrameworkVersion, testFramework)
330337
[SPAN_TYPE]: 'test_module_end',
331338
[RESOURCE_NAME]: `test_module.${command}`,
332339
[TEST_MODULE]: testFramework,
333-
...getTestLevelCommonTags(command, testFrameworkVersion)
340+
...getTestLevelCommonTags(command, testFrameworkVersion, testFramework)
334341
}
335342
}
336343

@@ -340,7 +347,7 @@ function getTestSuiteCommonTags (command, testFrameworkVersion, testSuite, testF
340347
[RESOURCE_NAME]: `test_suite.${testSuite}`,
341348
[TEST_MODULE]: testFramework,
342349
[TEST_SUITE]: testSuite,
343-
...getTestLevelCommonTags(command, testFrameworkVersion)
350+
...getTestLevelCommonTags(command, testFrameworkVersion, testFramework)
344351
}
345352
}
346353

0 commit comments

Comments
 (0)