You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/01/27 15:57:41 UTC
[skywalking-nodejs] branch master updated: Added http protocol to
plugins (#28)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-nodejs.git
The following commit(s) were added to refs/heads/master by this push:
new 01794e3 Added http protocol to plugins (#28)
01794e3 is described below
commit 01794e3612cd4493b63c5cd431c6516d56772204
Author: Tomasz Pytel <to...@gmail.com>
AuthorDate: Wed Jan 27 12:57:32 2021 -0300
Added http protocol to plugins (#28)
* Update expected.data.yaml
Co-authored-by: Zhenxu Ke <ke...@apache.org>
---
src/plugins/ExpressPlugin.ts | 3 ++-
src/plugins/HttpPlugin.ts | 8 ++++----
tests/plugins/axios/expected.data.yaml | 4 ++--
tests/plugins/express/expected.data.yaml | 8 ++++----
tests/plugins/http/expected.data.yaml | 4 ++--
5 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/plugins/ExpressPlugin.ts b/src/plugins/ExpressPlugin.ts
index cd94ca3..5a550e3 100644
--- a/src/plugins/ExpressPlugin.ts
+++ b/src/plugins/ExpressPlugin.ts
@@ -76,7 +76,6 @@ class ExpressPlugin implements SwPlugin {
|| (req.connection.remoteFamily === 'IPv6'
? `[${req.connection.remoteAddress}]:${req.connection.remotePort}`
: `${req.connection.remoteAddress}:${req.connection.remotePort}`);
- span.tag(Tag.httpURL((req.headers.host || '') + req.url));
span.tag(Tag.httpMethod(req.method));
const ret = _handle.call(this, req, res, (err: Error) => {
@@ -95,6 +94,8 @@ class ExpressPlugin implements SwPlugin {
} catch (e) {
stopIfNotStopped(e);
throw e;
+ } finally { // req.protocol is only possibly available after call to _handle()
+ span.tag(Tag.httpURL(((req as any).protocol ? (req as any).protocol + '://' : '') + (req.headers.host || '') + req.url));
}
};
}
diff --git a/src/plugins/HttpPlugin.ts b/src/plugins/HttpPlugin.ts
index 8c1e090..e324b00 100644
--- a/src/plugins/HttpPlugin.ts
+++ b/src/plugins/HttpPlugin.ts
@@ -38,9 +38,9 @@ class HttpPlugin implements SwPlugin {
const https = require('https');
this.interceptClientRequest(http);
- this.interceptServerRequest(http);
+ this.interceptServerRequest(http, 'http');
this.interceptClientRequest(https);
- this.interceptServerRequest(https);
+ this.interceptServerRequest(https, 'https');
}
private interceptClientRequest(module: any) {
@@ -120,7 +120,7 @@ class HttpPlugin implements SwPlugin {
};
}
- private interceptServerRequest(module: any) {
+ private interceptServerRequest(module: any, protocol: string) {
/// TODO? full event protocol support not currently implemented (prependListener(), removeListener(), etc...)
const _addListener = module.Server.prototype.addListener;
@@ -159,7 +159,7 @@ class HttpPlugin implements SwPlugin {
|| (req.connection.remoteFamily === 'IPv6'
? `[${req.connection.remoteAddress}]:${req.connection.remotePort}`
: `${req.connection.remoteAddress}:${req.connection.remotePort}`);
- span.tag(Tag.httpURL((req.headers.host || '') + req.url));
+ span.tag(Tag.httpURL(protocol + '://' + (req.headers.host || '') + req.url));
span.tag(Tag.httpMethod(req.method));
let ret = handler.call(this, req, res, ...reqArgs);
diff --git a/tests/plugins/axios/expected.data.yaml b/tests/plugins/axios/expected.data.yaml
index f5c66d3..ddb2fc9 100644
--- a/tests/plugins/axios/expected.data.yaml
+++ b/tests/plugins/axios/expected.data.yaml
@@ -54,7 +54,7 @@ segmentItems:
skipAnalysis: false
tags:
- key: http.url
- value: server:5000/axios
+ value: http://server:5000/axios
- key: http.method
value: GET
- key: http.status.code
@@ -102,7 +102,7 @@ segmentItems:
spanLayer: Http
tags:
- key: http.url
- value: localhost:5001/axios
+ value: http://localhost:5001/axios
- key: http.method
value: GET
- key: http.status.code
diff --git a/tests/plugins/express/expected.data.yaml b/tests/plugins/express/expected.data.yaml
index 23ba437..240a481 100644
--- a/tests/plugins/express/expected.data.yaml
+++ b/tests/plugins/express/expected.data.yaml
@@ -47,10 +47,10 @@ segmentItems:
spanId: 0
spanLayer: Http
tags:
- - key: http.url
- value: server:5000/express
- key: http.method
value: GET
+ - key: http.url
+ value: http://server:5000/express
- key: http.status.code
value: '200'
- key: http.status.msg
@@ -101,10 +101,10 @@ segmentItems:
spanId: 0
spanLayer: Http
tags:
- - key: http.url
- value: localhost:5001/express
- key: http.method
value: GET
+ - key: http.url
+ value: http://localhost:5001/express
- key: http.status.code
value: '200'
- key: http.status.msg
diff --git a/tests/plugins/http/expected.data.yaml b/tests/plugins/http/expected.data.yaml
index b7e241d..486b6ce 100644
--- a/tests/plugins/http/expected.data.yaml
+++ b/tests/plugins/http/expected.data.yaml
@@ -34,7 +34,7 @@ segmentItems:
skipAnalysis: false
tags:
- key: http.url
- value: server:5000/test
+ value: http://server:5000/test
- key: http.method
value: GET
- key: http.status.code
@@ -86,7 +86,7 @@ segmentItems:
skipAnalysis: false
tags:
- key: http.url
- value: localhost:5001/test
+ value: http://localhost:5001/test
- key: http.method
value: GET
- key: http.status.code