Skip to content

Commit

Permalink
Add result to client telemetry spans (#334)
Browse files Browse the repository at this point in the history
* Add result to client telemetry spans

This PR unifies client spans with server spans so that the result is present.

* Add result to the docs

---------

Co-authored-by: Paulo Valente <[email protected]>
  • Loading branch information
davydog187 and polvalente authored Nov 27, 2023
1 parent 37a31e0 commit ab18c93
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/grpc/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ defmodule GRPC.Telemetry do
### Metadata
* `:stream` - the `%GRPC.Server.Stream{}` for the request
* `:function_name` - the name of the function called
* `:server` - the server module name
* `:endpoint` - the endpoint module name
* `:request` - the client request
* `:result` - the result returned from the interceptor pipeline.
`:exception` events also include some error metadata:
Expand Down Expand Up @@ -113,7 +117,9 @@ defmodule GRPC.Telemetry do

:telemetry.span(@client_rpc, start_metadata, fn ->
try do
{span_fn.(), start_metadata}
result = span_fn.()

{result, Map.put(start_metadata, :result, result)}
rescue
e ->
:erlang.error(Exception.normalize(:error, e, __STACKTRACE__))
Expand Down

0 comments on commit ab18c93

Please sign in to comment.