Skip to content
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
21 changes: 9 additions & 12 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,31 @@ 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

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
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 26 additions & 12 deletions integration-tests/ci-visibility.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
Expand All @@ -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)

Expand Down Expand Up @@ -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
)
Expand All @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 6 additions & 1 deletion packages/datadog-instrumentations/src/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
19 changes: 8 additions & 11 deletions packages/datadog-plugin-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 10 additions & 13 deletions packages/datadog-plugin-jest/test/circus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions packages/datadog-plugin-mocha/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions packages/dd-trace/src/exporters/common/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`
}
Expand Down
Loading