Tesla

This feature requires AppSignal for Elixir version 2.7.3 or higher.
This feature requires Tesla version 1.4.3 or higher.

The AppSignal for Elixir package instruments HTTP requests performed by Tesla.

Tesla is a flexible HTTP client library for Elixir. It can use multiple middlewares and adapters to modify and perform HTTP request, and it has built-in support for request telemetry.

After configuring Tesla's Telemetry middleware, AppSignal will recognize requests executed via Tesla and show them as request.tesla events on your performance samples' Event Timeline.

In the Event Timeline, you'll see how much time Tesla spends making external API requests. This data may help inform you to move the API requests to a background job or introduce caching to help speed up performance and limit unnecessary API requests.

In the Slow API Requests performance view, you'll be able to see aggregated throughput and average times for different kinds of HTTP requests. Follow the instructions in the Path Params Grouping section in order to improve the information shown in this view.

Configuration

Add the Tesla.Middleware.Telemetry middleware to your module or client's middleware chain, before any other middlewares:

Elixir
defmodule MyAPIClient do use Tesla plug Tesla.Middleware.Telemetry # ... plug other middlewares here, **after** the Telemetry middleware end
Elixir
client = Tesla.client([ Tesla.Middleware.Telemetry, # ... add other middlewares here, **after** the Telemetry middleware ])

If using the Finch adapter for Tesla, you should disable AppSignal's Finch instrumentation by setting the instrument_finch configuration option to false.

Enhanced Grouping

By default, the AppSignal instrumentation for Tesla will group requests by the domain name they're performed against. The path of the request will not be shown in AppSignal. However, by using certain Tesla middlewares, it's possible to add more information about the request.

The following sections describe each middleware's behaviour separately, but it is also possible to use them together.

Base URL Grouping

When using the BaseUrl middleware, the base URL provided, including its path, will be used for grouping, providing you with some additional insight into the target of the HTTP requests performed by Tesla:

Elixir
defmodule MyAPIClient do use Tesla plug Tesla.Middleware.Telemetry # make sure Telemetry appears **before** any other middleware! plug Tesla.Middleware.BaseUrl, "https://api.example.com/v2/users" def user_comments(id) do get("/#{id}/comments") end end

In the above example, requests performed by this client will be shown in the sample's Event Timeline and in the Slow API Requests performance view as GET https://api.example.com/v2/users, instead of just GET https://api.example.com, providing additional information about the requests that are being performed.

Path Params Grouping

When using the PathParams middleware, the URL given to Tesla for the request will be a template, with path parameters being passed separately:

Elixir
defmodule MyAPIClient do use Tesla plug Tesla.Middleware.Telemetry # make sure Telemetry appears **before** any other middleware! plug Tesla.Middleware.PathParams def user_comments(id) do params = [user: id] get("https://api.example.com/v2/users/:user/comments", opts: [path_params: params]) end end

When PathParams is used, the URL template will be shown in AppSignal. Requests will appear as GET https://api.example.com/v2/users/:user/comments in the sample's Event Timeline and in the Slow API Requests performance view, providing you with a detailed view of each request type that your client performs.

Disable Tesla Instrumentation

To disable the Tesla instrumentation, set the instrument_tesla config option to false.