dd-trace 4.0.0-pre-d46f64a → 4.0.0-pre-1ac80f8
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/LICENSE-3rdparty.csv +1 -2
- package/index.d.ts +6 -2
- package/package.json +18 -17
- package/packages/datadog-instrumentations/src/cucumber.js +80 -3
- package/packages/datadog-instrumentations/src/mariadb.js +130 -11
- package/packages/datadog-instrumentations/src/mocha.js +30 -6
- package/packages/datadog-instrumentations/src/mongodb-core.js +8 -2
- package/packages/datadog-instrumentations/src/next.js +32 -4
- package/packages/datadog-plugin-aws-sdk/src/base.js +4 -1
- package/packages/datadog-plugin-cucumber/src/index.js +28 -2
- package/packages/datadog-plugin-cypress/src/plugin.js +40 -33
- package/packages/datadog-plugin-jest/src/index.js +0 -5
- package/packages/datadog-plugin-mariadb/src/index.js +17 -0
- package/packages/datadog-plugin-mocha/src/index.js +2 -2
- package/packages/datadog-plugin-net/src/index.js +9 -75
- package/packages/dd-trace/src/appsec/gateway/engine/runner.js +2 -1
- package/packages/dd-trace/src/appsec/iast/analyzers/analyzers.js +2 -0
- package/packages/dd-trace/src/appsec/iast/analyzers/vulnerability-analyzer.js +2 -2
- package/packages/dd-trace/src/appsec/iast/iast-log.js +111 -0
- package/packages/dd-trace/src/appsec/iast/index.js +7 -4
- package/packages/dd-trace/src/appsec/iast/path-line.js +3 -6
- package/packages/dd-trace/src/appsec/iast/taint-tracking/index.js +2 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/operations.js +2 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/origin-types.js +2 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/plugin.js +2 -0
- package/packages/dd-trace/src/appsec/iast/taint-tracking/rewriter.js +5 -3
- package/packages/dd-trace/src/appsec/iast/taint-tracking/taint-tracking-impl.js +5 -3
- package/packages/dd-trace/src/appsec/iast/telemetry/log_collector.js +96 -0
- package/packages/dd-trace/src/appsec/iast/telemetry/logs.js +87 -0
- package/packages/dd-trace/src/appsec/iast/vulnerability-reporter.js +27 -2
- package/packages/dd-trace/src/config.js +21 -2
- package/packages/dd-trace/src/exporters/common/agents.js +42 -0
- package/packages/dd-trace/src/exporters/common/request.js +1 -4
- package/packages/dd-trace/src/lambda/handler.js +14 -6
- package/packages/dd-trace/src/opentracing/span.js +5 -0
- package/packages/dd-trace/src/plugins/util/ci.js +12 -0
- package/packages/dd-trace/src/plugins/util/test.js +12 -0
- package/packages/dd-trace/src/profiling/config.js +68 -2
- package/packages/dd-trace/src/profiling/constants.js +16 -0
- package/packages/dd-trace/src/profiling/exporter_cli.js +62 -0
- package/packages/dd-trace/src/profiling/exporters/agent.js +2 -1
- package/packages/dd-trace/src/profiling/profiler.js +21 -8
- package/packages/dd-trace/src/profiling/profilers/space.js +21 -1
- package/packages/dd-trace/src/span_sampler.js +3 -2
- package/packages/dd-trace/src/telemetry/index.js +16 -2
- package/packages/dd-trace/src/util.js +10 -1
- package/scripts/junit_report.js +0 -25
- package/scripts/tdd.js +0 -34
package/LICENSE-3rdparty.csv
CHANGED
|
@@ -51,8 +51,6 @@ dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
|
|
|
51
51
|
dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
|
|
52
52
|
dev,mkdirp,MIT,Copyright 2010 James Halliday
|
|
53
53
|
dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
|
|
54
|
-
dev,mocha-junit-reporter,MIT,Copyright (c) 2015 Michael Allen
|
|
55
|
-
dev,mocha-multi-reporters,MIT,Copyright 2019 Yousaf Nabi and 2015 Stanley Ng
|
|
56
54
|
dev,multer,MIT,Copyright 2014 Hage Yaapa
|
|
57
55
|
dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
|
|
58
56
|
dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
|
|
@@ -62,6 +60,7 @@ dev,proxyquire,MIT,Copyright 2013 Thorsten Lorenz
|
|
|
62
60
|
dev,rimraf,ISC,Copyright Isaac Z. Schlueter and Contributors
|
|
63
61
|
dev,sinon,BSD-3-Clause,Copyright 2010-2017 Christian Johansen
|
|
64
62
|
dev,sinon-chai,WTFPL and BSD-2-Clause,Copyright 2004 Sam Hocevar 2012–2017 Domenic Denicola
|
|
63
|
+
dev,tap,ISC,Copyright 2011-2022 Isaac Z. Schlueter and Contributors
|
|
65
64
|
dev,tape,MIT,Copyright James Halliday
|
|
66
65
|
dev,wait-on,MIT,Copyright 2015 Jeff Barczewski
|
|
67
66
|
file,aws-lambda-nodejs-runtime-interface-client,Apache 2.0,Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
package/index.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ export declare interface Tracer extends opentracing.Tracer {
|
|
|
98
98
|
* * The function doesn't accept a callback and doesn't return a promise, in
|
|
99
99
|
* which case the span will finish at the end of the function execution.
|
|
100
100
|
*/
|
|
101
|
-
wrap<T = (...args: any[]) => any> (name: string, fn: T
|
|
101
|
+
wrap<T = (...args: any[]) => any> (name: string, fn: T): T;
|
|
102
102
|
wrap<T = (...args: any[]) => any> (name: string, options: TraceOptions & SpanOptions, fn: T): T;
|
|
103
103
|
wrap<T = (...args: any[]) => any> (name: string, options: (...args: any[]) => TraceOptions & SpanOptions, fn: T): T;
|
|
104
104
|
|
|
@@ -438,7 +438,11 @@ export declare interface TracerOptions {
|
|
|
438
438
|
* Controls how many code vulnerabilities can be detected in the same request
|
|
439
439
|
* @default 2
|
|
440
440
|
*/
|
|
441
|
-
maxContextOperations?: number
|
|
441
|
+
maxContextOperations?: number,
|
|
442
|
+
/**
|
|
443
|
+
* Whether to enable vulnerability deduplication
|
|
444
|
+
*/
|
|
445
|
+
deduplicationEnabled?: boolean
|
|
442
446
|
}
|
|
443
447
|
};
|
|
444
448
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dd-trace",
|
|
3
|
-
"version": "4.0.0-pre-
|
|
3
|
+
"version": "4.0.0-pre-1ac80f8",
|
|
4
4
|
"description": "Datadog APM tracing client for JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -14,27 +14,29 @@
|
|
|
14
14
|
"type:test": "cd docs && yarn && yarn test",
|
|
15
15
|
"lint": "node scripts/check_licenses.js && eslint . && yarn audit --groups dependencies",
|
|
16
16
|
"services": "node ./scripts/install_plugin_modules && node packages/dd-trace/test/setup/services",
|
|
17
|
-
"tdd": "node scripts/tdd.js",
|
|
18
17
|
"test": "SERVICES=* yarn services && mocha --colors --exit --expose-gc 'packages/dd-trace/test/setup/node.js' 'packages/*/test/**/*.spec.js'",
|
|
19
|
-
"test:
|
|
20
|
-
"test:
|
|
21
|
-
"test:
|
|
18
|
+
"test:appsec": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" \"packages/dd-trace/test/appsec/**/*.spec.js\"",
|
|
19
|
+
"test:appsec:ci": "nyc --no-clean --include \"packages/dd-trace/src/appsec/**/*.js\" --exclude \"packages/dd-trace/test/appsec/iast/**/*.plugin.spec.js\" -- npm run test:appsec",
|
|
20
|
+
"test:appsec:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\"",
|
|
21
|
+
"test:appsec:plugins:ci": "yarn services && nyc --no-clean --include \"packages/dd-trace/test/appsec/iast/**/*.@($(echo $PLUGINS)).plugin.spec.js\" -- npm run test:appsec:plugins",
|
|
22
|
+
"test:trace:core": "tap packages/dd-trace/test/*.spec.js packages/dd-trace/test/{ci-visibility,encode,exporters,opentracing,plugins,telemetry}/**/*.spec.js",
|
|
23
|
+
"test:trace:core:ci": "npm run test:trace:core -- --coverage --nyc-arg=--include=packages/dd-trace/src/**/*.js",
|
|
24
|
+
"test:instrumentations": "mocha --colors -r 'packages/dd-trace/test/setup/mocha.js' 'packages/datadog-instrumentations/test/**/*.spec.js'",
|
|
22
25
|
"test:instrumentations:ci": "nyc --no-clean --include 'packages/datadog-instrumentations/src/**/*.js' -- npm run test:instrumentations",
|
|
23
|
-
"test:core": "
|
|
24
|
-
"test:core:ci": "
|
|
25
|
-
"test:lambda": "mocha --colors --exit
|
|
26
|
+
"test:core": "tap packages/datadog-core/test/**/*.spec.js",
|
|
27
|
+
"test:core:ci": "npm run test:core -- --coverage --nyc-arg=--include=packages/datadog-core/src/**/*.js",
|
|
28
|
+
"test:lambda": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/dd-trace/test/lambda/**/*.spec.js\"",
|
|
26
29
|
"test:lambda:ci": "nyc --no-clean --include \"packages/dd-trace/src/lambda/**/*.js\" -- npm run test:lambda",
|
|
27
|
-
"test:plugins": "mocha --colors --exit
|
|
28
|
-
"test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" --
|
|
30
|
+
"test:plugins": "mocha --colors --exit -r \"packages/dd-trace/test/setup/mocha.js\" \"packages/datadog-instrumentations/test/@($(echo $PLUGINS)).spec.js\" \"packages/datadog-plugin-@($(echo $PLUGINS))/test/**/*.spec.js\"",
|
|
31
|
+
"test:plugins:ci": "yarn services && nyc --no-clean --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS)).js\" --include \"packages/datadog-instrumentations/src/@($(echo $PLUGINS))/**/*.js\" --include \"packages/datadog-plugin-@($(echo $PLUGINS))/src/**/*.js\" -- npm run test:plugins",
|
|
29
32
|
"test:plugins:upstream": "node ./packages/dd-trace/test/plugins/suite.js",
|
|
30
|
-
"test:profiler": "
|
|
31
|
-
"test:profiler:ci": "
|
|
33
|
+
"test:profiler": "tap packages/dd-trace/test/profiling/**/*.spec.js",
|
|
34
|
+
"test:profiler:ci": "npm run test:profiler -- --coverage --nyc-arg=--include=packages/dd-trace/src/profiling/**/*.js",
|
|
32
35
|
"test:integration": "mocha --colors --timeout 30000 \"integration-tests/**/*.spec.js\"",
|
|
33
36
|
"test:shimmer": "mocha --colors 'packages/datadog-shimmer/test/**/*.spec.js'",
|
|
34
37
|
"test:shimmer:ci": "nyc --no-clean --include 'packages/datadog-shimmer/src/**/*.js' -- npm run test:shimmer",
|
|
35
38
|
"leak:core": "node ./scripts/install_plugin_modules && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape 'packages/dd-trace/test/leak/**/*.js'",
|
|
36
|
-
"leak:plugins": "yarn services && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape \"packages/datadog-plugin-@($(echo $PLUGINS))/test/leak.js\""
|
|
37
|
-
"junit:upload": "node ./scripts/junit_report.js"
|
|
39
|
+
"leak:plugins": "yarn services && (cd packages/memwatch && yarn) && NODE_PATH=./packages/memwatch/node_modules node --no-warnings ./node_modules/.bin/tape \"packages/datadog-plugin-@($(echo $PLUGINS))/test/leak.js\""
|
|
38
40
|
},
|
|
39
41
|
"repository": {
|
|
40
42
|
"type": "git",
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
"@datadog/native-iast-rewriter": "2.0.1",
|
|
65
67
|
"@datadog/native-iast-taint-tracking": "1.1.1",
|
|
66
68
|
"@datadog/native-metrics": "^1.5.0",
|
|
67
|
-
"@datadog/pprof": "^2.
|
|
69
|
+
"@datadog/pprof": "^2.1.0",
|
|
68
70
|
"@datadog/sketches-js": "^2.1.0",
|
|
69
71
|
"crypto-randomuuid": "^1.0.0",
|
|
70
72
|
"diagnostics_channel": "^1.1.0",
|
|
@@ -114,8 +116,6 @@
|
|
|
114
116
|
"jszip": "^3.5.0",
|
|
115
117
|
"mkdirp": "^0.5.1",
|
|
116
118
|
"mocha": "8",
|
|
117
|
-
"mocha-junit-reporter": "^2.1.0",
|
|
118
|
-
"mocha-multi-reporters": "^1.5.1",
|
|
119
119
|
"msgpack-lite": "^0.1.26",
|
|
120
120
|
"multer": "^1.4.5-lts.1",
|
|
121
121
|
"nock": "^11.3.3",
|
|
@@ -125,6 +125,7 @@
|
|
|
125
125
|
"rimraf": "^3.0.0",
|
|
126
126
|
"sinon": "^11.1.2",
|
|
127
127
|
"sinon-chai": "^3.7.0",
|
|
128
|
+
"tap": "^16.3.4",
|
|
128
129
|
"tape": "^4.9.1",
|
|
129
130
|
"wait-on": "^5.0.0"
|
|
130
131
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
const { createCoverageMap } = require('istanbul-lib-coverage')
|
|
2
3
|
|
|
3
4
|
const { addHook, channel, AsyncResource } = require('./helpers/instrument')
|
|
4
5
|
const shimmer = require('../../datadog-shimmer')
|
|
@@ -12,10 +13,24 @@ const errorCh = channel('ci:cucumber:error')
|
|
|
12
13
|
|
|
13
14
|
const testSuiteStartCh = channel('ci:cucumber:test-suite:start')
|
|
14
15
|
const testSuiteFinishCh = channel('ci:cucumber:test-suite:finish')
|
|
16
|
+
const testSuiteCodeCoverageCh = channel('ci:cucumber:test-suite:code-coverage')
|
|
15
17
|
|
|
18
|
+
const itrConfigurationCh = channel('ci:cucumber:itr-configuration')
|
|
19
|
+
const skippableSuitesCh = channel('ci:cucumber:test-suite:skippable')
|
|
16
20
|
const sessionStartCh = channel('ci:cucumber:session:start')
|
|
17
21
|
const sessionFinishCh = channel('ci:cucumber:session:finish')
|
|
18
22
|
|
|
23
|
+
const {
|
|
24
|
+
getCoveredFilenamesFromCoverage,
|
|
25
|
+
resetCoverage,
|
|
26
|
+
mergeCoverage,
|
|
27
|
+
fromCoverageMapToCoverage,
|
|
28
|
+
getTestSuitePath
|
|
29
|
+
} = require('../../dd-trace/src/plugins/util/test')
|
|
30
|
+
|
|
31
|
+
// We'll preserve the original coverage here
|
|
32
|
+
const originalCoverageMap = createCoverageMap()
|
|
33
|
+
|
|
19
34
|
// TODO: remove in a later major version
|
|
20
35
|
const patched = new WeakSet()
|
|
21
36
|
|
|
@@ -88,12 +103,25 @@ function wrapRun (pl, isLatestVersion) {
|
|
|
88
103
|
} else {
|
|
89
104
|
pickleResultByFile[testSuiteFullPath].push(status)
|
|
90
105
|
}
|
|
106
|
+
testFinishCh.publish({ status, skipReason, errorMessage })
|
|
91
107
|
// last test in suite
|
|
92
108
|
if (pickleResultByFile[testSuiteFullPath].length === pickleByFile[testSuiteFullPath].length) {
|
|
93
109
|
const testSuiteStatus = getSuiteStatusFromTestStatuses(pickleResultByFile[testSuiteFullPath])
|
|
110
|
+
if (global.__coverage__) {
|
|
111
|
+
const coverageFiles = getCoveredFilenamesFromCoverage(global.__coverage__)
|
|
112
|
+
|
|
113
|
+
testSuiteCodeCoverageCh.publish({
|
|
114
|
+
coverageFiles,
|
|
115
|
+
suiteFile: testSuiteFullPath
|
|
116
|
+
})
|
|
117
|
+
// We need to reset coverage to get a code coverage per suite
|
|
118
|
+
// Before that, we preserve the original coverage
|
|
119
|
+
mergeCoverage(global.__coverage__, originalCoverageMap)
|
|
120
|
+
resetCoverage(global.__coverage__)
|
|
121
|
+
}
|
|
122
|
+
|
|
94
123
|
testSuiteFinishCh.publish(testSuiteStatus)
|
|
95
124
|
}
|
|
96
|
-
testFinishCh.publish({ status, skipReason, errorMessage })
|
|
97
125
|
})
|
|
98
126
|
return promise
|
|
99
127
|
} catch (err) {
|
|
@@ -164,6 +192,13 @@ addHook({
|
|
|
164
192
|
file: 'lib/runtime/test_case_runner.js'
|
|
165
193
|
}, testCaseHook)
|
|
166
194
|
|
|
195
|
+
function getPicklesToRun (runtime, suitesToSkip) {
|
|
196
|
+
return runtime.pickleIds.filter((pickleId) => {
|
|
197
|
+
const test = runtime.eventDataCollector.getPickle(pickleId)
|
|
198
|
+
return !suitesToSkip.includes(getTestSuitePath(test.uri, process.cwd()))
|
|
199
|
+
}, {})
|
|
200
|
+
}
|
|
201
|
+
|
|
167
202
|
function getPickleByFile (runtime) {
|
|
168
203
|
return runtime.pickleIds.reduce((acc, pickleId) => {
|
|
169
204
|
const test = runtime.eventDataCollector.getPickle(pickleId)
|
|
@@ -182,19 +217,61 @@ addHook({
|
|
|
182
217
|
file: 'lib/runtime/index.js'
|
|
183
218
|
}, (runtimePackage, cucumberVersion) => {
|
|
184
219
|
shimmer.wrap(runtimePackage.default.prototype, 'start', start => async function () {
|
|
220
|
+
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
221
|
+
let onDone
|
|
222
|
+
|
|
223
|
+
const configPromise = new Promise(resolve => {
|
|
224
|
+
onDone = resolve
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
asyncResource.runInAsyncScope(() => {
|
|
228
|
+
itrConfigurationCh.publish({ onDone })
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
await configPromise
|
|
232
|
+
|
|
233
|
+
const skippableSuitesPromise = new Promise(resolve => {
|
|
234
|
+
onDone = resolve
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
asyncResource.runInAsyncScope(() => {
|
|
238
|
+
skippableSuitesCh.publish({ onDone })
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const { err, skippableSuites } = await skippableSuitesPromise
|
|
242
|
+
|
|
243
|
+
if (!err) {
|
|
244
|
+
this.pickleIds = getPicklesToRun(this, skippableSuites)
|
|
245
|
+
}
|
|
246
|
+
|
|
185
247
|
pickleByFile = getPickleByFile(this)
|
|
186
248
|
|
|
187
249
|
const processArgv = process.argv.slice(2).join(' ')
|
|
188
250
|
const command = process.env.npm_lifecycle_script || `cucumber-js ${processArgv}`
|
|
189
251
|
|
|
190
|
-
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
191
252
|
asyncResource.runInAsyncScope(() => {
|
|
192
253
|
sessionStartCh.publish({ command, frameworkVersion: cucumberVersion })
|
|
193
254
|
})
|
|
194
255
|
const success = await start.apply(this, arguments)
|
|
195
256
|
|
|
257
|
+
let testCodeCoverageLinesTotal
|
|
258
|
+
|
|
259
|
+
if (global.__coverage__) {
|
|
260
|
+
try {
|
|
261
|
+
testCodeCoverageLinesTotal = originalCoverageMap.getCoverageSummary().lines.pct
|
|
262
|
+
} catch (e) {
|
|
263
|
+
// ignore errors
|
|
264
|
+
}
|
|
265
|
+
// restore the original coverage
|
|
266
|
+
global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
|
|
267
|
+
}
|
|
268
|
+
|
|
196
269
|
asyncResource.runInAsyncScope(() => {
|
|
197
|
-
sessionFinishCh.publish(
|
|
270
|
+
sessionFinishCh.publish({
|
|
271
|
+
status: success ? 'pass' : 'fail',
|
|
272
|
+
isSuitesSkipped: skippableSuites ? !!skippableSuites.length : false,
|
|
273
|
+
testCodeCoverageLinesTotal
|
|
274
|
+
})
|
|
198
275
|
})
|
|
199
276
|
return success
|
|
200
277
|
})
|
|
@@ -7,17 +7,17 @@ const shimmer = require('../../datadog-shimmer')
|
|
|
7
7
|
const startCh = channel('apm:mariadb:query:start')
|
|
8
8
|
const finishCh = channel('apm:mariadb:query:finish')
|
|
9
9
|
const errorCh = channel('apm:mariadb:query:error')
|
|
10
|
+
const skipCh = channel('apm:mariadb:pool:skip')
|
|
11
|
+
const unskipCh = channel('apm:mariadb:pool:unskip')
|
|
10
12
|
|
|
11
|
-
function wrapCommandStart (start) {
|
|
13
|
+
function wrapCommandStart (start, callbackResource) {
|
|
12
14
|
return function () {
|
|
13
15
|
if (!startCh.hasSubscribers) return start.apply(this, arguments)
|
|
14
16
|
|
|
15
|
-
const callbackResource = new AsyncResource('bound-anonymous-fn')
|
|
16
|
-
|
|
17
17
|
const resolve = callbackResource.bind(this.resolve)
|
|
18
18
|
const reject = callbackResource.bind(this.reject)
|
|
19
19
|
|
|
20
|
-
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
20
|
+
const asyncResource = callbackResource.runInAsyncScope(() => new AsyncResource('bound-anonymous-fn'))
|
|
21
21
|
|
|
22
22
|
shimmer.wrap(this, 'resolve', function wrapResolve () {
|
|
23
23
|
return function () {
|
|
@@ -47,17 +47,136 @@ function wrapCommandStart (start) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
function wrapCommand (Command) {
|
|
51
|
+
return class extends Command {
|
|
52
|
+
constructor (...args) {
|
|
53
|
+
super(...args)
|
|
54
|
+
|
|
55
|
+
const callbackResource = new AsyncResource('bound-anonymous-fn')
|
|
56
|
+
|
|
57
|
+
if (this.start) {
|
|
58
|
+
this.start = wrapCommandStart(this.start, callbackResource)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createWrapQuery (options) {
|
|
65
|
+
return function wrapQuery (query) {
|
|
66
|
+
return function (sql) {
|
|
67
|
+
if (!startCh.hasSubscribers) return query.apply(this, arguments)
|
|
68
|
+
|
|
69
|
+
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
70
|
+
|
|
71
|
+
return asyncResource.runInAsyncScope(() => {
|
|
72
|
+
startCh.publish({ sql, conf: options })
|
|
73
|
+
|
|
74
|
+
return query.apply(this, arguments)
|
|
75
|
+
.then(result => {
|
|
76
|
+
finishCh.publish()
|
|
77
|
+
return result
|
|
78
|
+
}, error => {
|
|
79
|
+
errorCh.publish(error)
|
|
80
|
+
finishCh.publish()
|
|
81
|
+
throw error
|
|
82
|
+
})
|
|
83
|
+
}, 'bound-anonymous-fn')
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function createWrapQueryCallback (options) {
|
|
89
|
+
return function wrapQuery (query) {
|
|
90
|
+
return function (sql) {
|
|
91
|
+
if (!startCh.hasSubscribers) return query.apply(this, arguments)
|
|
92
|
+
|
|
93
|
+
const cb = arguments[arguments.length - 1]
|
|
94
|
+
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
95
|
+
const callbackResource = new AsyncResource('bound-anonymous-fn')
|
|
96
|
+
|
|
97
|
+
if (typeof cb !== 'function') {
|
|
98
|
+
arguments.length = arguments.length + 1
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
arguments[arguments.length - 1] = asyncResource.bind(function (err) {
|
|
102
|
+
if (err) {
|
|
103
|
+
errorCh.publish(err)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
finishCh.publish()
|
|
107
|
+
|
|
108
|
+
if (typeof cb === 'function') {
|
|
109
|
+
return callbackResource.runInAsyncScope(() => cb.apply(this, arguments))
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
return asyncResource.runInAsyncScope(() => {
|
|
114
|
+
startCh.publish({ sql, conf: options })
|
|
115
|
+
|
|
116
|
+
return query.apply(this, arguments)
|
|
117
|
+
}, 'bound-anonymous-fn')
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function wrapConnection (Connection, promiseMethod) {
|
|
123
|
+
return function (options) {
|
|
124
|
+
Connection.apply(this, arguments)
|
|
125
|
+
|
|
126
|
+
shimmer.wrap(this, promiseMethod, createWrapQuery(options))
|
|
127
|
+
shimmer.wrap(this, '_queryCallback', createWrapQueryCallback(options))
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function wrapPoolBase (PoolBase) {
|
|
132
|
+
return function (options, processTask, createConnectionPool, pingPromise) {
|
|
133
|
+
arguments[1] = wrapPoolMethod(processTask)
|
|
134
|
+
arguments[2] = wrapPoolMethod(createConnectionPool)
|
|
135
|
+
|
|
136
|
+
PoolBase.apply(this, arguments)
|
|
137
|
+
|
|
138
|
+
shimmer.wrap(this, 'query', createWrapQuery(options.connOptions))
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// It's not possible to prevent connection pools from leaking across queries,
|
|
143
|
+
// so instead we just skip instrumentation completely to avoid memory leaks
|
|
144
|
+
// and/or orphan spans.
|
|
145
|
+
function wrapPoolMethod (createConnection) {
|
|
146
|
+
return function () {
|
|
147
|
+
skipCh.publish()
|
|
148
|
+
try {
|
|
149
|
+
return createConnection.apply(this, arguments)
|
|
150
|
+
} finally {
|
|
151
|
+
unskipCh.publish()
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
50
156
|
const name = 'mariadb'
|
|
51
|
-
const versions = ['>=2.0.3']
|
|
52
157
|
|
|
53
|
-
addHook({ name, file: 'lib/cmd/query.js', versions }, (Query) => {
|
|
54
|
-
|
|
158
|
+
addHook({ name, file: 'lib/cmd/query.js', versions: ['>=3'] }, (Query) => {
|
|
159
|
+
return wrapCommand(Query)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
addHook({ name, file: 'lib/cmd/execute.js', versions: ['>=3'] }, (Execute) => {
|
|
163
|
+
return wrapCommand(Execute)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
addHook({ name, file: 'lib/pool.js', versions: ['>=3'] }, (Pool) => {
|
|
167
|
+
shimmer.wrap(Pool.prototype, '_createConnection', wrapPoolMethod)
|
|
55
168
|
|
|
56
|
-
return
|
|
169
|
+
return Pool
|
|
57
170
|
})
|
|
58
171
|
|
|
59
|
-
addHook({ name, file: 'lib/
|
|
60
|
-
shimmer.wrap(
|
|
172
|
+
addHook({ name, file: 'lib/connection.js', versions: ['>=2.5.2 <3'] }, (Connection) => {
|
|
173
|
+
return shimmer.wrap(Connection, wrapConnection(Connection, '_queryPromise'))
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
addHook({ name, file: 'lib/connection.js', versions: ['>=2.0.4 <=2.5.1'] }, (Connection) => {
|
|
177
|
+
return shimmer.wrap(Connection, wrapConnection(Connection, 'query'))
|
|
178
|
+
})
|
|
61
179
|
|
|
62
|
-
|
|
180
|
+
addHook({ name, file: 'lib/pool-base.js', versions: ['>=2.0.4 <3'] }, (PoolBase) => {
|
|
181
|
+
return shimmer.wrap(PoolBase, wrapPoolBase(PoolBase))
|
|
63
182
|
})
|
|
@@ -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
|
|
|
@@ -120,9 +125,18 @@ function mochaHook (Runner) {
|
|
|
120
125
|
|
|
121
126
|
const isSuitesSkipped = !!suitesToSkip.length
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
let testCodeCoverageLinesTotal
|
|
129
|
+
if (global.__coverage__) {
|
|
130
|
+
try {
|
|
131
|
+
testCodeCoverageLinesTotal = originalCoverageMap.getCoverageSummary().lines.pct
|
|
132
|
+
} catch (e) {
|
|
133
|
+
// ignore errors
|
|
134
|
+
}
|
|
135
|
+
// restore the original coverage
|
|
136
|
+
global.__coverage__ = fromCoverageMapToCoverage(originalCoverageMap)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
testSessionFinishCh.publish({ status, isSuitesSkipped, testCodeCoverageLinesTotal })
|
|
126
140
|
}))
|
|
127
141
|
|
|
128
142
|
this.once('start', testRunAsyncResource.bind(function () {
|
|
@@ -321,7 +335,15 @@ addHook({
|
|
|
321
335
|
* If ITR is disabled, `onDone` is called immediately on the subscriber
|
|
322
336
|
*/
|
|
323
337
|
shimmer.wrap(Mocha.prototype, 'run', run => function () {
|
|
324
|
-
if (
|
|
338
|
+
if (this.options.parallel) {
|
|
339
|
+
log.warn(`Unable to initialize CI Visibility because Mocha is running in parallel mode.`)
|
|
340
|
+
return run.apply(this, arguments)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (!itrConfigurationCh.hasSubscribers || this.isWorker) {
|
|
344
|
+
if (this.isWorker) {
|
|
345
|
+
isWorker = true
|
|
346
|
+
}
|
|
325
347
|
return run.apply(this, arguments)
|
|
326
348
|
}
|
|
327
349
|
this.options.delay = true
|
|
@@ -379,7 +401,9 @@ addHook({
|
|
|
379
401
|
* This attaches `run` to the global context, which we'll call after
|
|
380
402
|
* our configuration and skippable suites requests
|
|
381
403
|
*/
|
|
382
|
-
mocha.options.
|
|
404
|
+
if (!mocha.options.parallel) {
|
|
405
|
+
mocha.options.delay = true
|
|
406
|
+
}
|
|
383
407
|
return runMocha.apply(this, arguments)
|
|
384
408
|
})
|
|
385
409
|
return run
|
|
@@ -25,13 +25,19 @@ addHook({ name: 'mongodb-core', versions: ['2 - 3.1.9'] }, Server => {
|
|
|
25
25
|
return Server
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
-
addHook({ name: 'mongodb', versions: ['>=4'], file: 'lib/cmap/connection.js' }, Connection => {
|
|
28
|
+
addHook({ name: 'mongodb', versions: ['>=4 <4.6.0'], file: 'lib/cmap/connection.js' }, Connection => {
|
|
29
29
|
const proto = Connection.Connection.prototype
|
|
30
30
|
shimmer.wrap(proto, 'command', command => wrapConnectionCommand(command, 'command'))
|
|
31
31
|
shimmer.wrap(proto, 'query', query => wrapConnectionCommand(query, 'query'))
|
|
32
32
|
return Connection
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
+
addHook({ name: 'mongodb', versions: ['>=4.6.0'], file: 'lib/cmap/connection.js' }, Connection => {
|
|
36
|
+
const proto = Connection.Connection.prototype
|
|
37
|
+
shimmer.wrap(proto, 'command', command => wrapConnectionCommand(command, 'command'))
|
|
38
|
+
return Connection
|
|
39
|
+
})
|
|
40
|
+
|
|
35
41
|
addHook({ name: 'mongodb', versions: ['>=3.3 <4'], file: 'lib/core/wireprotocol/index.js' }, wp => wrapWp(wp))
|
|
36
42
|
|
|
37
43
|
addHook({ name: 'mongodb-core', versions: ['>=3.2'], file: 'lib/wireprotocol/index.js' }, wp => wrapWp(wp))
|
|
@@ -46,7 +52,7 @@ addHook({ name: 'mongodb-core', versions: ['~3.1.10'], file: 'lib/wireprotocol/2
|
|
|
46
52
|
return WireProtocol
|
|
47
53
|
})
|
|
48
54
|
|
|
49
|
-
addHook({ name: 'mongodb', versions: ['>=3.5.4'], file: 'lib/utils.js' }, util => {
|
|
55
|
+
addHook({ name: 'mongodb', versions: ['>=3.5.4 <4.11.0'], file: 'lib/utils.js' }, util => {
|
|
50
56
|
shimmer.wrap(util, 'maybePromise', maybePromise => function (parent, callback, fn) {
|
|
51
57
|
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
52
58
|
const callbackIndex = arguments.length - 2
|
|
@@ -26,16 +26,33 @@ function wrapHandleApiRequest (handleApiRequest) {
|
|
|
26
26
|
return promise.then(handled => {
|
|
27
27
|
if (!handled) return handled
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
return this.hasPage(pathname).then(pageFound => {
|
|
30
|
+
const page = pageFound ? pathname : getPageFromPath(pathname, this.dynamicRoutes)
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
pageLoadChannel.publish({ page })
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
return handled
|
|
35
|
+
})
|
|
34
36
|
})
|
|
35
37
|
})
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
// next 13.2 handleApiRequest uses a different set of parameters
|
|
42
|
+
function wrapHandleApiRequestWithMatch (handleApiRequest) {
|
|
43
|
+
return function (req, res, query, match) {
|
|
44
|
+
return instrument(req, res, () => {
|
|
45
|
+
const page = (typeof match === 'object' && typeof match.definition === 'object')
|
|
46
|
+
? match.definition.pathname
|
|
47
|
+
: undefined
|
|
48
|
+
|
|
49
|
+
pageLoadChannel.publish({ page })
|
|
50
|
+
|
|
51
|
+
return handleApiRequest.apply(this, arguments)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
39
56
|
function wrapRenderToResponse (renderToResponse) {
|
|
40
57
|
return function (ctx) {
|
|
41
58
|
return instrument(ctx.req, ctx.res, () => renderToResponse.apply(this, arguments))
|
|
@@ -127,7 +144,18 @@ function finish (req, res, result, err) {
|
|
|
127
144
|
return result
|
|
128
145
|
}
|
|
129
146
|
|
|
130
|
-
|
|
147
|
+
addHook({ name: 'next', versions: ['>=13.2'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
148
|
+
const Server = nextServer.default
|
|
149
|
+
|
|
150
|
+
shimmer.wrap(Server.prototype, 'handleRequest', wrapHandleRequest)
|
|
151
|
+
shimmer.wrap(Server.prototype, 'handleApiRequest', wrapHandleApiRequestWithMatch)
|
|
152
|
+
shimmer.wrap(Server.prototype, 'renderToResponse', wrapRenderToResponse)
|
|
153
|
+
shimmer.wrap(Server.prototype, 'renderErrorToResponse', wrapRenderErrorToResponse)
|
|
154
|
+
shimmer.wrap(Server.prototype, 'findPageComponents', wrapFindPageComponents)
|
|
155
|
+
|
|
156
|
+
return nextServer
|
|
157
|
+
})
|
|
158
|
+
|
|
131
159
|
addHook({ name: 'next', versions: ['>=11.1 <13.2'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
132
160
|
const Server = nextServer.default
|
|
133
161
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
4
|
const Plugin = require('../../dd-trace/src/plugins/plugin')
|
|
5
5
|
const { storage } = require('../../datadog-core')
|
|
6
|
+
const { isTrue } = require('../../dd-trace/src/util')
|
|
6
7
|
|
|
7
8
|
class BaseAwsSdkPlugin extends Plugin {
|
|
8
9
|
get serviceIdentifier () {
|
|
@@ -74,7 +75,9 @@ class BaseAwsSdkPlugin extends Plugin {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
isEnabled (request) {
|
|
77
|
-
|
|
78
|
+
const serviceId = this.serviceIdentifier.toUpperCase()
|
|
79
|
+
const envVarValue = process.env[`DD_TRACE_AWS_SDK_${serviceId}_ENABLED`]
|
|
80
|
+
return envVarValue ? isTrue(envVarValue) : true
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
addResponseTags (span, response) {
|
|
@@ -8,7 +8,8 @@ const {
|
|
|
8
8
|
TEST_STATUS,
|
|
9
9
|
finishAllTraceSpans,
|
|
10
10
|
getTestSuitePath,
|
|
11
|
-
getTestSuiteCommonTags
|
|
11
|
+
getTestSuiteCommonTags,
|
|
12
|
+
addIntelligentTestRunnerSpanTags
|
|
12
13
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
13
14
|
const { RESOURCE_NAME } = require('../../../ext/tags')
|
|
14
15
|
const { COMPONENT, ERROR_MESSAGE } = require('../../dd-trace/src/constants')
|
|
@@ -23,12 +24,21 @@ class CucumberPlugin extends CiPlugin {
|
|
|
23
24
|
|
|
24
25
|
this.sourceRoot = process.cwd()
|
|
25
26
|
|
|
26
|
-
this.addSub('ci:cucumber:session:finish', (status) => {
|
|
27
|
+
this.addSub('ci:cucumber:session:finish', ({ status, isSuitesSkipped, testCodeCoverageLinesTotal }) => {
|
|
28
|
+
const { isSuitesSkippingEnabled, isCodeCoverageEnabled } = this.itrConfig || {}
|
|
29
|
+
addIntelligentTestRunnerSpanTags(
|
|
30
|
+
this.testSessionSpan,
|
|
31
|
+
this.testModuleSpan,
|
|
32
|
+
{ isSuitesSkipped, isSuitesSkippingEnabled, isCodeCoverageEnabled, testCodeCoverageLinesTotal }
|
|
33
|
+
)
|
|
34
|
+
|
|
27
35
|
this.testSessionSpan.setTag(TEST_STATUS, status)
|
|
28
36
|
this.testModuleSpan.setTag(TEST_STATUS, status)
|
|
29
37
|
this.testModuleSpan.finish()
|
|
30
38
|
this.testSessionSpan.finish()
|
|
31
39
|
finishAllTraceSpans(this.testSessionSpan)
|
|
40
|
+
|
|
41
|
+
this.itrConfig = null
|
|
32
42
|
this.tracer._exporter.flush()
|
|
33
43
|
})
|
|
34
44
|
|
|
@@ -54,6 +64,22 @@ class CucumberPlugin extends CiPlugin {
|
|
|
54
64
|
this.testSuiteSpan.finish()
|
|
55
65
|
})
|
|
56
66
|
|
|
67
|
+
this.addSub('ci:cucumber:test-suite:code-coverage', ({ coverageFiles, suiteFile }) => {
|
|
68
|
+
if (!this.itrConfig || !this.itrConfig.isCodeCoverageEnabled) {
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
const relativeCoverageFiles = [...coverageFiles, suiteFile]
|
|
72
|
+
.map(filename => getTestSuitePath(filename, this.sourceRoot))
|
|
73
|
+
|
|
74
|
+
const formattedCoverage = {
|
|
75
|
+
traceId: this.testSuiteSpan.context()._traceId,
|
|
76
|
+
spanId: this.testSuiteSpan.context()._spanId,
|
|
77
|
+
files: relativeCoverageFiles
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
this.tracer._exporter.exportCoverage(formattedCoverage)
|
|
81
|
+
})
|
|
82
|
+
|
|
57
83
|
this.addSub('ci:cucumber:test:start', ({ testName, fullTestSuite }) => {
|
|
58
84
|
const store = storage.getStore()
|
|
59
85
|
const testSuite = getTestSuitePath(fullTestSuite, this.sourceRoot)
|