<commit_before>/*jslint unparam: true, node: true */
'use strict';

/**
 * This is a backend implementation for StatsD which will flush all
 * the metrics data directly to New Relic using the agent API
 */


/**
 *  Instantiation of dispatcher and newrelic are delayed up to the init function
 *  to use the newrelic app name and license key configured through statsD
 */
var dispatcher,
    newrelic;

var debug, l;

var options = {
    // Metrics to be sent to New Relic
    dispatchMetrics: ['gauges', 'counters', 'timers', 'sets'],

    // Dispatchers to be used
    dispatchers: ['customEvent'],

    // Custom metrics names to be used
    metricPrefix: {
        gauges: 'Gauges',
        timers: 'Timers',
        counters: 'Counters',
        sets: 'Sets'
    }
};

/**
 *  Handle the flush event triggered by StatsD.
 *  This handler will read the gauges and counters data and send them to New Relic as Custom Metrics
 *  through the agent API recordMetric.
 *
 *  Unless other names are provided as part of the configuration, the Custom Metrics naming
 *  follows the New Relic suggested convention:
 *      - Custom/[gauge.key.metric]
 *      - Custom/[counter.key.metric]
 *      ...
 *
 */
var onFlush = function (time, metrics) {
    /**
     * Iterate over every kind of metric we want to send to new relic
     */
    options.dispatchMetrics.forEach(function (metricType) {
        var statsdKeysForType = metrics[metricType],
            statsdKey,
            statsdValue,
            dispatchMetric = function (dispatcherType) {
                dispatcher[dispatcherType](metricType, statsdKey, statsdValue);
            };

        for (statsdKey in statsdKeysForType) {
            if (statsdKeysForType.hasOwnProperty(statsdKey)) {
                statsdValue = metrics[metricType][statsdKey];
                options.dispatchers.forEach(dispatchMetric);
            }
        }

    });
};

/**
 *  Expose the init function to StatsD.
 *  The init function simply waits for the event flush to be fired
 *  by StatsD and then process the metrics and sends them to New Relic
 */
exports.init = function (startup_time, config, events, logger) {
    if (!startup_time || !config || !events) {
        return false;
    }

	debug = config.debug;
    l = logger;

    options.dispatchMetrics = config.dispatchMetrics || options.dispatchMetrics;
    options.dispatchers = config.dispatchers || options.dispatchers;

    /**
     * Global metric prefix option will override any other configured metric prefixes
     */
    if (config.globalMetricPrefix) {
        options.metricPrefix.gauges
            = options.metricPrefix.counters
            = options.metricPrefix.timers
            = options.metricPrefix.sets
            = config.globalMetricPrefix;
    } else if (config.metricPrefix) {
        options.metricPrefix.gauges = config.metricPrefix.gauges || options.metricPrefix.gauges;
        options.metricPrefix.counters = config.metricPrefix.counters || options.metricPrefix.counters;
        options.metricPrefix.timers = config.metricPrefix.timers || options.metricPrefix.timers;
        options.metricPrefix.sets = config.metricPrefix.sets || options.metricPrefix.sets;
    }

    if (config.newRelicApp) {
        process.env.NEW_RELIC_APP_NAME = config.newRelicApp;
    }
    if (config.newRelicLicense) {
        process.env.NEW_RELIC_LICENSE_KEY = config.newRelicLicense;
    }
    if (config.newRelicApp &&
        config.newRelicLicense) {
      	process.env.NEW_RELIC_NO_CONFIG_FILE = 'yes'
    }

    newrelic = require('newrelic');
    dispatcher = require('./dispatcher')(newrelic, options.metricPrefix);

    events.on('flush', onFlush);

    return true;
};<commit_msg>linted the mofo<commit_after>/*jslint unparam: true, node: true */
'use strict';

/**
 * This is a backend implementation for StatsD which will flush all
 * the metrics data directly to New Relic using the agent API
 */


/**
 *  Instantiation of dispatcher and newrelic are delayed up to the init function
 *  to use the newrelic app name and license key configured through statsD
 */
var dispatcher,
    newrelic;

var debug, l;

var options = {
    // Metrics to be sent to New Relic
    dispatchMetrics: ['gauges', 'counters', 'timers', 'sets'],

    // Dispatchers to be used
    dispatchers: ['customEvent'],

    // Custom metrics names to be used
    metricPrefix: {
        gauges: 'Gauges',
        timers: 'Timers',
        counters: 'Counters',
        sets: 'Sets'
    }
};

/**
 *  Handle the flush event triggered by StatsD.
 *  This handler will read the gauges and counters data and send them to New Relic as Custom Metrics
 *  through the agent API recordMetric.
 *
 *  Unless other names are provided as part of the configuration, the Custom Metrics naming
 *  follows the New Relic suggested convention:
 *      - Custom/[gauge.key.metric]
 *      - Custom/[counter.key.metric]
 *      ...
 *
 */
var onFlush = function (time, metrics) {
    /**
     * Iterate over every kind of metric we want to send to new relic
     */
    options.dispatchMetrics.forEach(function (metricType) {
        var statsdKeysForType = metrics[metricType],
            statsdKey,
            statsdValue,
            dispatchMetric = function (dispatcherType) {
                dispatcher[dispatcherType](metricType, statsdKey, statsdValue);
            };

        for (statsdKey in statsdKeysForType) {
            if (statsdKeysForType.hasOwnProperty(statsdKey)) {
                statsdValue = metrics[metricType][statsdKey];
                options.dispatchers.forEach(dispatchMetric);
            }
        }

    });
};

/**
 *  Expose the init function to StatsD.
 *  The init function simply waits for the event flush to be fired
 *  by StatsD and then process the metrics and sends them to New Relic
 */
exports.init = function (startup_time, config, events, logger) {
    if (!startup_time || !config || !events) {
        return false;
    }

    debug = config.debug;
    l = logger;

    options.dispatchMetrics = config.dispatchMetrics || options.dispatchMetrics;
    options.dispatchers = config.dispatchers || options.dispatchers;

    /**
     * Global metric prefix option will override any other configured metric prefixes
     */
    if (config.globalMetricPrefix) {
        options.metricPrefix.gauges
            = options.metricPrefix.counters
            = options.metricPrefix.timers
            = options.metricPrefix.sets
            = config.globalMetricPrefix;
    } else if (config.metricPrefix) {
        options.metricPrefix.gauges = config.metricPrefix.gauges || options.metricPrefix.gauges;
        options.metricPrefix.counters = config.metricPrefix.counters || options.metricPrefix.counters;
        options.metricPrefix.timers = config.metricPrefix.timers || options.metricPrefix.timers;
        options.metricPrefix.sets = config.metricPrefix.sets || options.metricPrefix.sets;
    }

    if (config.newRelicApp) {
        process.env.NEW_RELIC_APP_NAME = config.newRelicApp;
    }
    if (config.newRelicLicense) {
        process.env.NEW_RELIC_LICENSE_KEY = config.newRelicLicense;
    }
    if (config.newRelicApp && config.newRelicLicense) {
        process.env.NEW_RELIC_NO_CONFIG_FILE = 'yes';
    }

    newrelic = require('newrelic');
    dispatcher = require('./dispatcher')(newrelic, options.metricPrefix);

    events.on('flush', onFlush);

    return true;
};

{'fraction_non_alphanumeric': 0.09606575047157101, 'fraction_numerical': 0.0, 'mean_word_length': 2.722668004012036, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3543152', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2095, 'n_words': 590}