Tesla.Middleware.OpenTelemetry: handle 400 as error (#153)
This commit is contained in:
parent
8897400d4e
commit
bc11851360
|
@ -59,7 +59,7 @@ defmodule Tesla.Middleware.OpenTelemetry do
|
|||
result
|
||||
end
|
||||
|
||||
defp handle_result({:ok, %Tesla.Env{status: status} = env}) when status > 400 do
|
||||
defp handle_result({:ok, %Tesla.Env{status: status} = env}) when status >= 400 do
|
||||
OpenTelemetry.Tracer.set_status(OpenTelemetry.status(:error, ""))
|
||||
|
||||
{:ok, env}
|
||||
|
|
|
@ -191,7 +191,39 @@ defmodule Tesla.Middleware.OpenTelemetryTest do
|
|||
assert_receive {:span, span(name: "HTTP GET", attributes: _attributes)}
|
||||
end
|
||||
|
||||
test "Marks Span status as :error when HTTP request fails", %{bypass: bypass} do
|
||||
@error_codes [
|
||||
400,
|
||||
401,
|
||||
402,
|
||||
403,
|
||||
404,
|
||||
405,
|
||||
406,
|
||||
407,
|
||||
408,
|
||||
409,
|
||||
410,
|
||||
411,
|
||||
412,
|
||||
413,
|
||||
414,
|
||||
415,
|
||||
416,
|
||||
417,
|
||||
418,
|
||||
500,
|
||||
501,
|
||||
502,
|
||||
503,
|
||||
504,
|
||||
505,
|
||||
506,
|
||||
507,
|
||||
508
|
||||
]
|
||||
|
||||
for code <- @error_codes do
|
||||
test "Marks Span status as :error when HTTP request fails with #{code}", %{bypass: bypass} do
|
||||
defmodule TestClient do
|
||||
def get(client) do
|
||||
Tesla.get(client, "/users/")
|
||||
|
@ -208,7 +240,7 @@ defmodule Tesla.Middleware.OpenTelemetryTest do
|
|||
end
|
||||
|
||||
Bypass.expect_once(bypass, "GET", "/users", fn conn ->
|
||||
Plug.Conn.resp(conn, 500, "")
|
||||
Plug.Conn.resp(conn, unquote(code), "")
|
||||
end)
|
||||
|
||||
bypass.port
|
||||
|
@ -218,6 +250,7 @@ defmodule Tesla.Middleware.OpenTelemetryTest do
|
|||
|
||||
assert_receive {:span, span(status: {:status, :error, ""})}
|
||||
end
|
||||
end
|
||||
|
||||
test "Marks Span status as :errors when max redirects are exceeded", %{bypass: bypass} do
|
||||
defmodule TestClient do
|
||||
|
|
Loading…
Reference in New Issue