dd-trace 2.6.0 → 2.8.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/LICENSE-3rdparty.csv +1 -4
- package/index.d.ts +0 -7
- package/package.json +18 -24
- package/packages/datadog-instrumentations/index.js +16 -0
- package/packages/datadog-instrumentations/src/amqp10.js +33 -32
- package/packages/datadog-instrumentations/src/amqplib.js +16 -11
- package/packages/datadog-instrumentations/src/aws-sdk.js +104 -0
- package/packages/datadog-instrumentations/src/cassandra-driver.js +53 -51
- package/packages/datadog-instrumentations/src/connect.js +111 -0
- package/packages/datadog-instrumentations/src/couchbase.js +41 -39
- package/packages/datadog-instrumentations/src/cucumber.js +38 -38
- package/packages/datadog-instrumentations/src/dns.js +20 -19
- package/packages/datadog-instrumentations/src/elasticsearch.js +30 -32
- package/packages/datadog-instrumentations/src/express.js +27 -0
- package/packages/datadog-instrumentations/src/fastify.js +187 -0
- package/packages/datadog-instrumentations/src/find-my-way.js +30 -0
- package/packages/datadog-instrumentations/src/google-cloud-pubsub.js +100 -0
- package/packages/datadog-instrumentations/src/hapi.js +210 -0
- package/packages/datadog-instrumentations/src/http/client.js +44 -44
- package/packages/datadog-instrumentations/src/http/server.js +15 -13
- package/packages/datadog-instrumentations/src/ioredis.js +16 -17
- package/packages/datadog-instrumentations/src/jest.js +22 -17
- package/packages/datadog-instrumentations/src/kafkajs.js +112 -0
- package/packages/datadog-instrumentations/src/knex.js +20 -0
- package/packages/datadog-instrumentations/src/koa.js +159 -0
- package/packages/datadog-instrumentations/src/limitd-client.js +21 -0
- package/packages/datadog-instrumentations/src/memcached.js +14 -12
- package/packages/datadog-instrumentations/src/mocha.js +37 -39
- package/packages/datadog-instrumentations/src/moleculer/client.js +46 -0
- package/packages/datadog-instrumentations/src/moleculer/server.js +59 -0
- package/packages/datadog-instrumentations/src/moleculer.js +4 -0
- package/packages/datadog-instrumentations/src/mongodb-core.js +29 -33
- package/packages/datadog-instrumentations/src/mysql.js +30 -29
- package/packages/datadog-instrumentations/src/mysql2.js +8 -9
- package/packages/datadog-instrumentations/src/net.js +23 -24
- package/packages/datadog-instrumentations/src/oracledb.js +128 -0
- package/packages/datadog-instrumentations/src/paperplane.js +77 -0
- package/packages/datadog-instrumentations/src/pg.js +32 -32
- package/packages/datadog-instrumentations/src/redis.js +49 -47
- package/packages/datadog-instrumentations/src/restify.js +58 -0
- package/packages/datadog-instrumentations/src/rhea.js +52 -50
- package/packages/datadog-instrumentations/src/router.js +177 -0
- package/packages/datadog-instrumentations/src/sharedb.js +20 -20
- package/packages/datadog-instrumentations/src/tedious.js +19 -19
- package/packages/datadog-plugin-amqp10/src/index.js +2 -7
- package/packages/datadog-plugin-amqplib/src/index.js +1 -2
- package/packages/datadog-plugin-aws-sdk/src/base.js +146 -0
- package/packages/datadog-plugin-aws-sdk/src/index.js +16 -106
- package/packages/datadog-plugin-aws-sdk/src/services/cloudwatchlogs.js +4 -2
- package/packages/datadog-plugin-aws-sdk/src/services/default.js +7 -0
- package/packages/datadog-plugin-aws-sdk/src/services/dynamodb.js +3 -1
- package/packages/datadog-plugin-aws-sdk/src/services/eventbridge.js +5 -4
- package/packages/datadog-plugin-aws-sdk/src/services/index.js +12 -0
- package/packages/datadog-plugin-aws-sdk/src/services/kinesis.js +4 -3
- package/packages/datadog-plugin-aws-sdk/src/services/lambda.js +4 -3
- package/packages/datadog-plugin-aws-sdk/src/services/redshift.js +3 -1
- package/packages/datadog-plugin-aws-sdk/src/services/s3.js +3 -1
- package/packages/datadog-plugin-aws-sdk/src/services/sns.js +4 -3
- package/packages/datadog-plugin-aws-sdk/src/services/sqs.js +45 -6
- package/packages/datadog-plugin-cassandra-driver/src/index.js +1 -5
- package/packages/datadog-plugin-connect/src/index.js +10 -114
- package/packages/datadog-plugin-couchbase/src/index.js +3 -4
- package/packages/datadog-plugin-cucumber/src/index.js +1 -9
- package/packages/datadog-plugin-dns/src/index.js +15 -5
- package/packages/datadog-plugin-elasticsearch/src/index.js +1 -5
- package/packages/datadog-plugin-express/src/index.js +11 -25
- package/packages/datadog-plugin-fastify/src/index.js +17 -4
- package/packages/datadog-plugin-find-my-way/src/index.js +20 -0
- package/packages/datadog-plugin-google-cloud-pubsub/src/index.js +56 -111
- package/packages/datadog-plugin-hapi/src/index.js +34 -3
- package/packages/datadog-plugin-http/src/client.js +1 -3
- package/packages/datadog-plugin-http/src/server.js +2 -6
- package/packages/datadog-plugin-jest/src/index.js +2 -3
- package/packages/datadog-plugin-kafkajs/src/index.js +61 -91
- package/packages/datadog-plugin-koa/src/index.js +12 -164
- package/packages/datadog-plugin-memcached/src/index.js +1 -5
- package/packages/datadog-plugin-mocha/src/index.js +3 -7
- package/packages/datadog-plugin-moleculer/src/client.js +34 -44
- package/packages/datadog-plugin-moleculer/src/index.js +32 -3
- package/packages/datadog-plugin-moleculer/src/server.js +28 -50
- package/packages/datadog-plugin-mongodb-core/src/index.js +1 -5
- package/packages/datadog-plugin-mysql/src/index.js +1 -5
- package/packages/datadog-plugin-net/src/index.js +3 -7
- package/packages/datadog-plugin-oracledb/src/index.js +34 -100
- package/packages/datadog-plugin-paperplane/src/index.js +14 -100
- package/packages/datadog-plugin-paperplane/src/logger.js +11 -0
- package/packages/datadog-plugin-paperplane/src/server.js +24 -0
- package/packages/datadog-plugin-pg/src/index.js +1 -5
- package/packages/datadog-plugin-redis/src/index.js +1 -5
- package/packages/datadog-plugin-restify/src/index.js +13 -75
- package/packages/datadog-plugin-rhea/src/index.js +1 -5
- package/packages/datadog-plugin-router/src/index.js +67 -164
- package/packages/datadog-plugin-sharedb/src/index.js +1 -5
- package/packages/datadog-plugin-tedious/src/index.js +1 -5
- package/packages/datadog-plugin-web/src/index.js +20 -0
- package/packages/dd-trace/lib/version.js +1 -1
- package/packages/dd-trace/src/appsec/callbacks/ddwaf.js +8 -2
- package/packages/dd-trace/src/appsec/reporter.js +4 -0
- package/packages/dd-trace/src/encode/agentless-ci-visibility.js +3 -1
- package/packages/dd-trace/src/plugin_manager.js +13 -7
- package/packages/dd-trace/src/plugins/index.js +1 -2
- package/packages/dd-trace/src/plugins/log_plugin.js +8 -4
- package/packages/dd-trace/src/plugins/plugin.js +8 -8
- package/packages/dd-trace/src/plugins/util/test.js +5 -1
- package/packages/dd-trace/src/plugins/util/web.js +40 -12
- package/packages/dd-trace/src/profiling/config.js +8 -8
- package/packages/dd-trace/src/profiling/index.js +4 -4
- package/packages/dd-trace/src/profiling/profilers/{heap.js → space.js} +2 -2
- package/packages/dd-trace/src/profiling/profilers/{cpu.js → wall.js} +2 -2
- package/scripts/install_plugin_modules.js +23 -11
- package/packages/datadog-plugin-aws-sdk/src/helpers.js +0 -103
- package/packages/datadog-plugin-fastify/src/fastify.js +0 -198
- package/packages/datadog-plugin-fastify/src/find-my-way.js +0 -37
- package/packages/datadog-plugin-hapi/src/route.js +0 -75
- package/packages/datadog-plugin-hapi/src/server.js +0 -204
- package/packages/datadog-plugin-knex/src/index.js +0 -23
- package/packages/datadog-plugin-limitd-client/src/index.js +0 -30
- package/scripts/postpublish.js +0 -24
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
channel,
|
|
5
|
+
addHook,
|
|
6
|
+
AsyncResource
|
|
7
|
+
} = require('./helpers/instrument')
|
|
8
|
+
const shimmer = require('../../datadog-shimmer')
|
|
9
|
+
|
|
10
|
+
const producerStartCh = channel('apm:kafkajs:produce:start')
|
|
11
|
+
const producerFinishCh = channel('apm:kafkajs:produce:finish')
|
|
12
|
+
const producerErrorCh = channel('apm:kafkajs:produce:error')
|
|
13
|
+
|
|
14
|
+
const consumerStartCh = channel('apm:kafkajs:consume:start')
|
|
15
|
+
const consumerFinishCh = channel('apm:kafkajs:consume:finish')
|
|
16
|
+
const consumerErrorCh = channel('apm:kafkajs:consume:error')
|
|
17
|
+
|
|
18
|
+
addHook({ name: 'kafkajs', versions: ['>=1.4'] }, (obj) => {
|
|
19
|
+
const Kafka = obj.Kafka
|
|
20
|
+
shimmer.wrap(Kafka.prototype, 'producer', createProducer => function () {
|
|
21
|
+
const producer = createProducer.apply(this, arguments)
|
|
22
|
+
const send = producer.send
|
|
23
|
+
|
|
24
|
+
producer.send = function () {
|
|
25
|
+
const innerAsyncResource = new AsyncResource('bound-anonymous-fn')
|
|
26
|
+
|
|
27
|
+
return innerAsyncResource.runInAsyncScope(() => {
|
|
28
|
+
if (!producerStartCh.hasSubscribers) {
|
|
29
|
+
return send.apply(this, arguments)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const { topic, messages = [] } = arguments[0]
|
|
34
|
+
for (const message of messages) {
|
|
35
|
+
if (typeof message === 'object') {
|
|
36
|
+
message.headers = message.headers || {}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
producerStartCh.publish({ topic, messages })
|
|
40
|
+
|
|
41
|
+
const result = send.apply(this, arguments)
|
|
42
|
+
|
|
43
|
+
result.then(
|
|
44
|
+
innerAsyncResource.bind(() => producerFinishCh.publish(undefined)),
|
|
45
|
+
innerAsyncResource.bind(err => {
|
|
46
|
+
if (err) {
|
|
47
|
+
producerErrorCh.publish(err)
|
|
48
|
+
}
|
|
49
|
+
producerFinishCh.publish(undefined)
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
return result
|
|
54
|
+
} catch (e) {
|
|
55
|
+
producerErrorCh.publish(e)
|
|
56
|
+
producerFinishCh.publish(undefined)
|
|
57
|
+
throw e
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
return producer
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
shimmer.wrap(Kafka.prototype, 'consumer', createConsumer => function () {
|
|
65
|
+
if (!consumerStartCh.hasSubscribers) {
|
|
66
|
+
return createConsumer.apply(this, arguments)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const consumer = createConsumer.apply(this, arguments)
|
|
70
|
+
const run = consumer.run
|
|
71
|
+
|
|
72
|
+
consumer.run = function ({ eachMessage, ...runArgs }) {
|
|
73
|
+
if (typeof eachMessage !== 'function') return run({ eachMessage, ...runArgs })
|
|
74
|
+
|
|
75
|
+
return run({
|
|
76
|
+
eachMessage: function (...eachMessageArgs) {
|
|
77
|
+
const innerAsyncResource = new AsyncResource('bound-anonymous-fn')
|
|
78
|
+
return innerAsyncResource.runInAsyncScope(() => {
|
|
79
|
+
const { topic, partition, message } = eachMessageArgs[0]
|
|
80
|
+
consumerStartCh.publish({ topic, partition, message })
|
|
81
|
+
try {
|
|
82
|
+
const result = eachMessage.apply(this, eachMessageArgs)
|
|
83
|
+
|
|
84
|
+
if (result && typeof result.then === 'function') {
|
|
85
|
+
result.then(
|
|
86
|
+
innerAsyncResource.bind(() => consumerFinishCh.publish(undefined)),
|
|
87
|
+
innerAsyncResource.bind(err => {
|
|
88
|
+
if (err) {
|
|
89
|
+
consumerErrorCh.publish(err)
|
|
90
|
+
}
|
|
91
|
+
consumerFinishCh.publish(undefined)
|
|
92
|
+
})
|
|
93
|
+
)
|
|
94
|
+
} else {
|
|
95
|
+
consumerFinishCh.publish(undefined)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return result
|
|
99
|
+
} catch (e) {
|
|
100
|
+
consumerErrorCh.publish(e)
|
|
101
|
+
consumerFinishCh.publish(undefined)
|
|
102
|
+
throw e
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
...runArgs
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
return consumer
|
|
110
|
+
})
|
|
111
|
+
return obj
|
|
112
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook } = require('./helpers/instrument')
|
|
4
|
+
const { wrapThen } = require('./helpers/promise')
|
|
5
|
+
const shimmer = require('../../datadog-shimmer')
|
|
6
|
+
|
|
7
|
+
patch('lib/query/builder.js')
|
|
8
|
+
patch('lib/raw.js')
|
|
9
|
+
patch('lib/schema/builder.js')
|
|
10
|
+
|
|
11
|
+
function patch (file) {
|
|
12
|
+
addHook({
|
|
13
|
+
name: 'knex',
|
|
14
|
+
versions: ['>=0.8.0'],
|
|
15
|
+
file
|
|
16
|
+
}, Builder => {
|
|
17
|
+
shimmer.wrap(Builder.prototype, 'then', wrapThen)
|
|
18
|
+
return Builder
|
|
19
|
+
})
|
|
20
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const shimmer = require('../../datadog-shimmer')
|
|
4
|
+
const { addHook, channel, AsyncResource } = require('./helpers/instrument')
|
|
5
|
+
|
|
6
|
+
const enterChannel = channel('apm:koa:middleware:enter')
|
|
7
|
+
const errorChannel = channel('apm:koa:middleware:error')
|
|
8
|
+
const nextChannel = channel('apm:koa:middleware:next')
|
|
9
|
+
const handleChannel = channel('apm:koa:request:handle')
|
|
10
|
+
const routeChannel = channel('apm:koa:request:route')
|
|
11
|
+
|
|
12
|
+
const originals = new WeakMap()
|
|
13
|
+
|
|
14
|
+
function wrapCallback (callback) {
|
|
15
|
+
return function callbackWithTrace () {
|
|
16
|
+
const handleRequest = callback.apply(this, arguments)
|
|
17
|
+
|
|
18
|
+
if (typeof handleRequest !== 'function') return handleRequest
|
|
19
|
+
|
|
20
|
+
return function handleRequestWithTrace (req, res) {
|
|
21
|
+
handleChannel.publish({ req, res })
|
|
22
|
+
|
|
23
|
+
return handleRequest.apply(this, arguments)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function wrapUse (use) {
|
|
29
|
+
return function useWithTrace () {
|
|
30
|
+
const result = use.apply(this, arguments)
|
|
31
|
+
|
|
32
|
+
if (!Array.isArray(this.middleware)) return result
|
|
33
|
+
|
|
34
|
+
const fn = this.middleware.pop()
|
|
35
|
+
|
|
36
|
+
this.middleware.push(wrapMiddleware(fn))
|
|
37
|
+
|
|
38
|
+
return result
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function wrapRegister (register) {
|
|
43
|
+
return function registerWithTrace (path, methods, middleware, opts) {
|
|
44
|
+
const route = register.apply(this, arguments)
|
|
45
|
+
|
|
46
|
+
if (!Array.isArray(path) && route && Array.isArray(route.stack)) {
|
|
47
|
+
wrapStack(route)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return route
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function wrapRouterUse (use) {
|
|
55
|
+
return function useWithTrace () {
|
|
56
|
+
const router = use.apply(this, arguments)
|
|
57
|
+
|
|
58
|
+
router.stack.forEach(wrapStack)
|
|
59
|
+
|
|
60
|
+
return router
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function wrapStack (layer) {
|
|
65
|
+
layer.stack = layer.stack.map(middleware => {
|
|
66
|
+
if (typeof middleware !== 'function') return middleware
|
|
67
|
+
|
|
68
|
+
const original = originals.get(middleware)
|
|
69
|
+
|
|
70
|
+
middleware = original || middleware
|
|
71
|
+
|
|
72
|
+
const handler = shimmer.wrap(middleware, wrapMiddleware(middleware, layer))
|
|
73
|
+
|
|
74
|
+
originals.set(handler, middleware)
|
|
75
|
+
|
|
76
|
+
return handler
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function wrapMiddleware (fn, layer) {
|
|
81
|
+
if (typeof fn !== 'function') return fn
|
|
82
|
+
|
|
83
|
+
const name = fn.name
|
|
84
|
+
|
|
85
|
+
return function (ctx, next) {
|
|
86
|
+
if (!ctx || !enterChannel.hasSubscribers) return fn.apply(this, arguments)
|
|
87
|
+
|
|
88
|
+
const middlewareResource = new AsyncResource('bound-anonymous-fn')
|
|
89
|
+
const req = ctx.req
|
|
90
|
+
|
|
91
|
+
return middlewareResource.runInAsyncScope(() => {
|
|
92
|
+
enterChannel.publish({ req, name })
|
|
93
|
+
|
|
94
|
+
if (typeof next === 'function') {
|
|
95
|
+
arguments[1] = next
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const result = fn.apply(this, arguments)
|
|
100
|
+
|
|
101
|
+
if (result && typeof result.then === 'function') {
|
|
102
|
+
return result.then(
|
|
103
|
+
result => {
|
|
104
|
+
fulfill(ctx, layer)
|
|
105
|
+
return result
|
|
106
|
+
},
|
|
107
|
+
err => {
|
|
108
|
+
fulfill(ctx, layer, err)
|
|
109
|
+
throw err
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
} else {
|
|
113
|
+
fulfill(ctx, layer)
|
|
114
|
+
return result
|
|
115
|
+
}
|
|
116
|
+
} catch (e) {
|
|
117
|
+
fulfill(ctx, layer, e)
|
|
118
|
+
throw e
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function fulfill (ctx, layer, error) {
|
|
125
|
+
if (error) {
|
|
126
|
+
errorChannel.publish(error)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const req = ctx.req
|
|
130
|
+
const route = ctx.routePath || (layer && layer.path)
|
|
131
|
+
|
|
132
|
+
// TODO: make sure that the parent class cannot override this in `enter`
|
|
133
|
+
if (route) {
|
|
134
|
+
routeChannel.publish({ req, route })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
nextChannel.publish(ctx)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
addHook({ name: 'koa', versions: ['>=2'] }, Koa => {
|
|
141
|
+
shimmer.wrap(Koa.prototype, 'callback', wrapCallback)
|
|
142
|
+
shimmer.wrap(Koa.prototype, 'use', wrapUse)
|
|
143
|
+
|
|
144
|
+
return Koa
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
addHook({ name: '@koa/router', versions: ['>=8'] }, Router => {
|
|
148
|
+
shimmer.wrap(Router.prototype, 'register', wrapRegister)
|
|
149
|
+
shimmer.wrap(Router.prototype, 'use', wrapRouterUse)
|
|
150
|
+
|
|
151
|
+
return Router
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
addHook({ name: 'koa-router', versions: ['>=7'] }, Router => {
|
|
155
|
+
shimmer.wrap(Router.prototype, 'register', wrapRegister)
|
|
156
|
+
shimmer.wrap(Router.prototype, 'use', wrapRouterUse)
|
|
157
|
+
|
|
158
|
+
return Router
|
|
159
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { addHook, AsyncResource } = require('./helpers/instrument')
|
|
4
|
+
const shimmer = require('../../datadog-shimmer')
|
|
5
|
+
|
|
6
|
+
function wrapRequest (original) {
|
|
7
|
+
return function () {
|
|
8
|
+
const id = arguments.length - 1
|
|
9
|
+
arguments[id] = AsyncResource.bind(arguments[id])
|
|
10
|
+
return original.apply(this, arguments)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addHook({
|
|
15
|
+
name: 'limitd-client',
|
|
16
|
+
versions: ['>=2.8']
|
|
17
|
+
}, LimitdClient => {
|
|
18
|
+
shimmer.wrap(LimitdClient.prototype, '_directRequest', wrapRequest)
|
|
19
|
+
shimmer.wrap(LimitdClient.prototype, '_retriedRequest', wrapRequest)
|
|
20
|
+
return LimitdClient
|
|
21
|
+
})
|
|
@@ -10,8 +10,7 @@ const shimmer = require('../../datadog-shimmer')
|
|
|
10
10
|
addHook({ name: 'memcached', versions: ['>=2.2'] }, Memcached => {
|
|
11
11
|
const startCh = channel('apm:memcached:command:start')
|
|
12
12
|
const startWithArgsCh = channel('apm:memcached:command:start:with-args')
|
|
13
|
-
const
|
|
14
|
-
const endCh = channel('apm:memcached:command:end')
|
|
13
|
+
const finishCh = channel('apm:memcached:command:finish')
|
|
15
14
|
const errorCh = channel('apm:memcached:command:error')
|
|
16
15
|
|
|
17
16
|
shimmer.wrap(Memcached.prototype, 'command', command => function (queryCompiler, server) {
|
|
@@ -19,34 +18,37 @@ addHook({ name: 'memcached', versions: ['>=2.2'] }, Memcached => {
|
|
|
19
18
|
return command.apply(this, arguments)
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
const callbackResource = new AsyncResource('bound-anonymous-fn')
|
|
22
22
|
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
23
23
|
|
|
24
24
|
const client = this
|
|
25
25
|
|
|
26
|
-
const wrappedQueryCompiler = function () {
|
|
26
|
+
const wrappedQueryCompiler = asyncResource.bind(function () {
|
|
27
27
|
const query = queryCompiler.apply(this, arguments)
|
|
28
|
-
const callback =
|
|
28
|
+
const callback = callbackResource.bind(query.callback)
|
|
29
29
|
|
|
30
|
-
query.callback =
|
|
30
|
+
query.callback = asyncResource.bind(function (err) {
|
|
31
31
|
if (err) {
|
|
32
32
|
errorCh.publish(err)
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
finishCh.publish()
|
|
35
35
|
|
|
36
36
|
return callback.apply(this, arguments)
|
|
37
37
|
})
|
|
38
38
|
startWithArgsCh.publish({ client, server, query })
|
|
39
39
|
|
|
40
40
|
return query
|
|
41
|
-
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return asyncResource.runInAsyncScope(() => {
|
|
44
|
+
startCh.publish()
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
arguments[0] = wrappedQueryCompiler
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
const result = command.apply(this, arguments)
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return result
|
|
50
|
+
return result
|
|
51
|
+
})
|
|
50
52
|
})
|
|
51
53
|
|
|
52
54
|
return Memcached
|
|
@@ -4,12 +4,11 @@ const shimmer = require('../../datadog-shimmer')
|
|
|
4
4
|
const testStartCh = channel('ci:mocha:test:start')
|
|
5
5
|
const errorCh = channel('ci:mocha:test:error')
|
|
6
6
|
const skipCh = channel('ci:mocha:test:skip')
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const suiteEndCh = channel('ci:mocha:suite:end')
|
|
7
|
+
const testFinishCh = channel('ci:mocha:test:finish')
|
|
8
|
+
const suiteFinishCh = channel('ci:mocha:suite:finish')
|
|
10
9
|
const hookErrorCh = channel('ci:mocha:hook:error')
|
|
11
10
|
const parameterizedTestCh = channel('ci:mocha:test:parameterize')
|
|
12
|
-
const
|
|
11
|
+
const testRunFinishCh = channel('ci:mocha:run:finish')
|
|
13
12
|
|
|
14
13
|
// TODO: remove when root hooks and fixtures are implemented
|
|
15
14
|
const patched = new WeakSet()
|
|
@@ -38,59 +37,58 @@ function mochaHook (Runner) {
|
|
|
38
37
|
patched.add(Runner)
|
|
39
38
|
|
|
40
39
|
shimmer.wrap(Runner.prototype, 'runTest', runTest => function () {
|
|
41
|
-
if (!testStartCh.hasSubscribers) {
|
|
40
|
+
if (!testStartCh.hasSubscribers || isRetry(this.test)) {
|
|
42
41
|
return runTest.apply(this, arguments)
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
const asyncResource = new AsyncResource('bound-anonymous-fn')
|
|
45
|
+
return asyncResource.runInAsyncScope(() => {
|
|
46
46
|
testStartCh.publish(this.test)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.once('test end', AsyncResource.bind(() => {
|
|
50
|
-
let status
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
status
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
this.once('test end', AsyncResource.bind(() => {
|
|
49
|
+
let status
|
|
50
|
+
|
|
51
|
+
if (this.test.pending) {
|
|
52
|
+
status = 'skipped'
|
|
53
|
+
} else if (this.test.state !== 'failed' && !this.test.timedOut) {
|
|
54
|
+
status = 'pass'
|
|
55
|
+
} else {
|
|
56
|
+
status = 'fail'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
testFinishCh.publish(status)
|
|
60
|
+
}))
|
|
61
|
+
|
|
62
|
+
this.once('fail', AsyncResource.bind((test, err) => {
|
|
63
|
+
errorCh.publish(err)
|
|
64
|
+
}))
|
|
65
|
+
|
|
66
|
+
this.once('pending', AsyncResource.bind((test) => {
|
|
67
|
+
skipCh.publish(test)
|
|
68
|
+
}))
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
return runTest.apply(this, arguments)
|
|
72
|
+
} catch (err) {
|
|
73
|
+
errorCh.publish(err)
|
|
74
|
+
throw err
|
|
58
75
|
}
|
|
59
|
-
|
|
60
|
-
testAsyncEndCh.publish(status)
|
|
61
|
-
}))
|
|
62
|
-
|
|
63
|
-
this.once('fail', AsyncResource.bind((test, err) => {
|
|
64
|
-
errorCh.publish(err)
|
|
65
|
-
}))
|
|
66
|
-
|
|
67
|
-
this.once('pending', AsyncResource.bind((test) => {
|
|
68
|
-
skipCh.publish(test)
|
|
69
|
-
}))
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
return runTest.apply(this, arguments)
|
|
73
|
-
} catch (err) {
|
|
74
|
-
errorCh.publish(err)
|
|
75
|
-
throw err
|
|
76
|
-
} finally {
|
|
77
|
-
testEndCh.publish(undefined)
|
|
78
|
-
}
|
|
76
|
+
})
|
|
79
77
|
})
|
|
80
78
|
|
|
81
79
|
shimmer.wrap(Runner.prototype, 'runTests', runTests => function () {
|
|
82
|
-
if (!
|
|
80
|
+
if (!suiteFinishCh.hasSubscribers) {
|
|
83
81
|
return runTests.apply(this, arguments)
|
|
84
82
|
}
|
|
85
83
|
this.once('end', AsyncResource.bind(() => {
|
|
86
|
-
|
|
84
|
+
testRunFinishCh.publish()
|
|
87
85
|
}))
|
|
88
86
|
runTests.apply(this, arguments)
|
|
89
87
|
const suite = arguments[0]
|
|
90
88
|
// We call `getAllTestsInSuite` with the root suite so every skipped test
|
|
91
89
|
// should already have an associated test span.
|
|
92
90
|
const tests = getAllTestsInSuite(suite)
|
|
93
|
-
|
|
91
|
+
suiteFinishCh.publish(tests)
|
|
94
92
|
})
|
|
95
93
|
|
|
96
94
|
shimmer.wrap(Runner.prototype, 'fail', fail => function (hook, error) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { channel, addHook, AsyncResource } = require('../helpers/instrument')
|
|
4
|
+
const shimmer = require('../../../datadog-shimmer')
|
|
5
|
+
|
|
6
|
+
const startChannel = channel('apm:moleculer:call:start')
|
|
7
|
+
const finishChannel = channel('apm:moleculer:call:finish')
|
|
8
|
+
const errorChannel = channel('apm:moleculer:call:error')
|
|
9
|
+
|
|
10
|
+
function wrapCall (call) {
|
|
11
|
+
return function (actionName, params, opts) {
|
|
12
|
+
const callResource = new AsyncResource('bound-anonymous-fn')
|
|
13
|
+
|
|
14
|
+
opts = arguments[2] = opts || {}
|
|
15
|
+
opts.meta = opts.meta || {}
|
|
16
|
+
|
|
17
|
+
arguments.length = Math.max(3, arguments.length)
|
|
18
|
+
|
|
19
|
+
return callResource.runInAsyncScope(() => {
|
|
20
|
+
startChannel.publish({ actionName, params, opts })
|
|
21
|
+
|
|
22
|
+
const promise = call.apply(this, arguments)
|
|
23
|
+
const broker = this
|
|
24
|
+
const ctx = promise.ctx
|
|
25
|
+
|
|
26
|
+
return promise
|
|
27
|
+
.then(
|
|
28
|
+
result => {
|
|
29
|
+
finishChannel.publish({ broker, ctx })
|
|
30
|
+
return result
|
|
31
|
+
},
|
|
32
|
+
error => {
|
|
33
|
+
errorChannel.publish(error)
|
|
34
|
+
finishChannel.publish({ broker, ctx })
|
|
35
|
+
throw error
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addHook({ name: 'moleculer', versions: ['>=0.14'] }, moleculer => {
|
|
43
|
+
shimmer.wrap(moleculer.ServiceBroker.prototype, 'call', wrapCall)
|
|
44
|
+
|
|
45
|
+
return moleculer
|
|
46
|
+
})
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { channel, addHook, AsyncResource } = require('../helpers/instrument')
|
|
4
|
+
const shimmer = require('../../../datadog-shimmer')
|
|
5
|
+
|
|
6
|
+
const startChannel = channel('apm:moleculer:action:start')
|
|
7
|
+
const finishChannel = channel('apm:moleculer:action:finish')
|
|
8
|
+
const errorChannel = channel('apm:moleculer:action:error')
|
|
9
|
+
|
|
10
|
+
function wrapRegisterMiddlewares (registerMiddlewares) {
|
|
11
|
+
return function (userMiddlewares) {
|
|
12
|
+
if (this.middlewares && this.middlewares.add) {
|
|
13
|
+
this.middlewares.add(createMiddleware())
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return registerMiddlewares.apply(this, arguments)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function createMiddleware () {
|
|
21
|
+
return {
|
|
22
|
+
name: 'Datadog',
|
|
23
|
+
|
|
24
|
+
localAction (next, action) {
|
|
25
|
+
const broker = this
|
|
26
|
+
|
|
27
|
+
return function datadogMiddleware (ctx) {
|
|
28
|
+
const actionResource = new AsyncResource('bound-anonymous-fn')
|
|
29
|
+
|
|
30
|
+
return actionResource.runInAsyncScope(() => {
|
|
31
|
+
startChannel.publish({ action, ctx, broker })
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
return next(ctx).then(
|
|
35
|
+
result => {
|
|
36
|
+
finishChannel.publish()
|
|
37
|
+
return result
|
|
38
|
+
},
|
|
39
|
+
error => {
|
|
40
|
+
errorChannel.publish(error)
|
|
41
|
+
finishChannel.publish()
|
|
42
|
+
throw error
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
} catch (e) {
|
|
46
|
+
errorChannel.publish(e)
|
|
47
|
+
finishChannel.publish()
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
addHook({ name: 'moleculer', versions: ['>=0.14'] }, moleculer => {
|
|
56
|
+
shimmer.wrap(moleculer.ServiceBroker.prototype, 'registerMiddlewares', wrapRegisterMiddlewares)
|
|
57
|
+
|
|
58
|
+
return moleculer
|
|
59
|
+
})
|