The following is the meta-theorem I have in mind:

Given $G < \mathrm{GL}(n)$, let $\Phi: \mathbb{R}^n \rightarrow \mathbb{R}$ a smooth $G$-invariant function. Let $\Phi': \mathbb{R}^n \rightarrow (\mathbb{R}^n)^*$ denote the differential of $\Phi$, defined to be
$$
\langle\Phi'(x),v\rangle = \left.\frac{d}{dt}\right|_{t=0}\Phi(x + tv).
$$
Let $V$ be a rank $n$ vector bundle with structure group $G$ (using the same representation as above) and compatible connection $\nabla$. The function $\Phi$ induces naturally a function $\widehat\Phi: V \rightarrow \mathbb{R}$, which is equal to $\Phi$ on each fiber $V_x$. Similarly, $\Phi'$ induces a bundle map $\widehat\Phi': V \rightarrow V^*$.

Given any section $v$ of $V$, let $f(x) = \widehat\Phi(v(x))$.
Then given any tangent vector $t \in T_x\mathcal{M}$,
$$
\langle df(x), t\rangle
= \langle \widehat\Phi'(v(x)), \nabla_tv(x)\rangle.
$$

This can be proved by using a curve passing through $x$ and tangent to $t$ and a $G$-frame parallel translated along the curve and writing the section $v$ in terms of the frame.