alchemetrics_tesla

Tesla middleware to report external call metrics.

Latest version: 2.0.1 registry icon
Maintenance score
0
Safety score
0
Popularity score
76
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
2.0.1 0 0 0 0 0
2.0.0 0 0 0 0 0
1.1.4 0 0 0 0 0
1.1.3 0 0 0 0 0
1.1.2 0 0 0 0 0
1.1.0 0 0 0 0 0
1.0.0 0 0 0 0 0
0.1.2 0 0 0 0 0
0.1.1 0 0 0 0 0
0.1.0 0 0 0 0 0

Stability
Latest release:

2.0.1 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



Alchemetrics Tesla

Alchemetrics Tesla

Tesla middleware to report external call metrics.

Travis Hex

About

Alchemetrics Tesla is a very simple middleware that report metrics like response_time and calls count.

Installing

Add to your dependencies:

def deps do
  [{:alchemetrics_tesla, "~> 2.0"}]
end

Usage

All you need to do is adding the middleware to your Tesla module, like this:

defmodule PetsClient do
  use Tesla
  plug Tesla.Middleware.Alchemetrics
  plug Tesla.Middleware.BaseUrl, "http://pets.api.com"

  def dogs do
    get("/v1/dogs/")
  end
end

And when you make any request it will be automatically reported:

### Sample call
PetsClient.dogs()

### What is reported
# Response time (avg, max, min, p99 and p95)
[
  type: "external_call.response_time",
  request_details: %{
    service: "PetsClient",
    domain: "pets.api.com",
    method: :get,
    port: 80,
    protocol: "http",
  }
]

# Calls count (last interval and total)
[
  type: "external_call.count",
  request_details: %{
    service: "PetsClient",
    domain: "pets.api.com",
    method: :get,
    port: 80,
    protocol: "http",
  },
  response_details: %{
    status_code: "200",
    status_code_group: "2xx"
  }
]

Adding extra metric metadata

You can also add extra metadata:

defmodule PetsClient do
  use Tesla
  plug Tesla.Middleware.Alchemetrics
  plug Tesla.Middleware.BaseUrl, "http://pets.api.com"

  def dogs do
    get("/v1/dogs/", opts: [alchemetrics_metadata: %{route: "get.dogs"}])
  end

  def logged_user_pet(pet_id) do
    get("/user/pets/#{pet_id}", opts: [alchemetrics_metadata: %{route: "get.user.pets.show"}])
  end
end

This extra metadata will be added to request_details key:

## Sample call (1)
PetsClient.logged_user_pet(100)

# Reported response time (avg, max, min, p99 and p95)
[
  type: "external_call.response_time",
  request_details: %{
    service: "PetsClient",
    domain: "pets.api.com",
    method: :get,
    port: 80,
    protocol: "http",
  },
  extra: %{ route: "get.user.pets" }
]


## Sample call (2)
PetsClient.dogs()

# Reported response time (avg, max, min, p99 and p95)
[
  type: "external_call.response_time",
  request_details: %{
    service: "PetsClient",
    domain: "pets.api.com",
    method: :get,
    port: 80,
    protocol: "http",
  },
  extra: %{ route: "get.dogs" }
]