Socket
Socket
Sign inDemoInstall

@google-cloud/trace-agent

Package Overview
Dependencies
Maintainers
15
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/trace-agent - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

54

build/src/plugins/plugin-http.js

@@ -21,9 +21,5 @@ /**

var isString = require('is').string;
var merge = require('lodash.merge');
var httpAgent = require('_http_agent');
var semver = require('semver');
function getSpanName(options) {
if (isString(options)) {
options = url.parse(options);
}
// c.f. _http_client.js ClientRequest constructor

@@ -54,3 +50,3 @@ return options.hostname || options.host || 'localhost';

if (!options) {
return request.apply(this, arguments);
return request(options, callback);
}

@@ -62,15 +58,19 @@ // Don't trace ourselves lest we get into infinite loops

if (isTraceAgentRequest(options, api)) {
return request.apply(this, arguments);
return request(options, callback);
}
options = isString(options) ? url.parse(options) : merge({}, options);
options.headers = options.headers || {};
var uri = extractUrl(options);
var uri;
if (isString(options)) {
// save the value of uri so we don't have to reconstruct it later
uri = extractUrl(options);
options = url.parse(options);
}
var requestLifecycleSpan = api.createChildSpan({ name: getSpanName(options) });
if (!requestLifecycleSpan) {
return request.apply(this, arguments);
return request(options, callback);
}
if (!uri) {
uri = extractUrl(options);
}
requestLifecycleSpan.addLabel(api.labels.HTTP_METHOD_LABEL_KEY, options.method);
requestLifecycleSpan.addLabel(api.labels.HTTP_URL_LABEL_KEY, uri);
options.headers[api.constants.TRACE_CONTEXT_HEADER_NAME] =
requestLifecycleSpan.getTraceContext();
var req = request.call(this, options, function (res) {

@@ -110,2 +110,3 @@ api.wrapEmitter(res);

});
req.setHeader(api.constants.TRACE_CONTEXT_HEADER_NAME, requestLifecycleSpan.getTraceContext());
api.wrapEmitter(req);

@@ -133,9 +134,22 @@ req.on('error', function (e) {

// http.get in Node 8 calls the private copy of request rather than the one
// we have patched on module.export. We need to patch get as well. Luckily,
// the request patch we have does work for get as well.
shimmer.wrap(http, 'get', function getWrap(get) {
return makeRequestTrace(get, api);
// we have patched on module.export, so patch get as well.
shimmer.wrap(http, 'get', function getWrap() {
// 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(options, callback) {
var req = http.request(options, callback);
req.end();
return req;
};
});
}
}
// https.get depends on https.request in <8.9 and >=8.9.1
function patchHttps(https, api) {

@@ -145,4 +159,8 @@ shimmer.wrap(https, 'request', function requestWrap(request) {

});
shimmer.wrap(https, 'get', function getWrap(get) {
return makeRequestTrace(get, api);
shimmer.wrap(https, 'get', function getWrap() {
return function getTrace(options, callback) {
var req = https.request(options, callback);
req.end();
return req;
};
});

@@ -149,0 +167,0 @@ }

{
"name": "@google-cloud/trace-agent",
"version": "2.4.0",
"version": "2.4.1",
"description": "Node.js Support for StackDriver Trace",

@@ -9,8 +9,10 @@ "main": "build/src/index.js",

"scripts": {
"test": "npm run script npm-check npm-compile init-test-fixtures run-unit-tests",
"non-interference": "npm run script npm-compile test-non-interference",
"system-test": "npm run script npm-compile decrypt-service-account-key run-system-tests",
"init-test-fixtures": "npm run script init-test-fixtures",
"test": "npm run script run-unit-tests",
"posttest": "npm run license-check",
"non-interference": "npm run script test-non-interference",
"system-test": "npm run script decrypt-service-account-credentials run-system-tests",
"changelog": "./bin/run-changelog.sh",
"check-install": "npm run script npm-compile check-install",
"coverage": "npm run script npm-check npm-compile init-test-fixtures run-unit-tests-with-coverage report-coverage",
"check-install": "npm run script check-install",
"coverage": "npm run script run-unit-tests-with-coverage report-coverage",
"bump": "./bin/run-bump.sh",

@@ -24,3 +26,4 @@ "check": "gts check",

"prepare": "npm run script npm-clean npm-compile",
"script": "ts-node -P ./scripts ./scripts"
"script": "ts-node -P ./scripts ./scripts",
"license-check": "jsgl --local ."
},

@@ -58,3 +61,3 @@ "files": [

"@types/ncp": "^2.0.1",
"@types/node": "^8.0.58",
"@types/node": "^9.3.0",
"@types/once": "^1.4.0",

@@ -68,3 +71,3 @@ "@types/pify": "^3.0.0",

"changelog-maker": "^2.2.2",
"coveralls": "^3.0.0",
"codecov": "^3.0.0",
"express": "^4.15.2",

@@ -76,2 +79,3 @@ "glob": "^7.0.3",

"istanbul": "^0.4.2",
"js-green-licenses": "^0.3.1",
"jshint": "^2.9.1",

@@ -100,3 +104,2 @@ "mocha": "^4.0.1",

"lodash.isequal": "^4.0.0",
"lodash.merge": "^4.6.0",
"methods": "^1.1.1",

@@ -103,0 +106,0 @@ "semver": "^5.4.1",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc