Skip to content

Commit 9047e85

Browse files
committed
feat(http2): add http context info
1 parent 9df32af commit 9047e85

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

lib/instrumentation/modules/http2.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,25 @@ module.exports = function (http2, agent, { enabled }) {
159159
ins.bindEmitter(req)
160160

161161
var urlObj = parseUrl(headers[':path'])
162+
var method = headers[':method'] || 'GET'
162163
var path = urlObj.pathname
163-
span.name = headers[':method'] + ' ' + host + path
164+
var url = host + path
165+
span.name = method + ' ' + url
166+
167+
var statusCode
168+
req.on('response', (headers) => {
169+
statusCode = headers[':status']
170+
})
164171

165172
req.on('end', () => {
166173
agent.logger.debug('intercepted http2 client end event %o', { id })
174+
175+
span.setHttpContext({
176+
method,
177+
status_code: statusCode,
178+
url
179+
})
180+
167181
span.end()
168182
})
169183

test/instrumentation/modules/http2.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ isSecure.forEach(secure => {
282282
t.ok(span, 'root transaction should have span')
283283
t.equal(span.type, 'external')
284284
t.equal(span.subtype, 'http2')
285-
t.equal(span.name, `undefined http${secure ? 's' : ''}://localhost:${port}/sub`)
285+
t.equal(span.name, `GET http${secure ? 's' : ''}://localhost:${port}/sub`)
286+
t.deepEqual(span.context.http, {
287+
method: 'GET',
288+
status_code: 200,
289+
url: `http${secure ? 's' : ''}://localhost:${port}/sub`
290+
})
286291

287292
server.close()
288293
t.end()

0 commit comments

Comments
 (0)