From 96918a4de2720319eb35fd2cb3ecf0221ab537ba Mon Sep 17 00:00:00 2001 From: Ben Marini Date: Tue, 8 Sep 2015 14:03:08 -0700 Subject: [PATCH] Add globalPrefix before performing sourceRegex match --- lib/librato.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/librato.js b/lib/librato.js index ad5955a..edd08f3 100644 --- a/lib/librato.js +++ b/lib/librato.js @@ -253,13 +253,15 @@ var flush_stats = function librato_flush(ts, metrics) countStat = typeof countStat !== 'undefined' ? countStat : true; var match; - if (sourceRegex && (match = measure.name.match(sourceRegex)) && match[1]) { - // Use first capturing group as source name + var measureName = globalPrefix + measure.name; + + // Use first capturing group as source name + if (sourceRegex && (match = measureName.match(sourceRegex)) && match[1]) { measure.source = sanitize_name(match[1]); // Remove entire matching string from the measure name & add global prefix. - measure.name = globalPrefix + sanitize_name(measure.name.slice(0, match.index) + measure.name.slice(match.index + match[0].length)); + measure.name = sanitize_name(measureName.slice(0, match.index) + measureName.slice(match.index + match[0].length)); } else { - measure.name = globalPrefix + sanitize_name(measure.name); + measure.name = sanitize_name(measureName); } if (brokenMetrics[measure.name]) {