dd-trace 5.0.0-pre-36f0d8e → 5.0.0-pre-733fec7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dd-trace",
3
- "version": "5.0.0-pre-36f0d8e",
3
+ "version": "5.0.0-pre-733fec7",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -31,6 +31,10 @@ const {
31
31
  getTestSuitePath
32
32
  } = require('../../dd-trace/src/plugins/util/test')
33
33
 
34
+ const isMarkedAsUnskippable = (pickle) => {
35
+ return !!pickle.tags.find(tag => tag.name === '@datadog:unskippable')
36
+ }
37
+
34
38
  // We'll preserve the original coverage here
35
39
  const originalCoverageMap = createCoverageMap()
36
40
 
@@ -39,6 +43,9 @@ const patched = new WeakSet()
39
43
 
40
44
  let pickleByFile = {}
41
45
  const pickleResultByFile = {}
46
+ let skippableSuites = []
47
+ let isForcedToRun = false
48
+ let isUnskippable = false
42
49
 
43
50
  function getSuiteStatusFromTestStatuses (testStatuses) {
44
51
  if (testStatuses.some(status => status === 'fail')) {
@@ -91,7 +98,11 @@ function wrapRun (pl, isLatestVersion) {
91
98
  const testSuiteFullPath = this.pickle.uri
92
99
 
93
100
  if (!pickleResultByFile[testSuiteFullPath]) { // first test in suite
94
- testSuiteStartCh.publish(testSuiteFullPath)
101
+ isUnskippable = isMarkedAsUnskippable(this.pickle)
102
+ const testSuitePath = getTestSuitePath(testSuiteFullPath, process.cwd())
103
+ isForcedToRun = isUnskippable && skippableSuites.includes(testSuitePath)
104
+
105
+ testSuiteStartCh.publish({ testSuitePath, isUnskippable, isForcedToRun })
95
106
  }
96
107
 
97
108
  const testSourceLine = this.gherkinDocument &&
@@ -221,8 +232,11 @@ function getFilteredPickles (runtime, suitesToSkip) {
221
232
  return runtime.pickleIds.reduce((acc, pickleId) => {
222
233
  const test = runtime.eventDataCollector.getPickle(pickleId)
223
234
  const testSuitePath = getTestSuitePath(test.uri, process.cwd())
235
+
236
+ const isUnskippable = isMarkedAsUnskippable(test)
224
237
  const isSkipped = suitesToSkip.includes(testSuitePath)
225
- if (isSkipped) {
238
+
239
+ if (isSkipped && !isUnskippable) {
226
240
  acc.skippedSuites.add(testSuitePath)
227
241
  } else {
228
242
  acc.picklesToRun.push(pickleId)
@@ -270,7 +284,11 @@ addHook({
270
284
  skippableSuitesCh.publish({ onDone })
271
285
  })
272
286
 
273
- const { err, skippableSuites } = await skippableSuitesPromise
287
+ const skippableResponse = await skippableSuitesPromise
288
+
289
+ const err = skippableResponse.err
290
+ skippableSuites = skippableResponse.skippableSuites
291
+
274
292
  let skippedSuites = []
275
293
  let isSuitesSkipped = false
276
294
 
@@ -315,7 +333,9 @@ addHook({
315
333
  status: success ? 'pass' : 'fail',
316
334
  isSuitesSkipped,
317
335
  testCodeCoverageLinesTotal,
318
- numSkippedSuites: skippedSuites.length
336
+ numSkippedSuites: skippedSuites.length,
337
+ hasUnskippableSuites: isUnskippable,
338
+ hasForcedToRunSuites: isForcedToRun
319
339
  })
320
340
  })
321
341
  return success
@@ -29,7 +29,7 @@ const collectionMethodsWithTwoFilters = [
29
29
 
30
30
  const startCh = channel('datadog:mongodb:collection:filter:start')
31
31
 
32
- addHook({ name: 'mongodb', versions: ['>=3.3'] }, mongodb => {
32
+ addHook({ name: 'mongodb', versions: ['>=3.3 <5', '5', '>=6'] }, mongodb => {
33
33
  [...collectionMethodsWithFilter, ...collectionMethodsWithTwoFilters].forEach(methodName => {
34
34
  if (!(methodName in mongodb.Collection.prototype)) return
35
35
 
@@ -181,6 +181,15 @@ function dispatcherHook (dispatcherExport) {
181
181
  return dispatcherExport
182
182
  }
183
183
 
184
+ function getTestByTestId (dispatcher, testId) {
185
+ if (dispatcher._testById) {
186
+ return dispatcher._testById.get(testId)?.test
187
+ }
188
+ if (dispatcher._allTests) {
189
+ return dispatcher._allTests.find(({ id }) => id === testId)
190
+ }
191
+ }
192
+
184
193
  function dispatcherHookNew (dispatcherExport, runWrapper) {
185
194
  shimmer.wrap(dispatcherExport.Dispatcher.prototype, 'run', runWrapper)
186
195
  shimmer.wrap(dispatcherExport.Dispatcher.prototype, '_createWorker', createWorker => function () {
@@ -188,11 +197,11 @@ function dispatcherHookNew (dispatcherExport, runWrapper) {
188
197
  const worker = createWorker.apply(this, arguments)
189
198
 
190
199
  worker.on('testBegin', ({ testId }) => {
191
- const { test } = dispatcher._testById.get(testId)
200
+ const test = getTestByTestId(dispatcher, testId)
192
201
  testBeginHandler(test)
193
202
  })
194
203
  worker.on('testEnd', ({ testId, status, errors }) => {
195
- const { test } = dispatcher._testById.get(testId)
204
+ const test = getTestByTestId(dispatcher, testId)
196
205
 
197
206
  testEndHandler(test, STATUS_TO_TEST_STATUS[status], errors && errors[0])
198
207
  })
@@ -10,7 +10,9 @@ const {
10
10
  finishAllTraceSpans,
11
11
  getTestSuitePath,
12
12
  getTestSuiteCommonTags,
13
- addIntelligentTestRunnerSpanTags
13
+ addIntelligentTestRunnerSpanTags,
14
+ TEST_ITR_UNSKIPPABLE,
15
+ TEST_ITR_FORCED_RUN
14
16
  } = require('../../dd-trace/src/plugins/util/test')
15
17
  const { RESOURCE_NAME } = require('../../../ext/tags')
16
18
  const { COMPONENT, ERROR_MESSAGE } = require('../../dd-trace/src/constants')
@@ -29,7 +31,9 @@ class CucumberPlugin extends CiPlugin {
29
31
  status,
30
32
  isSuitesSkipped,
31
33
  numSkippedSuites,
32
- testCodeCoverageLinesTotal
34
+ testCodeCoverageLinesTotal,
35
+ hasUnskippableSuites,
36
+ hasForcedToRunSuites
33
37
  }) => {
34
38
  const { isSuitesSkippingEnabled, isCodeCoverageEnabled } = this.itrConfig || {}
35
39
  addIntelligentTestRunnerSpanTags(
@@ -41,7 +45,9 @@ class CucumberPlugin extends CiPlugin {
41
45
  isCodeCoverageEnabled,
42
46
  testCodeCoverageLinesTotal,
43
47
  skippingCount: numSkippedSuites,
44
- skippingType: 'suite'
48
+ skippingType: 'suite',
49
+ hasUnskippableSuites,
50
+ hasForcedToRunSuites
45
51
  }
46
52
  )
47
53
 
@@ -55,13 +61,19 @@ class CucumberPlugin extends CiPlugin {
55
61
  this.tracer._exporter.flush()
56
62
  })
57
63
 
58
- this.addSub('ci:cucumber:test-suite:start', (testSuiteFullPath) => {
64
+ this.addSub('ci:cucumber:test-suite:start', ({ testSuitePath, isUnskippable, isForcedToRun }) => {
59
65
  const testSuiteMetadata = getTestSuiteCommonTags(
60
66
  this.command,
61
67
  this.frameworkVersion,
62
- getTestSuitePath(testSuiteFullPath, this.sourceRoot),
68
+ testSuitePath,
63
69
  'cucumber'
64
70
  )
71
+ if (isUnskippable) {
72
+ testSuiteMetadata[TEST_ITR_UNSKIPPABLE] = 'true'
73
+ }
74
+ if (isForcedToRun) {
75
+ testSuiteMetadata[TEST_ITR_FORCED_RUN] = 'true'
76
+ }
65
77
  this.testSuiteSpan = this.tracer.startSpan('cucumber.test_suite', {
66
78
  childOf: this.testModuleSpan,
67
79
  tags: {
@@ -21,11 +21,14 @@ const {
21
21
  getCoveredFilenamesFromCoverage,
22
22
  getTestSuitePath,
23
23
  addIntelligentTestRunnerSpanTags,
24
- TEST_SKIPPED_BY_ITR
24
+ TEST_SKIPPED_BY_ITR,
25
+ TEST_ITR_UNSKIPPABLE,
26
+ TEST_ITR_FORCED_RUN
25
27
  } = require('../../dd-trace/src/plugins/util/test')
26
28
  const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
27
29
  const log = require('../../dd-trace/src/log')
28
30
  const NoopTracer = require('../../dd-trace/src/noop/tracer')
31
+ const { isMarkedAsUnskippable } = require('../../datadog-plugin-jest/src/util')
29
32
 
30
33
  const TEST_FRAMEWORK_NAME = 'cypress'
31
34
 
@@ -185,8 +188,11 @@ module.exports = (on, config) => {
185
188
  let isSuitesSkippingEnabled = false
186
189
  let isCodeCoverageEnabled = false
187
190
  let testsToSkip = []
191
+ const unskippableSuites = []
192
+ let hasForcedToRunSuites = false
193
+ let hasUnskippableSuites = false
188
194
 
189
- function getTestSpan (testName, testSuite) {
195
+ function getTestSpan (testName, testSuite, isUnskippable, isForcedToRun) {
190
196
  const testSuiteTags = {
191
197
  [TEST_COMMAND]: command,
192
198
  [TEST_COMMAND]: command,
@@ -212,6 +218,16 @@ module.exports = (on, config) => {
212
218
  testSpanMetadata[TEST_CODE_OWNERS] = codeOwners
213
219
  }
214
220
 
221
+ if (isUnskippable) {
222
+ hasUnskippableSuites = true
223
+ testSpanMetadata[TEST_ITR_UNSKIPPABLE] = 'true'
224
+ }
225
+
226
+ if (isForcedToRun) {
227
+ hasForcedToRunSuites = true
228
+ testSpanMetadata[TEST_ITR_FORCED_RUN] = 'true'
229
+ }
230
+
215
231
  return tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test`, {
216
232
  childOf,
217
233
  tags: {
@@ -233,13 +249,21 @@ module.exports = (on, config) => {
233
249
  isCodeCoverageEnabled = itrConfig.isCodeCoverageEnabled
234
250
  }
235
251
 
236
- getSkippableTests(isSuitesSkippingEnabled, tracer, testConfiguration).then(({ err, skippableTests }) => {
252
+ return getSkippableTests(isSuitesSkippingEnabled, tracer, testConfiguration).then(({ err, skippableTests }) => {
237
253
  if (err) {
238
254
  log.error(err)
239
255
  } else {
240
256
  testsToSkip = skippableTests || []
241
257
  }
242
258
 
259
+ // `details.specs` are test files
260
+ details.specs.forEach(({ absolute, relative }) => {
261
+ const isUnskippableSuite = isMarkedAsUnskippable({ path: absolute })
262
+ if (isUnskippableSuite) {
263
+ unskippableSuites.push(relative)
264
+ }
265
+ })
266
+
243
267
  const childOf = getTestParentSpan(tracer)
244
268
  rootDir = getRootDir(details)
245
269
 
@@ -340,7 +364,9 @@ module.exports = (on, config) => {
340
364
  isSuitesSkippingEnabled,
341
365
  isCodeCoverageEnabled,
342
366
  skippingType: 'test',
343
- skippingCount: skippedTests.length
367
+ skippingCount: skippedTests.length,
368
+ hasForcedToRunSuites,
369
+ hasUnskippableSuites
344
370
  }
345
371
  )
346
372
 
@@ -384,17 +410,21 @@ module.exports = (on, config) => {
384
410
  },
385
411
  'dd:beforeEach': (test) => {
386
412
  const { testName, testSuite } = test
387
- // skip test
388
- if (testsToSkip.find(test => {
413
+ const shouldSkip = !!testsToSkip.find(test => {
389
414
  return testName === test.name && testSuite === test.suite
390
- })) {
415
+ })
416
+ const isUnskippable = unskippableSuites.includes(testSuite)
417
+ const isForcedToRun = shouldSkip && isUnskippable
418
+
419
+ // skip test
420
+ if (shouldSkip && !isUnskippable) {
391
421
  skippedTests.push(test)
392
422
  isTestsSkipped = true
393
423
  return { shouldSkip: true }
394
424
  }
395
425
 
396
426
  if (!activeSpan) {
397
- activeSpan = getTestSpan(testName, testSuite)
427
+ activeSpan = getTestSpan(testName, testSuite, isUnskippable, isForcedToRun)
398
428
  }
399
429
 
400
430
  return activeSpan ? { traceId: activeSpan.context().toTraceId() } : {}
@@ -32,6 +32,8 @@ function enable (_config) {
32
32
  if (isEnabled) return
33
33
 
34
34
  try {
35
+ appsecTelemetry.enable(_config.telemetry)
36
+
35
37
  setTemplates(_config)
36
38
 
37
39
  RuleManager.applyRules(_config.appsec.rules, _config.appsec)
@@ -40,8 +42,6 @@ function enable (_config) {
40
42
 
41
43
  Reporter.setRateLimit(_config.appsec.rateLimit)
42
44
 
43
- appsecTelemetry.enable(_config.telemetry)
44
-
45
45
  incomingHttpRequestStart.subscribe(incomingHttpStartTranslator)
46
46
  incomingHttpRequestEnd.subscribe(incomingHttpEndTranslator)
47
47
  bodyParser.subscribe(onRequestBodyParsed)
@@ -602,6 +602,23 @@ module.exports = {
602
602
  tags[refKey] = ref
603
603
  }
604
604
 
605
+ if (env.CODEBUILD_INITIATOR?.startsWith('codepipeline/')) {
606
+ const {
607
+ CODEBUILD_BUILD_ARN,
608
+ DD_ACTION_EXECUTION_ID,
609
+ DD_PIPELINE_EXECUTION_ID
610
+ } = env
611
+ tags = {
612
+ [CI_PROVIDER_NAME]: 'awscodepipeline',
613
+ [CI_PIPELINE_ID]: DD_PIPELINE_EXECUTION_ID,
614
+ [CI_ENV_VARS]: JSON.stringify({
615
+ CODEBUILD_BUILD_ARN,
616
+ DD_PIPELINE_EXECUTION_ID,
617
+ DD_ACTION_EXECUTION_ID
618
+ })
619
+ }
620
+ }
621
+
605
622
  normalizeTag(tags, CI_WORKSPACE_PATH, resolveTilde)
606
623
  normalizeTag(tags, GIT_REPOSITORY_URL, filterSensitiveInfoFromRepository)
607
624
  normalizeTag(tags, GIT_BRANCH, normalizeRef)