Skip to content

Commit

Permalink
Update the data structure of telemetry and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanSiu1995 committed Jan 9, 2019
1 parent 7bb05bc commit 7d22213
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/tesla/middleware/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Tesla.Middleware.Telemetry do
@doc false
def call(env, next, _opts) do
{time, res} = :timer.tc(Tesla, :run, [env, next])
:telemetry.execute([:tesla, :telemetry, :traffic], time, Enum.into([res], %{}))
:telemetry.execute([:tesla, :request], time, %{result: res})
res
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule Tesla.Mixfile do

# other
{:fuse, "~> 2.4", optional: true},
{:telemetry, "~> 0.3.0", optional: true},
{:telemetry, "~> 0.3", optional: true},

# testing & docs
{:excoveralls, "~> 0.8", only: :test},
Expand Down
12 changes: 6 additions & 6 deletions test/tesla/middleware/telemetry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ defmodule Tesla.Middleware.TelemetryTest do
test "Get the info from telemetry" do
:telemetry.attach(
"telemetry_test",
[:tesla, :telemetry, :traffic],
fn ([:tesla, :telemetry, :traffic], response, meta, _config) ->
[:tesla, :request],
fn ([:tesla, :request], response, meta, _config) ->
send self(), {:ok_called, is_integer(response), meta}
end,
nil)
Client.get("/telemetry")
assert_receive {:ok_called, true, %{ok: %Tesla.Env{url: "/telemetry", method: :get}}}, 1000
assert_receive {:ok_called, true, %{result: {:ok, %Tesla.Env{url: "/telemetry", method: :get}}}}, 1000
end

test "Get the error from telemetry" do
:telemetry.attach(
"telemetry_test_error",
[:tesla, :telemetry, :traffic],
fn([:tesla, :telemetry, :traffic], response, meta, _config) ->
[:tesla, :request],
fn([:tesla, :request], response, meta, _config) ->
send self(), {:error_called, is_integer(response), meta}
end,
nil)
Client.get("/telemetry_error")
assert_receive {:error_called, true, %{error: :econnrefused}}, 1000
assert_receive {:error_called, true, %{result: {:error, :econnrefused}}}, 1000
end
end

0 comments on commit 7d22213

Please sign in to comment.