Skip to content

Commit

Permalink
chore: improve docs about telemetry middleware (#720)
Browse files Browse the repository at this point in the history
closes #638
  • Loading branch information
yordis authored Oct 25, 2024
1 parent ca26020 commit 1cf6812
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/tesla/middleware/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ if Code.ensure_loaded?(:telemetry) do
Telemetry events. For such cases, a combination of the `Tesla.Middleware.PathParams`,
`Tesla.Middleware.Telemetry` and `Tesla.Middleware.KeepRequest` may be used.
```
```elixir
defmodule MyClient do
use Tesla
# The KeepRequest middleware sets the template URL as a Tesla.Env.opts entry
# Said entry must be used because on happy-path scenarios,
# the Telemetry middleware will receive the Tesla.Env.url resolved by PathParams.
plug Tesla.Middleware.KeepRequest
plug Tesla.Middleware.Telemetry
plug Tesla.Middleware.PathParams
plug Tesla.Middleware.Telemetry
end
:telemetry.attach(
Expand All @@ -78,6 +78,14 @@ if Code.ensure_loaded?(:telemetry) do
nil
)
```
> #### Order Matters {: .warning}
> Place the `Tesla.Middleware.Telemetry` middleware as close as possible to
> the end of the middleware stack to ensure that you are measuring the
> actual request itself and do not lose any information about the
> `t:Tesla.Env.t/0` due to some transformation that happens in the
> middleware stack before reaching the `Tesla.Middleware.Telemetry`
> middleware.
"""

@disable_legacy_event Application.compile_env(
Expand Down

0 comments on commit 1cf6812

Please sign in to comment.