-
Notifications
You must be signed in to change notification settings - Fork 296
/
index.js
40 lines (29 loc) · 854 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict'
const HttpClientPlugin = require('../../datadog-plugin-http/src/client')
class FetchPlugin extends HttpClientPlugin {
static get id () { return 'fetch' }
static get prefix () { return 'tracing:apm:fetch:request' }
bindStart (ctx) {
const req = ctx.req
const options = new URL(req.url)
const headers = options.headers = Object.fromEntries(req.headers.entries())
options.method = req.method
ctx.args = { options }
const store = super.bindStart(ctx)
for (const name in headers) {
if (!req.headers.has(name)) {
req.headers.set(name, headers[name])
}
}
return store
}
error (ctx) {
if (ctx.error.name === 'AbortError') return
return super.error(ctx)
}
asyncEnd (ctx) {
ctx.res = ctx.result
return this.finish(ctx)
}
}
module.exports = FetchPlugin