Skip to content

Commit

Permalink
[ci-visibility] Fix error in test fingerprint calculation due to `tes…
Browse files Browse the repository at this point in the history
…t.bundle` (#2880)
  • Loading branch information
juan-fernandez committed Mar 28, 2023
1 parent dd7ed1e commit 43b4046
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/datadog-plugin-cucumber/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class CucumberPlugin extends CiPlugin {
const testSuiteMetadata = getTestSuiteCommonTags(
this.command,
this.frameworkVersion,
getTestSuitePath(testSuiteFullPath, this.sourceRoot)
getTestSuitePath(testSuiteFullPath, this.sourceRoot),
'cucumber'
)
this.testSuiteSpan = this.tracer.startSpan('cucumber.test_suite', {
childOf: this.testModuleSpan,
Expand Down
10 changes: 6 additions & 4 deletions packages/datadog-plugin-cypress/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
TEST_SESSION_ID,
TEST_COMMAND,
TEST_BUNDLE,
TEST_MODULE,
finishAllTraceSpans
} = require('../../dd-trace/src/plugins/util/test')

Expand Down Expand Up @@ -95,8 +96,8 @@ module.exports = (on, config) => {
command = getCypressCommand(details)
frameworkVersion = getCypressVersion(details)

const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion)
const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion)
const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion, 'cypress')
const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion, 'cypress')

