dd-trace 2.12.0 → 2.12.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/package.json +1 -1
- package/packages/datadog-instrumentations/src/connect.js +4 -4
- package/packages/datadog-instrumentations/src/fastify.js +12 -25
- package/packages/datadog-instrumentations/src/koa.js +4 -4
- package/packages/datadog-instrumentations/src/router.js +4 -4
- package/packages/datadog-plugin-router/src/index.js +13 -8
- package/packages/dd-trace/src/plugins/util/web.js +4 -1
package/package.json
CHANGED
|
@@ -78,12 +78,12 @@ function wrapLayerHandle (layer) {
|
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
80
|
return original.apply(this, arguments)
|
|
81
|
-
} catch (
|
|
82
|
-
errorChannel.publish(
|
|
81
|
+
} catch (error) {
|
|
82
|
+
errorChannel.publish({ req, error })
|
|
83
83
|
nextChannel.publish({ req })
|
|
84
84
|
exitChannel.publish({ req })
|
|
85
85
|
|
|
86
|
-
throw
|
|
86
|
+
throw error
|
|
87
87
|
}
|
|
88
88
|
})
|
|
89
89
|
})
|
|
@@ -92,7 +92,7 @@ function wrapLayerHandle (layer) {
|
|
|
92
92
|
function wrapNext (req, next) {
|
|
93
93
|
return function (error) {
|
|
94
94
|
if (error) {
|
|
95
|
-
errorChannel.publish(error)
|
|
95
|
+
errorChannel.publish({ req, error })
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
nextChannel.publish({ req })
|
|
@@ -6,7 +6,6 @@ const { addHook, channel, AsyncResource } = require('./helpers/instrument')
|
|
|
6
6
|
const errorChannel = channel('apm:fastify:middleware:error')
|
|
7
7
|
const handleChannel = channel('apm:fastify:request:handle')
|
|
8
8
|
|
|
9
|
-
const requestResources = new WeakMap()
|
|
10
9
|
const parsingResources = new WeakMap()
|
|
11
10
|
|
|
12
11
|
function wrapFastify (fastify, hasParsingEvents) {
|
|
@@ -42,16 +41,13 @@ function wrapAddHook (addHook) {
|
|
|
42
41
|
|
|
43
42
|
arguments[arguments.length - 1] = shimmer.wrap(fn, function (request, reply, done) {
|
|
44
43
|
const req = getReq(request)
|
|
45
|
-
const requestResource = requestResources.get(req)
|
|
46
|
-
|
|
47
|
-
if (!requestResource) return fn.apply(this, arguments)
|
|
48
44
|
|
|
49
45
|
try {
|
|
50
46
|
if (typeof done === 'function') {
|
|
51
47
|
done = arguments[arguments.length - 1]
|
|
52
48
|
|
|
53
49
|
arguments[arguments.length - 1] = function (err) {
|
|
54
|
-
publishError(err,
|
|
50
|
+
publishError(err, req)
|
|
55
51
|
|
|
56
52
|
if (name === 'onRequest' || name === 'preParsing') {
|
|
57
53
|
const parsingResource = new AsyncResource('bound-anonymous-fn')
|
|
@@ -71,13 +67,13 @@ function wrapAddHook (addHook) {
|
|
|
71
67
|
const promise = fn.apply(this, arguments)
|
|
72
68
|
|
|
73
69
|
if (promise && typeof promise.catch === 'function') {
|
|
74
|
-
return promise.catch(err => publishError(err,
|
|
70
|
+
return promise.catch(err => publishError(err, req))
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
return promise
|
|
78
74
|
}
|
|
79
75
|
} catch (e) {
|
|
80
|
-
throw publishError(e,
|
|
76
|
+
throw publishError(e, req)
|
|
81
77
|
}
|
|
82
78
|
})
|
|
83
79
|
|
|
@@ -90,14 +86,10 @@ function onRequest (request, reply, done) {
|
|
|
90
86
|
|
|
91
87
|
const req = getReq(request)
|
|
92
88
|
const res = getRes(reply)
|
|
93
|
-
const requestResource = new AsyncResource('bound-anonymous-fn')
|
|
94
89
|
|
|
95
|
-
|
|
90
|
+
handleChannel.publish({ req, res })
|
|
96
91
|
|
|
97
|
-
return
|
|
98
|
-
handleChannel.publish({ req, res })
|
|
99
|
-
return done()
|
|
100
|
-
})
|
|
92
|
+
return done()
|
|
101
93
|
}
|
|
102
94
|
|
|
103
95
|
function preHandler (request, reply, done) {
|
|
@@ -105,9 +97,8 @@ function preHandler (request, reply, done) {
|
|
|
105
97
|
if (!reply || typeof reply.send !== 'function') return done()
|
|
106
98
|
|
|
107
99
|
const req = getReq(request)
|
|
108
|
-
const requestResource = requestResources.get(req)
|
|
109
100
|
|
|
110
|
-
reply.send = wrapSend(reply.send,
|
|
101
|
+
reply.send = wrapSend(reply.send, req)
|
|
111
102
|
|
|
112
103
|
done()
|
|
113
104
|
}
|
|
@@ -133,12 +124,10 @@ function preParsing (request, reply, payload, done) {
|
|
|
133
124
|
parsingResource.runInAsyncScope(() => done())
|
|
134
125
|
}
|
|
135
126
|
|
|
136
|
-
function wrapSend (send,
|
|
137
|
-
return function sendWithTrace (
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
errorChannel.publish(payload)
|
|
141
|
-
})
|
|
127
|
+
function wrapSend (send, req) {
|
|
128
|
+
return function sendWithTrace (error) {
|
|
129
|
+
if (error instanceof Error) {
|
|
130
|
+
errorChannel.publish({ req, error })
|
|
142
131
|
}
|
|
143
132
|
|
|
144
133
|
return send.apply(this, arguments)
|
|
@@ -153,11 +142,9 @@ function getRes (reply) {
|
|
|
153
142
|
return reply && (reply.raw || reply.res || reply)
|
|
154
143
|
}
|
|
155
144
|
|
|
156
|
-
function publishError (error,
|
|
145
|
+
function publishError (error, req) {
|
|
157
146
|
if (error) {
|
|
158
|
-
|
|
159
|
-
errorChannel.publish(error)
|
|
160
|
-
})
|
|
147
|
+
errorChannel.publish({ error, req })
|
|
161
148
|
}
|
|
162
149
|
|
|
163
150
|
return error
|
|
@@ -126,13 +126,13 @@ function wrapMiddleware (fn, layer) {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
function fulfill (ctx, error) {
|
|
129
|
-
if (error) {
|
|
130
|
-
errorChannel.publish(error)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
129
|
const req = ctx.req
|
|
134
130
|
const route = ctx.routePath
|
|
135
131
|
|
|
132
|
+
if (error) {
|
|
133
|
+
errorChannel.publish({ req, error })
|
|
134
|
+
}
|
|
135
|
+
|
|
136
136
|
// TODO: make sure that the parent class cannot override this in `enter`
|
|
137
137
|
if (route) {
|
|
138
138
|
routeChannel.publish({ req, route })
|
|
@@ -49,12 +49,12 @@ function createWrapRouterMethod (name) {
|
|
|
49
49
|
|
|
50
50
|
try {
|
|
51
51
|
return original.apply(this, arguments)
|
|
52
|
-
} catch (
|
|
53
|
-
errorChannel.publish(
|
|
52
|
+
} catch (error) {
|
|
53
|
+
errorChannel.publish({ req, error })
|
|
54
54
|
nextChannel.publish({ req })
|
|
55
55
|
exitChannel.publish({ req })
|
|
56
56
|
|
|
57
|
-
throw
|
|
57
|
+
throw error
|
|
58
58
|
}
|
|
59
59
|
})
|
|
60
60
|
})
|
|
@@ -91,7 +91,7 @@ function createWrapRouterMethod (name) {
|
|
|
91
91
|
function wrapNext (req, next) {
|
|
92
92
|
return function (error) {
|
|
93
93
|
if (error) {
|
|
94
|
-
errorChannel.publish(error)
|
|
94
|
+
errorChannel.publish({ req, error })
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
nextChannel.publish({ req })
|
|
@@ -16,7 +16,10 @@ class RouterPlugin extends WebPlugin {
|
|
|
16
16
|
this._contexts = new WeakMap()
|
|
17
17
|
|
|
18
18
|
this.addSub(`apm:${this.constructor.name}:middleware:enter`, ({ req, name, route }) => {
|
|
19
|
-
const childOf = this._getActive(req)
|
|
19
|
+
const childOf = this._getActive(req) || this._getStoreSpan()
|
|
20
|
+
|
|
21
|
+
if (!childOf) return
|
|
22
|
+
|
|
20
23
|
const span = this._getMiddlewareSpan(name, childOf)
|
|
21
24
|
const context = this._createContext(req, route, childOf)
|
|
22
25
|
|
|
@@ -46,14 +49,16 @@ class RouterPlugin extends WebPlugin {
|
|
|
46
49
|
context.middleware.pop().finish()
|
|
47
50
|
})
|
|
48
51
|
|
|
49
|
-
this.addSub(`apm:${this.constructor.name}:middleware:error`,
|
|
50
|
-
|
|
52
|
+
this.addSub(`apm:${this.constructor.name}:middleware:error`, ({ req, error }) => {
|
|
53
|
+
web.addError(req, error)
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
if (!this.config.middleware) return
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
const span = this._getActive(req)
|
|
58
|
+
|
|
59
|
+
if (!span) return
|
|
60
|
+
|
|
61
|
+
span.setTag('error', error)
|
|
57
62
|
})
|
|
58
63
|
|
|
59
64
|
this.addSub(`apm:http:server:request:finish`, ({ req }) => {
|
|
@@ -72,7 +77,7 @@ class RouterPlugin extends WebPlugin {
|
|
|
72
77
|
_getActive (req) {
|
|
73
78
|
const context = this._contexts.get(req)
|
|
74
79
|
|
|
75
|
-
if (!context) return
|
|
80
|
+
if (!context) return
|
|
76
81
|
if (context.middleware.length === 0) return context.span
|
|
77
82
|
|
|
78
83
|
return context.middleware[context.middleware.length - 1]
|