Skip to content

Commit

Permalink
Merge pull request #502 from ibarchenkov/add-env-to-tesla.request.exc…
Browse files Browse the repository at this point in the history
…eption-metadata

Add Tesla.Env.t() to tesla.request.exception Telemetry metadata
  • Loading branch information
teamon authored Dec 17, 2021
2 parents f19cac9 + 1577fde commit 7e59411
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/tesla/middleware/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if Code.ensure_loaded?(:telemetry) do
* `[:tesla, :request, :exception]` - emitted when an exception has been raised.
* Measurement: `%{duration: native_time}`
* Metadata: `%{kind: Exception.kind(), reason: term(), stacktrace: Exception.stacktrace()}`
* Metadata: `%{env: Tesla.Env.t(), kind: Exception.kind(), reason: term(), stacktrace: Exception.stacktrace()}`
## Legacy Telemetry Events
Expand Down Expand Up @@ -102,7 +102,7 @@ if Code.ensure_loaded?(:telemetry) do

emit_exception(
duration,
Map.merge(metadata, %{kind: kind, reason: reason, stacktrace: stacktrace})
Map.merge(metadata, %{env: env, kind: kind, reason: reason, stacktrace: stacktrace})
)

:erlang.raise(kind, reason, stacktrace)
Expand Down
9 changes: 8 additions & 1 deletion test/tesla/middleware/telemetry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ defmodule Tesla.Middleware.TelemetryTest do
end

assert_receive {:event, [:tesla, :request, :exception], %{duration: _time}, metadata}
assert %{kind: _kind, reason: _reason, stacktrace: _stacktrace, custom: "meta"} = metadata

assert %{
env: _env,
kind: _kind,
reason: _reason,
stacktrace: _stacktrace,
custom: "meta"
} = metadata
end

test "middleware works in tandem with PathParams and KeepRequest" do
Expand Down

0 comments on commit 7e59411

Please sign in to comment.