diff --git a/CHANGELOG.md b/CHANGELOG.md index 00434f64..2e27e236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,16 @@ # Changelog +### v2.30.4 + +* Use `Object.create(null)` rather than object initializer notation when initializing objects to store metric data. + +### v2.30.3 + +* Ensure error strings are encapsulated in an `Error`-like object for transmission to the APM server. + ### v2.30.2 -Fix [#144](https://github.com/meteorhacks/kadira/issues/144). +* Fix [#144](https://github.com/meteorhacks/kadira/issues/144). ### v2.30.0 diff --git a/lib/client/models/error.js b/lib/client/models/error.js index 1038caab..0cb22e04 100644 --- a/lib/client/models/error.js +++ b/lib/client/models/error.js @@ -10,7 +10,7 @@ ErrorModel = function(options) { // errorsSentCount will be reseted at the start of the interval self.errorsSentCount = 0; - self.errorsSent = {}; + self.errorsSent = Object.create(null); self.intervalTimeoutHandler = setInterval(function() { self.errorsSentCount = 0; self._flushErrors(); @@ -73,7 +73,7 @@ ErrorModel.prototype._flushErrors = function() { if(errors.length > 0) { Kadira.send({errors: errors}, '/errors'); } - self.errorsSent = {}; + self.errorsSent = Object.create(null); }; ErrorModel.prototype.isErrorExists = function(name) { diff --git a/lib/hijack/db.js b/lib/hijack/db.js index 4960fbf9..042a99df 100644 --- a/lib/hijack/db.js +++ b/lib/hijack/db.js @@ -99,12 +99,12 @@ hijackDBOps = function hijackDBOps() { var originalFunc = cursorProto[type]; cursorProto[type] = function() { var cursorDescription = this._cursorDescription; - var payload = { + var payload = Object.assign(Object.create(null), { coll: cursorDescription.collectionName, selector: JSON.stringify(cursorDescription.selector), func: type, cursor: true - }; + }); if(cursorDescription.options) { var cursorOptions = _.pick(cursorDescription.options, ['fields', 'sort', 'limit']); diff --git a/lib/hijack/wrap_subscription.js b/lib/hijack/wrap_subscription.js index 1c47bac2..47f423d7 100644 --- a/lib/hijack/wrap_subscription.js +++ b/lib/hijack/wrap_subscription.js @@ -43,6 +43,10 @@ wrapSubscription = function(subscriptionProto) { var originalError = subscriptionProto.error; subscriptionProto.error = function(err) { + if (typeof err === 'string') { + err = { message: err }; + } + var kadiraInfo = Kadira._getInfo(); if(kadiraInfo && this._subscriptionId == kadiraInfo.trace.id) { @@ -91,4 +95,4 @@ wrapSubscription = function(subscriptionProto) { return res; }; }); -}; \ No newline at end of file +}; diff --git a/lib/models/methods.js b/lib/models/methods.js index 87c097b1..cc383264 100644 --- a/lib/models/methods.js +++ b/lib/models/methods.js @@ -3,8 +3,8 @@ var METHOD_METRICS_FIELDS = ['wait', 'db', 'http', 'email', 'async', 'compute', MethodsModel = function (metricsThreshold) { var self = this; - this.methodMetricsByMinute = {}; - this.errorMap = {}; + this.methodMetricsByMinute = Object.create(null); + this.errorMap = Object.create(null); this._metricsThreshold = _.extend({ "wait": 100, @@ -14,10 +14,10 @@ MethodsModel = function (metricsThreshold) { "async": 100, "compute": 100, "total": 200 - }, metricsThreshold || {}); + }, metricsThreshold || Object.create(null)); //store max time elapsed methods for each method, event(metrics-field) - this.maxEventTimesForMethods = {}; + this.maxEventTimesForMethods = Object.create(null); this.tracerStore = new TracerStore({ interval: 1000 * 60, //process traces every minute @@ -35,7 +35,7 @@ MethodsModel.prototype._getMetrics = function(timestamp, method) { if(!this.methodMetricsByMinute[dateId]) { this.methodMetricsByMinute[dateId] = { - methods: {} + methods: Object.create(null), }; } @@ -124,7 +124,7 @@ MethodsModel.prototype.buildPayload = function(buildDetailedInfo) { //handling metrics var methodMetricsByMinute = this.methodMetricsByMinute; - this.methodMetricsByMinute = {}; + this.methodMetricsByMinute = Object.create(null); //create final paylod for methodMetrics for(var key in methodMetricsByMinute) { diff --git a/lib/models/pubsub.js b/lib/models/pubsub.js index 7b9e2fce..239cbb92 100644 --- a/lib/models/pubsub.js +++ b/lib/models/pubsub.js @@ -1,8 +1,8 @@ var logger = Npm.require('debug')('kadira:pubsub'); PubsubModel = function() { - this.metricsByMinute = {}; - this.subscriptions = {}; + this.metricsByMinute = Object.create(null); + this.subscriptions = Object.create(null); this.tracerStore = new TracerStore({ interval: 1000 * 60, //process traces every minute @@ -111,7 +111,7 @@ PubsubModel.prototype._getMetrics = function(timestamp, publication) { this.metricsByMinute[dateId] = { // startTime needs to be convert to serverTime before sending to the server startTime: timestamp, - pubs: {} + pubs: Object.create(null) }; } @@ -155,12 +155,12 @@ PubsubModel.prototype._getPublicationName = function(name) { PubsubModel.prototype._getSubscriptionInfo = function() { var self = this; - var activeSubs = {}; - var activeDocs = {}; - var totalDocsSent = {}; - var totalDataSent = {}; - var totalObservers = {}; - var cachedObservers = {}; + var activeSubs = Object.create(null); + var activeDocs = Object.create(null); + var totalDocsSent = Object.create(null); + var totalDataSent = Object.create(null); + var totalObservers = Object.create(null); + var cachedObservers = Object.create(null); for(var sessionId in Meteor.default_server.sessions) { var session = Meteor.default_server.sessions[sessionId]; @@ -168,7 +168,7 @@ PubsubModel.prototype._getSubscriptionInfo = function() { _.each(session._universalSubs, countSubData); } - var avgObserverReuse = {}; + var avgObserverReuse = Object.create(null); _.each(totalObservers, function(value, publication) { avgObserverReuse[publication] = cachedObservers[publication] / totalObservers[publication]; }); @@ -209,7 +209,7 @@ PubsubModel.prototype._getSubscriptionInfo = function() { PubsubModel.prototype.buildPayload = function(buildDetailInfo) { var metricsByMinute = this.metricsByMinute; - this.metricsByMinute = {}; + this.metricsByMinute = Object.create(null); var payload = { pubMetrics: [] diff --git a/lib/tracer/tracer_store.js b/lib/tracer/tracer_store.js index 8e3dc813..9575d060 100644 --- a/lib/tracer/tracer_store.js +++ b/lib/tracer/tracer_store.js @@ -8,16 +8,16 @@ TracerStore = function TracerStore(options) { this.archiveEvery = options.archiveEvery || this.maxTotalPoints / 6; //store max total on the past 30 minutes (or past 30 items) - this.maxTotals = {}; + this.maxTotals = Object.create(null); //store the max trace of the current interval - this.currentMaxTrace = {}; + this.currentMaxTrace = Object.create(null); //archive for the traces this.traceArchive = []; - this.processedCnt = {}; + this.processedCnt = Object.create(null); //group errors by messages between an interval - this.errorMap = {}; + this.errorMap = Object.create(null); }; TracerStore.prototype.addTrace = function(trace) { @@ -106,7 +106,7 @@ TracerStore.prototype.processTraces = function() { }); //reset the errorMap - self.errorMap = {}; + self.errorMap = Object.create(null); }; TracerStore.prototype._isTraceOutlier = function(kind, trace) { diff --git a/package.js b/package.js index 2eeb1ed7..582cda0f 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ "summary": "Performance Monitoring for Meteor", - "version": "2.30.2", + "version": "2.30.4", "git": "https://github.com/meteorhacks/kadira.git", "name": "meteorhacks:kadira" });