CallMetricsRecorderFromContext returns the RPC-specific custom metrics recorder embedded in the provided RPC context. Returns nil if no custom metrics recorder is found in the provided context, which will be the case when custom metrics reporting is not enabled.
(ctx context.Context)
| 56 | // Returns nil if no custom metrics recorder is found in the provided context, |
| 57 | // which will be the case when custom metrics reporting is not enabled. |
| 58 | func CallMetricsRecorderFromContext(ctx context.Context) CallMetricsRecorder { |
| 59 | rw, ok := ctx.Value(callMetricsRecorderCtxKey{}).(*recorderWrapper) |
| 60 | if !ok { |
| 61 | return nil |
| 62 | } |
| 63 | return rw.recorder() |
| 64 | } |
| 65 | |
| 66 | // recorderWrapper is a wrapper around a CallMetricsRecorder to ensure that |
| 67 | // concurrent calls to CallMetricsRecorderFromContext() results in only one |