You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a middleware returns an error, then metadata.env struct doesn't have status, body, headers etc, while these fields were available in the middleware. I'd expect to have this data in telemetry handler, as it helps in debugging.
Script:
Mix.install([:tesla,:telemetry]):telemetry.attach_many("tesla.request",[[:tesla,:request,:stop]],fn_event,measurements,metadata,_->dbg(metadata)end,nil)defmoduleExpectOKMiddlewaredo@behaviourTesla.Middleware@implTesla.Middlewaredefcall(env,next,_opts)dowith{:ok,env}<-Tesla.run(env,next)doifdbg(env).status==200do{:ok,env}else{:error,{:unexpected_response,"not ok :("}}endendendendclient=Tesla.client([Tesla.Middleware.Telemetry,{Tesla.Middleware.BaseUrl,"https://hex.pm/api"},ExpectOKMiddleware])client|>Tesla.get("/packages/tesla")|>dbg()
@fuelen I am updating the documentation, it works as intended, but you must place the telemetry as close as possible to the actual request; the issue is that your ExpectOKMiddleware is transforming the response into an error tuple; so you los the information; here is working test case:
defmoduleTelemetryTestdouseExUnit.CasedefmoduleExpectOKMiddlewaredo@behaviourTesla.Middleware@implTesla.Middlewaredefcall(env,next,_opts)dowith{:ok,env}<-Tesla.run(env,next)doifdbg(env).status==200do{:ok,env}else{:error,{:unexpected_response,"not ok :("}}endendendendtest"assering proper telemetry metadata"do:telemetry.attach_many("tesla.request",[[:tesla,:request,:stop]],fn_event,measurements,metadata,_->send(self(),{:telemetry,metadata})end,nil)client=Tesla.client([{Tesla.Middleware.BaseUrl,"https://hex.pm/api"},ExpectOKMiddleware,Tesla.Middleware.Telemetry,])Tesla.get(client,"/packages/tesla")assert_receive{:telemetry,metadata}assertmetadata.env.status==400endend
When a middleware returns an error, then
metadata.env
struct doesn't have status, body, headers etc, while these fields were available in the middleware. I'd expect to have this data in telemetry handler, as it helps in debugging.Script:
output:
The text was updated successfully, but these errors were encountered: