This is captured from a chapter talking about completion of metric space in Real Analysis, Carothers, 1ed:

Definition of completion:

Actually, I cannot understand some parts of the proof.
Generally, to show $M_1$ and $M_2$ are isometric, we need to prove that map $f$ is both $1-1$, onto and its preservation of distance from $M_1$ to $M_2$ as well and vice-versa. Since we haven't proved its preservation of distance from $M_1$ to $M_2$, how to get "$d_2(x_n, z_n) = d_1(x_n,z_n) = d(x_n,z_n) \rightarrow 0$"? I mean before "$d_2(x_n, z_n) = $d_1(x_n,z_n) = d(x_n,z_n) \rightarrow 0$$", it seems that we haven't proved the $d_1 = d_2$ that is the preservation of distance.
Why should we find two sequences, $\{x_n\}$ and $\{z_n\}$, in $M$? Why not one of them?
This proof is based on the suppose that $M$ is actually a subset of $M_1$ and $M_2$, which, in my opinion, nevertheless is a particular example of $M_1$ and $M_2$. I mean M may not be a subset of M1 and M2 or even, intersection of M1 and M or M2 and M are both empty. More precisely, Completion of M should not inherit some elements from the original space M, according to definition of completion, which push me into a deep thinking that does isometry will preserve the elements from the original space into a new space? My idea seems to be a little weird. But hope to figure them out.
To show that they are isometric you need to show a distance preserving bijection between them.
We have three spaces and distances $(M,d), (M_1,d_1), (M_2, d_2)$.
We have isometries $i_1:M \to D_1$, $i_2:M \to D_2$, where $D_k$ is dense (with respect to $d_k$) in $M_k$.
So we have an isometry $\phi:D_1 \to D_2$ given by $\phi = i_2 \circ i_1^{-1}$.
We want to extend $\phi$ so that it is an isometry between $M_1$ and $M_2$.
Let $x \in M_1$, and let $x_n \in D_1$ such that $x_n \to x$ (remember, $D_1$ is dense in $M_1$). Then $x_n$ is Cauchy, and $y_n = \phi(x_n)$ is also Cauchy (since $\phi$ is an isometry), and converges to some $y \in M_2$.
Before we extend $\phi$ by defining $\tilde{\phi}(x) = y$, we need to check that this is well defined, that is, if $x_n' \to x$ is another sequence, then we need to check that $y_n'=\phi(x_n')$ converges to the same point. We have $d_2(y, y_n') \le d_2(y,y_n)+d_2(y_n,y_n')$. We know that $d_2(y,y_n) \to 0$, and $d_2(y_n,y_n') = d_1(x_n,x_n')$, and furthermore, $d_1(x_n,x_n') \le d_1(x_n,x)+d_1(x,x_n')$, hence $d_1(x_n,x_n') \to 0$. Hence all such sequences converge to $y$, and so we can define $\tilde{\phi}(x) = y$.
We note that since the sequence $x_n = x$ converges to $x$, we have $\tilde{\phi}(x) = \phi(x)$ whenever $x \in D_1$, as expected. Furthermore, $\tilde{\phi}$ is distance preserving; suppose $x,x' \in M_1$, and $x_n \to x, x_n' \to x'$. Then $d_1(x,x') = \lim_n d_1(x_n,x_n')$. Then $d_2(\tilde{\phi}(x), \tilde{\phi}(x')) = \lim_n d_2(\tilde{\phi}(x_n), \tilde{\phi}(x_n')) = \lim_n d_1(x_n, x_n') = d_1(x,x')$, and so we see that $\tilde{\phi}$ preserves distances.
Note that if $\tilde{\phi}$ preserves distances, it must be injective.
Finally we need to show that $\tilde{\phi}$ is onto. If $y \in M_2$, then we have some $y_n \in D_2$ such that $y_n \to y$. Then $x_n = \phi^{-1} ( y_n)$ is Cauchy in $D_1$ and so $x_n \to x$ for some $x \in M_1$. Hence $d_2(\tilde{\phi}(x), y) = \lim_n d_2(y_n,y) = 0$, and so $\tilde{\phi}(x) = y$, and so $\tilde{\phi}$ is onto.