From 1cf6812d6c5349fe96bcf2cb1a7bbed0b2b02748 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Thu, 24 Oct 2024 22:36:06 -0400 Subject: [PATCH] chore: improve docs about telemetry middleware (#720) closes #638 --- lib/tesla/middleware/telemetry.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/tesla/middleware/telemetry.ex b/lib/tesla/middleware/telemetry.ex index fa8f098f..633de1fc 100644 --- a/lib/tesla/middleware/telemetry.ex +++ b/lib/tesla/middleware/telemetry.ex @@ -54,7 +54,7 @@ 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 @@ -62,8 +62,8 @@ if Code.ensure_loaded?(:telemetry) do # 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( @@ -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(