Datadogstatsd::send PHP Method

send() public static method

Squirt the metrics over UDP
public static send ( array $data, float $sampleRate = 1, array $tags = null ) : null
$data array Incoming Data
$sampleRate float the rate (0-1) for sampling.
$tags array Key Value array of Tag => Value, or single tag as string
return null
    public static function send($data, $sampleRate = 1.0, array $tags = null)
    {
        // sampling
        $sampledData = array();
        if ($sampleRate < 1) {
            foreach ($data as $stat => $value) {
                if (mt_rand() / mt_getrandmax() <= $sampleRate) {
                    $sampledData[$stat] = "{$value}|@{$sampleRate}";
                }
            }
        } else {
            $sampledData = $data;
        }
        if (empty($sampledData)) {
            return;
        }
        foreach ($sampledData as $stat => $value) {
            if ($tags !== NULL && is_array($tags) && count($tags) > 0) {
                $value .= '|';
                foreach ($tags as $tag_key => $tag_val) {
                    $value .= '#' . $tag_key . ':' . $tag_val . ',';
                }
                $value = substr($value, 0, -1);
            } elseif (isset($tags) && !empty($tags)) {
                $value .= '|#' . $tags;
            }
            static::report_metric("{$stat}:{$value}");
        }
    }