in packages/core/lib/middleware/sampling/rule_cache.js [40:72]
loadRules: function loadRules(rules) {
// Record the old rules for later merging.
var oldRules = {};
this.rules.forEach(function(rule) {
oldRules[rule.getName()] = rule;
});
// Update the rules in the cache.
this.rules = rules;
// Transfer state information to refreshed rules.
this.rules.forEach(function(rule) {
var oldRule = oldRules[rule.getName()];
if (oldRule) {
rule.merge(oldRule);
}
});
// The cache should maintain the order of the rules based on
// priority. If priority is the same we sort name by alphabet
// as rule name is unique.
this.rules.sort(function(a, b) {
var v = a.getPriority() - b.getPriority();
if (v !== 0) {
return v;
}
if (a.getName() > b.getName()) {
return 1;
} else {
return -1;
}
});
},