dd-trace 2.2.0 → 2.2.1
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 +0 -2
- package/index.d.ts +0 -12
- package/package.json +3 -5
- package/packages/datadog-instrumentations/index.js +8 -0
- package/packages/datadog-instrumentations/src/bunyan.js +22 -0
- package/packages/datadog-instrumentations/src/elasticsearch.js +6 -1
- package/packages/datadog-instrumentations/src/generic-pool.js +48 -0
- package/packages/datadog-instrumentations/src/ioredis.js +49 -0
- package/packages/datadog-instrumentations/src/mongoose.js +30 -0
- package/packages/datadog-instrumentations/src/pino.js +105 -0
- package/packages/datadog-instrumentations/src/redis.js +118 -0
- package/packages/datadog-instrumentations/src/sharedb.js +78 -0
- package/packages/datadog-instrumentations/src/winston.js +57 -0
- package/packages/datadog-plugin-bunyan/src/index.js +5 -22
- package/packages/datadog-plugin-fastify/src/find-my-way.js +0 -1
- package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +8 -6
- package/packages/datadog-plugin-graphql/src/index.js +34 -28
- package/packages/datadog-plugin-grpc/src/client.js +20 -6
- package/packages/datadog-plugin-http2/src/server.js +2 -0
- package/packages/datadog-plugin-ioredis/src/index.js +5 -35
- package/packages/datadog-plugin-jest/src/jest-environment.js +26 -30
- package/packages/datadog-plugin-koa/src/index.js +6 -2
- package/packages/datadog-plugin-microgateway-core/src/index.js +1 -3
- package/packages/datadog-plugin-mocha/src/index.js +5 -3
- package/packages/datadog-plugin-mongodb-core/src/util.js +31 -7
- package/packages/datadog-plugin-next/src/index.js +9 -4
- package/packages/datadog-plugin-oracledb/src/index.js +10 -7
- package/packages/datadog-plugin-pino/src/index.js +5 -158
- package/packages/datadog-plugin-redis/src/index.js +96 -80
- package/packages/datadog-plugin-restify/src/index.js +18 -3
- package/packages/datadog-plugin-rhea/src/index.js +8 -5
- package/packages/datadog-plugin-router/src/index.js +23 -14
- package/packages/datadog-plugin-sharedb/src/index.js +47 -87
- package/packages/datadog-plugin-winston/src/index.js +5 -113
- package/packages/datadog-shimmer/src/shimmer.js +1 -1
- package/packages/dd-trace/lib/version.js +1 -1
- package/packages/dd-trace/src/appsec/index.js +2 -1
- package/packages/dd-trace/src/appsec/reporter.js +3 -2
- package/packages/dd-trace/src/constants.js +1 -6
- package/packages/dd-trace/src/opentracing/propagation/text_map.js +0 -34
- package/packages/dd-trace/src/plugins/index.js +0 -2
- package/packages/dd-trace/src/plugins/log_plugin.js +44 -0
- package/packages/dd-trace/src/plugins/plugin.js +7 -0
- package/packages/dd-trace/src/plugins/util/web.js +102 -84
- package/packages/dd-trace/src/priority_sampler.js +1 -49
- package/packages/dd-trace/src/scope.js +47 -23
- package/packages/datadog-plugin-generic-pool/src/index.js +0 -52
- package/packages/datadog-plugin-mongoose/src/index.js +0 -51
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
4
|
|
|
5
|
+
const messageSpans = new WeakMap()
|
|
6
|
+
|
|
5
7
|
function createWrapRequest (tracer, config) {
|
|
6
8
|
return function wrapRequest (request) {
|
|
7
9
|
return function requestWithTrace (cfg = { reqOpts: {} }, cb) {
|
|
@@ -45,11 +47,11 @@ function createWrapRequest (tracer, config) {
|
|
|
45
47
|
function createWrapSubscriptionEmit (tracer, config) {
|
|
46
48
|
return function wrapSubscriptionEmit (emit) {
|
|
47
49
|
return function emitWithTrace (eventName, message) {
|
|
48
|
-
if (eventName !== 'message' || !message
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
if (eventName !== 'message' || !message) return emit.apply(this, arguments)
|
|
51
|
+
|
|
52
|
+
const span = messageSpans.get(message)
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
if (!span) return emit.apply(this, arguments)
|
|
53
55
|
|
|
54
56
|
return tracer.scope().activate(span, () => {
|
|
55
57
|
try {
|
|
@@ -83,7 +85,7 @@ function createWrapLeaseDispense (tracer, config) {
|
|
|
83
85
|
|
|
84
86
|
analyticsSampler.sample(span, config.measured, true)
|
|
85
87
|
|
|
86
|
-
message
|
|
88
|
+
messageSpans.set(message, span)
|
|
87
89
|
|
|
88
90
|
return dispense.apply(this, arguments)
|
|
89
91
|
}
|
|
@@ -119,7 +121,7 @@ function getTopic (cfg) {
|
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
function finish (message) {
|
|
122
|
-
const span = message
|
|
124
|
+
const span = messageSpans.get(message)
|
|
123
125
|
|
|
124
126
|
if (!span) return
|
|
125
127
|
|
|
@@ -4,6 +4,11 @@ const pick = require('lodash.pick')
|
|
|
4
4
|
const log = require('../../dd-trace/src/log')
|
|
5
5
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
6
6
|
|
|
7
|
+
const contexts = new WeakMap()
|
|
8
|
+
const documentSources = new WeakMap()
|
|
9
|
+
const patchedTypes = new WeakSet()
|
|
10
|
+
const patchedResolvers = new WeakSet()
|
|
11
|
+
|
|
7
12
|
let tools
|
|
8
13
|
|
|
9
14
|
function createWrapExecute (tracer, config, defaultFieldResolver) {
|
|
@@ -12,11 +17,11 @@ function createWrapExecute (tracer, config, defaultFieldResolver) {
|
|
|
12
17
|
const args = normalizeArgs(arguments, tracer, config, defaultFieldResolver)
|
|
13
18
|
const schema = args.schema
|
|
14
19
|
const document = args.document
|
|
15
|
-
const source = document
|
|
20
|
+
const source = documentSources.get(document)
|
|
16
21
|
const contextValue = args.contextValue
|
|
17
22
|
const operation = getOperation(document, args.operationName)
|
|
18
23
|
|
|
19
|
-
if (contextValue
|
|
24
|
+
if (contexts.has(contextValue)) {
|
|
20
25
|
return execute.apply(this, arguments)
|
|
21
26
|
}
|
|
22
27
|
|
|
@@ -26,11 +31,12 @@ function createWrapExecute (tracer, config, defaultFieldResolver) {
|
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
const span = startExecutionSpan(tracer, config, operation, args)
|
|
34
|
+
const context = { source, span, fields: {} }
|
|
29
35
|
|
|
30
|
-
contextValue
|
|
36
|
+
contexts.set(contextValue, context)
|
|
31
37
|
|
|
32
38
|
return call(execute, span, this, arguments, (err, res) => {
|
|
33
|
-
finishResolvers(
|
|
39
|
+
finishResolvers(context)
|
|
34
40
|
|
|
35
41
|
setError(span, err || (res && res.errors && res.errors[0]))
|
|
36
42
|
config.hooks.execute(span, args, res)
|
|
@@ -55,7 +61,7 @@ function createWrapParse (tracer, config) {
|
|
|
55
61
|
if (!operation) return document // skip schema parsing
|
|
56
62
|
|
|
57
63
|
if (source) {
|
|
58
|
-
document
|
|
64
|
+
documentSources.set(document, source.body || source)
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
addDocumentTags(span, document, config)
|
|
@@ -103,11 +109,11 @@ function createWrapValidate (tracer, config) {
|
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
function wrapFields (type, tracer, config) {
|
|
106
|
-
if (!type || !type._fields || type
|
|
112
|
+
if (!type || !type._fields || patchedTypes.has(type)) {
|
|
107
113
|
return
|
|
108
114
|
}
|
|
109
115
|
|
|
110
|
-
type
|
|
116
|
+
patchedTypes.add(type)
|
|
111
117
|
|
|
112
118
|
Object.keys(type._fields).forEach(key => {
|
|
113
119
|
const field = type._fields[key]
|
|
@@ -136,14 +142,16 @@ function wrapFieldType (field, tracer, config) {
|
|
|
136
142
|
}
|
|
137
143
|
|
|
138
144
|
function wrapResolve (resolve, tracer, config) {
|
|
139
|
-
if (
|
|
145
|
+
if (typeof resolve !== 'function' || patchedResolvers.has(resolve)) return resolve
|
|
140
146
|
|
|
141
147
|
const responsePathAsArray = config.collapse
|
|
142
148
|
? withCollapse(pathToArray)
|
|
143
149
|
: pathToArray
|
|
144
150
|
|
|
145
151
|
function resolveWithTrace (source, args, contextValue, info) {
|
|
146
|
-
|
|
152
|
+
const context = contexts.get(contextValue)
|
|
153
|
+
|
|
154
|
+
if (!context) return resolve.apply(this, arguments)
|
|
147
155
|
|
|
148
156
|
const path = responsePathAsArray(info && info.path)
|
|
149
157
|
|
|
@@ -151,18 +159,18 @@ function wrapResolve (resolve, tracer, config) {
|
|
|
151
159
|
const depth = path.filter(item => typeof item === 'string').length
|
|
152
160
|
|
|
153
161
|
if (config.depth < depth) {
|
|
154
|
-
const parent = getParentField(tracer,
|
|
162
|
+
const parent = getParentField(tracer, context, path)
|
|
155
163
|
|
|
156
164
|
return call(resolve, parent.span, this, arguments)
|
|
157
165
|
}
|
|
158
166
|
}
|
|
159
167
|
|
|
160
|
-
const field = assertField(tracer, config,
|
|
168
|
+
const field = assertField(tracer, config, context, info, path)
|
|
161
169
|
|
|
162
170
|
return call(resolve, field.span, this, arguments, err => updateField(field, err))
|
|
163
171
|
}
|
|
164
172
|
|
|
165
|
-
resolveWithTrace
|
|
173
|
+
patchedResolvers.add(resolveWithTrace)
|
|
166
174
|
|
|
167
175
|
return resolveWithTrace
|
|
168
176
|
}
|
|
@@ -191,9 +199,9 @@ function call (fn, span, thisArg, args, callback) {
|
|
|
191
199
|
}
|
|
192
200
|
}
|
|
193
201
|
|
|
194
|
-
function getParentField (tracer,
|
|
202
|
+
function getParentField (tracer, context, path) {
|
|
195
203
|
for (let i = path.length - 1; i > 0; i--) {
|
|
196
|
-
const field = getField(
|
|
204
|
+
const field = getField(context, path.slice(0, i))
|
|
197
205
|
|
|
198
206
|
if (field) {
|
|
199
207
|
return field
|
|
@@ -201,12 +209,12 @@ function getParentField (tracer, contextValue, path) {
|
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
return {
|
|
204
|
-
span:
|
|
212
|
+
span: context.span
|
|
205
213
|
}
|
|
206
214
|
}
|
|
207
215
|
|
|
208
|
-
function getField (
|
|
209
|
-
return
|
|
216
|
+
function getField (context, path) {
|
|
217
|
+
return context.fields[path.join('.')]
|
|
210
218
|
}
|
|
211
219
|
|
|
212
220
|
function normalizeArgs (args, tracer, config, defaultFieldResolver) {
|
|
@@ -267,8 +275,8 @@ function addExecutionTags (span, config, operation, document, operationName) {
|
|
|
267
275
|
function addDocumentTags (span, document, config) {
|
|
268
276
|
const tags = {}
|
|
269
277
|
|
|
270
|
-
if (config.source && document
|
|
271
|
-
tags['graphql.source'] = document
|
|
278
|
+
if (config.source && document) {
|
|
279
|
+
tags['graphql.source'] = documentSources.get(document)
|
|
272
280
|
}
|
|
273
281
|
|
|
274
282
|
span.addTags(tags)
|
|
@@ -300,9 +308,9 @@ function startSpan (tracer, config, name, options) {
|
|
|
300
308
|
})
|
|
301
309
|
}
|
|
302
310
|
|
|
303
|
-
function startResolveSpan (tracer, config, childOf, path, info,
|
|
311
|
+
function startResolveSpan (tracer, config, childOf, path, info, { source }) {
|
|
304
312
|
const span = startSpan(tracer, config, 'resolve', { childOf })
|
|
305
|
-
const document =
|
|
313
|
+
const document = source
|
|
306
314
|
const fieldNode = info.fieldNodes.find(fieldNode => fieldNode.kind === 'Field')
|
|
307
315
|
|
|
308
316
|
analyticsSampler.sample(span, config.measured)
|
|
@@ -345,9 +353,7 @@ function finish (span, finishTime) {
|
|
|
345
353
|
span.finish(finishTime)
|
|
346
354
|
}
|
|
347
355
|
|
|
348
|
-
function finishResolvers (
|
|
349
|
-
const fields = contextValue._datadog_graphql.fields
|
|
350
|
-
|
|
356
|
+
function finishResolvers ({ fields }) {
|
|
351
357
|
Object.keys(fields).reverse().forEach(key => {
|
|
352
358
|
const field = fields[key]
|
|
353
359
|
|
|
@@ -369,18 +375,18 @@ function withCollapse (responsePathAsArray) {
|
|
|
369
375
|
}
|
|
370
376
|
}
|
|
371
377
|
|
|
372
|
-
function assertField (tracer, config,
|
|
378
|
+
function assertField (tracer, config, context, info, path) {
|
|
373
379
|
const pathString = path.join('.')
|
|
374
|
-
const fields =
|
|
380
|
+
const fields = context.fields
|
|
375
381
|
|
|
376
382
|
let field = fields[pathString]
|
|
377
383
|
|
|
378
384
|
if (!field) {
|
|
379
|
-
const parent = getParentField(tracer,
|
|
385
|
+
const parent = getParentField(tracer, context, path)
|
|
380
386
|
|
|
381
387
|
field = fields[pathString] = {
|
|
382
388
|
parent,
|
|
383
|
-
span: startResolveSpan(tracer, config, parent.span, path, info,
|
|
389
|
+
span: startResolveSpan(tracer, config, parent.span, path, info, context),
|
|
384
390
|
error: null
|
|
385
391
|
}
|
|
386
392
|
}
|
|
@@ -7,6 +7,9 @@ const { ERROR } = require('../../../ext/tags')
|
|
|
7
7
|
const kinds = require('./kinds')
|
|
8
8
|
const { addMethodTags, addMetadataTags, getFilter } = require('./util')
|
|
9
9
|
|
|
10
|
+
const patched = new WeakSet()
|
|
11
|
+
const instances = new WeakMap()
|
|
12
|
+
|
|
10
13
|
function createWrapMakeRequest (tracer, config, methodKind) {
|
|
11
14
|
const filter = getFilter(config, 'metadata')
|
|
12
15
|
|
|
@@ -80,7 +83,7 @@ function wrapClientConstructor (tracer, config, ServiceClient, methods) {
|
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
function wrapMethod (tracer, config, method, path, methodKind) {
|
|
83
|
-
if (typeof method !== 'function' || method
|
|
86
|
+
if (typeof method !== 'function' || patched.has(method)) {
|
|
84
87
|
return method
|
|
85
88
|
}
|
|
86
89
|
|
|
@@ -94,7 +97,7 @@ function wrapMethod (tracer, config, method, path, methodKind) {
|
|
|
94
97
|
|
|
95
98
|
Object.assign(methodWithTrace, method)
|
|
96
99
|
|
|
97
|
-
methodWithTrace
|
|
100
|
+
patched.add(methodWithTrace)
|
|
98
101
|
|
|
99
102
|
return methodWithTrace
|
|
100
103
|
}
|
|
@@ -186,7 +189,9 @@ function startSpan (tracer, config, path, methodKind) {
|
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
function ensureMetadata (client, args, index) {
|
|
189
|
-
|
|
192
|
+
const grpc = getGrpc(client)
|
|
193
|
+
|
|
194
|
+
if (!client || !grpc) return args
|
|
190
195
|
|
|
191
196
|
const meta = args[index]
|
|
192
197
|
const normalized = []
|
|
@@ -196,7 +201,7 @@ function ensureMetadata (client, args, index) {
|
|
|
196
201
|
}
|
|
197
202
|
|
|
198
203
|
if (!meta || !meta.constructor || meta.constructor.name !== 'Metadata') {
|
|
199
|
-
normalized.push(new
|
|
204
|
+
normalized.push(new grpc.Metadata())
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
if (meta) {
|
|
@@ -238,6 +243,15 @@ function getMethodKind (definition) {
|
|
|
238
243
|
return kinds.unary
|
|
239
244
|
}
|
|
240
245
|
|
|
246
|
+
function getGrpc (client) {
|
|
247
|
+
let proto = client
|
|
248
|
+
|
|
249
|
+
do {
|
|
250
|
+
const instance = instances.get(proto)
|
|
251
|
+
if (instance) return instance
|
|
252
|
+
} while ((proto = Object.getPrototypeOf(proto)))
|
|
253
|
+
}
|
|
254
|
+
|
|
241
255
|
function patch (grpc, tracer, config) {
|
|
242
256
|
if (config.client === false) return
|
|
243
257
|
|
|
@@ -245,7 +259,7 @@ function patch (grpc, tracer, config) {
|
|
|
245
259
|
|
|
246
260
|
const proto = grpc.Client.prototype
|
|
247
261
|
|
|
248
|
-
proto
|
|
262
|
+
instances.set(proto, grpc)
|
|
249
263
|
|
|
250
264
|
this.wrap(proto, 'makeBidiStreamRequest', createWrapMakeRequest(tracer, config, kinds.bidi))
|
|
251
265
|
this.wrap(proto, 'makeClientStreamRequest', createWrapMakeRequest(tracer, config, kinds.clientStream))
|
|
@@ -256,7 +270,7 @@ function patch (grpc, tracer, config) {
|
|
|
256
270
|
function unpatch (grpc) {
|
|
257
271
|
const proto = grpc.Client.prototype
|
|
258
272
|
|
|
259
|
-
delete
|
|
273
|
+
instances.delete(proto)
|
|
260
274
|
|
|
261
275
|
this.unwrap(proto, 'makeBidiStreamRequest')
|
|
262
276
|
this.unwrap(proto, 'makeClientStreamRequest')
|
|
@@ -1,41 +1,11 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const RedisPlugin = require('../../datadog-plugin-redis/src')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
if (!command || !command.promise || !config.filter(command.name)) return sendCommand.apply(this, arguments)
|
|
9
|
-
|
|
10
|
-
const options = this.options || {}
|
|
11
|
-
const connectionName = this.options.connectionName
|
|
12
|
-
const db = options.db
|
|
13
|
-
const span = tx.instrument(tracer, config, db, command.name, command.args)
|
|
14
|
-
|
|
15
|
-
tx.setHost(span, options.host, options.port)
|
|
16
|
-
tx.wrap(span, command.promise)
|
|
17
|
-
|
|
18
|
-
if (config.splitByInstance && connectionName) {
|
|
19
|
-
const service = config.service
|
|
20
|
-
? `${config.service}-${connectionName}`
|
|
21
|
-
: connectionName
|
|
22
|
-
|
|
23
|
-
span.setTag('service.name', service)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return tracer.scope().bind(sendCommand, span).apply(this, arguments)
|
|
27
|
-
}
|
|
5
|
+
class IORedisPlugin extends RedisPlugin {
|
|
6
|
+
static get name () {
|
|
7
|
+
return 'ioredis'
|
|
28
8
|
}
|
|
29
9
|
}
|
|
30
10
|
|
|
31
|
-
module.exports =
|
|
32
|
-
name: 'ioredis',
|
|
33
|
-
versions: ['>=2'],
|
|
34
|
-
patch (Redis, tracer, config) {
|
|
35
|
-
config = tx.normalizeConfig(config)
|
|
36
|
-
this.wrap(Redis.prototype, 'sendCommand', createWrapSendCommand(tracer, config))
|
|
37
|
-
},
|
|
38
|
-
unpatch (Redis) {
|
|
39
|
-
this.unwrap(Redis.prototype, 'sendCommand')
|
|
40
|
-
}
|
|
41
|
-
}
|
|
11
|
+
module.exports = IORedisPlugin
|
|
@@ -22,6 +22,8 @@ const {
|
|
|
22
22
|
setSuppressedErrors
|
|
23
23
|
} = require('./util')
|
|
24
24
|
|
|
25
|
+
const originals = new WeakMap()
|
|
26
|
+
|
|
25
27
|
function getVmContext (environment) {
|
|
26
28
|
if (typeof environment.getVmContext === 'function') {
|
|
27
29
|
return environment.getVmContext()
|
|
@@ -234,43 +236,37 @@ function createHandleTestEvent (tracer, testEnvironmentMetadata, instrumenter) {
|
|
|
234
236
|
}
|
|
235
237
|
}
|
|
236
238
|
|
|
239
|
+
function patch (Environment, tracer, config) {
|
|
240
|
+
const testEnvironmentMetadata = getTestEnvironmentMetadata('jest', config)
|
|
241
|
+
const proto = Environment.prototype
|
|
242
|
+
|
|
243
|
+
this.wrap(proto, 'teardown', createWrapTeardown(tracer, this))
|
|
244
|
+
|
|
245
|
+
const newHandleTestEvent = createHandleTestEvent(tracer, testEnvironmentMetadata, this)
|
|
246
|
+
originals.set(newHandleTestEvent, proto.handleTestEvent)
|
|
247
|
+
proto.handleTestEvent = newHandleTestEvent
|
|
248
|
+
|
|
249
|
+
return wrapEnvironment(Environment)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function unpatch (Environment) {
|
|
253
|
+
const proto = Environment.prototype
|
|
254
|
+
|
|
255
|
+
this.unwrap(Environment.prototype, 'teardown')
|
|
256
|
+
proto.handleTestEvent = originals.get(proto.handleTestEvent)
|
|
257
|
+
}
|
|
258
|
+
|
|
237
259
|
module.exports = [
|
|
238
260
|
{
|
|
239
261
|
name: 'jest-environment-node',
|
|
240
262
|
versions: ['>=24.8.0'],
|
|
241
|
-
patch
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this.wrap(NodeEnvironment.prototype, 'teardown', createWrapTeardown(tracer, this))
|
|
245
|
-
|
|
246
|
-
const newHandleTestEvent = createHandleTestEvent(tracer, testEnvironmentMetadata, this)
|
|
247
|
-
newHandleTestEvent._dd_original = NodeEnvironment.prototype.handleTestEvent
|
|
248
|
-
NodeEnvironment.prototype.handleTestEvent = newHandleTestEvent
|
|
249
|
-
|
|
250
|
-
return wrapEnvironment(NodeEnvironment)
|
|
251
|
-
},
|
|
252
|
-
unpatch: function (NodeEnvironment) {
|
|
253
|
-
this.unwrap(NodeEnvironment.prototype, 'teardown')
|
|
254
|
-
NodeEnvironment.prototype.handleTestEvent = NodeEnvironment.prototype.handleTestEvent._dd_original
|
|
255
|
-
}
|
|
263
|
+
patch,
|
|
264
|
+
unpatch
|
|
256
265
|
},
|
|
257
266
|
{
|
|
258
267
|
name: 'jest-environment-jsdom',
|
|
259
268
|
versions: ['>=24.8.0'],
|
|
260
|
-
patch
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.wrap(JsdomEnvironment.prototype, 'teardown', createWrapTeardown(tracer, this))
|
|
264
|
-
|
|
265
|
-
const newHandleTestEvent = createHandleTestEvent(tracer, testEnvironmentMetadata, this)
|
|
266
|
-
newHandleTestEvent._dd_original = JsdomEnvironment.prototype.handleTestEvent
|
|
267
|
-
JsdomEnvironment.prototype.handleTestEvent = newHandleTestEvent
|
|
268
|
-
|
|
269
|
-
return wrapEnvironment(JsdomEnvironment)
|
|
270
|
-
},
|
|
271
|
-
unpatch: function (JsdomEnvironment) {
|
|
272
|
-
this.unwrap(JsdomEnvironment.prototype, 'teardown')
|
|
273
|
-
JsdomEnvironment.prototype.handleTestEvent = JsdomEnvironment.prototype.handleTestEvent._dd_original
|
|
274
|
-
}
|
|
269
|
+
patch,
|
|
270
|
+
unpatch
|
|
275
271
|
}
|
|
276
272
|
]
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const web = require('../../dd-trace/src/plugins/util/web')
|
|
4
4
|
|
|
5
|
+
const originals = new WeakMap()
|
|
6
|
+
|
|
5
7
|
function createWrapCallback (tracer, config) {
|
|
6
8
|
config = web.normalizeConfig(config)
|
|
7
9
|
|
|
@@ -83,7 +85,9 @@ function wrapStack (layer) {
|
|
|
83
85
|
layer.stack = layer.stack.map(middleware => {
|
|
84
86
|
if (typeof middleware !== 'function') return middleware
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
const original = originals.get(middleware)
|
|
89
|
+
|
|
90
|
+
middleware = original || middleware
|
|
87
91
|
|
|
88
92
|
const wrappedMiddleware = wrapMiddleware(middleware)
|
|
89
93
|
|
|
@@ -96,7 +100,7 @@ function wrapStack (layer) {
|
|
|
96
100
|
return wrappedMiddleware.apply(this, arguments)
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
handler
|
|
103
|
+
originals.set(handler, middleware)
|
|
100
104
|
|
|
101
105
|
return handler
|
|
102
106
|
})
|
|
@@ -84,9 +84,7 @@ function wrapPluginInit (init) {
|
|
|
84
84
|
return function initWithTrace (config, logging, stats) {
|
|
85
85
|
const handler = init.apply(this, arguments)
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
wrapListeners(handler)
|
|
89
|
-
}
|
|
87
|
+
wrapListeners(handler)
|
|
90
88
|
|
|
91
89
|
return handler
|
|
92
90
|
}
|
|
@@ -18,6 +18,8 @@ const {
|
|
|
18
18
|
getTestSuitePath
|
|
19
19
|
} = require('../../dd-trace/src/plugins/util/test')
|
|
20
20
|
|
|
21
|
+
const skippedTests = new WeakSet()
|
|
22
|
+
|
|
21
23
|
function getTestSpanMetadata (tracer, test, sourceRoot) {
|
|
22
24
|
const childOf = getTestParentSpan(tracer)
|
|
23
25
|
|
|
@@ -131,12 +133,12 @@ function createWrapRunTests (tracer, testEnvironmentMetadata, sourceRoot) {
|
|
|
131
133
|
// We call `getAllTestsInSuite` with the root suite so every skipped test
|
|
132
134
|
// should already have an associated test span.
|
|
133
135
|
// This function is called with every suite, so we need a way to mark
|
|
134
|
-
// the test as already accounted for. We do this through `
|
|
136
|
+
// the test as already accounted for. We do this through `skippedTests`.
|
|
135
137
|
// If the test is already marked as skipped, we don't create an additional test span.
|
|
136
|
-
if (!isSkipped || test
|
|
138
|
+
if (!isSkipped || skippedTests.has(test)) {
|
|
137
139
|
return
|
|
138
140
|
}
|
|
139
|
-
test
|
|
141
|
+
skippedTests.add(test)
|
|
140
142
|
const { childOf, resource, ...testSpanMetadata } = getTestSpanMetadata(tracer, test, sourceRoot)
|
|
141
143
|
|
|
142
144
|
const testSpan = tracer
|
|
@@ -94,15 +94,39 @@ function getResource (ns, query, operationName) {
|
|
|
94
94
|
return parts.join(' ')
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (!isObject(input) || Buffer.isBuffer(input) || isBSON(input)) return '?'
|
|
97
|
+
function shouldHide (input) {
|
|
98
|
+
return !isObject(input) || Buffer.isBuffer(input) || isBSON(input)
|
|
99
|
+
}
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
function sanitize (input) {
|
|
102
|
+
if (shouldHide(input)) return '?'
|
|
104
103
|
|
|
105
|
-
|
|
104
|
+
const output = {}
|
|
105
|
+
const queue = [{
|
|
106
|
+
input,
|
|
107
|
+
output,
|
|
108
|
+
depth: 0
|
|
109
|
+
}]
|
|
110
|
+
|
|
111
|
+
while (queue.length) {
|
|
112
|
+
const {
|
|
113
|
+
input, output, depth
|
|
114
|
+
} = queue.pop()
|
|
115
|
+
const nextDepth = depth + 1
|
|
116
|
+
for (const key in input) {
|
|
117
|
+
if (typeof input[key] === 'function') continue
|
|
118
|
+
|
|
119
|
+
const child = input[key]
|
|
120
|
+
if (depth >= 20 || shouldHide(child)) {
|
|
121
|
+
output[key] = '?'
|
|
122
|
+
} else {
|
|
123
|
+
queue.push({
|
|
124
|
+
input: child,
|
|
125
|
+
output: output[key] = {},
|
|
126
|
+
depth: nextDepth
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
106
130
|
}
|
|
107
131
|
|
|
108
132
|
return output
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
6
6
|
|
|
7
|
+
const contexts = new WeakMap()
|
|
8
|
+
|
|
7
9
|
function createWrapHandleRequest (tracer, config) {
|
|
8
10
|
return function wrapHandleRequest (handleRequest) {
|
|
9
11
|
return function handleRequestWithTrace (req, res, pathname, query) {
|
|
@@ -92,8 +94,9 @@ function getPageFromPath (page, dynamicRoutes = []) {
|
|
|
92
94
|
|
|
93
95
|
function trace (tracer, config, req, res, handler) {
|
|
94
96
|
const scope = tracer.scope()
|
|
97
|
+
const context = contexts.get(req)
|
|
95
98
|
|
|
96
|
-
if (
|
|
99
|
+
if (context) return scope.activate(context.span, handler)
|
|
97
100
|
|
|
98
101
|
const childOf = scope.active()
|
|
99
102
|
const tags = {
|
|
@@ -107,7 +110,7 @@ function trace (tracer, config, req, res, handler) {
|
|
|
107
110
|
|
|
108
111
|
analyticsSampler.sample(span, config.measured, true)
|
|
109
112
|
|
|
110
|
-
req
|
|
113
|
+
contexts.set(req, { span })
|
|
111
114
|
|
|
112
115
|
const promise = scope.activate(span, handler)
|
|
113
116
|
|
|
@@ -124,9 +127,11 @@ function trace (tracer, config, req, res, handler) {
|
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
function addPage (req, page) {
|
|
127
|
-
|
|
130
|
+
const context = contexts.get(req)
|
|
131
|
+
|
|
132
|
+
if (!context) return
|
|
128
133
|
|
|
129
|
-
|
|
134
|
+
context.span.addTags({
|
|
130
135
|
'resource.name': `${req.method} ${page}`.trim(),
|
|
131
136
|
'next.page': page
|
|
132
137
|
})
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const analyticsSampler = require('../../dd-trace/src/analytics_sampler')
|
|
4
4
|
|
|
5
|
+
const connectionAttributes = new WeakMap()
|
|
6
|
+
const poolAttributes = new WeakMap()
|
|
7
|
+
|
|
5
8
|
function createWrapExecute (tracer, config) {
|
|
6
9
|
return function wrapExecute (execute) {
|
|
7
10
|
return function executeWithTrace (dbQuery, ...args) {
|
|
8
|
-
const connAttrs = this
|
|
11
|
+
const connAttrs = connectionAttributes.get(this)
|
|
9
12
|
const service = getServiceName(tracer, config, connAttrs)
|
|
10
13
|
const connectStringObj = new URL('http://' + connAttrs.connectString)
|
|
11
14
|
const tags = {
|
|
@@ -37,7 +40,7 @@ function createWrapGetConnection (tracer, config) {
|
|
|
37
40
|
if (callback) {
|
|
38
41
|
arguments[1] = (err, connection) => {
|
|
39
42
|
if (connection) {
|
|
40
|
-
connection
|
|
43
|
+
connectionAttributes.set(connection, connAttrs)
|
|
41
44
|
}
|
|
42
45
|
callback(err, connection)
|
|
43
46
|
}
|
|
@@ -45,7 +48,7 @@ function createWrapGetConnection (tracer, config) {
|
|
|
45
48
|
getConnection.apply(this, arguments)
|
|
46
49
|
} else {
|
|
47
50
|
return getConnection.apply(this, arguments).then((connection) => {
|
|
48
|
-
connection
|
|
51
|
+
connectionAttributes.set(connection, connAttrs)
|
|
49
52
|
return connection
|
|
50
53
|
})
|
|
51
54
|
}
|
|
@@ -59,7 +62,7 @@ function createWrapCreatePool (tracer, config) {
|
|
|
59
62
|
if (callback) {
|
|
60
63
|
arguments[1] = (err, pool) => {
|
|
61
64
|
if (pool) {
|
|
62
|
-
pool
|
|
65
|
+
poolAttributes.set(pool, poolAttrs)
|
|
63
66
|
}
|
|
64
67
|
callback(err, pool)
|
|
65
68
|
}
|
|
@@ -67,7 +70,7 @@ function createWrapCreatePool (tracer, config) {
|
|
|
67
70
|
createPool.apply(this, arguments)
|
|
68
71
|
} else {
|
|
69
72
|
return createPool.apply(this, arguments).then((pool) => {
|
|
70
|
-
pool
|
|
73
|
+
poolAttributes.set(pool, poolAttrs)
|
|
71
74
|
return pool
|
|
72
75
|
})
|
|
73
76
|
}
|
|
@@ -85,14 +88,14 @@ function createWrapPoolGetConnection (tracer, config) {
|
|
|
85
88
|
if (callback) {
|
|
86
89
|
arguments[arguments.length - 1] = (err, connection) => {
|
|
87
90
|
if (connection) {
|
|
88
|
-
connection.
|
|
91
|
+
connectionAttributes.set(connection, poolAttributes.get(this))
|
|
89
92
|
}
|
|
90
93
|
callback(err, connection)
|
|
91
94
|
}
|
|
92
95
|
getConnection.apply(this, arguments)
|
|
93
96
|
} else {
|
|
94
97
|
return getConnection.apply(this, arguments).then((connection) => {
|
|
95
|
-
connection.
|
|
98
|
+
connectionAttributes.set(connection, poolAttributes.get(this))
|
|
96
99
|
return connection
|
|
97
100
|
})
|
|
98
101
|
}
|