When a golang gRPC server calls a handler function, the ctx value handed is derived from a private top context created here, in the grpc transport layer:
/go/pkg/mod/google.golang.org/grpc@v1.27.0/internal/transport/http2_server.go:219
t := &http2Server{
ctx: context.Background(),
done: done,
conn: conn,
remoteAddr: conn.RemoteAddr()
...
Is there a reason why that context is not derived from a root context provided at the construction of the server?
Perhaps grpc.NewServer(opt ...ServerOption)
could have a ctx variant grpc.NewServerCtx(ctx, ...ServerOption)
?
That would give you the option for transmitting values you'd like all the contexts to contain.