shouldSample: function shouldSample()

in packages/core/lib/middleware/sampling/local_sampler.js [23:53]


  shouldSample: function shouldSample(sampleRequest) {
    var host = sampleRequest.host;
    var httpMethod = sampleRequest.httpMethod;
    var urlPath = sampleRequest.urlPath;

    var formatted = '{ http_method: ' + httpMethod + ', host: ' + host + ', url_path: ' + urlPath + ' }';
    var matched;

    this.rules.some(function(rule) {
      // Any null parameters provided will be considered an implicit match.
      if (rule.default || (host == null || (Utils.wildcardMatch(rule.host, host))
        && (httpMethod == null || Utils.wildcardMatch(rule.http_method, httpMethod))
        && (urlPath == null || Utils.wildcardMatch(rule.url_path, urlPath)))) {

        matched = rule.reservoir;

        logger.getLogger().debug('Local sampling rule match found for ' + formatted + '. Matched ' + (rule.default ?
          'default' : '{ http_method: ' + rule.http_method + ', host: ' + rule.host + ', url_path: ' +
          rule.url_path + ' }') + '. Using fixed_target: ' + matched.fixedTarget + ' and rate: ' + matched.fallbackRate + '.');

        return true;
      }
    });

    if (matched) {
      return matched.isSampled();
    } else {
      logger.getLogger().debug('No sampling rule matched for ' + formatted);
      return false;
    }
  },