dd-trace 5.0.0-pre-733fec7 → 5.0.0-pre-945b42f

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-733fec7",
3
+ "version": "5.0.0-pre-945b42f",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -70,9 +70,9 @@
70
70
  "dependencies": {
71
71
  "@datadog/native-appsec": "^4.0.0",
72
72
  "@datadog/native-iast-rewriter": "2.1.3",
73
- "@datadog/native-iast-taint-tracking": "1.6.1",
73
+ "@datadog/native-iast-taint-tracking": "1.6.3",
74
74
  "@datadog/native-metrics": "^2.0.0",
75
- "@datadog/pprof": "4.0.0",
75
+ "@datadog/pprof": "4.0.1",
76
76
  "@datadog/sketches-js": "^2.1.0",
77
77
  "@opentelemetry/api": "^1.0.0",
78
78
  "@opentelemetry/core": "^1.14.0",
@@ -363,23 +363,23 @@ function jestAdapterWrapper (jestAdapter, jestVersion) {
363
363
  status = 'fail'
364
364
  }
365
365
 
366
- const coverageFiles = getCoveredFilenamesFromCoverage(environment.global.__coverage__)
367
- .map(filename => getTestSuitePath(filename, environment.rootDir))
368
-
369
366
  /**
370
367
  * Child processes do not each request ITR configuration, so the jest's parent process
371
368
  * needs to pass them the configuration. This is done via _ddTestCodeCoverageEnabled, which
372
369
  * controls whether coverage is reported.
373
- */
374
- if (coverageFiles &&
375
- environment.testEnvironmentOptions &&
376
- environment.testEnvironmentOptions._ddTestCodeCoverageEnabled) {
370
+ */
371
+ if (environment.testEnvironmentOptions?._ddTestCodeCoverageEnabled) {
372
+ const coverageFiles = getCoveredFilenamesFromCoverage(environment.global.__coverage__)
373
+ .map(filename => getTestSuitePath(filename, environment.rootDir))
377
374
  asyncResource.runInAsyncScope(() => {
378
375
  testSuiteCodeCoverageCh.publish([...coverageFiles, environment.testSuite])
379
376
  })
380
377
  }
381
378
  testSuiteFinishCh.publish({ status, errorMessage })
382
379
  return suiteResults
380
+ }).catch(error => {
381
+ testSuiteFinishCh.publish({ status: 'fail', error })
382
+ throw error
383
383
  })
384
384
  })
385
385
  })
@@ -1,5 +1,6 @@
1
1
  const { addHook, channel, AsyncResource } = require('./helpers/instrument')
2
2
  const shimmer = require('../../datadog-shimmer')
3
+ const { parseAnnotations } = require('../../dd-trace/src/plugins/util/test')
3
4
 
4
5
  const testStartCh = channel('ci:playwright:test:start')
5
6
  const testFinishCh = channel('ci:playwright:test:finish')
@@ -103,7 +104,11 @@ function testBeginHandler (test) {
103
104
  })
104
105
  }
105
106
 
106
- function testEndHandler (test, testStatus, error) {
107
+ function testEndHandler (test, annotations, testStatus, error) {
108
+ let annotationTags
109
+ if (annotations.length) {
110
+ annotationTags = parseAnnotations(annotations)
111
+ }
107
112
  const { _requireFile: testSuiteAbsolutePath, results, _type } = test
108
113
 
109
114
  if (_type === 'beforeAll' || _type === 'afterAll') {
@@ -113,7 +118,7 @@ function testEndHandler (test, testStatus, error) {
113
118
  const testResult = results[results.length - 1]
114
119
  const testAsyncResource = testToAr.get(test)
115
120
  testAsyncResource.runInAsyncScope(() => {
116
- testFinishCh.publish({ testStatus, steps: testResult.steps, error })
121
+ testFinishCh.publish({ testStatus, steps: testResult.steps, error, extraTags: annotationTags })
117
122
  })
118
123
 
119
124
  if (!testSuiteToTestStatuses.has(testSuiteAbsolutePath)) {
@@ -172,7 +177,7 @@ function dispatcherHook (dispatcherExport) {
172
177
  const { results } = test
173
178
  const testResult = results[results.length - 1]
174
179
 
175
- testEndHandler(test, STATUS_TO_TEST_STATUS[testResult.status], testResult.error)
180
+ testEndHandler(test, params.annotations, STATUS_TO_TEST_STATUS[testResult.status], testResult.error)
176
181
  }
177
182
  })
178
183
 
@@ -200,10 +205,10 @@ function dispatcherHookNew (dispatcherExport, runWrapper) {
200
205
  const test = getTestByTestId(dispatcher, testId)
201
206
  testBeginHandler(test)
202
207
  })
203
- worker.on('testEnd', ({ testId, status, errors }) => {
208
+ worker.on('testEnd', ({ testId, status, errors, annotations }) => {
204
209
  const test = getTestByTestId(dispatcher, testId)
205
210
 
206
- testEndHandler(test, STATUS_TO_TEST_STATUS[status], errors && errors[0])
211
+ testEndHandler(test, annotations, STATUS_TO_TEST_STATUS[status], errors && errors[0])
207
212
  })
208
213
 
209
214
  return worker
@@ -230,7 +235,7 @@ function runnerHook (runnerExport, playwrightVersion) {
230
235
  // because they were skipped
231
236
  tests.forEach(test => {
232
237
  testBeginHandler(test)
233
- testEndHandler(test, 'skip')
238
+ testEndHandler(test, [], 'skip')
234
239
  })
235
240
  })
236
241
 
@@ -150,9 +150,11 @@ class JestPlugin extends CiPlugin {
150
150
  })
151
151
  })
