dd-trace 5.21.0 → 5.22.0
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 +3 -3
- package/packages/datadog-instrumentations/src/aerospike.js +1 -1
- package/packages/datadog-instrumentations/src/apollo-server.js +1 -1
- package/packages/datadog-instrumentations/src/aws-sdk.js +4 -4
- package/packages/datadog-instrumentations/src/body-parser.js +4 -4
- package/packages/datadog-instrumentations/src/cassandra-driver.js +2 -2
- package/packages/datadog-instrumentations/src/child_process.js +2 -2
- package/packages/datadog-instrumentations/src/connect.js +4 -4
- package/packages/datadog-instrumentations/src/cookie-parser.js +4 -4
- package/packages/datadog-instrumentations/src/couchbase.js +12 -12
- package/packages/datadog-instrumentations/src/cucumber.js +6 -5
- package/packages/datadog-instrumentations/src/dns.js +10 -10
- package/packages/datadog-instrumentations/src/elasticsearch.js +4 -4
- package/packages/datadog-instrumentations/src/express-mongo-sanitize.js +3 -3
- package/packages/datadog-instrumentations/src/express.js +4 -4
- package/packages/datadog-instrumentations/src/fastify.js +6 -6
- package/packages/datadog-instrumentations/src/fetch.js +1 -1
- package/packages/datadog-instrumentations/src/find-my-way.js +2 -2
- package/packages/datadog-instrumentations/src/fs.js +2 -2
- package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +2 -2
- package/packages/datadog-instrumentations/src/grpc/client.js +4 -6
- package/packages/datadog-instrumentations/src/grpc/server.js +2 -2
- package/packages/datadog-instrumentations/src/hapi.js +10 -13
- package/packages/datadog-instrumentations/src/helpers/register.js +1 -1
- package/packages/datadog-instrumentations/src/http/client.js +3 -3
- package/packages/datadog-instrumentations/src/jest.js +5 -4
- package/packages/datadog-instrumentations/src/knex.js +2 -2
- package/packages/datadog-instrumentations/src/koa.js +5 -5
- package/packages/datadog-instrumentations/src/ldapjs.js +1 -1
- package/packages/datadog-instrumentations/src/mariadb.js +8 -8
- package/packages/datadog-instrumentations/src/memcached.js +2 -2
- package/packages/datadog-instrumentations/src/microgateway-core.js +4 -4
- package/packages/datadog-instrumentations/src/mocha/common.js +1 -1
- package/packages/datadog-instrumentations/src/mocha/main.js +1 -0
- package/packages/datadog-instrumentations/src/mocha/utils.js +2 -3
- package/packages/datadog-instrumentations/src/mocha.js +4 -0
- package/packages/datadog-instrumentations/src/moleculer/server.js +2 -2
- package/packages/datadog-instrumentations/src/mongodb-core.js +7 -7
- package/packages/datadog-instrumentations/src/mongoose.js +5 -6
- package/packages/datadog-instrumentations/src/mysql.js +3 -3
- package/packages/datadog-instrumentations/src/mysql2.js +6 -6
- package/packages/datadog-instrumentations/src/net.js +2 -2
- package/packages/datadog-instrumentations/src/next.js +5 -5
- package/packages/datadog-instrumentations/src/openai.js +58 -69
- package/packages/datadog-instrumentations/src/oracledb.js +8 -8
- package/packages/datadog-instrumentations/src/passport-http.js +1 -1
- package/packages/datadog-instrumentations/src/passport-local.js +1 -1
- package/packages/datadog-instrumentations/src/passport-utils.js +1 -1
- package/packages/datadog-instrumentations/src/pg.js +1 -1
- package/packages/datadog-instrumentations/src/pino.js +4 -4
- package/packages/datadog-instrumentations/src/playwright.js +6 -4
- package/packages/datadog-instrumentations/src/redis.js +2 -2
- package/packages/datadog-instrumentations/src/restify.js +4 -4
- package/packages/datadog-instrumentations/src/rhea.js +4 -4
- package/packages/datadog-instrumentations/src/router.js +5 -5
- package/packages/datadog-instrumentations/src/sharedb.js +2 -2
- package/packages/datadog-instrumentations/src/vitest.js +4 -3
- package/packages/datadog-instrumentations/src/winston.js +2 -3
- package/packages/datadog-plugin-cypress/src/cypress-plugin.js +5 -6
- package/packages/datadog-plugin-hapi/src/index.js +2 -2
- package/packages/datadog-plugin-jest/src/index.js +1 -0
- package/packages/datadog-plugin-openai/src/index.js +58 -47
- package/packages/datadog-shimmer/src/shimmer.js +144 -10
- package/packages/dd-trace/src/appsec/blocking.js +23 -17
- package/packages/dd-trace/src/appsec/graphql.js +3 -1
- package/packages/dd-trace/src/appsec/iast/iast-log.js +2 -1
- package/packages/dd-trace/src/appsec/remote_config/manager.js +4 -1
- package/packages/dd-trace/src/appsec/rule_manager.js +8 -0
- package/packages/dd-trace/src/appsec/telemetry.js +3 -3
- package/packages/dd-trace/src/ci-visibility/exporters/ci-visibility-exporter.js +2 -1
- package/packages/dd-trace/src/config.js +40 -31
- package/packages/dd-trace/src/lambda/handler.js +1 -0
- package/packages/dd-trace/src/lambda/index.js +12 -1
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +1 -6
- package/packages/dd-trace/src/plugins/util/test.js +1 -5
- package/packages/dd-trace/src/profiler.js +15 -5
- package/packages/dd-trace/src/profiling/config.js +2 -4
- package/packages/dd-trace/src/profiling/exporter_cli.js +13 -1
- package/packages/dd-trace/src/profiling/exporters/agent.js +7 -1
- package/packages/dd-trace/src/profiling/profiler.js +0 -9
- package/packages/dd-trace/src/profiling/ssi-heuristics.js +49 -58
- package/packages/dd-trace/src/proxy.js +21 -21
- package/packages/dd-trace/src/telemetry/index.js +23 -6
- package/packages/dd-trace/src/telemetry/logs/index.js +20 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const tracingChannel = require('dc-polyfill').tracingChannel
|
|
3
4
|
const shimmer = require('../../datadog-shimmer')
|
|
4
|
-
const { addHook, channel
|
|
5
|
+
const { addHook, channel } = require('./helpers/instrument')
|
|
5
6
|
|
|
6
7
|
const handleChannel = channel('apm:hapi:request:handle')
|
|
7
8
|
const routeChannel = channel('apm:hapi:request:route')
|
|
8
9
|
const errorChannel = channel('apm:hapi:request:error')
|
|
9
|
-
const
|
|
10
|
+
const hapiTracingChannel = tracingChannel('apm:hapi:extension')
|
|
10
11
|
|
|
11
12
|
function wrapServer (server) {
|
|
12
13
|
return function (options) {
|
|
@@ -27,17 +28,17 @@ function wrapServer (server) {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
function wrapStart (start) {
|
|
30
|
-
return function () {
|
|
31
|
+
return shimmer.wrapFunction(start, start => function () {
|
|
31
32
|
if (this && typeof this.ext === 'function') {
|
|
32
33
|
this.ext('onPreResponse', onPreResponse)
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
return start.apply(this, arguments)
|
|
36
|
-
}
|
|
37
|
+
})
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
function wrapExt (ext) {
|
|
40
|
-
return function (events, method, options) {
|
|
41
|
+
return shimmer.wrapFunction(ext, ext => function (events, method, options) {
|
|
41
42
|
if (events !== null && typeof events === 'object') {
|
|
42
43
|
arguments[0] = wrapEvents(events)
|
|
43
44
|
} else {
|
|
@@ -45,7 +46,7 @@ function wrapExt (ext) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
return ext.apply(this, arguments)
|
|
48
|
-
}
|
|
49
|
+
})
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
function wrapDispatch (dispatch) {
|
|
@@ -91,19 +92,15 @@ function wrapEvents (events) {
|
|
|
91
92
|
function wrapHandler (handler) {
|
|
92
93
|
if (typeof handler !== 'function') return handler
|
|
93
94
|
|
|
94
|
-
return function (request, h) {
|
|
95
|
+
return shimmer.wrapFunction(handler, handler => function (request, h) {
|
|
95
96
|
const req = request && request.raw && request.raw.req
|
|
96
97
|
|
|
97
98
|
if (!req) return handler.apply(this, arguments)
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return asyncResource.runInAsyncScope(() => {
|
|
102
|
-
enterChannel.publish({ req })
|
|
103
|
-
|
|
100
|
+
return hapiTracingChannel.traceSync(() => {
|
|
104
101
|
return handler.apply(this, arguments)
|
|
105
102
|
})
|
|
106
|
-
}
|
|
103
|
+
})
|
|
107
104
|
}
|
|
108
105
|
|
|
109
106
|
function onPreResponse (request, h) {
|
|
@@ -98,7 +98,7 @@ for (const packageName of names) {
|
|
|
98
98
|
log.error(e)
|
|
99
99
|
continue
|
|
100
100
|
}
|
|
101
|
-
if (
|
|
101
|
+
if (typeof namesAndSuccesses[`${name}@${version}`] === 'undefined') {
|
|
102
102
|
namesAndSuccesses[`${name}@${version}`] = false
|
|
103
103
|
}
|
|
104
104
|
|
|
@@ -52,11 +52,11 @@ function patch (http, methodName) {
|
|
|
52
52
|
let callback = args.callback
|
|
53
53
|
|
|
54
54
|
if (callback) {
|
|
55
|
-
callback = function () {
|
|
55
|
+
callback = shimmer.wrapFunction(args.callback, cb => function () {
|
|
56
56
|
return asyncStartChannel.runStores(ctx, () => {
|
|
57
|
-
return
|
|
57
|
+
return cb.apply(this, arguments)
|
|
58
58
|
})
|
|
59
|
-
}
|
|
59
|
+
})
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const options = args.options
|
|
@@ -12,8 +12,7 @@ const {
|
|
|
12
12
|
getTestParametersString,
|
|
13
13
|
addEfdStringToTestName,
|
|
14
14
|
removeEfdStringFromTestName,
|
|
15
|
-
getIsFaultyEarlyFlakeDetection
|
|
16
|
-
NUM_FAILED_TEST_RETRIES
|
|
15
|
+
getIsFaultyEarlyFlakeDetection
|
|
17
16
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
18
17
|
const {
|
|
19
18
|
getFormattedJestTestParameters,
|
|
@@ -132,6 +131,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
132
131
|
|
|
133
132
|
this.isEarlyFlakeDetectionEnabled = this.testEnvironmentOptions._ddIsEarlyFlakeDetectionEnabled
|
|
134
133
|
this.isFlakyTestRetriesEnabled = this.testEnvironmentOptions._ddIsFlakyTestRetriesEnabled
|
|
134
|
+
this.flakyTestRetriesCount = this.testEnvironmentOptions._ddFlakyTestRetriesCount
|
|
135
135
|
|
|
136
136
|
if (this.isEarlyFlakeDetectionEnabled) {
|
|
137
137
|
const hasKnownTests = !!knownTests.jest
|
|
@@ -149,7 +149,7 @@ function getWrappedEnvironment (BaseEnvironment, jestVersion) {
|
|
|
149
149
|
if (this.isFlakyTestRetriesEnabled) {
|
|
150
150
|
const currentNumRetries = this.global[RETRY_TIMES]
|
|
151
151
|
if (!currentNumRetries) {
|
|
152
|
-
this.global[RETRY_TIMES] =
|
|
152
|
+
this.global[RETRY_TIMES] = this.flakyTestRetriesCount
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
@@ -638,7 +638,7 @@ addHook({
|
|
|
638
638
|
|
|
639
639
|
function jestAdapterWrapper (jestAdapter, jestVersion) {
|
|
640
640
|
const adapter = jestAdapter.default ? jestAdapter.default : jestAdapter
|
|
641
|
-
const newAdapter = shimmer.
|
|
641
|
+
const newAdapter = shimmer.wrapFunction(adapter, adapter => function () {
|
|
642
642
|
const environment = arguments[2]
|
|
643
643
|
if (!environment) {
|
|
644
644
|
return adapter.apply(this, arguments)
|
|
@@ -773,6 +773,7 @@ addHook({
|
|
|
773
773
|
_ddEarlyFlakeDetectionNumRetries,
|
|
774
774
|
_ddRepositoryRoot,
|
|
775
775
|
_ddIsFlakyTestRetriesEnabled,
|
|
776
|
+
_ddFlakyTestRetriesCount,
|
|
776
777
|
...restOfTestEnvironmentOptions
|
|
777
778
|
} = testEnvironmentOptions
|
|
778
779
|
|
|
@@ -81,8 +81,8 @@ addHook({
|
|
|
81
81
|
function wrapCallbackWithFinish (callback, finish) {
|
|
82
82
|
if (typeof callback !== 'function') return callback
|
|
83
83
|
|
|
84
|
-
return function () {
|
|
84
|
+
return shimmer.wrapFunction(callback, callback => function () {
|
|
85
85
|
finish()
|
|
86
86
|
callback.apply(this, arguments)
|
|
87
|
-
}
|
|
87
|
+
})
|
|
88
88
|
}
|
|
@@ -71,7 +71,7 @@ function wrapStack (layer) {
|
|
|
71
71
|
|
|
72
72
|
middleware = original || middleware
|
|
73
73
|
|
|
74
|
-
const handler = shimmer.
|
|
74
|
+
const handler = shimmer.wrapFunction(middleware, middleware => wrapMiddleware(middleware, layer))
|
|
75
75
|
|
|
76
76
|
originals.set(handler, middleware)
|
|
77
77
|
|
|
@@ -84,7 +84,7 @@ function wrapMiddleware (fn, layer) {
|
|
|
84
84
|
|
|
85
85
|
const name = fn.name
|
|
86
86
|
|
|
87
|
-
return function (ctx, next) {
|
|
87
|
+
return shimmer.wrapFunction(fn, fn => function (ctx, next) {
|
|
88
88
|
if (!ctx || !enterChannel.hasSubscribers) return fn.apply(this, arguments)
|
|
89
89
|
|
|
90
90
|
const req = ctx.req
|
|
@@ -122,7 +122,7 @@ function wrapMiddleware (fn, layer) {
|
|
|
122
122
|
} finally {
|
|
123
123
|
exitChannel.publish({ req })
|
|
124
124
|
}
|
|
125
|
-
}
|
|
125
|
+
})
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
function fulfill (ctx, error) {
|
|
@@ -142,11 +142,11 @@ function fulfill (ctx, error) {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
function wrapNext (req, next) {
|
|
145
|
-
return function () {
|
|
145
|
+
return shimmer.wrapFunction(next, next => function () {
|
|
146
146
|
nextChannel.publish({ req })
|
|
147
147
|
|
|
148
148
|
return next.apply(this, arguments)
|
|
149
|
-
}
|
|
149
|
+
})
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
addHook({ name: 'koa', versions: ['>=2'] }, Koa => {
|
|
@@ -77,7 +77,7 @@ addHook({ name: 'ldapjs', versions: ['>=2'] }, ldapjs => {
|
|
|
77
77
|
if (callbackIndex > -1) {
|
|
78
78
|
const callback = arguments[callbackIndex]
|
|
79
79
|
// eslint-disable-next-line n/handle-callback-err
|
|
80
|
-
arguments[callbackIndex] = shimmer.
|
|
80
|
+
arguments[callbackIndex] = shimmer.wrapFunction(callback, callback => function (err, corkedEmitter) {
|
|
81
81
|
if (corkedEmitter !== null && typeof corkedEmitter === 'object' && typeof corkedEmitter.on === 'function') {
|
|
82
82
|
wrapEmitter(corkedEmitter)
|
|
83
83
|
}
|
|
@@ -11,7 +11,7 @@ const skipCh = channel('apm:mariadb:pool:skip')
|
|
|
11
11
|
const unskipCh = channel('apm:mariadb:pool:unskip')
|
|
12
12
|
|
|
13
13
|
function wrapCommandStart (start, callbackResource) {
|
|
14
|
-
return function () {
|
|
14
|
+
return shimmer.wrapFunction(start, start => function () {
|
|
15
15
|
if (!startCh.hasSubscribers) return start.apply(this, arguments)
|
|
16
16
|
|
|
17
17
|
const resolve = callbackResource.bind(this.resolve)
|
|
@@ -44,7 +44,7 @@ function wrapCommandStart (start, callbackResource) {
|
|
|
44
44
|
startCh.publish({ sql: this.sql, conf: this.opts })
|
|
45
45
|
return start.apply(this, arguments)
|
|
46
46
|
})
|
|
47
|
-
}
|
|
47
|
+
})
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
function wrapCommand (Command) {
|
|
@@ -98,7 +98,7 @@ function createWrapQueryCallback (options) {
|
|
|
98
98
|
arguments.length = arguments.length + 1
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
arguments[arguments.length - 1] = asyncResource.bind(function (err) {
|
|
101
|
+
arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (err) {
|
|
102
102
|
if (err) {
|
|
103
103
|
errorCh.publish(err)
|
|
104
104
|
}
|
|
@@ -108,7 +108,7 @@ function createWrapQueryCallback (options) {
|
|
|
108
108
|
if (typeof cb === 'function') {
|
|
109
109
|
return callbackResource.runInAsyncScope(() => cb.apply(this, arguments))
|
|
110
110
|
}
|
|
111
|
-
})
|
|
111
|
+
}))
|
|
112
112
|
|
|
113
113
|
return asyncResource.runInAsyncScope(() => {
|
|
114
114
|
startCh.publish({ sql, conf: options })
|
|
@@ -119,7 +119,7 @@ function createWrapQueryCallback (options) {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function wrapConnection (
|
|
122
|
+
function wrapConnection (promiseMethod, Connection) {
|
|
123
123
|
return function (options) {
|
|
124
124
|
Connection.apply(this, arguments)
|
|
125
125
|
|
|
@@ -170,13 +170,13 @@ addHook({ name, file: 'lib/pool.js', versions: ['>=3'] }, (Pool) => {
|
|
|
170
170
|
})
|
|
171
171
|
|
|
172
172
|
addHook({ name, file: 'lib/connection.js', versions: ['>=2.5.2 <3'] }, (Connection) => {
|
|
173
|
-
return shimmer.
|
|
173
|
+
return shimmer.wrapFunction(Connection, wrapConnection.bind(null, '_queryPromise'))
|
|
174
174
|
})
|
|
175
175
|
|
|
176
176
|
addHook({ name, file: 'lib/connection.js', versions: ['>=2.0.4 <=2.5.1'] }, (Connection) => {
|
|
177
|
-
return shimmer.
|
|
177
|
+
return shimmer.wrapFunction(Connection, wrapConnection.bind(null, 'query'))
|
|
178
178
|
})
|
|
179
179
|
|
|
180
180
|
addHook({ name, file: 'lib/pool-base.js', versions: ['>=2.0.4 <3'] }, (PoolBase) => {
|
|
181
|
-
return shimmer.
|
|
181
|
+
return shimmer.wrapFunction(PoolBase, wrapPoolBase)
|
|
182
182
|
})
|
|
@@ -26,14 +26,14 @@ addHook({ name: 'memcached', versions: ['>=2.2'] }, Memcached => {
|
|
|
26
26
|
const query = queryCompiler.apply(this, arguments)
|
|
27
27
|
const callback = callbackResource.bind(query.callback)
|
|
28
28
|
|
|
29
|
-
query.callback = asyncResource.bind(function (err) {
|
|
29
|
+
query.callback = shimmer.wrapFunction(callback, callback => asyncResource.bind(function (err) {
|
|
30
30
|
if (err) {
|
|
31
31
|
errorCh.publish(err)
|
|
32
32
|
}
|
|
33
33
|
finishCh.publish()
|
|
34
34
|
|
|
35
35
|
return callback.apply(this, arguments)
|
|
36
|
-
})
|
|
36
|
+
}))
|
|
37
37
|
startCh.publish({ client, server, query })
|
|
38
38
|
|
|
39
39
|
return query
|
|
@@ -40,7 +40,7 @@ function wrapPluginsFactory (pluginsFactory) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function wrapNext (req, res, next) {
|
|
43
|
-
return function nextWithTrace (err) {
|
|
43
|
+
return shimmer.wrapFunction(next, next => function nextWithTrace (err) {
|
|
44
44
|
const requestResource = requestResources.get(req)
|
|
45
45
|
|
|
46
46
|
requestResource.runInAsyncScope(() => {
|
|
@@ -54,13 +54,13 @@ function wrapNext (req, res, next) {
|
|
|
54
54
|
})
|
|
55
55
|
|
|
56
56
|
return next.apply(this, arguments)
|
|
57
|
-
}
|
|
57
|
+
})
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
addHook({ name, versions, file: 'lib/config-proxy-middleware.js' }, configProxyFactory => {
|
|
61
|
-
return shimmer.
|
|
61
|
+
return shimmer.wrapFunction(configProxyFactory, wrapConfigProxyFactory)
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
addHook({ name, versions, file: 'lib/plugins-middleware.js' }, pluginsFactory => {
|
|
65
|
-
return shimmer.
|
|
65
|
+
return shimmer.wrapFunction(pluginsFactory, wrapPluginsFactory)
|
|
66
66
|
})
|
|
@@ -15,7 +15,7 @@ addHook({
|
|
|
15
15
|
|
|
16
16
|
patched.add(mochaEach)
|
|
17
17
|
|
|
18
|
-
return shimmer.
|
|
18
|
+
return shimmer.wrapFunction(mochaEach, mochaEach => function () {
|
|
19
19
|
const [params] = arguments
|
|
20
20
|
const { it, ...rest } = mochaEach.apply(this, arguments)
|
|
21
21
|
return {
|
|
@@ -217,6 +217,7 @@ function getExecutionConfiguration (runner, onFinishRequest) {
|
|
|
217
217
|
config.isSuitesSkippingEnabled = isSuitesSkippingEnabled
|
|
218
218
|
config.earlyFlakeDetectionNumRetries = earlyFlakeDetectionNumRetries
|
|
219
219
|
config.isFlakyTestRetriesEnabled = isFlakyTestRetriesEnabled
|
|
220
|
+
config.flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
|
|
220
221
|
|
|
221
222
|
if (isEarlyFlakeDetectionEnabled) {
|
|
222
223
|
knownTestsCh.publish({
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
const {
|
|
4
4
|
getTestSuitePath,
|
|
5
5
|
removeEfdStringFromTestName,
|
|
6
|
-
addEfdStringToTestName
|
|
7
|
-
NUM_FAILED_TEST_RETRIES
|
|
6
|
+
addEfdStringToTestName
|
|
8
7
|
} = require('../../../dd-trace/src/plugins/util/test')
|
|
9
8
|
const { channel, AsyncResource } = require('../helpers/instrument')
|
|
10
9
|
const shimmer = require('../../../datadog-shimmer')
|
|
@@ -114,7 +113,7 @@ function runnableWrapper (RunnablePackage, libraryConfig) {
|
|
|
114
113
|
}
|
|
115
114
|
// Flaky test retries does not work in parallel mode
|
|
116
115
|
if (libraryConfig?.isFlakyTestRetriesEnabled) {
|
|
117
|
-
this.retries(
|
|
116
|
+
this.retries(libraryConfig?.flakyTestRetriesCount)
|
|
118
117
|
}
|
|
119
118
|
// The reason why the wrapping logic is here is because we need to cover
|
|
120
119
|
// `afterEach` and `beforeEach` hooks as well.
|
|
@@ -3,3 +3,7 @@ if (process.env.MOCHA_WORKER_ID) {
|
|
|
3
3
|
} else {
|
|
4
4
|
require('./mocha/main')
|
|
5
5
|
}
|
|
6
|
+
|
|
7
|
+
// TODO add appropriate calls to wrapFunction whenever we're adding a callback
|
|
8
|
+
// wrapper. Right now this is less of an issue since that only has effect in
|
|
9
|
+
// SSI, where CI Vis isn't supported.
|
|
@@ -24,7 +24,7 @@ function createMiddleware () {
|
|
|
24
24
|
localAction (next, action) {
|
|
25
25
|
const broker = this
|
|
26
26
|
|
|
27
|
-
return function datadogMiddleware (ctx) {
|
|
27
|
+
return shimmer.wrapFunction(next, next => function datadogMiddleware (ctx) {
|
|
28
28
|
const actionResource = new AsyncResource('bound-anonymous-fn')
|
|
29
29
|
|
|
30
30
|
return actionResource.runInAsyncScope(() => {
|
|
@@ -47,7 +47,7 @@ function createMiddleware () {
|
|
|
47
47
|
finishChannel.publish()
|
|
48
48
|
}
|
|
49
49
|
})
|
|
50
|
-
}
|
|
50
|
+
})
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -92,7 +92,7 @@ function wrapUnifiedCommand (command, operation, name) {
|
|
|
92
92
|
}
|
|
93
93
|
return instrument(operation, command, this, arguments, server, ns, ops, { name })
|
|
94
94
|
}
|
|
95
|
-
return
|
|
95
|
+
return wrapped
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
function wrapConnectionCommand (command, operation, name, instrumentFn = instrument) {
|
|
@@ -109,7 +109,7 @@ function wrapConnectionCommand (command, operation, name, instrumentFn = instrum
|
|
|
109
109
|
ns = `${ns.db}.${ns.collection}`
|
|
110
110
|
return instrumentFn(operation, command, this, arguments, topology, ns, ops, { name })
|
|
111
111
|
}
|
|
112
|
-
return
|
|
112
|
+
return wrapped
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function wrapQuery (query, operation, name) {
|
|
@@ -123,7 +123,7 @@ function wrapQuery (query, operation, name) {
|
|
|
123
123
|
return instrument(operation, query, this, arguments, pool, ns, ops)
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
return
|
|
126
|
+
return wrapped
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
function wrapCursor (cursor, operation, name) {
|
|
@@ -135,7 +135,7 @@ function wrapCursor (cursor, operation, name) {
|
|
|
135
135
|
const ns = this.ns
|
|
136
136
|
return instrument(operation, cursor, this, arguments, pool, ns, {}, { name })
|
|
137
137
|
}
|
|
138
|
-
return
|
|
138
|
+
return wrapped
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
function wrapCommand (command, operation, name) {
|
|
@@ -145,7 +145,7 @@ function wrapCommand (command, operation, name) {
|
|
|
145
145
|
}
|
|
146
146
|
return instrument(operation, command, this, arguments, this, ns, ops, { name })
|
|
147
147
|
}
|
|
148
|
-
return
|
|
148
|
+
return wrapped
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
function instrument (operation, command, ctx, args, server, ns, ops, options = {}) {
|
|
@@ -164,7 +164,7 @@ function instrument (operation, command, ctx, args, server, ns, ops, options = {
|
|
|
164
164
|
return asyncResource.runInAsyncScope(() => {
|
|
165
165
|
startCh.publish({ ns, ops, options: serverInfo, name })
|
|
166
166
|
|
|
167
|
-
args[index] = asyncResource.bind(function (err, res) {
|
|
167
|
+
args[index] = shimmer.wrapFunction(callback, callback => asyncResource.bind(function (err, res) {
|
|
168
168
|
if (err) {
|
|
169
169
|
errorCh.publish(err)
|
|
170
170
|
}
|
|
@@ -174,7 +174,7 @@ function instrument (operation, command, ctx, args, server, ns, ops, options = {
|
|
|
174
174
|
if (callback) {
|
|
175
175
|
return callback.apply(this, arguments)
|
|
176
176
|
}
|
|
177
|
-
})
|
|
177
|
+
}))
|
|
178
178
|
|
|
179
179
|
try {
|
|
180
180
|
return command.apply(ctx, args)
|
|
@@ -128,22 +128,21 @@ addHook({
|
|
|
128
128
|
const resolve = arguments[0]
|
|
129
129
|
const reject = arguments[1]
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
arguments[0] = function wrappedResolve () {
|
|
131
|
+
arguments[0] = shimmer.wrapFunction(resolve, resolve => function wrappedResolve () {
|
|
133
132
|
finish()
|
|
134
133
|
|
|
135
134
|
if (resolve) {
|
|
136
135
|
return resolve.apply(this, arguments)
|
|
137
136
|
}
|
|
138
|
-
}
|
|
137
|
+
})
|
|
139
138
|
|
|
140
|
-
arguments[1] = function wrappedReject () {
|
|
139
|
+
arguments[1] = shimmer.wrapFunction(reject, reject => function wrappedReject () {
|
|
141
140
|
finish()
|
|
142
141
|
|
|
143
142
|
if (reject) {
|
|
144
143
|
return reject.apply(this, arguments)
|
|
145
144
|
}
|
|
146
|
-
}
|
|
145
|
+
})
|
|
147
146
|
|
|
148
147
|
return originalThen.apply(this, arguments)
|
|
149
148
|
}
|
|
@@ -169,7 +168,7 @@ addHook({
|
|
|
169
168
|
versions: ['6', '>=7'],
|
|
170
169
|
file: 'lib/helpers/query/sanitizeFilter.js'
|
|
171
170
|
}, sanitizeFilter => {
|
|
172
|
-
return shimmer.
|
|
171
|
+
return shimmer.wrapFunction(sanitizeFilter, sanitizeFilter => function wrappedSanitizeFilter () {
|
|
173
172
|
const sanitizedObject = sanitizeFilter.apply(this, arguments)
|
|
174
173
|
|
|
175
174
|
if (sanitizeFilterFinishCh.hasSubscribers) {
|
|
@@ -37,14 +37,14 @@ addHook({ name: 'mysql', file: 'lib/Connection.js', versions: ['>=2'] }, Connect
|
|
|
37
37
|
|
|
38
38
|
if (res._callback) {
|
|
39
39
|
const cb = callbackResource.bind(res._callback)
|
|
40
|
-
res._callback = asyncResource.bind(function (error, result) {
|
|
40
|
+
res._callback = shimmer.wrapFunction(cb, cb => asyncResource.bind(function (error, result) {
|
|
41
41
|
if (error) {
|
|
42
42
|
errorCh.publish(error)
|
|
43
43
|
}
|
|
44
44
|
finishCh.publish(result)
|
|
45
45
|
|
|
46
46
|
return cb.apply(this, arguments)
|
|
47
|
-
})
|
|
47
|
+
}))
|
|
48
48
|
} else {
|
|
49
49
|
const cb = asyncResource.bind(function () {
|
|
50
50
|
finishCh.publish(undefined)
|
|
@@ -92,7 +92,7 @@ addHook({ name: 'mysql', file: 'lib/Pool.js', versions: ['>=2'] }, Pool => {
|
|
|
92
92
|
|
|
93
93
|
const cb = arguments[arguments.length - 1]
|
|
94
94
|
if (typeof cb === 'function') {
|
|
95
|
-
arguments[arguments.length - 1] = shimmer.
|
|
95
|
+
arguments[arguments.length - 1] = shimmer.wrapFunction(cb, cb => function () {
|
|
96
96
|
finish()
|
|
97
97
|
return cb.apply(this, arguments)
|
|
98
98
|
})
|
|
@@ -31,19 +31,19 @@ addHook({ name: 'mysql2', file: 'lib/connection.js', versions: ['>=1'] }, Connec
|
|
|
31
31
|
return Connection
|
|
32
32
|
|
|
33
33
|
function bindExecute (cmd, execute, asyncResource) {
|
|
34
|
-
return asyncResource.bind(function executeWithTrace (packet, connection) {
|
|
34
|
+
return shimmer.wrapFunction(execute, execute => asyncResource.bind(function executeWithTrace (packet, connection) {
|
|
35
35
|
if (this.onResult) {
|
|
36
36
|
this.onResult = asyncResource.bind(this.onResult)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
return execute.apply(this, arguments)
|
|
40
|
-
}, cmd)
|
|
40
|
+
}, cmd))
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function wrapExecute (cmd, execute, asyncResource, config) {
|
|
44
44
|
const callbackResource = new AsyncResource('bound-anonymous-fn')
|
|
45
45
|
|
|
46
|
-
return asyncResource.bind(function executeWithTrace (packet, connection) {
|
|
46
|
+
return shimmer.wrapFunction(execute, execute => asyncResource.bind(function executeWithTrace (packet, connection) {
|
|
47
47
|
const sql = cmd.statement ? cmd.statement.query : cmd.sql
|
|
48
48
|
const payload = { sql, conf: config }
|
|
49
49
|
startCh.publish(payload)
|
|
@@ -57,13 +57,13 @@ addHook({ name: 'mysql2', file: 'lib/connection.js', versions: ['>=1'] }, Connec
|
|
|
57
57
|
if (this.onResult) {
|
|
58
58
|
const onResult = callbackResource.bind(this.onResult)
|
|
59
59
|
|
|
60
|
-
this.onResult = asyncResource.bind(function (error) {
|
|
60
|
+
this.onResult = shimmer.wrapFunction(onResult, onResult => asyncResource.bind(function (error) {
|
|
61
61
|
if (error) {
|
|
62
62
|
errorCh.publish(error)
|
|
63
63
|
}
|
|
64
64
|
finishCh.publish(undefined)
|
|
65
65
|
onResult.apply(this, arguments)
|
|
66
|
-
}, 'bound-anonymous-fn', this)
|
|
66
|
+
}, 'bound-anonymous-fn', this))
|
|
67
67
|
} else {
|
|
68
68
|
this.on('error', asyncResource.bind(error => errorCh.publish(error)))
|
|
69
69
|
this.on('end', asyncResource.bind(() => finishCh.publish(undefined)))
|
|
@@ -76,6 +76,6 @@ addHook({ name: 'mysql2', file: 'lib/connection.js', versions: ['>=1'] }, Connec
|
|
|
76
76
|
} catch (err) {
|
|
77
77
|
errorCh.publish(err)
|
|
78
78
|
}
|
|
79
|
-
}, cmd)
|
|
79
|
+
}, cmd))
|
|
80
80
|
}
|
|
81
81
|
})
|
|
@@ -58,7 +58,7 @@ addHook({ name: names }, (net, version, name) => {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
const emit = this.emit
|
|
61
|
-
this.emit = function (eventName) {
|
|
61
|
+
this.emit = shimmer.wrapFunction(emit, emit => function (eventName) {
|
|
62
62
|
switch (eventName) {
|
|
63
63
|
case 'ready':
|
|
64
64
|
case 'connect':
|
|
@@ -68,7 +68,7 @@ addHook({ name: names }, (net, version, name) => {
|
|
|
68
68
|
default:
|
|
69
69
|
return emit.apply(this, arguments)
|
|
70
70
|
}
|
|
71
|
-
}
|
|
71
|
+
})
|
|
72
72
|
|
|
73
73
|
try {
|
|
74
74
|
return connect.apply(this, arguments)
|
|
@@ -188,7 +188,7 @@ function finish (ctx, result, err) {
|
|
|
188
188
|
// however, it is not provided as a class function or exported property
|
|
189
189
|
addHook({
|
|
190
190
|
name: 'next',
|
|
191
|
-
versions: ['>=13.3.0'],
|
|
191
|
+
versions: ['>=13.3.0 <14.2.7'],
|
|
192
192
|
file: 'dist/server/web/spec-extension/adapters/next-request.js'
|
|
193
193
|
}, NextRequestAdapter => {
|
|
194
194
|
shimmer.wrap(NextRequestAdapter.NextRequestAdapter, 'fromNodeNextRequest', fromNodeNextRequest => {
|
|
@@ -203,7 +203,7 @@ addHook({
|
|
|
203
203
|
|
|
204
204
|
addHook({
|
|
205
205
|
name: 'next',
|
|
206
|
-
versions: ['>=11.1'],
|
|
206
|
+
versions: ['>=11.1 <14.2.7'],
|
|
207
207
|
file: 'dist/server/serve-static.js'
|
|
208
208
|
}, serveStatic => shimmer.wrap(serveStatic, 'serveStatic', wrapServeStatic))
|
|
209
209
|
|
|
@@ -213,7 +213,7 @@ addHook({
|
|
|
213
213
|
file: 'dist/next-server/server/serve-static.js'
|
|
214
214
|
}, serveStatic => shimmer.wrap(serveStatic, 'serveStatic', wrapServeStatic))
|
|
215
215
|
|
|
216
|
-
addHook({ name: 'next', versions: ['>=11.1'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
216
|
+
addHook({ name: 'next', versions: ['>=11.1 <14.2.7'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
217
217
|
const Server = nextServer.default
|
|
218
218
|
|
|
219
219
|
shimmer.wrap(Server.prototype, 'handleRequest', wrapHandleRequest)
|
|
@@ -230,7 +230,7 @@ addHook({ name: 'next', versions: ['>=11.1'], file: 'dist/server/next-server.js'
|
|
|
230
230
|
})
|
|
231
231
|
|
|
232
232
|
// `handleApiRequest` changes parameters/implementation at 13.2.0
|
|
233
|
-
addHook({ name: 'next', versions: ['>=13.2'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
233
|
+
addHook({ name: 'next', versions: ['>=13.2 <14.2.7'], file: 'dist/server/next-server.js' }, nextServer => {
|
|
234
234
|
const Server = nextServer.default
|
|
235
235
|
shimmer.wrap(Server.prototype, 'handleApiRequest', wrapHandleApiRequestWithMatch)
|
|
236
236
|
return nextServer
|
|
@@ -264,7 +264,7 @@ addHook({
|
|
|
264
264
|
|
|
265
265
|
addHook({
|
|
266
266
|
name: 'next',
|
|
267
|
-
versions: ['>=13'],
|
|
267
|
+
versions: ['>=13 <14.2.7'],
|
|
268
268
|
file: 'dist/server/web/spec-extension/request.js'
|
|
269
269
|
}, request => {
|
|
270
270
|
const nextUrlDescriptor = Object.getOwnPropertyDescriptor(request.NextRequest.prototype, 'nextUrl')
|