$\newcommand{\bR}{\mathbb{R}}\newcommand{\pa}{\partial}$This questions has some nebulous roots in Morse theory. The most general version goes as follows. Fix an integer $n\geq 2$. Suppose that we have a smooth function $f$ defined on an open neighborhood $U$ of $0$ in $\bR^n$. To a smooth Riemannian metric $g$ defined on $U$ we associated the gradient $\nabla^g f$. 



> 
> For which smooth functions $f$ is the correspondence 
> 
> 
> $$g\mapsto \nabla^g f $$
> 
> 
> injective, i.e., from the knowledge that $\nabla^{g\_0} f=\nabla^{g\_1} f$
>  on $U$ we can conclude that $g\_0=g\_1$ on some neighborhood $V$ of
>  $0$ in $\bR^n$, $V\subset U$.
> 
> 
> 


Clearly, the above correspondence is not injective if $f\equiv const$, or $f(x)$ is linear in $x$.


The next interesting case is when $q$ is quadratic. Suppose that


$$
f(x)=q(x):=\frac{1}{2}(x\_1^2+\cdots +x\_n^2).
 $$


Denote by $g\_0$ the canonical Euclidean metric on $\bR^n$ so that


$$\nabla^{g\_0}q =\sum\_i x\_i\pa\_{x\_i}. $$


The special case of the question goes as follows. 



> 
> If $g$ is a real analytic Riemann metric defined on a neighborhood $U$
>  of $0$ and $\nabla^g q(x)= \nabla^{g\_0} q(x)$, $\forall x\in U$, can
>  we conclude that $g=g\_0$ in a neighborhood of $0$?
> 
> 
> 


I was not able to track results of this kind in the literature, and I would appreciate any pointers.



An unusual metric reconstruction problem
If $V$ is a vector field such that $Vf=0$ at every point, then the 2-tensor
$$
h^{ij}=g^{ij}+V^iV^j
$$
is also an inverse metric and satisfies $\nabla^gf=\nabla^hf$.
In a coordinate chart this amounts to finding a vector field orthogonal (in the Euclidean sense on the chart) pointwise orthogonal to the gradient of $f$.
In the case of your second example such a vector field has to vanish at the origin but need not vanish elsewhere.


Examples of such vector fields are not hard to find.
Just take $V=(\partial\_2f,-\partial\_1f,0,\dots,0)$ and change the indices if needed.
If this simple idea doesn't give a nonzero vector field, then $\nabla f\equiv0$ and any $V$ will do.
In any neighborhood one can find a nonzero vector field and therefore a distinct metric with the same gradient of $f$.


Therefore one function $f$ is never enough.
If you have a collection of functions, you need any vector field orthogonal to every one of them to vanish identically.
You need at least $n$ functions in $n$ dimensions.


If you take a non-analytic function $f$ and ask the question for analytic metrics, the answer may be different, but that's another story…


