-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong http.request.url reported when host header is set #401
Comments
Hi @danilobuerger, That's a fair calllout, we do parse the host header for the name of the subsegment here, and for the |
@willarmiros Thanks for your response. Sadly I don't have the time to submit a proper PR at this time. However, here is my patch file if somebody is willing to submit it as a PR or runs into the same issue: diff --git a/node_modules/aws-xray-sdk-core/lib/patchers/http_p.js b/node_modules/aws-xray-sdk-core/lib/patchers/http_p.js
index 7743ecd..6ea5fc7 100644
--- a/node_modules/aws-xray-sdk-core/lib/patchers/http_p.js
+++ b/node_modules/aws-xray-sdk-core/lib/patchers/http_p.js
@@ -135,7 +135,7 @@ function enableCapture(module, downstreamXRayEnabled, subsegmentCallback) {
} else {
var madeItToDownstream = (e.code !== 'ECONNREFUSED');
- subsegment.addRemoteRequestData(this, null, madeItToDownstream && downstreamXRayEnabled);
+ subsegment.addRemoteRequestData(this, options, null, madeItToDownstream && downstreamXRayEnabled);
subsegment.close(e);
}
@@ -164,7 +164,7 @@ function enableCapture(module, downstreamXRayEnabled, subsegmentCallback) {
if (cause)
subsegment[cause] = true;
- subsegment.addRemoteRequestData(res.req, res, !!downstreamXRayEnabled);
+ subsegment.addRemoteRequestData(res.req, options, res, !!downstreamXRayEnabled);
subsegment.close();
});
diff --git a/node_modules/aws-xray-sdk-core/lib/segments/attributes/remote_request_data.js b/node_modules/aws-xray-sdk-core/lib/segments/attributes/remote_request_data.js
index 6986794..bdb987b 100644
--- a/node_modules/aws-xray-sdk-core/lib/segments/attributes/remote_request_data.js
+++ b/node_modules/aws-xray-sdk-core/lib/segments/attributes/remote_request_data.js
@@ -12,9 +12,9 @@ function RemoteRequestData(req, res, downstreamXRayEnabled) {
this.init(req, res, downstreamXRayEnabled);
}
-RemoteRequestData.prototype.init = function init(req, res, downstreamXRayEnabled) {
+RemoteRequestData.prototype.init = function init(req, options, res, downstreamXRayEnabled) {
this.request = {
- url: (req.agent && req.agent.protocol) ? (req.agent.protocol + '//' + req.getHeader('host') + stripQueryStringFromPath(req.path)) : '',
+ url: (req.agent && req.agent.protocol) ? (req.agent.protocol + '//' + options.host + stripQueryStringFromPath(req.path)) : '',
method: req.method || '',
};
diff --git a/node_modules/aws-xray-sdk-core/lib/segments/attributes/subsegment.js b/node_modules/aws-xray-sdk-core/lib/segments/attributes/subsegment.js
index 5e717ef..5923cfe 100644
--- a/node_modules/aws-xray-sdk-core/lib/segments/attributes/subsegment.js
+++ b/node_modules/aws-xray-sdk-core/lib/segments/attributes/subsegment.js
@@ -217,8 +217,8 @@ Subsegment.prototype.addError = function addError(err, remote) {
* @param {boolean} downstreamXRayEnabled - when true, adds a "traced": true hint to generated subsegments such that the AWS X-Ray service expects a corresponding segment from the downstream service.
*/
-Subsegment.prototype.addRemoteRequestData = function addRemoteRequestData(req, res, downstreamXRayEnabled) {
- this.http = new RemoteRequestData(req, res, downstreamXRayEnabled);
+Subsegment.prototype.addRemoteRequestData = function addRemoteRequestData(req, options, res, downstreamXRayEnabled) {
+ this.http = new RemoteRequestData(req, options, res, downstreamXRayEnabled);
if ('traced' in this.http.request) {
this.traced = this.http.request.traced;
delete this.http.request.traced; |
@danilobuerger thanks for adding this! We can't reorder the parameters like that to avoid a breaking change, but adding the |
Sometimes it is useful to connect to a url and have a different host header:
https://tools.ietf.org/html/rfc7230#section-5.4
When this is the case, the reported
http.request.url
contains the host header instead of the host from the connecting url.For example:
would be reported as
http://host.example/path
instead ofhttp://url.example/path
.The text was updated successfully, but these errors were encountered: