dd-trace 6.0.0-pre-ce51217 → 6.0.0-pre-ca25754
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/ci/init.js +7 -0
- package/ext/exporters.d.ts +2 -1
- package/ext/exporters.js +2 -1
- package/package.json +1 -1
- package/packages/datadog-instrumentations/src/aws-sdk.js +4 -1
- package/packages/datadog-instrumentations/src/cucumber.js +182 -105
- package/packages/datadog-instrumentations/src/helpers/fetch.js +9 -4
- package/packages/datadog-instrumentations/src/openai.js +149 -0
- package/packages/datadog-instrumentations/src/otel-sdk-trace.js +6 -1
- package/packages/datadog-plugin-aws-sdk/src/services/index.js +3 -0
- package/packages/datadog-plugin-aws-sdk/src/services/sfn.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/states.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/stepfunctions.js +64 -0
- package/packages/datadog-plugin-cucumber/src/index.js +83 -11
- package/packages/datadog-plugin-fetch/src/index.js +5 -2
- package/packages/datadog-plugin-openai/src/index.js +159 -32
- package/packages/dd-trace/src/appsec/iast/taint-tracking/operations-taint-object.js +1 -9
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +4 -2
- package/packages/dd-trace/src/appsec/remote_config/index.js +5 -5
- package/packages/dd-trace/src/ci-visibility/exporters/test-worker/index.js +56 -0
- package/packages/dd-trace/src/ci-visibility/exporters/{jest-worker → test-worker}/writer.js +7 -0
- package/packages/dd-trace/src/config.js +94 -9
- package/packages/dd-trace/src/exporter.js +2 -1
- package/packages/dd-trace/src/index.js +5 -1
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +10 -4
- package/packages/dd-trace/src/plugins/util/test.js +7 -0
- package/packages/dd-trace/src/proxy.js +26 -6
- package/packages/dd-trace/src/tagger.js +13 -3
- package/packages/dd-trace/src/ci-visibility/exporters/jest-worker/index.js +0 -33
package/ci/init.js
CHANGED
|
@@ -3,6 +3,7 @@ const tracer = require('../packages/dd-trace')
|
|
|
3
3
|
const { isTrue } = require('../packages/dd-trace/src/util')
|
|
4
4
|
|
|
5
5
|
const isJestWorker = !!process.env.JEST_WORKER_ID
|
|
6
|
+
const isCucumberWorker = !!process.env.CUCUMBER_WORKER_ID
|
|
6
7
|
|
|
7
8
|
const options = {
|
|
8
9
|
startupLogs: false,
|
|
@@ -37,6 +38,12 @@ if (isJestWorker) {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
if (isCucumberWorker) {
|
|
42
|
+
options.experimental = {
|
|
43
|
+
exporter: 'cucumber_worker'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
if (shouldInit) {
|
|
41
48
|
tracer.init(options)
|
|
42
49
|
tracer.use('fs', false)
|
package/ext/exporters.d.ts
CHANGED
package/ext/exporters.js
CHANGED
package/package.json
CHANGED
|
@@ -22,6 +22,8 @@ const skippableSuitesCh = channel('ci:cucumber:test-suite:skippable')
|
|
|
22
22
|
const sessionStartCh = channel('ci:cucumber:session:start')
|
|
23
23
|
const sessionFinishCh = channel('ci:cucumber:session:finish')
|
|
24
24
|
|
|
25
|
+
const workerReportTraceCh = channel('ci:cucumber:worker-report:trace')
|
|
26
|
+
|
|
25
27
|
const itrSkippedSuitesCh = channel('ci:cucumber:itr:skipped-suites')
|
|
26
28
|
|
|
27
29
|
const {
|
|
@@ -29,7 +31,8 @@ const {
|
|
|
29
31
|
resetCoverage,
|
|
30
32
|
mergeCoverage,
|
|
31
33
|
fromCoverageMapToCoverage,
|
|
32
|
-
getTestSuitePath
|
|
34
|
+
getTestSuitePath,
|
|
35
|
+
CUCUMBER_WORKER_TRACE_PAYLOAD_CODE
|
|
33
36
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
34
37
|
|
|
35
38
|
const isMarkedAsUnskippable = (pickle) => {
|
|
@@ -47,13 +50,19 @@ const numRetriesByPickleId = new Map()
|
|
|
47
50
|
|
|
48
51
|
let pickleByFile = {}
|
|
49
52
|
const pickleResultByFile = {}
|
|
53
|
+
|
|
54
|
+
const sessionAsyncResource = new AsyncResource('bound-anonymous-fn')
|
|
55
|
+
|
|
50
56
|
let skippableSuites = []
|
|
51
57
|
let itrCorrelationId = ''
|
|
52
58
|
let isForcedToRun = false
|
|
53
59
|
let isUnskippable = false
|
|
60
|
+
let isSuitesSkippingEnabled = false
|
|
54
61
|
let isEarlyFlakeDetectionEnabled = false
|
|
55
62
|
let earlyFlakeDetectionNumRetries = 0
|
|
56
63
|
let knownTests = []
|
|
64
|
+
let skippedSuites = []
|
|
65
|
+
let isSuitesSkipped = false
|
|
57
66
|
|
|
58
67
|
function getSuiteStatusFromTestStatuses (testStatuses) {
|
|
59
68
|
if (testStatuses.some(status => status === 'fail')) {
|
|
@@ -106,6 +115,43 @@ function getTestStatusFromRetries (testStatuses) {
|
|
|
106
115
|
return 'pass'
|
|
107
116
|
}
|
|
108
117
|
|
|
118
|
+
function getChannelPromise (channelToPublishTo) {
|
|
119
|
+
return new Promise(resolve => {
|
|
120
|
+
sessionAsyncResource.runInAsyncScope(() => {
|
|
121
|
+
channelToPublishTo.publish({ onDone: resolve })
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getFilteredPickles (runtime, suitesToSkip) {
|
|
127
|
+
return runtime.pickleIds.reduce((acc, pickleId) => {
|
|
128
|
+
const test = runtime.eventDataCollector.getPickle(pickleId)
|
|
129
|
+
const testSuitePath = getTestSuitePath(test.uri, process.cwd())
|
|
130
|
+
|
|
131
|
+
const isUnskippable = isMarkedAsUnskippable(test)
|
|
132
|
+
const isSkipped = suitesToSkip.includes(testSuitePath)
|
|
133
|
+
|
|
134
|
+
if (isSkipped && !isUnskippable) {
|
|
135
|
+
acc.skippedSuites.add(testSuitePath)
|
|
136
|
+
} else {
|
|
137
|
+
acc.picklesToRun.push(pickleId)
|
|
138
|
+
}
|
|
139
|
+
return acc
|
|
140
|
+
}, { skippedSuites: new Set(), picklesToRun: [] })
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getPickleByFile (runtime) {
|
|
144
|
+
return runtime.pickleIds.reduce((acc, pickleId) => {
|
|
145
|
+
const test = runtime.eventDataCollector.getPickle(pickleId)
|
|
146
|
+
if (acc[test.uri]) {
|
|
147
|
+
acc[test.uri].push(test)
|
|
148
|
+
} else {
|
|
149
|
+
acc[test.uri] = [test]
|
|
150
|
+
}
|
|
151
|
+
return acc
|
|
152
|
+
}, {})
|
|
153
|
+
}
|
|
154
|
+
|
|
109
155
|
function wrapRun (pl, isLatestVersion) {
|
|
110
156
|
if (patched.has(pl)) return
|
|
111
157
|
|
|
@@ -125,7 +171,8 @@ function wrapRun (pl, isLatestVersion) {
|
|
|
125
171
|
testStartCh.publish({
|
|
126
172
|
testName: this.pickle.name,
|
|
127
173
|
testFileAbsolutePath,
|
|
128
|
-
testSourceLine
|
|
174
|
+
testSourceLine,
|
|
175
|
+
isParallel: !!process.env.CUCUMBER_WORKER_ID
|
|
129
176
|
})
|
|
130
177
|
try {
|
|
131
178
|
const promise = run.apply(this, arguments)
|
|
@@ -193,12 +240,6 @@ function wrapRun (pl, isLatestVersion) {
|
|
|
193
240
|
}
|
|
194
241
|
|
|
195
242
|
function pickleHook (PickleRunner) {
|
|
196
|
-
if (process.env.CUCUMBER_WORKER_ID) {
|
|
197
|
-
// Parallel mode is not supported
|
|
198
|
-
log.warn('Unable to initialize CI Visibility because Cucumber is running in parallel mode.')
|
|
199
|
-
return PickleRunner
|
|
200
|
-
}
|
|
201
|
-
|
|
202
243
|
const pl = PickleRunner.default
|
|
203
244
|
|
|
204
245
|
wrapRun(pl, false)
|
|
@@ -207,12 +248,6 @@ function pickleHook (PickleRunner) {
|
|
|
207
248
|
}
|
|
208
249
|
|
|
209
250
|
function testCaseHook (TestCaseRunner) {
|
|
210
|
-
if (process.env.CUCUMBER_WORKER_ID) {
|
|
211
|
-
// Parallel mode is not supported
|
|
212
|
-
log.warn('Unable to initialize CI Visibility because Cucumber is running in parallel mode.')
|
|
213
|
-
return TestCaseRunner
|
|
214
|
-
}
|
|
215
|
-
|
|
216
251
|
const pl = TestCaseRunner.default
|
|
217
252
|
|
|
218
253
|
wrapRun(pl, true)
|
|
@@ -220,76 +255,21 @@ function testCaseHook (TestCaseRunner) {
|
|
|
220
255
|
return TestCaseRunner
|
|
221
256
|
}
|
|
222
257
|
|
|
223
|
-
|
|
224
|
-
name: '@cucumber/cucumber',
|
|
225
|
-
versions: ['7.0.0 - 7.2.1'],
|
|
226
|
-
file: 'lib/runtime/pickle_runner.js'
|
|
227
|
-
}, pickleHook)
|
|
228
|
-
|
|
229
|
-
addHook({
|
|
230
|
-
name: '@cucumber/cucumber',
|
|
231
|
-
versions: ['>=7.3.0'],
|
|
232
|
-
file: 'lib/runtime/test_case_runner.js'
|
|
233
|
-
}, testCaseHook)
|
|
234
|
-
|
|
235
|
-
function getFilteredPickles (runtime, suitesToSkip) {
|
|
236
|
-
return runtime.pickleIds.reduce((acc, pickleId) => {
|
|
237
|
-
const test = runtime.eventDataCollector.getPickle(pickleId)
|
|
238
|
-
const testSuitePath = getTestSuitePath(test.uri, process.cwd())
|
|
239
|
-
|
|
240
|
-
const isUnskippable = isMarkedAsUnskippable(test)
|
|
241
|
-
const isSkipped = suitesToSkip.includes(testSuitePath)
|
|
242
|
-
|
|
243
|
-
if (isSkipped && !isUnskippable) {
|
|
244
|
-
acc.skippedSuites.add(testSuitePath)
|
|
245
|
-
} else {
|
|
246
|
-
acc.picklesToRun.push(pickleId)
|
|
247
|
-
}
|
|
248
|
-
return acc
|
|
249
|
-
}, { skippedSuites: new Set(), picklesToRun: [] })
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function getPickleByFile (runtime) {
|
|
253
|
-
return runtime.pickleIds.reduce((acc, pickleId) => {
|
|
254
|
-
const test = runtime.eventDataCollector.getPickle(pickleId)
|
|
255
|
-
if (acc[test.uri]) {
|
|
256
|
-
acc[test.uri].push(test)
|
|
257
|
-
} else {
|
|
258
|
-
acc[test.uri] = [test]
|
|
259
|
-
}
|
|
260
|
-
return acc
|
|
261
|
-
}, {})
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function getWrappedStart (start, frameworkVersion) {
|
|
258
|
+
function getWrappedStart (start, frameworkVersion, isParallel = false) {
|
|
265
259
|
return async function () {
|
|
266
260
|
if (!libraryConfigurationCh.hasSubscribers) {
|
|
267
261
|
return start.apply(this, arguments)
|
|
268
262
|
}
|
|
269
|
-
|
|
270
|
-
let onDone
|
|
271
|
-
|
|
272
|
-
const configPromise = new Promise(resolve => {
|
|
273
|
-
onDone = resolve
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
asyncResource.runInAsyncScope(() => {
|
|
277
|
-
libraryConfigurationCh.publish({ onDone })
|
|
278
|
-
})
|
|
263
|
+
let errorSkippableRequest
|
|
279
264
|
|
|
280
|
-
const configurationResponse = await
|
|
265
|
+
const configurationResponse = await getChannelPromise(libraryConfigurationCh)
|
|
281
266
|
|
|
282
267
|
isEarlyFlakeDetectionEnabled = configurationResponse.libraryConfig?.isEarlyFlakeDetectionEnabled
|
|
283
268
|
earlyFlakeDetectionNumRetries = configurationResponse.libraryConfig?.earlyFlakeDetectionNumRetries
|
|
269
|
+
isSuitesSkippingEnabled = configurationResponse.libraryConfig?.isSuitesSkippingEnabled
|
|
284
270
|
|
|
285
271
|
if (isEarlyFlakeDetectionEnabled) {
|
|
286
|
-
const
|
|
287
|
-
onDone = resolve
|
|
288
|
-
})
|
|
289
|
-
asyncResource.runInAsyncScope(() => {
|
|
290
|
-
knownTestsCh.publish({ onDone })
|
|
291
|
-
})
|
|
292
|
-
const knownTestsResponse = await knownTestsPromise
|
|
272
|
+
const knownTestsResponse = await getChannelPromise(knownTestsCh)
|
|
293
273
|
if (!knownTestsResponse.err) {
|
|
294
274
|
knownTests = knownTestsResponse.knownTests
|
|
295
275
|
} else {
|
|
@@ -297,35 +277,26 @@ function getWrappedStart (start, frameworkVersion) {
|
|
|
297
277
|
}
|
|
298
278
|
}
|
|
299
279
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
})
|
|
280
|
+
if (isSuitesSkippingEnabled) {
|
|
281
|
+
const skippableResponse = await getChannelPromise(skippableSuitesCh)
|
|
303
282
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
})
|
|
283
|
+
errorSkippableRequest = skippableResponse.err
|
|
284
|
+
skippableSuites = skippableResponse.skippableSuites
|
|
307
285
|
|
|
308
|
-
|
|
286
|
+
if (!errorSkippableRequest) {
|
|
287
|
+
const filteredPickles = getFilteredPickles(this, skippableSuites)
|
|
288
|
+
const { picklesToRun } = filteredPickles
|
|
289
|
+
isSuitesSkipped = picklesToRun.length !== this.pickleIds.length
|
|
309
290
|
|
|
310
|
-
|
|
311
|
-
|
|
291
|
+
log.debug(
|
|
292
|
+
() => `${picklesToRun.length} out of ${this.pickleIds.length} suites are going to run.`
|
|
293
|
+
)
|
|
312
294
|
|
|
313
|
-
|
|
314
|
-
let isSuitesSkipped = false
|
|
295
|
+
this.pickleIds = picklesToRun
|
|
315
296
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
isSuitesSkipped = picklesToRun.length !== this.pickleIds.length
|
|
320
|
-
|
|
321
|
-
log.debug(
|
|
322
|
-
() => `${picklesToRun.length} out of ${this.pickleIds.length} suites are going to run.`
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
this.pickleIds = picklesToRun
|
|
326
|
-
|
|
327
|
-
skippedSuites = Array.from(filteredPickles.skippedSuites)
|
|
328
|
-
itrCorrelationId = skippableResponse.itrCorrelationId
|
|
297
|
+
skippedSuites = Array.from(filteredPickles.skippedSuites)
|
|
298
|
+
itrCorrelationId = skippableResponse.itrCorrelationId
|
|
299
|
+
}
|
|
329
300
|
}
|
|
330
301
|
|
|
331
302
|
pickleByFile = getPickleByFile(this)
|
|
@@ -333,11 +304,11 @@ function getWrappedStart (start, frameworkVersion) {
|
|
|
333
304
|
const processArgv = process.argv.slice(2).join(' ')
|
|
334
305
|
const command = process.env.npm_lifecycle_script || `cucumber-js ${processArgv}`
|
|
335
306
|
|
|
336
|
-
|
|
307
|
+
sessionAsyncResource.runInAsyncScope(() => {
|
|
337
308
|
sessionStartCh.publish({ command, frameworkVersion })
|
|
338
309
|
})
|
|
339
310
|
|
|
340
|
-
if (!
|
|
311
|
+
if (!errorSkippableRequest && skippedSuites.length) {
|
|
341
312
|
itrSkippedSuitesCh.publish({ skippedSuites, frameworkVersion })
|
|
342
313
|
}
|
|
343
314
|
|
|
@@ -355,7 +326,7 @@ function getWrappedStart (start, frameworkVersion) {
|
|
|
355
326
|
global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
|
|
356
327
|
}
|
|
357
328
|
|
|
358
|
-
|
|
329
|
+
sessionAsyncResource.runInAsyncScope(() => {
|
|
359
330
|
sessionFinishCh.publish({
|
|
360
331
|
status: success ? 'pass' : 'fail',
|
|
361
332
|
isSuitesSkipped,
|
|
@@ -363,7 +334,8 @@ function getWrappedStart (start, frameworkVersion) {
|
|
|
363
334
|
numSkippedSuites: skippedSuites.length,
|
|
364
335
|
hasUnskippableSuites: isUnskippable,
|
|
365
336
|
hasForcedToRunSuites: isForcedToRun,
|
|
366
|
-
isEarlyFlakeDetectionEnabled
|
|
337
|
+
isEarlyFlakeDetectionEnabled,
|
|
338
|
+
isParallel
|
|
367
339
|
})
|
|
368
340
|
})
|
|
369
341
|
return success
|
|
@@ -432,7 +404,8 @@ function getWrappedRunTest (runTestFunction) {
|
|
|
432
404
|
|
|
433
405
|
testSuiteCodeCoverageCh.publish({
|
|
434
406
|
coverageFiles,
|
|
435
|
-
suiteFile: testFileAbsolutePath
|
|
407
|
+
suiteFile: testFileAbsolutePath,
|
|
408
|
+
testSuitePath
|
|
436
409
|
})
|
|
437
410
|
// We need to reset coverage to get a code coverage per suite
|
|
438
411
|
// Before that, we preserve the original coverage
|
|
@@ -440,14 +413,97 @@ function getWrappedRunTest (runTestFunction) {
|
|
|
440
413
|
resetCoverage(global.__coverage__)
|
|
441
414
|
}
|
|
442
415
|
|
|
443
|
-
testSuiteFinishCh.publish(testSuiteStatus)
|
|
416
|
+
testSuiteFinishCh.publish({ status: testSuiteStatus, testSuitePath })
|
|
444
417
|
}
|
|
445
418
|
|
|
446
419
|
return runTestCaseResult
|
|
447
420
|
}
|
|
448
421
|
}
|
|
449
422
|
|
|
450
|
-
|
|
423
|
+
function getWrappedParseWorkerMessage (parseWorkerMessageFunction) {
|
|
424
|
+
return function (worker, message) {
|
|
425
|
+
// If the message is an array, it's a dd-trace message, so we need to stop cucumber processing,
|
|
426
|
+
// or cucumber will throw an error
|
|
427
|
+
// TODO: identify the message better
|
|
428
|
+
if (Array.isArray(message)) {
|
|
429
|
+
const [messageCode, payload] = message
|
|
430
|
+
if (messageCode === CUCUMBER_WORKER_TRACE_PAYLOAD_CODE) {
|
|
431
|
+
sessionAsyncResource.runInAsyncScope(() => {
|
|
432
|
+
workerReportTraceCh.publish(payload)
|
|
433
|
+
})
|
|
434
|
+
return
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const { jsonEnvelope } = message
|
|
439
|
+
if (!jsonEnvelope) {
|
|
440
|
+
return parseWorkerMessageFunction.apply(this, arguments)
|
|
441
|
+
}
|
|
442
|
+
let parsed = jsonEnvelope
|
|
443
|
+
|
|
444
|
+
if (typeof parsed === 'string') {
|
|
445
|
+
try {
|
|
446
|
+
parsed = JSON.parse(jsonEnvelope)
|
|
447
|
+
} catch (e) {
|
|
448
|
+
// ignore errors and continue
|
|
449
|
+
return parseWorkerMessageFunction.apply(this, arguments)
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (parsed.testCaseStarted) {
|
|
453
|
+
const { pickleId } = this.eventDataCollector.testCaseMap[parsed.testCaseStarted.testCaseId]
|
|
454
|
+
const pickle = this.eventDataCollector.getPickle(pickleId)
|
|
455
|
+
const testFileAbsolutePath = pickle.uri
|
|
456
|
+
// First test in suite
|
|
457
|
+
if (!pickleResultByFile[testFileAbsolutePath]) {
|
|
458
|
+
pickleResultByFile[testFileAbsolutePath] = []
|
|
459
|
+
testSuiteStartCh.publish({
|
|
460
|
+
testSuitePath: getTestSuitePath(testFileAbsolutePath, process.cwd())
|
|
461
|
+
})
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const parseWorkerResponse = parseWorkerMessageFunction.apply(this, arguments)
|
|
466
|
+
|
|
467
|
+
// after calling `parseWorkerMessageFunction`, the test status can already be read
|
|
468
|
+
if (parsed.testCaseFinished) {
|
|
469
|
+
const { pickle, worstTestStepResult } =
|
|
470
|
+
this.eventDataCollector.getTestCaseAttempt(parsed.testCaseFinished.testCaseStartedId)
|
|
471
|
+
|
|
472
|
+
const { status } = getStatusFromResultLatest(worstTestStepResult)
|
|
473
|
+
|
|
474
|
+
const testFileAbsolutePath = pickle.uri
|
|
475
|
+
const finished = pickleResultByFile[testFileAbsolutePath]
|
|
476
|
+
finished.push(status)
|
|
477
|
+
|
|
478
|
+
if (finished.length === pickleByFile[testFileAbsolutePath].length) {
|
|
479
|
+
testSuiteFinishCh.publish({
|
|
480
|
+
status: getSuiteStatusFromTestStatuses(finished),
|
|
481
|
+
testSuitePath: getTestSuitePath(testFileAbsolutePath, process.cwd())
|
|
482
|
+
})
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return parseWorkerResponse
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Test start / finish for older versions. The only hook executed in workers when in parallel mode
|
|
491
|
+
addHook({
|
|
492
|
+
name: '@cucumber/cucumber',
|
|
493
|
+
versions: ['7.0.0 - 7.2.1'],
|
|
494
|
+
file: 'lib/runtime/pickle_runner.js'
|
|
495
|
+
}, pickleHook)
|
|
496
|
+
|
|
497
|
+
// Test start / finish for newer versions. The only hook executed in workers when in parallel mode
|
|
498
|
+
addHook({
|
|
499
|
+
name: '@cucumber/cucumber',
|
|
500
|
+
versions: ['>=7.3.0'],
|
|
501
|
+
file: 'lib/runtime/test_case_runner.js'
|
|
502
|
+
}, testCaseHook)
|
|
503
|
+
|
|
504
|
+
// From 7.3.0 onwards, runPickle becomes runTestCase. Not executed in parallel mode.
|
|
505
|
+
// `getWrappedStart` generates session start and finish events
|
|
506
|
+
// `getWrappedRunTest` generates suite start and finish events
|
|
451
507
|
addHook({
|
|
452
508
|
name: '@cucumber/cucumber',
|
|
453
509
|
versions: ['>=7.3.0'],
|
|
@@ -459,6 +515,9 @@ addHook({
|
|
|
459
515
|
return runtimePackage
|
|
460
516
|
})
|
|
461
517
|
|
|
518
|
+
// Not executed in parallel mode.
|
|
519
|
+
// `getWrappedStart` generates session start and finish events
|
|
520
|
+
// `getWrappedRunTest` generates suite start and finish events
|
|
462
521
|
addHook({
|
|
463
522
|
name: '@cucumber/cucumber',
|
|
464
523
|
versions: ['>=7.0.0 <7.3.0'],
|
|
@@ -469,3 +528,21 @@ addHook({
|
|
|
469
528
|
|
|
470
529
|
return runtimePackage
|
|
471
530
|
})
|
|
531
|
+
|
|
532
|
+
// Only executed in parallel mode.
|
|
533
|
+
// `getWrappedStart` generates session start and finish events
|
|
534
|
+
// `getWrappedGiveWork` generates suite start events and sets pickleResultByFile (used by suite finish events)
|
|
535
|
+
// `getWrappedParseWorkerMessage` generates suite finish events
|
|
536
|
+
addHook({
|
|
537
|
+
name: '@cucumber/cucumber',
|
|
538
|
+
versions: ['>=8.0.0'],
|
|
539
|
+
file: 'lib/runtime/parallel/coordinator.js'
|
|
540
|
+
}, (coordinatorPackage, frameworkVersion) => {
|
|
541
|
+
shimmer.wrap(coordinatorPackage.default.prototype, 'start', start => getWrappedStart(start, frameworkVersion, true))
|
|
542
|
+
shimmer.wrap(
|
|
543
|
+
coordinatorPackage.default.prototype,
|
|
544
|
+
'parseWorkerMessage',
|
|
545
|
+
parseWorkerMessage => getWrappedParseWorkerMessage(parseWorkerMessage)
|
|
546
|
+
)
|
|
547
|
+
return coordinatorPackage
|
|
548
|
+
})
|
|
@@ -7,11 +7,16 @@ exports.createWrapFetch = function createWrapFetch (Request, ch) {
|
|
|
7
7
|
return function (input, init) {
|
|
8
8
|
if (!ch.start.hasSubscribers) return fetch.apply(this, arguments)
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const ctx = { req, headers }
|
|
10
|
+
if (input instanceof Request) {
|
|
11
|
+
const ctx = { req: input }
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
return ch.tracePromise(() => fetch.call(this, input, init), ctx)
|
|
14
|
+
} else {
|
|
15
|
+
const req = new Request(input, init)
|
|
16
|
+
const ctx = { req }
|
|
17
|
+
|
|
18
|
+
return ch.tracePromise(() => fetch.call(this, req), ctx)
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
}
|
|
@@ -10,6 +10,98 @@ const startCh = channel('apm:openai:request:start')
|
|
|
10
10
|
const finishCh = channel('apm:openai:request:finish')
|
|
11
11
|
const errorCh = channel('apm:openai:request:error')
|
|
12
12
|
|
|
13
|
+
const V4_PACKAGE_SHIMS = [
|
|
14
|
+
{
|
|
15
|
+
file: 'resources/chat/completions.js',
|
|
16
|
+
targetClass: 'Completions',
|
|
17
|
+
baseResource: 'chat.completions',
|
|
18
|
+
methods: ['create']
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
file: 'resources/completions.js',
|
|
22
|
+
targetClass: 'Completions',
|
|
23
|
+
baseResource: 'completions',
|
|
24
|
+
methods: ['create']
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
file: 'resources/embeddings.js',
|
|
28
|
+
targetClass: 'Embeddings',
|
|
29
|
+
baseResource: 'embeddings',
|
|
30
|
+
methods: ['create']
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
file: 'resources/files.js',
|
|
34
|
+
targetClass: 'Files',
|
|
35
|
+
baseResource: 'files',
|
|
36
|
+
methods: ['create', 'del', 'list', 'retrieve']
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
file: 'resources/files.js',
|
|
40
|
+
targetClass: 'Files',
|
|
41
|
+
baseResource: 'files',
|
|
42
|
+
methods: ['retrieveContent'],
|
|
43
|
+
versions: ['>=4.0.0 <4.17.1']
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
file: 'resources/files.js',
|
|
47
|
+
targetClass: 'Files',
|
|
48
|
+
baseResource: 'files',
|
|
49
|
+
methods: ['content'], // replaced `retrieveContent` in v4.17.1
|
|
50
|
+
versions: ['>=4.17.1']
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
file: 'resources/images.js',
|
|
54
|
+
targetClass: 'Images',
|
|
55
|
+
baseResource: 'images',
|
|
56
|
+
methods: ['createVariation', 'edit', 'generate']
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
file: 'resources/fine-tuning/jobs/jobs.js',
|
|
60
|
+
targetClass: 'Jobs',
|
|
61
|
+
baseResource: 'fine_tuning.jobs',
|
|
62
|
+
methods: ['cancel', 'create', 'list', 'listEvents', 'retrieve'],
|
|
63
|
+
versions: ['>=4.34.0'] // file location changed in 4.34.0
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
file: 'resources/fine-tuning/jobs.js',
|
|
67
|
+
targetClass: 'Jobs',
|
|
68
|
+
baseResource: 'fine_tuning.jobs',
|
|
69
|
+
methods: ['cancel', 'create', 'list', 'listEvents', 'retrieve'],
|
|
70
|
+
versions: ['>=4.1.0 <4.34.0']
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
file: 'resources/fine-tunes.js', // deprecated after 4.1.0
|
|
74
|
+
targetClass: 'FineTunes',
|
|
75
|
+
baseResource: 'fine-tune',
|
|
76
|
+
methods: ['cancel', 'create', 'list', 'listEvents', 'retrieve'],
|
|
77
|
+
versions: ['>=4.0.0 <4.1.0']
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
file: 'resources/models.js',
|
|
81
|
+
targetClass: 'Models',
|
|
82
|
+
baseResource: 'models',
|
|
83
|
+
methods: ['del', 'list', 'retrieve']
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
file: 'resources/moderations.js',
|
|
87
|
+
targetClass: 'Moderations',
|
|
88
|
+
baseResource: 'moderations',
|
|
89
|
+
methods: ['create']
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
file: 'resources/audio/transcriptions.js',
|
|
93
|
+
targetClass: 'Transcriptions',
|
|
94
|
+
baseResource: 'audio.transcriptions',
|
|
95
|
+
methods: ['create']
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
file: 'resources/audio/translations.js',
|
|
99
|
+
targetClass: 'Translations',
|
|
100
|
+
baseResource: 'audio.translations',
|
|
101
|
+
methods: ['create']
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
|
|
13
105
|
addHook({ name: 'openai', file: 'dist/api.js', versions: ['>=3.0.0 <4'] }, exports => {
|
|
14
106
|
const methodNames = Object.getOwnPropertyNames(exports.OpenAIApi.prototype)
|
|
15
107
|
methodNames.shift() // remove leading 'constructor' method
|
|
@@ -48,3 +140,60 @@ addHook({ name: 'openai', file: 'dist/api.js', versions: ['>=3.0.0 <4'] }, expor
|
|
|
48
140
|
|
|
49
141
|
return exports
|
|
50
142
|
})
|
|
143
|
+
|
|
144
|
+
for (const shim of V4_PACKAGE_SHIMS) {
|
|
145
|
+
const { file, targetClass, baseResource, methods } = shim
|
|
146
|
+
addHook({ name: 'openai', file, versions: shim.versions || ['>=4'] }, exports => {
|
|
147
|
+
const targetPrototype = exports[targetClass].prototype
|
|
148
|
+
|
|
149
|
+
for (const methodName of methods) {
|
|
150
|
+
shimmer.wrap(targetPrototype, methodName, methodFn => function () {
|
|
151
|
+
if (!startCh.hasSubscribers) {
|
|
152
|
+
return methodFn.apply(this, arguments)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const client = this._client || this.client
|
|
156
|
+
|
|
157
|
+
startCh.publish({
|
|
158
|
+
methodName: `${baseResource}.${methodName}`,
|
|
159
|
+
args: arguments,
|
|
160
|
+
basePath: client.baseURL,
|
|
161
|
+
apiKey: client.apiKey
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const apiProm = methodFn.apply(this, arguments)
|
|
165
|
+
|
|
166
|
+
// wrapping `parse` avoids problematic wrapping of `then` when trying to call
|
|
167
|
+
// `withResponse` in userland code after. This way, we can return the whole `APIPromise`
|
|
168
|
+
shimmer.wrap(apiProm, 'parse', origApiPromParse => function () {
|
|
169
|
+
return origApiPromParse.apply(this, arguments)
|
|
170
|
+
// the original response is wrapped in a promise, so we need to unwrap it
|
|
171
|
+
.then(body => Promise.all([this.responsePromise, body]))
|
|
172
|
+
.then(([{ response, options }, body]) => {
|
|
173
|
+
finishCh.publish({
|
|
174
|
+
headers: response.headers,
|
|
175
|
+
body,
|
|
176
|
+
path: response.url,
|
|
177
|
+
method: options.method
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
return body
|
|
181
|
+
})
|
|
182
|
+
.catch(err => {
|
|
183
|
+
errorCh.publish({ err })
|
|
184
|
+
|
|
185
|
+
throw err
|
|
186
|
+
})
|
|
187
|
+
.finally(() => {
|
|
188
|
+
// maybe we don't want to unwrap here in case the promise is re-used?
|
|
189
|
+
// other hand: we want to avoid resource leakage
|
|
190
|
+
shimmer.unwrap(apiProm, 'parse')
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
return apiProm
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
return exports
|
|
198
|
+
})
|
|
199
|
+
}
|
|
@@ -4,7 +4,12 @@ const { addHook } = require('./helpers/instrument')
|
|
|
4
4
|
const shimmer = require('../../datadog-shimmer')
|
|
5
5
|
const tracer = require('../../dd-trace')
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const otelSdkEnabled = process.env.DD_TRACE_OTEL_ENABLED ||
|
|
8
|
+
process.env.OTEL_SDK_DISABLED
|
|
9
|
+
? !process.env.OTEL_SDK_DISABLED
|
|
10
|
+
: undefined
|
|
11
|
+
|
|
12
|
+
if (otelSdkEnabled) {
|
|
8
13
|
addHook({
|
|
9
14
|
name: '@opentelemetry/sdk-trace-node',
|
|
10
15
|
file: 'build/src/NodeTracerProvider.js',
|
|
@@ -7,6 +7,9 @@ exports.kinesis = require('./kinesis')
|
|
|
7
7
|
exports.lambda = require('./lambda')
|
|
8
8
|
exports.redshift = require('./redshift')
|
|
9
9
|
exports.s3 = require('./s3')
|
|
10
|
+
exports.sfn = require('./sfn')
|
|
10
11
|
exports.sns = require('./sns')
|
|
11
12
|
exports.sqs = require('./sqs')
|
|
13
|
+
exports.states = require('./states')
|
|
14
|
+
exports.stepfunctions = require('./stepfunctions')
|
|
12
15
|
exports.default = require('./default')
|