dd-trace 4.0.0-pre-d46f64a → 4.0.0-pre-3965634

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": "4.0.0-pre-d46f64a",
3
+ "version": "4.0.0-pre-3965634",
4
4
  "description": "Datadog APM tracing client for JavaScript",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -2,6 +2,8 @@ const { createCoverageMap } = require('istanbul-lib-coverage')
2
2
 
3
3
  const { addHook, channel, AsyncResource } = require('./helpers/instrument')
4
4
  const shimmer = require('../../datadog-shimmer')
5
+ const log = require('../../dd-trace/src/log')
6
+
5
7
  const {
6
8
  getCoveredFilenamesFromCoverage,
7
9
  resetCoverage,
@@ -34,6 +36,9 @@ const testToAr = new WeakMap()
34
36
  const originalFns = new WeakMap()
35
37
  const testFileToSuiteAr = new Map()
36
38
 
39
+ // `isWorker` is true if it's a Mocha worker
40
+ let isWorker = false
41
+
37
42
  // We'll preserve the original coverage here
38
43
  const originalCoverageMap = createCoverageMap()
39
44
 
@@ -101,7 +106,7 @@ function mochaHook (Runner) {
101
106
  patched.add(Runner)
102
107
 
103
108
  shimmer.wrap(Runner.prototype, 'run', run => function () {
104
- if (!testStartCh.hasSubscribers) {
109
+ if (!testStartCh.hasSubscribers || isWorker) {
105
110
  return run.apply(this, arguments)
106
111
  }
107
112
 
@@ -321,7 +326,15 @@ addHook({
321
326
  * If ITR is disabled, `onDone` is called immediately on the subscriber
322
327
  */
323
328
  shimmer.wrap(Mocha.prototype, 'run', run => function () {
324
- if (!itrConfigurationCh.hasSubscribers) {
329
+ if (this.options.parallel) {
330
+ log.warn(`Unable to initialize CI Visibility because Mocha is running in parallel mode.`)
331
+ return run.apply(this, arguments)
332
+ }
333
+
334
+ if (!itrConfigurationCh.hasSubscribers || this.isWorker) {
335
+ if (this.isWorker) {
336
+ isWorker = true
337
+ }
325
338
  return run.apply(this, arguments)
326
339
  }
327
340
  this.options.delay = true
@@ -379,7 +392,9 @@ addHook({
379
392
  * This attaches `run` to the global context, which we'll call after
380
393
  * our configuration and skippable suites requests
381
394
  */
382
- mocha.options.delay = true
395
+ if (!mocha.options.parallel) {
396
+ mocha.options.delay = true
397
+ }
383
398
  return runMocha.apply(this, arguments)
384
399
  })
385
400
  return run
@@ -20,6 +20,8 @@ const {
20
20
  finishAllTraceSpans
21
21
  } = require('../../dd-trace/src/plugins/util/test')
22
22
 
23
+ const TEST_FRAMEWORK_NAME = 'cypress'
24
+
23
25
  const { ORIGIN_KEY, COMPONENT } = require('../../dd-trace/src/constants')
24
26
 
25
27
  const CYPRESS_STATUS_TO_TEST_STATUS = {
@@ -52,9 +54,9 @@ function getCypressVersion (details) {
52
54
 
53
55
  function getCypressCommand (details) {
54
56
  if (!details) {
55
- return 'cypress'
57
+ return TEST_FRAMEWORK_NAME
56
58
  }
57
- return `cypress ${details.specPattern || ''}`
59
+ return `${TEST_FRAMEWORK_NAME} ${details.specPattern || ''}`
58
60
  }
59
61
 
60
62
  function getSessionStatus (summary) {
@@ -79,7 +81,7 @@ function getSuiteStatus (suiteStats) {
79
81
 
80
82
  module.exports = (on, config) => {
81
83
  const tracer = require('../../dd-trace')
82
- const testEnvironmentMetadata = getTestEnvironmentMetadata('cypress')
84
+ const testEnvironmentMetadata = getTestEnvironmentMetadata(TEST_FRAMEWORK_NAME)
83
85
 
84
86
  const codeOwnersEntries = getCodeOwnersFileEntries()
85
87
 
@@ -96,21 +98,21 @@ module.exports = (on, config) => {
96
98
  command = getCypressCommand(details)
97
99
  frameworkVersion = getCypressVersion(details)
98
100
 
99
- const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion, 'cypress')
100
- const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion, 'cypress')
101
+ const testSessionSpanMetadata = getTestSessionCommonTags(command, frameworkVersion, TEST_FRAMEWORK_NAME)
102
+ const testModuleSpanMetadata = getTestModuleCommonTags(command, frameworkVersion, TEST_FRAMEWORK_NAME)
101
103
 
102
- testSessionSpan = tracer.startSpan('cypress.test_session', {
104
+ testSessionSpan = tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test_session`, {
103
105
  childOf,
104
106
  tags: {
105
- [COMPONENT]: 'cypress',
107
+ [COMPONENT]: TEST_FRAMEWORK_NAME,
106
108
  ...testEnvironmentMetadata,
107
109
  ...testSessionSpanMetadata
108
110
  }
109
111
  })
110
- testModuleSpan = tracer.startSpan('cypress.test_module', {
112
+ testModuleSpan = tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test_module`, {
111
113
  childOf: testSessionSpan,
112
114
  tags: {
113
- [COMPONENT]: 'cypress',
115
+ [COMPONENT]: TEST_FRAMEWORK_NAME,
114
116
  ...testEnvironmentMetadata,
115
117
  ...testModuleSpanMetadata
116
118
  }
@@ -118,14 +120,16 @@ module.exports = (on, config) => {
118
120
  })
119
121
 
120
122
  on('after:run', (suiteStats) => {
121
- const testStatus = getSessionStatus(suiteStats)
122
- testModuleSpan.setTag(TEST_STATUS, testStatus)
123
- testSessionSpan.setTag(TEST_STATUS, testStatus)
123
+ if (testSessionSpan && testModuleSpan) {
124
+ const testStatus = getSessionStatus(suiteStats)
125
+ testModuleSpan.setTag(TEST_STATUS, testStatus)
126
+ testSessionSpan.setTag(TEST_STATUS, testStatus)
124
127
 
125
- testModuleSpan.finish()
126
- testSessionSpan.finish()
128
+ testModuleSpan.finish()
129
+ testSessionSpan.finish()
127
130
 
128
- finishAllTraceSpans(testSessionSpan)
131
+ finishAllTraceSpans(testSessionSpan)
132
+ }
129
133
 
130
134
  return new Promise(resolve => {
131
135
  tracer._tracer._exporter._writer.flush(() => {
@@ -138,11 +142,11 @@ module.exports = (on, config) => {
138
142
  if (testSuiteSpan) {
139
143
  return null
140
144
  }
141
- const testSuiteSpanMetadata = getTestSuiteCommonTags(command, frameworkVersion, suite, 'cypress')
142
- testSuiteSpan = tracer.startSpan('cypress.test_suite', {
145
+ const testSuiteSpanMetadata = getTestSuiteCommonTags(command, frameworkVersion, suite, TEST_FRAMEWORK_NAME)
146
+ testSuiteSpan = tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test_suite`, {
143
147
  childOf: testModuleSpan,
144
148
  tags: {
145
- [COMPONENT]: 'cypress',
149
+ [COMPONENT]: TEST_FRAMEWORK_NAME,
146
150
  ...testEnvironmentMetadata,
147
151
  ...testSuiteSpanMetadata
148
152
  }
@@ -150,26 +154,29 @@ module.exports = (on, config) => {
150
154
  return null
151
155
  },
152
156
  'dd:testSuiteFinish': (suiteStats) => {
153
- const status = getSuiteStatus(suiteStats)
154
- testSuiteSpan.setTag(TEST_STATUS, status)
155
- testSuiteSpan.finish()
156
- testSuiteSpan = null
157
+ if (testSuiteSpan) {
158
+ const status = getSuiteStatus(suiteStats)
159
+ testSuiteSpan.setTag(TEST_STATUS, status)
160
+ testSuiteSpan.finish()
161
+ testSuiteSpan = null
162
+ }
157
163
  return null
158
164
  },
159
165
  'dd:beforeEach': (test) => {
160
166
  const { testName, testSuite } = test
161
- const testSuiteId = testSuiteSpan.context().toSpanId()
162
- const testSessionId = testSessionSpan.context().toTraceId()
163
- const testModuleId = testModuleSpan.context().toSpanId()
164
167
 
165
168
  const testSuiteTags = {
166
- [TEST_SUITE_ID]: testSuiteId,
167
- [TEST_SESSION_ID]: testSessionId,
168
169
  [TEST_COMMAND]: command,
169
- [TEST_MODULE_ID]: testModuleId,
170
170
  [TEST_COMMAND]: command,
171
- [TEST_BUNDLE]: 'cypress',
172
- [TEST_MODULE]: 'cypress'
171
+ [TEST_BUNDLE]: TEST_FRAMEWORK_NAME,
172
+ [TEST_MODULE]: TEST_FRAMEWORK_NAME
173
+ }
174
+ if (testSuiteSpan) {
175
+ testSuiteTags[TEST_SUITE_ID] = testSuiteSpan.context().toSpanId()
176
+ }
177
+ if (testSessionSpan && testModuleSpan) {
178
+ testSuiteTags[TEST_SESSION_ID] = testSessionSpan.context().toTraceId()
179
+ testSuiteTags[TEST_MODULE_ID] = testModuleSpan.context().toSpanId()
173
180
  }
174
181
 
175
182
  const {
@@ -185,10 +192,10 @@ module.exports = (on, config) => {
185
192
  }
186
193
 
187
194
  if (!activeSpan) {
188
- activeSpan = tracer.startSpan('cypress.test', {
195
+ activeSpan = tracer.startSpan(`${TEST_FRAMEWORK_NAME}.test`, {
189
196
  childOf,
190
197
  tags: {
191
- [COMPONENT]: 'cypress',
198
+ [COMPONENT]: TEST_FRAMEWORK_NAME,
192
199
  [ORIGIN_KEY]: CI_APP_ORIGIN,
193
200
  ...testSpanMetadata,
194
201
  ...testEnvironmentMetadata,
@@ -196,7 +203,7 @@ module.exports = (on, config) => {
196
203
  }
197
204
  })
198
205
  }
199
- return activeSpan ? activeSpan._spanContext._traceId.toString(10) : null
206
+ return activeSpan ? activeSpan.context().toTraceId() : null
200
207
  },
201
208
  'dd:afterEach': (test) => {
202
209
  const { state, error, isRUMActive } = test