testSessionSpan = tracer.startSpan('cypress.test_session', {
childOf,
Expand Down Expand Up @@ -137,7 +138,7 @@ module.exports = (on, config) => {
if (testSuiteSpan) {
return null
}
const testSuiteSpanMetadata = getTestSuiteCommonTags(command, frameworkVersion, suite)
const testSuiteSpanMetadata = getTestSuiteCommonTags(command, frameworkVersion, suite, 'cypress')
testSuiteSpan = tracer.startSpan('cypress.test_suite', {
childOf: testModuleSpan,
tags: {
Expand Down Expand Up @@ -167,7 +168,8 @@ module.exports = (on, config) => {
[TEST_COMMAND]: command,
[TEST_MODULE_ID]: testModuleId,
[TEST_COMMAND]: command,
[TEST_BUNDLE]: command
[TEST_BUNDLE]: 'cypress',
[TEST_MODULE]: 'cypress'
}

const {
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class JestPlugin extends CiPlugin {
'x-datadog-parent-id': testModuleId
})

const testSuiteMetadata = getTestSuiteCommonTags(testCommand, frameworkVersion, testSuite)
const testSuiteMetadata = getTestSuiteCommonTags(testCommand, frameworkVersion, testSuite, 'jest')

this.testSuiteSpan = this.tracer.startSpan('jest.test_suite', {
childOf: testSessionSpanContext,
Expand Down
3 changes: 2 additions & 1 deletion packages/datadog-plugin-mocha/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class MochaPlugin extends CiPlugin {
const testSuiteMetadata = getTestSuiteCommonTags(
this.command,
this.frameworkVersion,
getTestSuitePath(suite.file, this.sourceRoot)
getTestSuitePath(suite.file, this.sourceRoot),
'mocha'
)
const testSuiteSpan = this.tracer.startSpan('mocha.test_suite', {
childOf: this.testModuleSpan,
Expand Down
3 changes: 2 additions & 1 deletion packages/datadog-plugin-playwright/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class PlaywrightPlugin extends CiPlugin {
const testSuiteMetadata = getTestSuiteCommonTags(
this.command,
this.frameworkVersion,
testSuite
testSuite,
'playwright'
)

const testSuiteSpan = this.tracer.startSpan('playwright.test_suite', {
Expand Down
10 changes: 6 additions & 4 deletions packages/dd-trace/src/plugins/ci_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const {
TEST_MODULE_ID,
TEST_SESSION_ID,
TEST_COMMAND,
TEST_BUNDLE
TEST_BUNDLE,
TEST_MODULE
} = require('./util/test')
const Plugin = require('./plugin')
const { COMPONENT } = require('../constants')
Expand Down Expand Up @@ -50,8 +51,8 @@ module.exports = class CiPlugin extends Plugin {

this.addSub(`ci:${this.constructor.name}:session:start`, ({ command, frameworkVersion, rootDir }) => {
const childOf = getTestParentSpan(this.tracer)
const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion)
const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion)
const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion, this.constructor.name)
const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion, this.constructor.name)

this.command = command
this.frameworkVersion = frameworkVersion
Expand Down Expand Up @@ -129,7 +130,8 @@ module.exports = class CiPlugin extends Plugin {
[TEST_SUITE_ID]: testSuiteSpan.context().toSpanId(),
[TEST_SESSION_ID]: testSuiteSpan.context().toTraceId(),
[TEST_COMMAND]: testSuiteSpan.context()._tags[TEST_COMMAND],
[TEST_BUNDLE]: testSuiteSpan.context()._tags[TEST_COMMAND]
[TEST_BUNDLE]: this.constructor.name,
[TEST_MODULE]: this.constructor.name
}
if (testSuiteSpan.context()._parentId) {
suiteTags[TEST_MODULE_ID] = testSuiteSpan.context()._parentId.toString(10)
Expand Down
16 changes: 11 additions & 5 deletions packages/dd-trace/src/plugins/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const TEST_SOURCE_FILE = 'test.source.file'
const LIBRARY_VERSION = 'library_version'
const TEST_COMMAND = 'test.command'
const TEST_BUNDLE = 'test.bundle'
const TEST_MODULE = 'test.module'
const TEST_SESSION_ID = 'test_session_id'
const TEST_MODULE_ID = 'test_module_id'
const TEST_SUITE_ID = 'test_suite_id'
Expand Down Expand Up @@ -87,6 +88,7 @@ module.exports = {
TEST_SUITE_ID,
TEST_ITR_TESTS_SKIPPED,
TEST_BUNDLE,
TEST_MODULE,
TEST_SESSION_ITR_SKIPPING_ENABLED,
TEST_SESSION_CODE_COVERAGE_ENABLED,
TEST_MODULE_ITR_SKIPPING_ENABLED,
Expand Down Expand Up @@ -261,28 +263,32 @@ function getTestLevelCommonTags (command, testFrameworkVersion) {
}
}

function getTestSessionCommonTags (command, testFrameworkVersion) {
function getTestSessionCommonTags (command, testFrameworkVersion, testFramework) {
return {
[SPAN_TYPE]: 'test_session_end',
[RESOURCE_NAME]: `test_session.${command}`,
[TEST_BUNDLE]: testFramework,
[TEST_MODULE]: testFramework,
...getTestLevelCommonTags(command, testFrameworkVersion)
}
}

function getTestModuleCommonTags (command, testFrameworkVersion) {
function getTestModuleCommonTags (command, testFrameworkVersion, testFramework) {
return {
[SPAN_TYPE]: 'test_module_end',
[RESOURCE_NAME]: `test_module.${command}`,
[TEST_BUNDLE]: command,
[TEST_BUNDLE]: testFramework,
[TEST_MODULE]: testFramework,
...getTestLevelCommonTags(command, testFrameworkVersion)
}
}

function getTestSuiteCommonTags (command, testFrameworkVersion, testSuite) {
function getTestSuiteCommonTags (command, testFrameworkVersion, testSuite, testFramework) {
return {
[SPAN_TYPE]: 'test_suite_end',
[RESOURCE_NAME]: `test_suite.${testSuite}`,
[TEST_BUNDLE]: command,
[TEST_BUNDLE]: testFramework,
[TEST_MODULE]: testFramework,
[TEST_SUITE]: testSuite,
...getTestLevelCommonTags(command, testFrameworkVersion)
}
Expand Down

0 comments on commit 43b4046

Please sign in to comment.