reinh / statsd

A Ruby Statsd client that isn't a direct port of the Python example code. Because Ruby isn't Python.
MIT License
411 stars 154 forks source link

Add Statsd::RackEndpoint #35

Closed jamesarosen closed 11 years ago

jamesarosen commented 11 years ago

This endpoint makes it easy for sites to collect client-side stats. It exposes (most of) the functionality of the existing Statsd client object as a Rack endpoint.

It is not automatically required when loading the library, nor did I add Rack as a runtime dependency. (I would have added it as an optional dependency if Rubygems supported that concept.)

jamesarosen commented 11 years ago
  1. It might be worth mentioning in the docs for this class that it is highly recommended that the front-end code use the sample_rate parameter and send only a portion of the requests to reduce HTTP traffic.
  2. If it would be useful, I'm happy to implement batch support via POST bodies. That would complicate the class a bit, but it might be worth it to make it easier to further reduce HTTP traffic.
jamesarosen commented 11 years ago

I'm also happy to add a reference client implementation. I'd like to keep it as framework-agnostic as possible, but I also don't want to reimplement $.ajax and _.debounce. Perhaps something like

var $ = window.$ || {},
    _ = window._ || {},
    ajax = $.ajax || function() { throw "Please define StatsdClient.ajax"; },
    debounce = $.debounce || _.debounce || function() { throw "Please define StatsdClient.debounce"; };

function StatsdClient() {
  // ...
}
StatsdClient.ajax = ajax;
StatsdClient.debounce = debounce;
reinh commented 11 years ago

I think this would be better as a separate gem is it isn't core functionality and it's easy to make it a separate gem.

jamesarosen commented 11 years ago

OK. I'll work on that.

reinh commented 11 years ago

@jamesarosen Let me know when it's available and I'll link it up in the README! Thanks!