Skip to content

Commit

Permalink
Merge pull request #2 from SkyAPM/master
Browse files Browse the repository at this point in the history
Merge main library code
  • Loading branch information
a526672351 committed Mar 16, 2019
2 parents 3ccbef1 + 09bf60e commit 479f5d2
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
17 changes: 15 additions & 2 deletions modules/nodejs-agent/lib/plugins/http/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ module.exports = function(httpModule, instrumentation, contextManager) {

return httpModule;

/**
* filterParams
* @param {endpointName} endpointName
* @return {*}
*/
function filterParams(endpointName) {
if (endpointName && endpointName.indexOf("?") > -1) {
// filter params
return endpointName.split("?")[0];
}
return endpointName;
}

/**
*
* @param {original} original
Expand All @@ -53,7 +66,7 @@ module.exports = function(httpModule, instrumentation, contextManager) {
return undefined;
});

let span = contextManager.createEntrySpan(req.url, contextCarrier);
let span = contextManager.createEntrySpan(filterParams(req.url), contextCarrier);
span.component(componentDefine.Components.HTTP);
span.spanLayer(layerDefine.Layers.HTTP);
onFinished(res, function(err) {
Expand Down Expand Up @@ -81,7 +94,7 @@ module.exports = function(httpModule, instrumentation, contextManager) {
function wrapRequest(original) {
return function(options, callback) {
let contextCarrier = new ContextCarrier();
let span = contextManager.createExitSpan(options.path, options.host + ":" + options.port, contextCarrier);
let span = contextManager.createExitSpan(options.pathname, options.host + ":" + options.port, contextCarrier);
contextCarrier.pushBy(function(key, value) {
if (!options.hasOwnProperty("headers")) {
options.headers = {};
Expand Down
11 changes: 11 additions & 0 deletions modules/nodejs-agent/lib/require-module-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = hook;
function hook(modules, requireCallback) {
const enhancedModuleCache = {};
const _origRequire = Module.prototype.require;
let progressingHookFiles = {};
Module.prototype.require = function(request) {
let filename = Module._resolveFilename(request, this);
let core = filename.indexOf(path.sep) === -1;
Expand All @@ -45,7 +46,17 @@ function hook(modules, requireCallback) {
return enhancedModuleCache[filename];
}

// check current module is in progressing,
// if yes, ignore it
let progressing = progressingHookFiles[filename];
if (!progressing) {
progressingHookFiles[filename] = true;
}

let exports = _origRequire.apply(this, arguments);
if (progressing) return exports;
delete progressingHookFiles[filename];

if (core) {
moduleName = filename;
enhanceFile = filename;
Expand Down
2 changes: 1 addition & 1 deletion modules/nodejs-agent/lib/services/register-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ RegisterService.prototype.launch = function() {
os_name: os.platform(),
host_name: os.hostname(),
process_no: process.pid + "",
language: "Node.js",
language: "nodejs",
ipV4s: getAllIPv4Address(),
},
instanceUUID: function() {
Expand Down
8 changes: 4 additions & 4 deletions modules/nodejs-agent/lib/trace/trace-segment-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = ID;

const AgentConfig = require("../config");
const process = require("process");
const randomize = require("randomatic");

/**
* @param {idParts} idParts
Expand All @@ -33,10 +34,9 @@ function ID(idParts) {
this._part3 = idParts.part3;
} else {
this._part1 = AgentConfig.getInstanceId();
this._part2 = process.pid *
process.ppid ? process.ppid : (((1 + Math.random()) * 0x10000) | 0)
+ (((1 + Math.random()) * 0x10000) | 0);
this._part3 = Number(process.hrtime().join(""));
this._part2 = (process.pid * process.ppid ? process.ppid : (((1 + Math.random()) * 0x10000) | 0)
+ (((1 + Math.random()) * 0x10000) | 0)) + Number(randomize("0", 5));
this._part3 = Number(process.hrtime().join("")) + Number(randomize("0", 9));
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/nodejs-agent/lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Utils.prototype.compare = function(x, y) {
if (!Object.equals(x[p], y[p])) return false;
}

for (p in y) {
for (let p in y) {
if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) return false;
}

Expand Down
9 changes: 8 additions & 1 deletion modules/nodejs-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
"js-base64": "^2.5.1",
"object-hash": "^1.3.1",
"on-finished": "^2.3.0",
"randomatic": "^3.1.1",
"resolve": "^1.8.1",
"semver": "^5.5.1",
"uuid": "^3.2.1"
},
"devDependencies": {
"cz-conventional-changelog": "^2.1.0",
"eslint": "^4.19.1",
"eslint-config-google": "^0.9.1",
"eslint-plugin-header": "^1.2.0",
Expand All @@ -58,5 +60,10 @@
"lib/network/common/*.js",
"lib/network/language-agent-v2/*.js",
"lib/network/register/*.js"
]
],
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

0 comments on commit 479f5d2

Please sign in to comment.