diff --git a/packages/datadog-instrumentations/src/jest.js b/packages/datadog-instrumentations/src/jest.js index 2b9b8d6bd2b..16874cfa055 100644 --- a/packages/datadog-instrumentations/src/jest.js +++ b/packages/datadog-instrumentations/src/jest.js @@ -313,11 +313,19 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) { const asyncResource = asyncResources.get(event.test) if (status === 'fail') { - log.warn('Setting probe because test failed') + const shouldSetProbe = this.isDiEnabled && willBeRetried && numTestExecutions === 1 + log.warn( + `Setting probe because test failed: ${getJestTestName(event.test)}, +num test executions: ${numTestExecutions} +will be retried: ${willBeRetried} +is di enabled: ${this.isDiEnabled} +should set probe: ${shouldSetProbe} +` + ) asyncResource.runInAsyncScope(() => { testErrCh.publish({ error: formatJestError(event.test.errors[0]), - shouldSetProbe: this.isDiEnabled && willBeRetried && numTestExecutions === 1, + shouldSetProbe, promises }) }) @@ -333,7 +341,9 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) { }) } + const shouldRemoveProbe = this.isDiEnabled && !willBeRetried asyncResource.runInAsyncScope(() => { + log.warn(`shouldRemoveProbe: ${shouldRemoveProbe}`) testFinishCh.publish({ status, testStartLine: getTestLineStart(event.test.asyncError, this.testSuite), diff --git a/packages/datadog-plugin-jest/src/index.js b/packages/datadog-plugin-jest/src/index.js index 667e8569782..98b0d2318d1 100644 --- a/packages/datadog-plugin-jest/src/index.js +++ b/packages/datadog-plugin-jest/src/index.js @@ -24,7 +24,8 @@ const { TEST_IS_RUM_ACTIVE, TEST_BROWSER_DRIVER, getFormattedError, - TEST_RETRY_REASON + TEST_RETRY_REASON, + TEST_NAME } = require('../../dd-trace/src/plugins/util/test') const { COMPONENT } = require('../../dd-trace/src/constants') const id = require('../../dd-trace/src/id') @@ -348,6 +349,7 @@ class JestPlugin extends CiPlugin { finishAllTraceSpans(span) this.activeTestSpan = null if (shouldRemoveProbe && this.runningTestProbeId) { + log.warn(`ci:jest:test:finish removing probe ${spanTags[TEST_NAME]}`) promises.isProbeRemoved = withTimeout(this.removeDiProbe(this.runningTestProbeId), 2000) this.runningTestProbeId = null }