From 92995957bc9173e2332dd117067dcba7935ab4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Thu, 2 Feb 2023 18:37:17 +0100 Subject: [PATCH 1/8] [ci-visibility] Keep functionality with `.asyncResource` (#2756) --- packages/datadog-instrumentations/src/mocha.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/datadog-instrumentations/src/mocha.js b/packages/datadog-instrumentations/src/mocha.js index febe1ed45ea..4a7ce7c1e0e 100644 --- a/packages/datadog-instrumentations/src/mocha.js +++ b/packages/datadog-instrumentations/src/mocha.js @@ -418,8 +418,13 @@ addHook({ // we store the original function, not to lose it originalFns.set(newFn, this.fn) - this.fn = newFn + + // Temporarily keep functionality when .asyncResource is removed from node + // in https://github.com/nodejs/node/pull/46432 + if (!this.fn.asyncResource) { + this.fn.asyncResource = asyncResource + } } } From 87959ba6e9c85ef0d01b249abd0d304947a39fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Thu, 2 Feb 2023 19:42:27 +0100 Subject: [PATCH 2/8] Parallelize integration tests (#2762) --- .github/workflows/project.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml index 7f640835a94..53fdcc40686 100644 --- a/.github/workflows/project.yml +++ b/.github/workflows/project.yml @@ -13,26 +13,23 @@ concurrency: jobs: integration: + strategy: + matrix: + version: [12, 14, 16, 18, latest] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/node/setup - run: yarn install - - uses: ./.github/actions/node/12 - - run: yarn test:integration - - uses: ./.github/actions/node/14 - - run: yarn test:integration - - uses: ./.github/actions/node/16 - - run: yarn test:integration - - uses: ./.github/actions/node/18 - - run: yarn test:integration - - uses: ./.github/actions/node/latest + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.version }} - run: yarn test:integration lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/node/setup - run: yarn install - run: yarn lint @@ -40,7 +37,7 @@ jobs: typescript: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: ./.github/actions/node/setup - run: yarn install - run: yarn type:test From 91d68bd7ddeb76ce4bd2e67e087ab07244e5aff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Thu, 2 Feb 2023 19:43:13 +0100 Subject: [PATCH 3/8] Fix log error message when intake request fails (#2757) --- .../dd-trace/src/exporters/common/request.js | 13 ++++++++--- .../exporters/git/git_metadata.spec.js | 2 +- .../test/exporters/common/request.spec.js | 22 ++++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/dd-trace/src/exporters/common/request.js b/packages/dd-trace/src/exporters/common/request.js index c79dbe4da45..5cdea0c82f6 100644 --- a/packages/dd-trace/src/exporters/common/request.js +++ b/packages/dd-trace/src/exporters/common/request.js @@ -98,9 +98,16 @@ function request (data, options, callback) { if (res.statusCode >= 200 && res.statusCode <= 299) { callback(null, responseData, res.statusCode) } else { - const fullUrl = `${options.url || options.hostname || `localhost:${options.port}`}${options.path}` - // eslint-disable-next-line - let errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.` + let errorMessage = '' + try { + const fullUrl = new URL( + options.path, + options.url || options.hostname || `http://localhost:${options.port}` + ).href + errorMessage = `Error from ${fullUrl}: ${res.statusCode} ${http.STATUS_CODES[res.statusCode]}.` + } catch (e) { + // ignore error + } if (responseData) { errorMessage += ` Response from the endpoint: "${responseData}"` } diff --git a/packages/dd-trace/test/ci-visibility/exporters/git/git_metadata.spec.js b/packages/dd-trace/test/ci-visibility/exporters/git/git_metadata.spec.js index 7f1da8c0162..67621098e61 100644 --- a/packages/dd-trace/test/ci-visibility/exporters/git/git_metadata.spec.js +++ b/packages/dd-trace/test/ci-visibility/exporters/git/git_metadata.spec.js @@ -91,7 +91,7 @@ describe('git_metadata', () => { gitMetadata.sendGitMetadata(new URL('https://api.test.com'), false, (err) => { // eslint-disable-next-line - expect(err.message).to.contain('Error fetching commits to exclude: Error from https://api.test.com//api/v2/git/repository/search_commits: 404 Not Found. Response from the endpoint: "Not found SHA"') + expect(err.message).to.contain('Error fetching commits to exclude: Error from https://api.test.com/api/v2/git/repository/search_commits: 404 Not Found. Response from the endpoint: "Not found SHA"') // to check that it is not called expect(scope.isDone()).to.be.false expect(scope.pendingMocks()).to.contain('POST https://api.test.com:443/api/v2/git/repository/packfile') diff --git a/packages/dd-trace/test/exporters/common/request.spec.js b/packages/dd-trace/test/exporters/common/request.spec.js index 10928195b61..5f275bbb1e8 100644 --- a/packages/dd-trace/test/exporters/common/request.spec.js +++ b/packages/dd-trace/test/exporters/common/request.spec.js @@ -79,17 +79,33 @@ describe('request', function () { }) it('should handle an http error', done => { - nock('http://localhost:80') + nock('http://localhost:8080') + .put('/path') + .reply(400) + + request(Buffer.from(''), { + path: '/path', + method: 'PUT', + port: 8080 + }, err => { + expect(err).to.be.instanceof(Error) + expect(err.message).to.equal('Error from http://localhost:8080/path: 400 Bad Request.') + done() + }) + }) + + it('should handle an http error when url is specified', done => { + nock('http://api.datadog.com') .put('/path') .reply(400) request(Buffer.from(''), { path: '/path', method: 'PUT', - port: 80 + url: new URL('http://api.datadog.com/') }, err => { expect(err).to.be.instanceof(Error) - expect(err.message).to.equal('Error from localhost:80/path: 400 Bad Request.') + expect(err.message).to.equal('Error from http://api.datadog.com/path: 400 Bad Request.') done() }) }) From 07e2dfd5faa7bbe6faf9b5ef336123192de9604e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Fri, 3 Feb 2023 09:36:16 +0100 Subject: [PATCH 4/8] Add dev release line on merge to master (#2755) --- .github/workflows/release-dev.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/release-dev.yml diff --git a/.github/workflows/release-dev.yml b/.github/workflows/release-dev.yml new file mode 100644 index 00000000000..173b0549371 --- /dev/null +++ b/.github/workflows/release-dev.yml @@ -0,0 +1,25 @@ +name: Release dev release line + +on: + push: + branches: + - master + +jobs: + dev_release: + runs-on: ubuntu-latest + environment: npm + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + registry-url: 'https://registry.npmjs.org' + - run: yarn install + - id: pkg + run: | + content=`cat ./package.json | tr '\n' ' '` + echo "::set-output name=json::$content" + - run: npm version --no-git-tag-version ${{ fromJson(steps.pkg.outputs.json).version }}-$(git rev-parse --short HEAD)+${{ github.run_id }}.${{ github.run_attempt }} + - run: npm publish --tag dev From d087916687fadc84a0176f839fb7eedb594e3e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Antonio=20Fern=C3=A1ndez=20de=20Alba?= Date: Fri, 3 Feb 2023 16:38:59 +0100 Subject: [PATCH 5/8] [ci-visibility] Update ITR tags (#2767) --- integration-tests/ci-visibility.spec.js | 38 +++++++++++++------ packages/datadog-plugin-jest/src/index.js | 19 ++++------ .../datadog-plugin-jest/test/circus.spec.js | 23 +++++------ packages/datadog-plugin-mocha/src/index.js | 17 +++++---- packages/dd-trace/src/plugins/util/test.js | 26 +++++++++++++ 5 files changed, 79 insertions(+), 44 deletions(-) diff --git a/integration-tests/ci-visibility.spec.js b/integration-tests/ci-visibility.spec.js index cdf21678085..de46a825481 100644 --- a/integration-tests/ci-visibility.spec.js +++ b/integration-tests/ci-visibility.spec.js @@ -17,6 +17,8 @@ const { FakeCiVisIntake } = require('./ci-visibility-intake') const { TEST_SESSION_CODE_COVERAGE_ENABLED, TEST_SESSION_ITR_SKIPPING_ENABLED, + TEST_MODULE_CODE_COVERAGE_ENABLED, + TEST_MODULE_ITR_SKIPPING_ENABLED, TEST_ITR_TESTS_SKIPPED } = require('../packages/dd-trace/src/plugins/util/test') @@ -227,7 +229,7 @@ testFrameworks.forEach(({ assert.propertyVal(packfileRequest.headers, 'dd-api-key', '1') const eventTypes = eventsRequest.payload.events.map(event => event.type) - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -276,7 +278,7 @@ testFrameworks.forEach(({ assert.exists(coveragePayload.content.coverages[0].test_suite_id) const eventTypes = eventsRequest.payload.events.map(event => event.type) - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -307,11 +309,15 @@ testFrameworks.forEach(({ receiver.assertPayloadReceived(({ headers, payload }) => { assert.propertyVal(headers, 'dd-api-key', '1') const eventTypes = payload.events.map(event => event.type) - assert.includeMembers(eventTypes, ['test', 'test_session_end', 'test_suite_end']) + assert.includeMembers(eventTypes, ['test', 'test_session_end', 'test_module_end', 'test_suite_end']) const testSession = payload.events.find(event => event.type === 'test_session_end').content assert.propertyVal(testSession.meta, TEST_ITR_TESTS_SKIPPED, 'false') assert.propertyVal(testSession.meta, TEST_SESSION_CODE_COVERAGE_ENABLED, 'false') assert.propertyVal(testSession.meta, TEST_SESSION_ITR_SKIPPING_ENABLED, 'false') + const testModule = payload.events.find(event => event.type === 'test_module_end').content + assert.propertyVal(testModule.meta, TEST_ITR_TESTS_SKIPPED, 'false') + assert.propertyVal(testModule.meta, TEST_MODULE_CODE_COVERAGE_ENABLED, 'false') + assert.propertyVal(testModule.meta, TEST_MODULE_ITR_SKIPPING_ENABLED, 'false') }, ({ url }) => url === '/api/v2/citestcycle').then(() => done()).catch(done) childProcess = exec( @@ -354,7 +360,7 @@ testFrameworks.forEach(({ event.content.resource === 'ci-visibility/test/ci-visibility-test.js.ci visibility can report tests' ) assert.notExists(skippedTest) - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -363,6 +369,10 @@ testFrameworks.forEach(({ assert.propertyVal(testSession.meta, TEST_ITR_TESTS_SKIPPED, 'true') assert.propertyVal(testSession.meta, TEST_SESSION_CODE_COVERAGE_ENABLED, 'true') assert.propertyVal(testSession.meta, TEST_SESSION_ITR_SKIPPING_ENABLED, 'true') + const testModule = eventsRequest.payload.events.find(event => event.type === 'test_module_end').content + assert.propertyVal(testModule.meta, TEST_ITR_TESTS_SKIPPED, 'true') + assert.propertyVal(testModule.meta, TEST_MODULE_CODE_COVERAGE_ENABLED, 'true') + assert.propertyVal(testModule.meta, TEST_MODULE_ITR_SKIPPING_ENABLED, 'true') done() }).catch(done) @@ -394,7 +404,7 @@ testFrameworks.forEach(({ assert.propertyVal(headers, 'dd-api-key', '1') const eventTypes = payload.events.map(event => event.type) // because they are not skipped - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -403,6 +413,10 @@ testFrameworks.forEach(({ assert.propertyVal(testSession.meta, TEST_ITR_TESTS_SKIPPED, 'false') assert.propertyVal(testSession.meta, TEST_SESSION_CODE_COVERAGE_ENABLED, 'true') assert.propertyVal(testSession.meta, TEST_SESSION_ITR_SKIPPING_ENABLED, 'true') + const testModule = payload.events.find(event => event.type === 'test_module_end').content + assert.propertyVal(testModule.meta, TEST_ITR_TESTS_SKIPPED, 'false') + assert.propertyVal(testModule.meta, TEST_MODULE_CODE_COVERAGE_ENABLED, 'true') + assert.propertyVal(testModule.meta, TEST_MODULE_ITR_SKIPPING_ENABLED, 'true') }, ({ url }) => url === '/api/v2/citestcycle').then(() => done()).catch(done) childProcess = exec( @@ -436,7 +450,7 @@ testFrameworks.forEach(({ assert.propertyVal(headers, 'dd-api-key', '1') const eventTypes = payload.events.map(event => event.type) // because they are not skipped - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -520,7 +534,7 @@ testFrameworks.forEach(({ assert.propertyVal(packfileRequest.headers, 'x-datadog-evp-subdomain', 'api') const eventTypes = eventsRequest.payload.events.map(event => event.type) - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -570,7 +584,7 @@ testFrameworks.forEach(({ assert.exists(coveragePayload.content.coverages[0].test_suite_id) const eventTypes = eventsRequest.payload.events.map(event => event.type) - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -602,7 +616,7 @@ testFrameworks.forEach(({ assert.notProperty(headers, 'dd-api-key') assert.propertyVal(headers, 'x-datadog-evp-subdomain', 'citestcycle-intake') const eventTypes = payload.events.map(event => event.type) - assert.includeMembers(eventTypes, ['test', 'test_session_end', 'test_suite_end']) + assert.includeMembers(eventTypes, ['test', 'test_session_end', 'test_module_end', 'test_suite_end']) }, ({ url }) => url === '/evp_proxy/v2/api/v2/citestcycle').then(() => done()).catch(done) childProcess = exec( @@ -651,7 +665,7 @@ testFrameworks.forEach(({ event.content.resource === 'ci-visibility/test/ci-visibility-test.js.ci visibility can report tests' ) assert.notExists(skippedTest) - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -679,7 +693,7 @@ testFrameworks.forEach(({ assert.propertyVal(headers, 'x-datadog-evp-subdomain', 'citestcycle-intake') const eventTypes = payload.events.map(event => event.type) // because they are not skipped - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) @@ -715,7 +729,7 @@ testFrameworks.forEach(({ assert.propertyVal(headers, 'x-datadog-evp-subdomain', 'citestcycle-intake') const eventTypes = payload.events.map(event => event.type) // because they are not skipped - assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_session_end']) + assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end']) const numSuites = eventTypes.reduce( (acc, type) => type === 'test_suite_end' ? acc + 1 : acc, 0 ) diff --git a/packages/datadog-plugin-jest/src/index.js b/packages/datadog-plugin-jest/src/index.js index b43149c5b11..331623ab27f 100644 --- a/packages/datadog-plugin-jest/src/index.js +++ b/packages/datadog-plugin-jest/src/index.js @@ -10,16 +10,13 @@ const { getTestSessionCommonTags, getTestModuleCommonTags, getTestSuiteCommonTags, + addIntelligentTestRunnerSpanTags, TEST_PARAMETERS, getCodeOwnersFileEntries, TEST_SESSION_ID, TEST_MODULE_ID, TEST_SUITE_ID, TEST_COMMAND, - TEST_ITR_TESTS_SKIPPED, - TEST_SESSION_CODE_COVERAGE_ENABLED, - TEST_SESSION_ITR_SKIPPING_ENABLED, - TEST_CODE_COVERAGE_LINES_TOTAL, TEST_BUNDLE } = require('../../dd-trace/src/plugins/util/test') const { COMPONENT } = require('../../dd-trace/src/constants') @@ -83,14 +80,14 @@ class JestPlugin extends CiPlugin { testCodeCoverageLinesTotal }) => { this.testSessionSpan.setTag(TEST_STATUS, status) - this.testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false') - this.testSessionSpan.setTag(TEST_SESSION_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false') - this.testSessionSpan.setTag(TEST_SESSION_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false') - - if (testCodeCoverageLinesTotal !== undefined) { - this.testSessionSpan.setTag(TEST_CODE_COVERAGE_LINES_TOTAL, testCodeCoverageLinesTotal) - } this.testModuleSpan.setTag(TEST_STATUS, status) + + addIntelligentTestRunnerSpanTags( + this.testSessionSpan, + this.testModuleSpan, + { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled, testCodeCoverageLinesTotal } + ) + this.testModuleSpan.finish() this.testSessionSpan.finish() finishAllTraceSpans(this.testSessionSpan) diff --git a/packages/datadog-plugin-jest/test/circus.spec.js b/packages/datadog-plugin-jest/test/circus.spec.js index cf67a13c236..e19cd1dc5af 100644 --- a/packages/datadog-plugin-jest/test/circus.spec.js +++ b/packages/datadog-plugin-jest/test/circus.spec.js @@ -23,7 +23,8 @@ const { TEST_COMMAND, TEST_SUITE_ID, TEST_SESSION_ID, - TEST_MODULE_ID + TEST_MODULE_ID, + TEST_BUNDLE } = require('../../dd-trace/src/plugins/util/test') const { version: ddTraceVersion } = require('../../../package.json') @@ -324,11 +325,6 @@ describe('Plugin', function () { status: 'pass', spanResourceMatch: /^test_session/ }, - { - type: 'test_module_end', - status: 'pass', - spanResourceMatch: /^test_module/ - }, { type: 'test_suite_end', status: 'pass', @@ -356,21 +352,21 @@ describe('Plugin', function () { const span = events.find(event => event.type === type).content expect(span.meta[TEST_STATUS]).to.equal(status) expect(span.meta[COMPONENT]).to.equal('jest') - if (type === 'test_session_end') { + if (type === 'test_session_end') { // session and module come in the same payload expect(span.meta[TEST_COMMAND]).not.to.equal(undefined) expect(span[TEST_SUITE_ID]).to.equal(undefined) expect(span[TEST_MODULE_ID]).to.equal(undefined) expect(span[TEST_SESSION_ID]).not.to.equal(undefined) - } - if (type === 'test_module_id') { - expect(span.meta[TEST_COMMAND]).not.to.equal(undefined) - expect(span[TEST_SUITE_ID]).to.equal(undefined) - expect(span[TEST_SESSION_ID]).not.to.equal(undefined) - expect(span[TEST_MODULE_ID]).not.to.equal(undefined) + const testModuleSpan = events.find(event => event.type === 'test_module_end').content + expect(testModuleSpan[TEST_SUITE_ID]).to.equal(undefined) + expect(testModuleSpan[TEST_MODULE_ID]).not.to.equal(undefined) + expect(testModuleSpan[TEST_SESSION_ID]).not.to.equal(undefined) + expect(testModuleSpan.meta[TEST_BUNDLE]).not.to.equal(undefined) } if (type === 'test_suite_end') { expect(span.meta[TEST_SUITE]).to.equal(suite) expect(span.meta[TEST_COMMAND]).not.to.equal(undefined) + expect(span.meta[TEST_BUNDLE]).not.to.equal(undefined) expect(span[TEST_SUITE_ID]).not.to.equal(undefined) expect(span[TEST_SESSION_ID]).not.to.equal(undefined) expect(span[TEST_MODULE_ID]).not.to.equal(undefined) @@ -379,6 +375,7 @@ describe('Plugin', function () { expect(span.meta[TEST_SUITE]).to.equal(suite) expect(span.meta[TEST_NAME]).to.equal(name) expect(span.meta[TEST_COMMAND]).not.to.equal(undefined) + expect(span.meta[TEST_BUNDLE]).not.to.equal(undefined) expect(span[TEST_SUITE_ID]).not.to.equal(undefined) expect(span[TEST_SESSION_ID]).not.to.equal(undefined) expect(span[TEST_MODULE_ID]).not.to.equal(undefined) diff --git a/packages/datadog-plugin-mocha/src/index.js b/packages/datadog-plugin-mocha/src/index.js index c07249d27ac..e69a7eeea10 100644 --- a/packages/datadog-plugin-mocha/src/index.js +++ b/packages/datadog-plugin-mocha/src/index.js @@ -13,14 +13,12 @@ const { getTestSessionCommonTags, getTestModuleCommonTags, getTestSuiteCommonTags, + addIntelligentTestRunnerSpanTags, TEST_SUITE_ID, TEST_SESSION_ID, TEST_MODULE_ID, TEST_BUNDLE, - TEST_COMMAND, - TEST_ITR_TESTS_SKIPPED, - TEST_SESSION_CODE_COVERAGE_ENABLED, - TEST_SESSION_ITR_SKIPPING_ENABLED + TEST_COMMAND } = require('../../dd-trace/src/plugins/util/test') const { COMPONENT } = require('../../dd-trace/src/constants') @@ -156,11 +154,14 @@ class MochaPlugin extends CiPlugin { if (this.testSessionSpan) { const { isSuitesSkippingEnabled, isCodeCoverageEnabled } = this.itrConfig || {} this.testSessionSpan.setTag(TEST_STATUS, status) - this.testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false') - this.testSessionSpan.setTag(TEST_SESSION_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false') - this.testSessionSpan.setTag(TEST_SESSION_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false') - this.testModuleSpan.setTag(TEST_STATUS, status) + + addIntelligentTestRunnerSpanTags( + this.testSessionSpan, + this.testModuleSpan, + { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled } + ) + this.testModuleSpan.finish() this.testSessionSpan.finish() finishAllTraceSpans(this.testSessionSpan) diff --git a/packages/dd-trace/src/plugins/util/test.js b/packages/dd-trace/src/plugins/util/test.js index 2e6af0ba56d..45ee493dfb1 100644 --- a/packages/dd-trace/src/plugins/util/test.js +++ b/packages/dd-trace/src/plugins/util/test.js @@ -50,6 +50,8 @@ const JEST_TEST_RUNNER = 'test.jest.test_runner' const TEST_ITR_TESTS_SKIPPED = '_dd.ci.itr.tests_skipped' const TEST_SESSION_ITR_SKIPPING_ENABLED = 'test_session.itr.tests_skipping.enabled' const TEST_SESSION_CODE_COVERAGE_ENABLED = 'test_session.code_coverage.enabled' +const TEST_MODULE_ITR_SKIPPING_ENABLED = 'test_module.itr.tests_skipping.enabled' +const TEST_MODULE_CODE_COVERAGE_ENABLED = 'test_module.code_coverage.enabled' const TEST_CODE_COVERAGE_LINES_TOTAL = 'test.codecov_lines_total' @@ -84,9 +86,13 @@ module.exports = { TEST_MODULE_ID, TEST_SUITE_ID, TEST_ITR_TESTS_SKIPPED, + TEST_BUNDLE, TEST_SESSION_ITR_SKIPPING_ENABLED, TEST_SESSION_CODE_COVERAGE_ENABLED, + TEST_MODULE_ITR_SKIPPING_ENABLED, + TEST_MODULE_CODE_COVERAGE_ENABLED, TEST_CODE_COVERAGE_LINES_TOTAL, + addIntelligentTestRunnerSpanTags, getCoveredFilenamesFromCoverage, resetCoverage, mergeCoverage, @@ -282,6 +288,26 @@ function getTestSuiteCommonTags (command, testFrameworkVersion, testSuite) { } } +function addIntelligentTestRunnerSpanTags ( + testSessionSpan, + testModuleSpan, + { isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled, testCodeCoverageLinesTotal } +) { + testSessionSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false') + testSessionSpan.setTag(TEST_SESSION_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false') + testSessionSpan.setTag(TEST_SESSION_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false') + + testModuleSpan.setTag(TEST_ITR_TESTS_SKIPPED, isSuitesSkipped ? 'true' : 'false') + testModuleSpan.setTag(TEST_MODULE_ITR_SKIPPING_ENABLED, isSuitesSkippingEnabled ? 'true' : 'false') + testModuleSpan.setTag(TEST_MODULE_CODE_COVERAGE_ENABLED, isCodeCoverageEnabled ? 'true' : 'false') + + // If suites have been skipped we don't want to report the total coverage, as it will be wrong + if (testCodeCoverageLinesTotal !== undefined && !isSuitesSkipped) { + testSessionSpan.setTag(TEST_CODE_COVERAGE_LINES_TOTAL, testCodeCoverageLinesTotal) + testModuleSpan.setTag(TEST_CODE_COVERAGE_LINES_TOTAL, testCodeCoverageLinesTotal) + } +} + function getCoveredFilenamesFromCoverage (coverage) { const coverageMap = istanbul.createCoverageMap(coverage) From 577b8b1043a8dd5683df9a8b2d6e5231606eced7 Mon Sep 17 00:00:00 2001 From: Igor Unanua Date: Mon, 6 Feb 2023 10:25:47 +0100 Subject: [PATCH 6/8] Check if channel has subscribers before call unsubscribe (#2770) --- packages/dd-trace/src/log/writer.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/dd-trace/src/log/writer.js b/packages/dd-trace/src/log/writer.js index 8fbe299b745..bd0bfb41fa0 100644 --- a/packages/dd-trace/src/log/writer.js +++ b/packages/dd-trace/src/log/writer.js @@ -23,10 +23,18 @@ function withNoop (fn) { } function unsubscribeAll () { - debugChannel.unsubscribe(onDebug) - infoChannel.unsubscribe(onInfo) - warnChannel.unsubscribe(onWarn) - errorChannel.unsubscribe(onError) + if (debugChannel.hasSubscribers) { + debugChannel.unsubscribe(onDebug) + } + if (infoChannel.hasSubscribers) { + infoChannel.unsubscribe(onInfo) + } + if (warnChannel.hasSubscribers) { + warnChannel.unsubscribe(onWarn) + } + if (errorChannel.hasSubscribers) { + errorChannel.unsubscribe(onError) + } } function toggleSubscription (enable) { From f14cfd725bc4963fedb4717fce83bf7abc06785a Mon Sep 17 00:00:00 2001 From: mehulsonowal <46061187+mehulsonowal@users.noreply.github.com> Date: Mon, 6 Feb 2023 09:48:04 -0500 Subject: [PATCH 7/8] add missing telemetry host data (#2682) * add os, kernel, architecture fields * test host obj * Update packages/dd-trace/src/telemetry/index.js Co-authored-by: simon-id * Update packages/dd-trace/src/telemetry/index.js Co-authored-by: simon-id * Update packages/dd-trace/src/telemetry/index.js Co-authored-by: simon-id * Update packages/dd-trace/src/telemetry/index.js Co-authored-by: simon-id * fix lint issues * Update packages/dd-trace/test/telemetry/index.spec.js Co-authored-by: simon-id * Update packages/dd-trace/src/telemetry/index.js Co-authored-by: simon-id --------- Co-authored-by: simon-id --- packages/dd-trace/src/telemetry/index.js | 25 +++++++++++- .../dd-trace/test/telemetry/index.spec.js | 38 ++++++++++++------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/packages/dd-trace/src/telemetry/index.js b/packages/dd-trace/src/telemetry/index.js index ad08bdc5dec..76ef7623943 100644 --- a/packages/dd-trace/src/telemetry/index.js +++ b/packages/dd-trace/src/telemetry/index.js @@ -1,7 +1,6 @@ 'use strict' const tracerVersion = require('../../../../package.json').version -const containerId = require('../exporters/common/docker').id() const os = require('os') const dependencies = require('./dependencies') const { sendData } = require('./send-data') @@ -76,9 +75,31 @@ function createAppObject () { } function createHostObject () { + const osName = os.type() + + if (osName === 'Linux' || osName === 'Darwin') { + return { + hostname: os.hostname(), + os: osName, + architecture: os.arch(), + kernel_version: os.version(), + kernel_release: os.release(), + kernel_name: osName + } + } + + if (osName === 'Windows_NT') { + return { + hostname: os.hostname(), + os: osName, + architecture: os.arch(), + os_version: os.version() + } + } + return { hostname: os.hostname(), // TODO is this enough? - container_id: containerId + os: osName } } diff --git a/packages/dd-trace/test/telemetry/index.spec.js b/packages/dd-trace/test/telemetry/index.spec.js index 10bb5a044bf..4be179f6276 100644 --- a/packages/dd-trace/test/telemetry/index.spec.js +++ b/packages/dd-trace/test/telemetry/index.spec.js @@ -5,6 +5,7 @@ const proxyquire = require('proxyquire') const http = require('http') const { once } = require('events') const { storage } = require('../../../datadog-core') +const os = require('os') let traceAgent @@ -46,11 +47,6 @@ describe('telemetry', () => { id () { return 'test docker id' } - }, - os: { - hostname () { - return 'test hostname' - } } }) @@ -178,11 +174,6 @@ describe('telemetry with interval change', () => { return 'test docker id' } }, - os: { - hostname () { - return 'test hostname' - } - }, './send-data': { sendData: () => {} } @@ -229,6 +220,28 @@ async function testSeq (seqId, reqType, validatePayload) { 'dd-telemetry-api-version': 'v1', 'dd-telemetry-request-type': reqType }) + const osName = os.type() + let host = { + hostname: os.hostname(), + os: osName + } + if (osName === 'Linux' || osName === 'Darwin') { + host = { + hostname: os.hostname(), + os: osName, + architecture: os.arch(), + kernel_version: os.version(), + kernel_release: os.release(), + kernel_name: osName + } + } else if (osName === 'Windows_NT') { + host = { + hostname: os.hostname(), + os: osName, + os_version: os.version(), + architecture: os.arch() + } + } expect(req.body).to.deep.include({ api_version: 'v1', request_type: reqType, @@ -242,10 +255,7 @@ async function testSeq (seqId, reqType, validatePayload) { language_name: 'nodejs', language_version: process.versions.node }, - host: { - hostname: 'test hostname', - container_id: 'test docker id' - } + host }) expect([1, 0, -1].includes(Math.floor(Date.now() / 1000) - req.body.tracer_time)).to.be.true From aba0e4f8dcb42ef2e879f68dc9ab3cb34531e776 Mon Sep 17 00:00:00 2001 From: Igor Unanua Date: Mon, 6 Feb 2023 17:56:08 +0100 Subject: [PATCH 8/8] v2.26.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 76cb6edf746..04568f97cdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dd-trace", - "version": "2.26.1", + "version": "2.26.2", "description": "Datadog APM tracing client for JavaScript", "main": "index.js", "typings": "index.d.ts",