152
152
 
153
- this.addSub('ci:jest:test-suite:finish', ({ status, errorMessage }) => {
153
+ this.addSub('ci:jest:test-suite:finish', ({ status, errorMessage, error }) => {
154
154
  this.testSuiteSpan.setTag(TEST_STATUS, status)
155
- if (errorMessage) {
155
+ if (error) {
156
+ this.testSuiteSpan.setTag('error', error)
157
+ } else if (errorMessage) {
156
158
  this.testSuiteSpan.setTag('error', new Error(errorMessage))
157
159
  }
158
160
  this.testSuiteSpan.finish()
@@ -72,7 +72,7 @@ class PlaywrightPlugin extends CiPlugin {
72
72
 
73
73
  this.enter(span, store)
74
74
  })
75
- this.addSub('ci:playwright:test:finish', ({ testStatus, steps, error }) => {
75
+ this.addSub('ci:playwright:test:finish', ({ testStatus, steps, error, extraTags }) => {
76
76
  const store = storage.getStore()
77
77
  const span = store && store.span
78
78
  if (!span) return
@@ -82,6 +82,9 @@ class PlaywrightPlugin extends CiPlugin {
82
82
  if (error) {
83
83
  span.setTag('error', error)
84
84
  }
85
+ if (extraTags) {
86
+ span.addTags(extraTags)
87
+ }
85
88
 
86
89
  steps.forEach(step => {
87
90
  const stepStartTime = step.startTime.getTime()
@@ -118,7 +118,8 @@ module.exports = {
118
118
  fromCoverageMapToCoverage,
119
119
  getTestLineStart,
120
120
  getCallSites,
121
- removeInvalidMetadata
121
+ removeInvalidMetadata,
122
+ parseAnnotations
122
123
  }
123
124
 
124
125
  // Returns pkg manager and its version, separated by '-', e.g. npm-8.15.0 or yarn-1.22.19
@@ -492,3 +493,30 @@ function getCallSites () {
492
493
 
493
494
  return v8StackTrace
494
495
  }
496
+
497
+ /**
498
+ * Gets an object of test tags from an Playwright annotations array.
499
+ * @param {Object[]} annotations - Annotations from a Playwright test.
500
+ * @param {string} annotations[].type - Type of annotation. A string of the shape DD_TAGS[$tag_name].
501
+ * @param {string} annotations[].description - Value of the tag.
502
+ */
503
+ function parseAnnotations (annotations) {
504
+ return annotations.reduce((tags, annotation) => {
505
+ if (!annotation?.type) {
506
+ return tags
507
+ }
508
+ const { type, description } = annotation
509
+ if (type.startsWith('DD_TAGS')) {
510
+ const regex = /\[(.*?)\]/
511
+ const match = regex.exec(type)
512
+ let tagValue = ''
513
+ if (match) {
514
+ tagValue = match[1]
515
+ }
516
+ if (tagValue) {
517
+ tags[tagValue] = description
518
+ }
519
+ }
520
+ return tags
521
+ }, {})
522
+ }
@@ -12,6 +12,12 @@ const beforeCh = dc.channel('dd-trace:storage:before')
12
12
  const enterCh = dc.channel('dd-trace:storage:enter')
13
13
  const profilerTelemetryMetrics = telemetryMetrics.manager.namespace('profilers')
14
14
 
15
+ const threadName = (function () {
16
+ const { isMainThread, threadId } = require('node:worker_threads')
17
+ const name = isMainThread ? 'Main' : `Worker #${threadId}`
18
+ return `${name} Event Loop`
19
+ })()
20
+
15
21
  let kSampleCount
16
22
 
17
23
  function getActiveSpan () {
@@ -24,7 +30,7 @@ function getStartedSpans (context) {
24
30
  }
25
31
 
26
32
  function generateLabels ({ context: { spanId, rootSpanId, webTags, endpoint }, timestamp }) {
27
- const labels = {}
33
+ const labels = { 'thread name': threadName }
28
34
  if (spanId) {
29
35
  labels['span id'] = spanId
30
36
  }