@google-cloud/trace-agent
Advanced tools
Comparing version 5.1.1 to 5.1.2
@@ -17,3 +17,2 @@ "use strict"; | ||
exports.cls = exports.TraceCLS = exports.TraceCLSMechanism = void 0; | ||
const semver = require("semver"); | ||
const async_hooks_1 = require("./cls/async-hooks"); | ||
@@ -25,3 +24,2 @@ const async_listener_1 = require("./cls/async-listener"); | ||
const util_1 = require("./util"); | ||
const asyncHooksAvailable = semver.satisfies(process.version, '>=8'); | ||
/** | ||
@@ -66,5 +64,2 @@ * An enumeration of the possible mechanisms for supporting context propagation | ||
case TraceCLSMechanism.ASYNC_HOOKS: | ||
if (!asyncHooksAvailable) { | ||
throw new Error(`CLS mechanism [${config.mechanism}] is not compatible with Node <8.`); | ||
} | ||
this.CLSClass = async_hooks_1.AsyncHooksCLS; | ||
@@ -71,0 +66,0 @@ this.rootSpanStackOffset = 4; |
@@ -20,3 +20,2 @@ "use strict"; | ||
// do I/O, or continuation-local-storage will not work. | ||
const semver = require("semver"); | ||
const config_1 = require("./config"); | ||
@@ -30,2 +29,9 @@ const extend = require("extend"); | ||
const cls_1 = require("./cls"); | ||
if (process && process.version) { | ||
const minNodeVersion = 10; | ||
const major = Number(process.version.match(/v(\d+)/)[1]); | ||
if (major < minNodeVersion) { | ||
throw Error(`trace-agent supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/googleapis/cloud-trace-nodejs#supported-nodejs-versions`); | ||
} | ||
} | ||
let traceAgent; | ||
@@ -74,7 +80,4 @@ /** | ||
// what it should be. | ||
const ahAvailable = semver.satisfies(process.version, '>=8'); | ||
if (clsMechanism === 'auto') { | ||
return ahAvailable | ||
? cls_1.TraceCLSMechanism.ASYNC_HOOKS | ||
: cls_1.TraceCLSMechanism.ASYNC_LISTENER; | ||
return cls_1.TraceCLSMechanism.ASYNC_HOOKS; | ||
} | ||
@@ -81,0 +84,0 @@ return clsMechanism; |
@@ -15,3 +15,2 @@ "use strict"; | ||
// limitations under the License. | ||
const semver = require("semver"); | ||
const shimmer = require("shimmer"); | ||
@@ -24,8 +23,3 @@ const url_1 = require("url"); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const isURL = semver.satisfies(process.version, '>=7') | ||
? // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(value) => value instanceof url_1.URL | ||
: // eslint-disable-next-line | ||
(value) => false; | ||
// tslint:enable:no-any | ||
const isURL = (value) => value instanceof url_1.URL; | ||
function getSpanName(options) { | ||
@@ -232,24 +226,22 @@ // c.f. _http_client.js ClientRequest constructor | ||
}); | ||
if (semver.satisfies(process.version, '>=8.0.0')) { | ||
// http.get in Node 8 calls the private copy of request rather than the one | ||
// we have patched on module.export, so patch get as well. | ||
shimmer.wrap(http, 'get', () => { | ||
// Re-implement http.get. This needs to be done (instead of using | ||
// makeRequestTrace to patch it) because we need to set the trace | ||
// context header before the returned ClientRequest is ended. | ||
// The Node.js docs state that the only differences between request and | ||
// get are that (1) get defaults to the HTTP GET method and (2) the | ||
// returned request object is ended immediately. | ||
// The former is already true (at least in supported Node versions up to | ||
// v9), so we simply follow the latter. | ||
// Ref: | ||
// https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback | ||
return function getTrace() { | ||
// eslint-disable-next-line prefer-rest-params | ||
const req = http.request.apply(this, arguments); | ||
req.end(); | ||
return req; | ||
}; | ||
}); | ||
} | ||
// http.get in Node 8 calls the private copy of request rather than the one | ||
// we have patched on module.export, so patch get as well. | ||
shimmer.wrap(http, 'get', () => { | ||
// Re-implement http.get. This needs to be done (instead of using | ||
// makeRequestTrace to patch it) because we need to set the trace | ||
// context header before the returned ClientRequest is ended. | ||
// The Node.js docs state that the only differences between request and | ||
// get are that (1) get defaults to the HTTP GET method and (2) the | ||
// returned request object is ended immediately. | ||
// The former is already true (at least in supported Node versions up to | ||
// v9), so we simply follow the latter. | ||
// Ref: | ||
// https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback | ||
return function getTrace() { | ||
// eslint-disable-next-line prefer-rest-params | ||
const req = http.request.apply(this, arguments); | ||
req.end(); | ||
return req; | ||
}; | ||
}); | ||
} | ||
@@ -273,5 +265,3 @@ // https.get depends on Node http internals in 8.9.0 and 9+ instead of the | ||
shimmer.unwrap(http, 'request'); | ||
if (semver.satisfies(process.version, '>=8.0.0')) { | ||
shimmer.unwrap(http, 'get'); | ||
} | ||
shimmer.unwrap(http, 'get'); | ||
} | ||
@@ -278,0 +268,0 @@ function unpatchHttps(https) { |
# Changelog | ||
### [5.1.2](https://www.github.com/googleapis/cloud-trace-nodejs/compare/v5.1.1...v5.1.2) (2021-02-04) | ||
### Performance Improvements | ||
* **deps:** avoid semver where possible ([#1309](https://www.github.com/googleapis/cloud-trace-nodejs/issues/1309)) ([4c05cae](https://www.github.com/googleapis/cloud-trace-nodejs/commit/4c05caeb3910657b3eb413da61aac03cb321bd7b)) | ||
### [5.1.1](https://www.github.com/googleapis/cloud-trace-nodejs/compare/v5.1.0...v5.1.1) (2020-09-12) | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "@google-cloud/trace-agent", | ||
"version": "5.1.1", | ||
"version": "5.1.2", | ||
"description": "Node.js Support for StackDriver Trace", | ||
@@ -76,11 +76,11 @@ "main": "build/src/index.js", | ||
"@types/uuid": "^8.0.0", | ||
"axios": "^0.20.0", | ||
"axios": "^0.21.0", | ||
"c8": "^7.0.0", | ||
"cpy": "^8.0.0", | ||
"express": "^4.15.2", | ||
"gaxios": "^3.0.2", | ||
"gaxios": "^4.0.0", | ||
"glob": "^7.0.3", | ||
"grpc": "1.24.3", | ||
"gts": "^2.0.0", | ||
"js-green-licenses": "^2.0.0", | ||
"grpc": "1.24.4", | ||
"gts": "^3.0.0", | ||
"js-green-licenses": "^3.0.0", | ||
"linkinator": "^2.0.0", | ||
@@ -87,0 +87,0 @@ "mocha": "^8.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
332193
6942