in packages/core/lib/middleware/sampling/default_sampler.js [12:43]
rulePoller: require('./rule_poller'),
targetPoller: require('./target_poller'),
ruleCache: require('./rule_cache'),
started: false,
/**
* Makes a sample decision based on the sample request.
* @param {object} sampleRequest - Contains information for rules matching.
* @module DefaultSampler
* @function shouldSample
*/
shouldSample: function shouldSample(sampleRequest) {
try {
if (!this.started) {
this.start();
}
if (!sampleRequest.serviceType) {
sampleRequest.serviceType = SegmentUtils.origin;
}
var now = Math.floor(new Date().getTime() / 1000);
var matchedRule = this.ruleCache.getMatchedRule(sampleRequest, now);
if (matchedRule) {
logger.getLogger().debug(util.format('Rule %s is matched.', matchedRule.getName()));
return processMatchedRule(matchedRule, now);
} else {
logger.getLogger().info('No effective centralized sampling rule match. Fallback to local rules.');
return this.localSampler.shouldSample(sampleRequest);
}
} catch (err) {
logger.getLogger().error('Unhandled exception by the SDK during making sampling decisions: ' + err);
}
},