From 71114f935de8ab278013dc4f7488a5c47d9d7ecf Mon Sep 17 00:00:00 2001 From: Roch Devost Date: Wed, 18 Sep 2019 18:00:44 -0400 Subject: [PATCH] fix web framework plugins error with http2 requests (#688) --- packages/dd-trace/src/plugins/util/web.js | 2 +- .../dd-trace/test/plugins/util/web.spec.js | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/dd-trace/src/plugins/util/web.js b/packages/dd-trace/src/plugins/util/web.js index 06344c3db3f..3966f2098ec 100644 --- a/packages/dd-trace/src/plugins/util/web.js +++ b/packages/dd-trace/src/plugins/util/web.js @@ -129,7 +129,7 @@ const web = { patch (req) { if (req._datadog) return - if (req.stream) { + if (req.stream && req.stream._datadog) { req._datadog = req.stream._datadog return } diff --git a/packages/dd-trace/test/plugins/util/web.spec.js b/packages/dd-trace/test/plugins/util/web.spec.js index e4d384a7c38..ef12125426f 100644 --- a/packages/dd-trace/test/plugins/util/web.spec.js +++ b/packages/dd-trace/test/plugins/util/web.spec.js @@ -247,6 +247,31 @@ describe('plugins/util/web', () => { }) }) }) + + it('should support HTTP2 compatibility API', () => { + req.stream = {} + req.method = 'GET' + req.headers = { + ':scheme': 'https', + ':authority': 'localhost', + ':method': 'GET', + ':path': '/user/123' + } + res.statusCode = '200' + + web.instrument(tracer, config, req, res, 'test.request', span => { + const tags = span.context()._tags + + res.end() + + expect(tags).to.include({ + [SPAN_TYPE]: WEB, + [HTTP_URL]: 'https://localhost/user/123', + [HTTP_METHOD]: 'GET', + [SPAN_KIND]: SERVER + }) + }) + }) }) describe('on request end', () => {