(smp ServerMetricsProvider)
| 156 | } |
| 157 | |
| 158 | func streamInt(smp ServerMetricsProvider) func(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { |
| 159 | return func(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error { |
| 160 | // We don't allocate the metric recorder here. It will be allocated the |
| 161 | // first time the user calls CallMetricsRecorderFromContext(). |
| 162 | rw := &recorderWrapper{smp: smp} |
| 163 | ws := &wrappedStream{ |
| 164 | ServerStream: ss, |
| 165 | ctx: newContextWithRecorderWrapper(ss.Context(), rw), |
| 166 | } |
| 167 | |
| 168 | err := handler(srv, ws) |
| 169 | |
| 170 | // It is safe to access the underlying metric recorder inside the wrapper at |
| 171 | // this point, as the user's RPC handler is done executing, and therefore |
| 172 | // there will be no more calls to CallMetricsRecorderFromContext(), which is |
| 173 | // where the metric recorder is lazy allocated. |
| 174 | if rw.r != nil { |
| 175 | rw.setTrailerMetadata(ss.Context()) |
| 176 | } |
| 177 | return err |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | func newContextWithRecorderWrapper(ctx context.Context, r *recorderWrapper) context.Context { |
| 182 | return context.WithValue(ctx, callMetricsRecorderCtxKey{}, r) |
no test coverage detected