@google-cloud/trace-agent
Advanced tools
Comparing version 2.10.0 to 2.10.1
@@ -33,2 +33,10 @@ "use strict"; | ||
} | ||
/** | ||
* Returns whether the Expect header is on the given options object. | ||
* @param options Options for http.request. | ||
*/ | ||
function hasExpectHeader(options) { | ||
return !!(options.headers && | ||
options.headers.Expect); | ||
} | ||
function extractUrl(options, fallbackProtocol) { | ||
@@ -92,2 +100,19 @@ let path; | ||
span.addLabel(api.labels.HTTP_URL_LABEL_KEY, uri); | ||
// If outgoing request headers contain the "Expect" header, the returned | ||
// ClientRequest will throw an error if any new headers are added. For this | ||
// reason, only in this scenario, we opt to clone the options object to | ||
// inject the trace context header instead of using ClientRequest#setHeader. | ||
// (We don't do this generally because cloning the options object is an | ||
// expensive operation.) | ||
let traceHeaderPreinjected = false; | ||
if (hasExpectHeader(options)) { | ||
traceHeaderPreinjected = true; | ||
// "Clone" the options object -- but don't deep-clone anything except for | ||
// headers. | ||
options = Object.assign({}, options); | ||
options.headers = Object.assign({}, options.headers); | ||
// Inject the trace context header. | ||
options.headers[api.constants.TRACE_CONTEXT_HEADER_NAME] = | ||
span.getTraceContext(); | ||
} | ||
const req = request(options, (res) => { | ||
@@ -126,3 +151,2 @@ api.wrapEmitter(res); | ||
api.wrapEmitter(req); | ||
req.setHeader(api.constants.TRACE_CONTEXT_HEADER_NAME, span.getTraceContext()); | ||
req.on('error', error => { | ||
@@ -133,2 +157,7 @@ span.addLabel(api.labels.ERROR_DETAILS_NAME, error.name); | ||
}); | ||
// Inject the trace context header, but only if it wasn't already injected | ||
// earlier. | ||
if (!traceHeaderPreinjected) { | ||
req.setHeader(api.constants.TRACE_CONTEXT_HEADER_NAME, span.getTraceContext()); | ||
} | ||
return req; | ||
@@ -135,0 +164,0 @@ }; |
{ | ||
"name": "@google-cloud/trace-agent", | ||
"version": "2.10.0", | ||
"version": "2.10.1", | ||
"description": "Node.js Support for StackDriver Trace", | ||
@@ -81,3 +81,3 @@ "main": "build/src/index.js", | ||
"nock": "^9.1.3", | ||
"nyc": "^11.4.1", | ||
"nyc": "^12.0.2", | ||
"once": "^1.4.0", | ||
@@ -84,0 +84,0 @@ "pify": "^3.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
530348
4931