From 3229d5e66a254b6acf2c2dfdd856e489473f057a Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 00:59:11 +0400 Subject: [PATCH 01/11] Update ExpressPlugin.ts --- src/plugins/ExpressPlugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/ExpressPlugin.ts b/src/plugins/ExpressPlugin.ts index 8382f2f..0587b3b 100644 --- a/src/plugins/ExpressPlugin.ts +++ b/src/plugins/ExpressPlugin.ts @@ -27,6 +27,7 @@ import DummySpan from '../trace/span/DummySpan'; import { ignoreHttpMethodCheck } from '../config/AgentConfig'; import PluginInstaller from '../core/PluginInstaller'; import HttpPlugin from './HttpPlugin'; +import { Request } from 'express'; class ExpressPlugin implements SwPlugin { readonly module = 'express'; @@ -40,7 +41,7 @@ class ExpressPlugin implements SwPlugin { const router = installer.require('express/lib/router'); const _handle = router.handle; - router.handle = function (req: IncomingMessage, res: ServerResponse, next: any) { + router.handle = function (req: Request, res: ServerResponse, next: any) { const carrier = ContextCarrier.from((req as any).headers || {}); const operation = (req.url || '/').replace(/\?.*/g, ''); const span = ignoreHttpMethodCheck(req.method ?? 'GET') From fc1f7be27e6e6ea97c34f1faf05ebaa554a2baeb Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 01:13:28 +0400 Subject: [PATCH 02/11] Update ExpressPlugin.ts --- src/plugins/ExpressPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/ExpressPlugin.ts b/src/plugins/ExpressPlugin.ts index 0587b3b..1dbc46d 100644 --- a/src/plugins/ExpressPlugin.ts +++ b/src/plugins/ExpressPlugin.ts @@ -43,7 +43,7 @@ class ExpressPlugin implements SwPlugin { router.handle = function (req: Request, res: ServerResponse, next: any) { const carrier = ContextCarrier.from((req as any).headers || {}); - const operation = (req.url || '/').replace(/\?.*/g, ''); + const operation = 'path:' + req.path + ';url:' + req.url + ';baseUrl:' + req.baseUrl; const span = ignoreHttpMethodCheck(req.method ?? 'GET') ? DummySpan.create() : ContextManager.current.newEntrySpan(operation, carrier, [Component.HTTP_SERVER, Component.EXPRESS]); From 9699db55e7e69e6b9d2552391c01d06d29448e52 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 01:29:12 +0400 Subject: [PATCH 03/11] Update client.ts --- tests/plugins/express/client.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/plugins/express/client.ts b/tests/plugins/express/client.ts index 20e0487..ccc1bb4 100644 --- a/tests/plugins/express/client.ts +++ b/tests/plugins/express/client.ts @@ -28,7 +28,10 @@ agent.start({ const app = express(); -app.get('/express', (req, res) => { +const testRouter = express.Router(); +app.use('/test', testRouter); + +testRouter.get('/express', (req, res) => { http .request(`http://${process.env.SERVER || 'localhost:5000'}${req.url}`, (r) => { let data = ''; From 9b75c09fc2730cb8863c52c062c9a69623e0496a Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 01:45:56 +0400 Subject: [PATCH 04/11] Update test.ts --- tests/plugins/express/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/express/test.ts b/tests/plugins/express/test.ts index b046f34..04a8f65 100644 --- a/tests/plugins/express/test.ts +++ b/tests/plugins/express/test.ts @@ -39,7 +39,7 @@ describe('plugin tests', () => { }); it(__filename, async () => { - await waitForExpect(async () => expect((await axios.get('http://localhost:5001/express')).status).toBe(200)); + await waitForExpect(async () => expect((await axios.get('http://localhost:5001/test/express')).status).toBe(200)); const expectedData = await fs.readFile(path.join(rootDir, 'expected.data.yaml'), 'utf8'); From 91fffc1a461b6ae3acee42d399e6e149cecb6fd5 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 01:59:55 +0400 Subject: [PATCH 05/11] Update ExpressPlugin.ts --- src/plugins/ExpressPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/ExpressPlugin.ts b/src/plugins/ExpressPlugin.ts index 1dbc46d..9fc73af 100644 --- a/src/plugins/ExpressPlugin.ts +++ b/src/plugins/ExpressPlugin.ts @@ -43,7 +43,7 @@ class ExpressPlugin implements SwPlugin { router.handle = function (req: Request, res: ServerResponse, next: any) { const carrier = ContextCarrier.from((req as any).headers || {}); - const operation = 'path:' + req.path + ';url:' + req.url + ';baseUrl:' + req.baseUrl; + const operation = 'path:' + req.path + ';url:' + req.url + ';baseUrl:' + req.baseUrl + ";orig:" + req.originalUrl; const span = ignoreHttpMethodCheck(req.method ?? 'GET') ? DummySpan.create() : ContextManager.current.newEntrySpan(operation, carrier, [Component.HTTP_SERVER, Component.EXPRESS]); From a3a92a8997acc99439be799b894a837abcb8bc1b Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 02:03:18 +0400 Subject: [PATCH 06/11] Update ExpressPlugin.ts --- src/plugins/ExpressPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/ExpressPlugin.ts b/src/plugins/ExpressPlugin.ts index 9fc73af..914a7a5 100644 --- a/src/plugins/ExpressPlugin.ts +++ b/src/plugins/ExpressPlugin.ts @@ -43,7 +43,7 @@ class ExpressPlugin implements SwPlugin { router.handle = function (req: Request, res: ServerResponse, next: any) { const carrier = ContextCarrier.from((req as any).headers || {}); - const operation = 'path:' + req.path + ';url:' + req.url + ';baseUrl:' + req.baseUrl + ";orig:" + req.originalUrl; + const operation = 'path:' + req.path + ';url:' + req.url + ';baseUrl:' + req.baseUrl + ';orig:' + req.originalUrl; const span = ignoreHttpMethodCheck(req.method ?? 'GET') ? DummySpan.create() : ContextManager.current.newEntrySpan(operation, carrier, [Component.HTTP_SERVER, Component.EXPRESS]); From cc9eca7972fa3e3a09a4ed460bb2108387db94e6 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 02:19:51 +0400 Subject: [PATCH 07/11] Update ExpressPlugin.ts --- src/plugins/ExpressPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/ExpressPlugin.ts b/src/plugins/ExpressPlugin.ts index 914a7a5..3e55e72 100644 --- a/src/plugins/ExpressPlugin.ts +++ b/src/plugins/ExpressPlugin.ts @@ -43,7 +43,7 @@ class ExpressPlugin implements SwPlugin { router.handle = function (req: Request, res: ServerResponse, next: any) { const carrier = ContextCarrier.from((req as any).headers || {}); - const operation = 'path:' + req.path + ';url:' + req.url + ';baseUrl:' + req.baseUrl + ';orig:' + req.originalUrl; + const operation = (req.originalUrl || req.url || '/').replace(/\?.*/g, ''); const span = ignoreHttpMethodCheck(req.method ?? 'GET') ? DummySpan.create() : ContextManager.current.newEntrySpan(operation, carrier, [Component.HTTP_SERVER, Component.EXPRESS]); From 118791786f313c7aa416ce2427d8b2f37e21e5a3 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 02:47:04 +0400 Subject: [PATCH 08/11] Update expected.data.yaml --- tests/plugins/express/expected.data.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/express/expected.data.yaml b/tests/plugins/express/expected.data.yaml index 6924540..cb6d9b7 100644 --- a/tests/plugins/express/expected.data.yaml +++ b/tests/plugins/express/expected.data.yaml @@ -77,7 +77,7 @@ segmentItems: segments: - segmentId: not null spans: - - operationName: /express + - operationName: /test/express operationId: 0 parentSpanId: -1 spanId: 0 From 458d6b862c5ad9554655db9b2a216c4f05d35360 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 03:02:13 +0400 Subject: [PATCH 09/11] Update expected.data.yaml --- tests/plugins/express/expected.data.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/express/expected.data.yaml b/tests/plugins/express/expected.data.yaml index cb6d9b7..b53cbf9 100644 --- a/tests/plugins/express/expected.data.yaml +++ b/tests/plugins/express/expected.data.yaml @@ -86,7 +86,7 @@ segmentItems: - key: coldStart value: 'true' - key: http.url - value: http://localhost:5001/express + value: http://localhost:5001/test/express - key: http.method value: GET - key: http.status.code From d71f3699a605b4e8d30bf5e3d853258e58d31ab3 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 09:17:52 +0400 Subject: [PATCH 10/11] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed07dcf..65fc3f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.5.2 +- Correct entry span url in endponts using Express middleware/router objects + # 0.5.1 - Fix `sw` header is not validated and might cause service unavailable. (#90) From 1ac865c5d2dd001f0e004205178c35b45c179f09 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Fri, 14 Oct 2022 09:19:36 +0400 Subject: [PATCH 11/11] Update CHANGELOG.md --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65fc3f9..ed07dcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,3 @@ -# 0.5.2 -- Correct entry span url in endponts using Express middleware/router objects - # 0.5.1 - Fix `sw` header is not validated and might cause service unavailable. (#90)