> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tesla

export const VersionRequirements = ({versions = []}) => {
  if (!Array.isArray(versions) || versions.length === 0) {
    return null;
  }
  const boundaries = {
    upper: " or lower",
    exact: "",
    lower: " or higher"
  };
  const containerStyle = {
    marginTop: "0.5rem",
    marginBottom: "1.5rem"
  };
  const lineStyle = {
    display: "block",
    margin: "0 0 0.35rem 0",
    fontSize: "0.875rem",
    lineHeight: "1.4"
  };
  const pillBaseStyle = {
    display: "inline-block",
    padding: "0.1em 0.4em",
    borderRadius: "0.25rem",
    border: "1px solid",
    fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
    fontSize: "0.85em",
    fontWeight: 500
  };
  const pillColors = {
    "AppSignal for Elixir": {
      background: "#f3e8ff",
      borderColor: "#e9d5ff",
      color: "#9333ea"
    },
    "AppSignal for Front-end": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Go": {
      background: "#ccfbf1",
      borderColor: "#99f6e4",
      color: "#0d9488"
    },
    "AppSignal for JavaScript": {
      background: "#fef9c3",
      borderColor: "#fde68a",
      color: "#ca8a04"
    },
    "AppSignal for Node.js": {
      background: "#dcfce7",
      borderColor: "#bbf7d0",
      color: "#16a34a"
    },
    "AppSignal for Python": {
      background: "#dbeafe",
      borderColor: "#bfdbfe",
      color: "#2563eb"
    },
    "AppSignal for Ruby": {
      background: "#fee2e2",
      borderColor: "#fecaca",
      color: "#dc2626"
    },
    "AppSignal for Rust": {
      background: "#ffedd5",
      borderColor: "#fed7aa",
      color: "#ea580c"
    }
  };
  const defaultPillColor = {
    background: "#f4f4f5",
    borderColor: "#e4e4e7",
    color: "#52525b"
  };
  const getPillStyle = name => ({
    ...pillBaseStyle,
    ...pillColors[name] || defaultPillColor
  });
  const getBoundText = bound => {
    return boundaries[bound] || boundaries.lower;
  };
  return <div style={containerStyle}>
      {versions.map((v, i) => <p key={`${v.name}-${v.version}-${v.bound || "lower"}-${i}`} style={lineStyle}>
          This feature requires{" "}
          <code style={getPillStyle(v.name)}>{v.name}</code> version {v.version}
          {getBoundText(v.bound)}.
        </p>)}
    </div>;
};

<VersionRequirements
  versions={[
{ name: "AppSignal for Elixir", version: "2.7.3" },
{ name: "Tesla", version: "1.4.3" }
]}
/>

The AppSignal for Elixir package instruments HTTP requests performed by [Tesla](https://github.com/elixir-tesla/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](#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**:

<CodeGroup>
  ```elixir Elixir theme={null}
  defmodule MyAPIClient do
    use Tesla

    plug Tesla.Middleware.Telemetry
    # ... plug other middlewares here, **after** the Telemetry middleware
  end
  ```
</CodeGroup>

<CodeGroup>
  ```elixir Elixir theme={null}
  client = Tesla.client([
    Tesla.Middleware.Telemetry,
    # ... add other middlewares here, **after** the Telemetry middleware
  ])
  ```
</CodeGroup>

<Tip>
  If using the Finch adapter for Tesla, you should [disable AppSignal's Finch
  instrumentation](/elixir/integrations/finch#automatic-instrumentation) by
  setting the `instrument_finch` configuration option to `false`.
</Tip>

## 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:

<CodeGroup>
  ```elixir Elixir theme={null}
  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
  ```
</CodeGroup>

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:

<CodeGroup>
  ```elixir Elixir theme={null}
  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
  ```
</CodeGroup>

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](/elixir/configuration/options#option-instrument_tesla) to `false`.
