   updateLatency = (time) ->
     currentLatency = time
 
-    if SEND_LATENCY and not latencySent
+    if options.sendLatency and not latencySent
       enqueue 'bucky.latency', time, 'timer'
 
       latencySent = true

# We grab a reference to it now before we mutate it
_XMLHttpRequest = window.XMLHttpRequest

exportDef = (Frosting) ->
  # The max time we should wait between sends
  MAX_INTERVAL = 30000

  # How long we should wait from getting the last datapoint
  # to do a send, if datapoints keep coming in eventually
  # the MAX_INTERVAL will trigger a send.
  AGGREGATION_INTERVAL = 5000

  DECIMAL_PRECISION = 3

  # Bucky can automatically report a datapoint of what it's response time
  # is.  This is useful because Bucky returns almost immediately, making
  # it's response time a good measure of the user's connection latency.
  SEND_LATENCY = true

  # Downsampling will cause Bucky to only send data 100*SAMPLE percent
  # of the time.  It is used to reduce the amount of data sent to the backend.  Keep
  # in mind that the goal is to have each datapoint sent at least once per minute.
  #
  # It's not done per datapoint, but per client, so you probably don't want to downsample
  # on node (you would be telling a percentage of your servers to not send data).
  SAMPLE = 1

  TYPE_MAP =
    'timer': 'ms'
    'gauge': 'g'
    'counter': 'c'

  BUCKY_HOST = '/bucky'

  ACTIVE = Math.random() < SAMPLE

  # Should we console.log if an ajax request is ended without us having recorded
  # the start time (usually means requests.monitor is being called too late).
  WARN_UNSTARTED_REQUEST = true

  HISTORY = {}

  round = (num, precision=DECIMAL_PRECISION) ->
    num.toFixed(precision)

  queue = {}

    body = JSON.stringify out

    request = new _XMLHttpRequest
    request.open 'POST', "#{ options.host }/send", true

    request.setRequestHeader 'Content-Type', 'application/json'
    request.setRequestHeader 'Content-Length', body.length
