New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

oneapm

Package Overview
Dependencies
Maintainers
3
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oneapm - npm Package Compare versions

Comparing version 2.1.11 to 3.0.0

lib/collector/api.js

63

lib/agent.js

@@ -11,3 +11,3 @@ 'use strict';

var NAMES = require(path.join(__dirname, 'metrics', 'names.js'));
var CollectorAPI = require('oneapm-server');
var CollectorAPI = require(path.join(__dirname, 'collector', 'api.js'));
var ErrorTracer = require(path.join(__dirname, 'error.js'));

@@ -92,2 +92,3 @@ var QueryTracer = require(path.join(__dirname, 'db', 'tracer.js'));

this.metrics = new Metrics(this.config.apdex_t, this.mapper, this.metricNameNormalizer);
this.topo = new Metrics(this.config.apdex_t, this.mapper, this.metricNameNormalizer);

@@ -110,2 +111,3 @@ // transaction naming

this.traces = new TraceAggregator(this.config);
this.trace_guid = null;

@@ -309,14 +311,18 @@ // insights events

agent._sendErrors(function cb__sendErrors(error) {
agent._sendTopo(function cb__sendTopo(error) {
if (error) return callback(error);
agent._sendTrace(function cb__sendTrace(error) {
agent._sendErrors(function cb__sendErrors(error) {
if (error) return callback(error);
agent._sendEvents(function cb_sendEvents(error) {
agent._sendTrace(function cb__sendTrace(error) {
if (error) return callback(error);
agent._sendQueries(callback);
agent._sendEvents(function cb_sendEvents(error) {
if (error) return callback(error);
agent._sendQueries(callback);
});
});
});

@@ -496,5 +502,5 @@ });

this.metrics.getOrCreateMetric(NAMES.ERRORS.OTHER).incrementCallCount(this.errors.errorOtherCount);
this.topo.getOrCreateMetric('Errors/TopoUser/' + this.config.application_id).incrementCallCount(this.errors.errorCount);
}
// merge internal metrics and send them

@@ -540,2 +546,37 @@ if (this.config.debug.supportability) {

Agent.prototype._sendTopo = function _sendTopo(callback) {
var agent = this;
if (this.collector.isConnected()) {
// wait to check until all the standard stuff has been added
if (this.topo.toJSON().length < 1) {
logger.debug("No topo to send.");
return process.nextTick(callback);
}
var topo = this.topo
, beginSeconds = topo.started * FROM_MILLIS
, endSeconds = Date.now() * FROM_MILLIS
, payload = [this.config.run_id, beginSeconds, endSeconds, topo]
;
// reset now to avoid losing topo that come in after delivery starts
this.topo = new Metrics(
this.config.apdex_t,
this.mapper,
this.metricNameNormalizer
);
this.collector.topoData(payload, function cb_topoData(error, rules) {
if (error) agent.topo.merge(topo);
callback(error);
});
}
else {
process.nextTick(function cb_nextTick() {
callback(new Error("not connected to OneAPM (topo will be held)"));
});
}
};
/**

@@ -596,2 +637,3 @@ * The error tracer doesn't know about the agent, and the connection

var agent = this;
this.trace_guid = null;
if (this.config.collect_traces && this.config.transaction_tracer.enabled) {

@@ -606,2 +648,3 @@ if (!this.collector.isConnected()) {

if (error || !encoded) return callback(error);
agent.trace_guid = trace.transaction.guid;

@@ -611,3 +654,2 @@ var payload = [agent.config.run_id, [encoded]];

if (!error) agent.traces.reset(trace);
callback(error);

@@ -654,6 +696,6 @@ });

Agent.prototype._sendEvents = function _sendEvents(callback) {
if (this.config.transaction_events.enabled) {
if (this.config.transaction_events.enabled && this.trace_guid) {
var agent = this;
var events = agent.events;
var sample = events.toArray();
var sample = events.toArray(this.trace_guid);
var run_id = agent.config.run_id;

@@ -779,2 +821,3 @@

this.errors.onTransactionFinished(transaction, this.metrics);
this.topo.merge(transaction.topo);
this.traces.add(transaction);

@@ -781,0 +824,0 @@

42

lib/db/parsed-statement.js
'use strict';
var path = require('path')
, DB = require(path.join(__dirname, '..', 'metrics', 'names')).DB
;
var path = require('path');
var DB = require(path.join(__dirname, '..', 'metrics', 'names')).DB;
var generateGuid = require('../util/generate-guid.js');

@@ -32,3 +32,3 @@ /**

this.getMetricName = function() {
return this.db.STATEMENT + ':' + this.host + ':' + this.port + '/' + this.model + '/' + this.operation;
return this.db.STATEMENT + ':' + this.host + ':' + this.port;
}

@@ -38,18 +38,24 @@ }

ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope) {
var duration = segment.getDurationInMillis()
, exclusive = segment.getExclusiveDurationInMillis()
, transaction = segment.trace.transaction
, type = transaction.isWeb() ? DB.WEB : DB.OTHER
, operation = DB.STATEMENT + '/' + this.type + ':' + this.host + ':' + this.port + '/' + this.operation
, model = DB.STATEMENT + '/' + this.type + ':' + this.host + ':' + this.port +
'/'+ this.database +'/' + this.model + '/' + this.operation
, all = DB.STATEMENT + '/' + this.type + ':' + this.host + ':' + this.port + '/all'
;
var duration = segment.getDurationInMillis();
var exclusive = segment.getExclusiveDurationInMillis();
var transaction = segment.trace.transaction;
var agent = transaction.agent;
var dbName = this.type + ':' + this.host + ':' + this.port;
var name = DB.STATEMENT + '/' + dbName;
var all = name + '/all';
if (scope) transaction.measure(model, scope, duration, exclusive);
transaction.measure(model, null, duration, exclusive);
if(scope) {
transaction.measure(name, scope, duration, exclusive);
agent.addEventFromTransaction(
transaction,
generateGuid(),
transaction.guid,
[-1, 'Database/statement/' + dbName, scope],
duration / 1000,
duration / 1000
);
}
transaction.measure(all, null, duration, exclusive);
transaction.topo.measureMilliseconds('TopoDatabase/' + dbName, null, duration, exclusive);
transaction.measure(operation, null, duration, exclusive);
transaction.measure(all, null, duration, exclusive);
if( this.raw ) { // If the ParsedStatment contains a raw SQL statement, add it to the agent's QueryTracer

@@ -56,0 +62,0 @@ transaction.agent.queries.addQuery( segment, this.type.toLowerCase(), this.raw, this.trace );

@@ -120,2 +120,3 @@ 'use strict'

this.trace = slowQuery
this.guids = [slowQuery.guid]
this.aggregate(slowQuery)

@@ -128,2 +129,5 @@ }

this.recordValueInMillis(slowQuery.duration * 1000)
if(this.guids.indexOf(slowQuery.guid) < 0) {
this.guids.push(slowQuery.guid)
}
if (this.trace && this.trace.duration >= slowQuery.duration) return

@@ -161,3 +165,4 @@ this.trace = slowQuery

sample.max,
data
data,
sample.guids
])

@@ -180,2 +185,3 @@ })

this.duration = segment.getDurationInMillis()
this.guid = segment.trace.transaction.guid;
}

@@ -182,0 +188,0 @@

@@ -7,2 +7,3 @@ 'use strict';

var NAMES = require(path.join(__dirname, 'metrics', 'names'));
var codec = require('./util/codec')

@@ -30,3 +31,3 @@ /*

*/
function createError(transaction, exception, customParameters, config) {
function createError(transaction, exception, customParameters, config, callback) {
// the collector throws this out, so don't bother setting it

@@ -134,3 +135,7 @@ var timestamp = Date.now() / 1000

return [timestamp, name, message, type, params];
codec.encode(params, function cb_encode(err, encoded) {
if (err) return callback(err, null, null);
var json = [timestamp, name, message, type, encoded, transaction.guid, transaction.trip_guid];
return callback(json);
});
}

@@ -225,13 +230,15 @@

var self = this;
if (this.errors.length < MAX_ERRORS) {
var error = createError(transaction, exception, customParameters, this.config);
logger.debug({ error: error }, "Error to be sent to collector:");
this.errors.push(error);
if (transaction) { // Finish the transaction to make sure when error occurs, the transaction can also be recorded.
transaction.end();
createError(transaction, exception, customParameters, this.config, function cb_createError(error) {
logger.debug({ error: error }, "Error to be sent to collector:");
self.errors.push(error);
transaction.end();
return;
});
}
}
else {
logger.debug("Already have %d errors to send to collector, not keeping.",
MAX_ERRORS);
logger.debug("Already have %d errors to send to collector, not keeping.", MAX_ERRORS);
}

@@ -238,0 +245,0 @@ };

@@ -21,6 +21,12 @@ var assert = require('assert')

Events.prototype.toArray = function () {
Events.prototype.toArray = function (guid) {
var mapper = this.mapper
var es = [];
this.list.forEach(function(event) {
if(event.guid === guid || event.tripGuid === guid) {
es.push(event);
}
});
// list of: [{name, events}, ...]
var groupByName = groupEventsByName(this.list)
var groupByName = groupEventsByName(es)
var array = groupByName.map(function (group) {

@@ -27,0 +33,0 @@ return [

@@ -13,2 +13,3 @@ 'use strict';

var generateGuid = require('../../util/generate-guid.js')
var urltils = require('../../util/urltils.js')

@@ -57,19 +58,28 @@ /*

if (request.headers[AE_REQ_HEADER_ID] && request.headers[AE_REQ_HEADER_TRANSACTION]) {
var ae_id = request.headers[AE_REQ_HEADER_ID];
var ae_transaction = request.headers[AE_REQ_HEADER_TRANSACTION];
var dura = transaction.timer.getDurationInMillis();
var tierId = agent.config.application_id;
var internalName = 'TopoInternal/' + tierId + '/';
var userName = 'TopoUser/' + tierId;
if (ae_id && ae_transaction) {
try {
var ae_id = request.headers[AE_REQ_HEADER_ID];
var ae_transaction = request.headers[AE_REQ_HEADER_TRANSACTION];
ae_transaction = JSON.parse(ae_transaction);
var txjson = urltils.decode(ae_transaction, agent.config.license_key);
logger.debug("Processing cross data : " + txjson);
ae_transaction = JSON.parse(txjson);
transaction.referer_guid = ae_transaction[0];
transaction.force_trace = ae_transaction[1];
transaction.trip_guid = ae_transaction[2];
// NOT USED:
// ae_transaction[3] -> WHAT?
// ae_transaction[4] -> ip_addr
// ae_transaction[5] -> WHAT?
var rid = ae_transaction[3];
internalName += rid;
var appData = JSON.stringify([agent.config.cross_process_id, transaction.name, 0, dura / 1000, null, transaction.guid])
response.setHeader(AE_RES_HEADER_APP_DATA, urltils.encode(appData, agent.config.license_key));
}
catch (err) {
transaction.hasEndUser = true;
// ignore JSON parsing error
console.error(err)
}
} else {
transaction.hasEndUser = true;
}

@@ -112,2 +122,9 @@

function instrumentedFinish() {
var duration = transaction.timer.getDurationInMillis();
if (ae_id && ae_transaction) {
transaction.topo.measureMilliseconds(internalName, null, duration, duration);
}
if (transaction.hasEndUser) {
transaction.topo.measureMilliseconds(userName, null, duration, duration);
}
/* Stats how many bytes sended and received

@@ -143,7 +160,2 @@ */

return agent.tracer.segmentProxy(function wrappedRequest(options, callback) {
if (callback && typeof callback === 'function') {
// want to bind callack into request regardless of current state
callback = agent.tracer.callbackProxy(callback);
}
// don't pollute metrics and calls with NR connections

@@ -155,3 +167,8 @@ var internalOnly = options && options[NR_CONNECTION_PROP];

var start = Date.now();
var host = options.hostname || options.host || DEFAULT_HOST;
var port = options.port || options.defaultPort || DEFAULT_PORT;
// inject headers for analytic events
var cb1 = callback;
var name = "External/HTTP/" + host + ":" + port;
if (transaction && !internalOnly) {

@@ -164,22 +181,44 @@ if (typeof options === 'string') {

// WARNING: maybe cross_process_id is not ready
var invokeRelationId = "HTTP:" + host + ":" + port + "/" + agent.config.application_id;
if (agent.config.cross_process_id) {
options.headers[AE_REQ_HEADER_ID] = agent.config.cross_process_id;
options.headers[AE_REQ_HEADER_TRANSACTION] = JSON.stringify([
var txjson = JSON.stringify([
transaction.temp_guid,
transaction.force_trace,
transaction.trip_guid,
null, // WHAT?
invokeRelationId,
myip().join(','),
null // WHAT?
])
null
]);
logger.debug("Sending cross data : " + txjson);
options.headers[AE_REQ_HEADER_TRANSACTION] = urltils.encode(txjson, agent.config.license_key);
}
var cb = function cb(args) {
var dura = Date.now() - start;
//TODO: GenerateExternalEvent
var exName = 'TopoExternal/' + agent.config.application_id + '/HTTP:' + host + ':' + port;
transaction.topo.measureMilliseconds(exName, null, dura, dura);
if(args && args.headers && args.headers[AE_RES_HEADER_APP_DATA]) {
//INFO: whatever
} else {
var scope = transaction.name;
if(scope) transaction.measure(name, scope, dura, dura);
transaction.measure(name + "/all", null, dura, dura);
}
if (callback && typeof callback === 'function') {
callback.call(args);
}
}
cb1 = agent.tracer.callbackProxy(cb);
} else {
if (callback && typeof callback === 'function') {
cb1 = agent.tracer.callbackProxy(callback);
}
}
var requested = request.call(this, options, callback);
var requested = request.call(this, options, cb1);
if (transaction && !internalOnly) {
// hostname & port logic pulled directly from node's 0.10 lib/http.js
var hostname = options.hostname || options.host || DEFAULT_HOST;
var port = options.port || options.defaultPort || DEFAULT_PORT;
instrumentOutbound(agent, requested, hostname, port);
instrumentOutbound(agent, requested, host, port);
}

@@ -186,0 +225,0 @@

@@ -6,3 +6,3 @@ 'use strict';

var stackUtil = require('../util/stack')
var recordMemcache = require('../metrics/recorders/memcached.js')
var record = require('../metrics/recorders/nosql.js')
var MEMCACHE = require('../metrics/names.js').MEMCACHE

@@ -60,4 +60,4 @@

var metacall = arguments[0]();
var name = MEMCACHE.OPERATION + ':' + host + ':' + port + '/' + (metacall.type || 'Unknown');
var segment = tracer.addSegment(name, recordMemcache);
var name = MEMCACHE.OPERATION + ':' + host + ':' + port;
var segment = tracer.addSegment(name, record(MEMCACHE.PREFIX, host, port));
segment.host = host;

@@ -64,0 +64,0 @@ segment.port = port;

"use strict";
var path = require('path');
var ParsedStatement = require('../db/nosql-statement');
var record = require('../metrics/recorders/nosql.js')
var shimmer = require('../shimmer');

@@ -88,7 +88,4 @@ var stackUtil = require('../util/stack.js');

function addMongoStatement(tracer, collection, operation, host, port) {
var statement = new ParsedStatement(MONGODB.PREFIX, operation, collection, host, port);
var recorder = statement.recordMetrics.bind(statement);
var name = MONGODB.STATEMENT + ':' + host + ':' + port + '/' + collection + '/' + operation;
return tracer.addSegment(name, recorder);
var name = MONGODB.STATEMENT + ':' + host + ':' + port;
return tracer.addSegment(name, record(MONGODB.PREFIX, host, port));
}

@@ -95,0 +92,0 @@

@@ -7,3 +7,3 @@ 'use strict';

var logger = require('oneapm-logger').child({ component: 'node-cassandra-cql' })
var record = require('../metrics/recorders/node-cassandra-cql.js')
var record = require('../metrics/recorders/nosql.js')
var CASSANDRA = require('../metrics/names').CASSANDRA

@@ -41,4 +41,4 @@

var args = tracer.slice(arguments)
var name = CASSANDRA.OPERATION + ':' + host + ':' + port + '/' + operation;
var segment = tracer.addSegment(name, record);
var name = CASSANDRA.OPERATION + ':' + host + ':' + port;
var segment = tracer.addSegment(name, record(CASSANDRA.PREFIX, host, port));
var position = args.length - 1

@@ -45,0 +45,0 @@ var last = args[position];

@@ -7,3 +7,3 @@ 'use strict';

var logger = require('oneapm-logger').child({ component: 'redis' })
var recordRedis = require('../metrics/recorders/redis.js')
var record = require('../metrics/recorders/nosql.js')
var REDIS = require('../metrics/names').REDIS

@@ -34,4 +34,4 @@

var args = tracer.slice(arguments);
var name = REDIS.OPERATION + ':' + host + ':' + port + '/' + (args[0] || 'unknown');
var segment = tracer.addSegment(name, recordRedis);
var name = REDIS.OPERATION + ':' + host + ':' + port;
var segment = tracer.addSegment(name, record(REDIS.PREFIX, host, port));
var position = args.length - 1;

@@ -137,4 +137,4 @@ var keys = args[1];

var transaction = tracer.getTransaction();
var name = REDIS.OPERATION + ':' + host + ':' + port + '/' + (command.toLowerCase() || 'unknown');
var segment = tracer.addSegment(name, recordRedis);
var name = REDIS.OPERATION + ':' + host + ':' + port;
var segment = tracer.addSegment(name, record(REDIS.PREFIX, host, port));
segment.port = port;

@@ -141,0 +141,0 @@ segment.host = host;

'use strict';
var path = require('path')
var EXTERNAL = require('../../metrics/names').EXTERNAL
var generateGuid = require('../../util/generate-guid.js')
function recordExternal(name, agent) {

@@ -8,0 +4,0 @@ return function cls_recordExternal(segment, scope) {

@@ -38,4 +38,5 @@ 'use strict';

transaction._setApdex(NAMES.APDEX, duration, null);
transaction._setTopoApdex(duration, null);
}
module.exports = recordWeb;

@@ -40,4 +40,5 @@ 'use strict';

transaction._setApdex(NAMES.APDEX, duration, null);
transaction._setTopoApdex(duration, null);
}
module.exports = recordThrift;

@@ -32,2 +32,8 @@ 'use strict';

);
this.topo = new Metrics(
agent.config.apdex_t,
agent.mapper,
agent.metricNameNormalizer
);
this.hasEndUser = false;

@@ -187,2 +193,12 @@ this.id = id++;

Transaction.prototype._setTopoApdex = function _setTopoApdex(duration, keyApdexInMillis) {
if (this.hasEndUser) {
var apdexStats = this.topo.getOrCreateApdexMetric('Apdex/' + this.agent.config.application_id, null, keyApdexInMillis);
if (urltils.isError(this.agent.config, this.statusCode)) {
apdexStats.incrementFrustrating();
} else {
apdexStats.recordValueInMillis(duration);
}
}
}

@@ -189,0 +205,0 @@ /**

@@ -166,3 +166,3 @@ 'use strict';

trace.transaction.name,
trace.transaction.url,
trace.transaction.fullUrl,
encoded,

@@ -173,3 +173,3 @@ trace.transaction.guid,

trace.transaction.trip_guid,
null, //TODO: XraySessionId, should be 0 in server 4.3
0,
0

@@ -176,0 +176,0 @@ ];

@@ -11,29 +11,10 @@ 'use strict';

function getExternalPath(url) {
var path = urltils.scrub(url);
if(!path && path.length === 0) {
return '//';
} else if(path.length === 1) {
if(path[0] === '/') {
return path + '/';
}
return '/' + path + '/';
}
var segs = path.split('/').filter(function(s){return s && s.length !== 0;});
if(segs.length >= 2) {
return '/' + segs[0] + '/' + segs[1] + '/';
}
return '/' + segs[0] + '/';
}
function instrumentOutbound(agent, request, hostname, port) {
if (!hostname) throw new Error("hostname must be defined!");
function instrumentOutbound(agent, request, host, port) {
if (!host) throw new Error("hostname must be defined!");
if (!port || port < 1) throw new Error("port must be defined!");
// this is silly
if (port && port !== DEFAULT_PORT) hostname = hostname + ':' + port;
var hostname = host + ':' + port;
var transaction = agent.tracer.getTransaction();
var path = getExternalPath(request.path);
var name = NAMES.EXTERNAL.PREFIX + 'HTTP/' + hostname + path;
var name = NAMES.EXTERNAL.PREFIX + 'HTTP/' + hostname;
var segment = agent.tracer.addSegment(name, recordExternal(name, agent));

@@ -40,0 +21,0 @@

@@ -0,6 +1,35 @@

function uuid(len, radix) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var uuid = [], i;
radix = radix || chars.length;
if (len) {
// Compact form
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
} else {
// rfc4122, version 4 form
var r;
// rfc4122 requires these characters
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random()*16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
function generateGuid() {
// 16 chars: [a-z0-9]
return Math.random().toString(36).substr(2, 16);
return uuid(16, 36);
}
module.exports = exports = generateGuid;

@@ -114,3 +114,34 @@ 'use strict';

}
},
encode: function encode(val, licenseKey) {
if (licenseKey) {
var bytes = Buffer(val, 'utf8');
var key = Buffer(licenseKey);
var len = Math.min(13, key.length);
for (var i = 0; i < bytes.length; i++) {
bytes[i] = bytes[i] ^ key[i % len];
}
return bytes.toString('base64');
}
return val;
},
decode: function decode(val, licenseKey) {
try {
if (licenseKey) {
var bytes = Buffer(val, 'base64');
var key = Buffer(licenseKey);
var len = Math.min(13, key.length);
for (var i = 0; i < bytes.length; i++) {
bytes[i] = bytes[i] ^ key[i % len];
}
return Buffer(bytes, 'utf8').toString();
}
}
catch(ex) {
console.log(ex)
}
return val;
}
};
{
"name": "oneapm",
"version": "2.1.11",
"version": "3.0.0",
"author": "OneAPM Node.js agent team <nodejs@oneapm.com>",

@@ -35,3 +35,2 @@ "description": "OneAPM agent",

"oneapm-logger": "^2.0.0",
"oneapm-server": "^1.0.0",
"oneapm-util": "^1.0.0",

@@ -41,3 +40,4 @@ "pidusage-fork": "^0.1.1",

"semver": "^4.3.6",
"sqlstring": "^2.2.0"
"sqlstring": "^2.2.0",
"request": "^2.79.0"
},

@@ -44,0 +44,0 @@ "files": [

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