wrap stream for tracing

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2024-05-06 00:28:56 +03:00
parent eecc3854b2
commit 6522a04a5b

14
grpc.go
View File

@@ -51,6 +51,18 @@ type ServerReflection struct {
} }
*/ */
type streamWrapper struct {
ctx context.Context
grpc.ServerStream
}
func (w *streamWrapper) Context() context.Context {
if w.ctx != nil {
return w.ctx
}
return w.ServerStream.Context()
}
type Server struct { type Server struct {
handlers map[string]server.Handler handlers map[string]server.Handler
srv *grpc.Server srv *grpc.Server
@@ -206,6 +218,8 @@ func (g *Server) handler(srv interface{}, stream grpc.ServerStream) error {
), ),
) )
stream = &streamWrapper{ctx, stream}
ts := time.Now() ts := time.Now()
g.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", fullMethod).Inc() g.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", fullMethod).Inc()