@@ -112,10 +112,12 @@ defmodule MetricsSupervisor do
112
112
:telemetry .attach_many (
113
113
" handler-#{ __MODULE__ } " ,
114
114
[
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 ]
117
119
],
118
- fn [:grpc , :server , :rpc , event_kind],
120
+ fn [:grpc , server_or_client , :rpc , event_kind],
119
121
%{duration: duration},
120
122
%{stream: stream} = metadata,
121
123
_opts ->
@@ -136,10 +138,18 @@ defmodule MetricsSupervisor do
136
138
}
137
139
138
140
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
+ )
140
146
end
141
147
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
+ )
143
153
end ,
144
154
nil
145
155
)
@@ -148,9 +158,12 @@ defmodule MetricsSupervisor do
148
158
# without having to attach and publish a new event. However, that would
149
159
# end up leaking an extraneous tag to Prometheus.
150
160
# This is cleaner in that sense.
151
- :telemetry .attach (
161
+ :telemetry .attach_many (
152
162
" handler-#{ __MODULE__ } -start" ,
153
- [:grpc , :server , :rpc , :start ],
163
+ [
164
+ GRPC .Telemetry .server_rpc_prefix () ++ [:start ],
165
+ GRPC .Telemetry .client_rpc_prefix () ++ [:start ]
166
+ ],
154
167
fn _event , _ , %{stream: stream}, _opts ->
155
168
if is_message (stream) do
156
169
:telemetry .execute ([:custom_grpc , :server_rpc , :message_received ], %{count: 1 })
@@ -219,10 +232,51 @@ defmodule MetricsSupervisor do
219
232
reporter_options: [
220
233
buckets: @histogram_buckets_seconds
221
234
]
222
- )
235
+ ),
223
236
224
237
# 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
+ )
226
280
]
227
281
end
228
282
0 commit comments