Skip to content

Commit

Permalink
Add client request to telemetry metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ssepml committed Jul 12, 2023
1 parent d5ad40a commit e448ce1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/grpc/stub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ defmodule GRPC.Stub do
accepted_compressors: accepted_compressors
}

GRPC.Telemetry.client_span(stream, fn ->
GRPC.Telemetry.client_span(stream, request, fn ->
do_call(req_stream, stream, request, opts)
end)
end
Expand Down
8 changes: 3 additions & 5 deletions lib/grpc/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ 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
`:exception` events also include some error metadata:
Expand Down Expand Up @@ -110,8 +108,8 @@ defmodule GRPC.Telemetry do
def client_rpc_start_name, do: @client_rpc_start_name

@doc false
def client_span(stream, span_fn) do
start_metadata = %{stream: stream}
def client_span(stream, request, span_fn) do
start_metadata = %{stream: stream, request: request}

:telemetry.span(@client_rpc, start_metadata, fn ->
try do
Expand Down
17 changes: 17 additions & 0 deletions test/grpc/integration/client_interceptor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ defmodule GRPC.Integration.ClientInterceptorTest do
end

test "client sends headers" do
client_prefix = GRPC.Telemetry.client_rpc_prefix()
stop_client_name = client_prefix ++ [:stop]
service_name = Helloworld.Greeter.Service.__meta__(:name)

attach_events([
stop_client_name
])

run_endpoint(HelloEndpoint, fn port ->
{:ok, channel} =
GRPC.Stub.connect("localhost:#{port}",
Expand All @@ -62,6 +70,15 @@ defmodule GRPC.Integration.ClientInterceptorTest do
req = Helloworld.HelloRequest.new(name: "Elixir")
{:ok, reply} = channel |> Helloworld.Greeter.Stub.say_hello(req)
assert reply.message == "Hello, Elixir one two"

assert_received {^stop_client_name, _measurements, metadata}
assert %{stream: stream, request: ^req} = metadata

assert %{
channel: ^channel,
service_name: ^service_name,
method_name: "SayHello"
} = stream
end)
end

Expand Down

0 comments on commit e448ce1

Please sign in to comment.