The metric function is continuous, therefore measurable.
One can show that measurable functions can be built with a hierarchy similar to the Borel hierarchy. You start with continuous functions (into $\mathbb R$), then take pointwise limits, and reiterate $\omega_1$ many steps (each time taking pointwise limits of previously defined stages).
This is done by taking functions that preserve $\Sigma^0_\alpha$ and $\Pi^0_\alpha$ sets (i.e. a preimage of a $\Sigma^0_\alpha(\mathbb R)$ is $\Sigma^0_\alpha(X)$, similarly for $\Pi$. Continuous functions are indeed the first level, as preimage of open/closed set is an open/closed set), and prove by induction that the pointwise limits behave as we would like.