diff --git a/packages/artillery-plugin-publish-metrics/lib/mixpanel.js b/packages/artillery-plugin-publish-metrics/lib/mixpanel.js index f50113f82a..b0e91f3c37 100644 --- a/packages/artillery-plugin-publish-metrics/lib/mixpanel.js +++ b/packages/artillery-plugin-publish-metrics/lib/mixpanel.js @@ -16,7 +16,7 @@ class MixPanelReporter { ); } if (!this.mixPanelOpts.projectToken) { - console.error(`mix panel project token not specified`); + console.error('mix panel project token not specified'); } this.mixpanel = Mixpanel.init(this.mixPanelOpts.projectToken); this.sendToMixPanel(config, events, script); @@ -25,17 +25,45 @@ class MixPanelReporter { sendToMixPanel(config, events, script) { events.on('stats', (stats) => { - const report = stats.report(); + const report = this.formatProperties(stats); let env = script._environment ? script._environment.toUpperCase() : script.config.target; - this.mixpanel.track(`${env}-${script.scenarios[0].name}`, { - ...report - }); + this.mixpanel.track( + `${env}-${script.scenarios[0]['name'] || 'Artillery.io'}`, + report + ); }); } + formatProperties(stats) { + const properties = {}; + + for (const [name, value] of Object.entries(stats)) { + if (name === 'histograms') { + continue; + } + if (typeof value !== 'object') { + properties[name] = value; + } + } + + for (const [name, value] of Object.entries( + { ...stats.counters, ...stats.rates } || {} + )) { + properties[name] = value; + } + + for (const [name, values] of Object.entries(stats.summaries || {})) { + for (const [aggregation, value] of Object.entries(values)) { + properties[`${name}.${aggregation}`] = value; + } + } + + return properties; + } + cleanup(done) { debug('cleaning up'); return done();