Skip to content

Commit c96cf72

Browse files
authored
docs: add client events to telemetry livebook (#317)
1 parent 435bfd7 commit c96cf72

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
elixir 1.14.1-otp-25
1+
elixir 1.14.2-otp-25
22
erlang 25.1.1

livebooks/telemetry.livemd

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ defmodule MetricsSupervisor do
112112
:telemetry.attach_many(
113113
"handler-#{__MODULE__}",
114114
[
115-
[:grpc, :server, :rpc, :stop],
116-
[:grpc, :server, :rpc, :exception]
115+
GRPC.Telemetry.server_rpc_prefix() ++ [:stop],
116+
GRPC.Telemetry.server_rpc_prefix() ++ [:exception],
117+
GRPC.Telemetry.client_rpc_prefix() ++ [:stop],
118+
GRPC.Telemetry.client_rpc_prefix() ++ [:exception]
117119
],
118-
fn [:grpc, :server, :rpc, event_kind],
120+
fn [:grpc, server_or_client, :rpc, event_kind],
119121
%{duration: duration},
120122
%{stream: stream} = metadata,
121123
_opts ->
@@ -136,10 +138,18 @@ defmodule MetricsSupervisor do
136138
}
137139

138140
if is_message(stream) do
139-
:telemetry.execute([:custom_grpc, :server_rpc, :sent], %{duration: duration}, metadata)
141+
:telemetry.execute(
142+
[:custom_grpc, :"#{server_or_client}_rpc", :sent],
143+
%{duration: duration},
144+
metadata
145+
)
140146
end
141147

142-
:telemetry.execute([:custom_grpc, :server_rpc, :handled], %{duration: duration}, metadata)
148+
:telemetry.execute(
149+
[:custom_grpc, :"#{server_or_client}_rpc", :handled],
150+
%{duration: duration},
151+
metadata
152+
)
143153
end,
144154
nil
145155
)
@@ -148,9 +158,12 @@ defmodule MetricsSupervisor do
148158
# without having to attach and publish a new event. However, that would
149159
# end up leaking an extraneous tag to Prometheus.
150160
# This is cleaner in that sense.
151-
:telemetry.attach(
161+
:telemetry.attach_many(
152162
"handler-#{__MODULE__}-start",
153-
[:grpc, :server, :rpc, :start],
163+
[
164+
GRPC.Telemetry.server_rpc_prefix() ++ [:start],
165+
GRPC.Telemetry.client_rpc_prefix() ++ [:start]
166+
],
154167
fn _event, _, %{stream: stream}, _opts ->
155168
if is_message(stream) do
156169
:telemetry.execute([:custom_grpc, :server_rpc, :message_received], %{count: 1})
@@ -219,10 +232,51 @@ defmodule MetricsSupervisor do
219232
reporter_options: [
220233
buckets: @histogram_buckets_seconds
221234
]
222-
)
235+
),
223236

224237
# Client Metrics
225-
# TO-DO
238+
counter(
239+
"grpc_client_started_total",
240+
event_name: "grpc.client.rpc.start",
241+
measurement: :count,
242+
tags: @tags,
243+
tag_values: &extract_tags_from_stream/1,
244+
description: "Total number of RPCs started on the client"
245+
),
246+
counter(
247+
"grpc_client_msg_received_total",
248+
event_name: "custom_grpc.client_rpc.message_received",
249+
measurement: :count,
250+
tags: @tags,
251+
tag_values: &extract_tags_from_stream/1,
252+
description: "Total number of RPC stream messages received on the client"
253+
),
254+
counter(
255+
"grpc_client_msg_sent_total",
256+
event_name: "custom_grpc.client_rpc.sent",
257+
measurement: :duration,
258+
tags: @tags,
259+
description: "Total number of gRPC stream messages sent by the client."
260+
),
261+
counter(
262+
"grpc_client_handled_total",
263+
event_name: "custom_grpc.client_rpc.handled",
264+
measurement: :duration,
265+
tags: @tags_with_code,
266+
description:
267+
"Total number of RPCs completed on the client, regardless of success or failure."
268+
),
269+
distribution(
270+
"grpc_client_handled_latency_seconds",
271+
event_name: "custom_grpc.client_rpc.handled",
272+
description: "Histogram of response latency of rpcs handled by the client, in seconds.",
273+
measurement: :duration,
274+
tags: @tags_with_code,
275+
unit: {:native, :second},
276+
reporter_options: [
277+
buckets: @histogram_buckets_seconds
278+
]
279+
)
226280
]
227281
end
228282

0 commit comments

Comments
 (0)