Let $f,g$ be entire functions, then the argument principle teaches us that
$$\frac{1}{2\pi i}\int_{\mathbb{C}} g(z) \frac{f'(z)}{f(z)} dz$$ is equal to $g$ evaluated at the zeros of $f.$
Now, let us assume that $f: \mathbb{C} \rightarrow \mathbb{C}^{2 \times 2}$ is matrix-valued and holomorphic.
If $f$ is diagonal, then it follows from the above theorem that $$\operatorname{tr}\left(\frac{1}{2\pi i}\int_{\mathbb{C}} g(z) Df(z)f(z)^{-1} dz\right)$$ is precisely $g$ evaluated at the singular points of $f$, i.e. the points $z$ for which $\operatorname{det}(f(z))=0$ times $2-\text{rank}(f(z))$ at those points.
I ask: If $f$ is now not assumed to be diagonal, but only self-adjoint, does this statement hold true, i.e. $$\operatorname{tr}\left(\frac{1}{2\pi i}\int_{\mathbb{C}} g(z) Df(z)f(z)^{-1} dz\right)=\sum_{z \in \mathbb{C}; \operatorname{det}(f(z))=0} g(z) \text{rank}(2-f(z)).$$
An obvious approach would be to use that $f$ is diagonalizable and the properties of the trace, but in this case the unitary transform also depends on $z$, so a bit more care seems to be needed.