MCPcopy
hub / github.com/grpc/grpc-go / streamInt

Function streamInt

orca/call_metrics.go:158–179  ·  view source on GitHub ↗
(smp ServerMetricsProvider)

Source from the content-addressed store, hash-verified

156}
157
158func 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
181func newContextWithRecorderWrapper(ctx context.Context, r *recorderWrapper) context.Context {
182 return context.WithValue(ctx, callMetricsRecorderCtxKey{}, r)

Callers 1

CallMetricsServerOptionFunction · 0.85

Calls 3

setTrailerMetadataMethod · 0.95
ContextMethod · 0.65

Tested by

no test coverage detected