# Tesla.StatsD

`Tesla.StatsD` is an instrumenting middleware for [tesla](
HTTP client that submits metrics to StatsD (includes support for Datadog tags).

Documentation can be found at [](

## Description

This middleware sends histogram or gauge stats to Datadog for every HTTP request.
The sent value is response time in milliseconds.

Metric name is configurable and defaults to "http.request".
The middleware also sends tags:

  * `http_status` - HTTP status code.
  * `http_status_family` (2xx, 4xx, 5xx) - HTTP status family
  * `http_host` - The host request has been sent to

Tags have "http" in their names to avoid collisions with default tags sent by
Datadog StatsD agent.

## Installation

The package can be installed by adding `tesla_statsd` to your list of dependencies in `mix.exs`:

### Tesla 1.x

def deps do
    {:tesla_statsd, "~> 0.3.0"}

### Tesla 0.9

def deps do
    {:tesla_statsd, "~> 0.1.0"}

## Configuration

  * `:backend` - StatsD backend module. Defaults to `Tesla.StatsD.Backend.ExStatsD`.
    A backend must implement `Tesla.StatsD.Backend` behaviour. `Statix` backends are
    supported by default, just provide a module name that uses `Statix` (`use Statix`).
  * `:metric` - Metric name. Can be ether string or function `(Tesla.Env.t -> String.t)`.
  * `:metric_type` - Metric type. Can be `:histogram` (default) or `:gauge`. See
    [Datadog documentation](
  * `:tags` - List of additional tags. Can be either list or function `(Tesla.Env.t -> [String.t])`.
  * `:sample_rate` - Limit how often the metric is collected (default: 1)

## Usage with Tesla

defmodule AccountsClient do
  use Tesla

  plug Tesla.StatsD, metric: "external.request", tags: ["service:accounts"]

## License

MIT License, Copyright (c) 2017 SaleMove