In real time, one can calculate the two point function of a given theory using
\begin{equation} G(\vec{x},t)=\langle \Omega | \phi(\vec{x},t)\phi^\dagger (0,0)|\Omega\rangle =\int_{\phi(0,0)}^{\phi(\vec{x},t)} \mathcal{D}\phi\ e^{-\frac{i}{\hbar}S[\phi]}\phi(\vec{x}',t')\phi(\vec{x},t) \end{equation}
where the limits of the path integral should match the initial and final state.
On the other hand, I know that the generating functional $\mathcal{Z}$
\begin{equation} \mathcal{Z}=\langle\phi'|e^{-iHT}|\phi\rangle=\int_\phi^{\phi'}e^{-\frac{i}{\hbar}S[\phi]} \end{equation}
can be identified with the quantum partition function $Z$ if we evaluate on imaginary time $t=-i\tau$ and we trace over the initial and final state
\begin{equation} Z=\sum_{\phi}\langle \phi | e^{-\beta H}|\phi\rangle =\int_{\phi(0)=\phi(\beta)}e^{-\beta S_E[\phi]} \end{equation}
So the relation between quantum mechanical and thermodynamic expectation values is: analytically continuate $t\rightarrow -i\tau$ with period $\tau \in [0,\beta]$, set inital and final states equal and sum over them. Now, in every book I see, the real time Green's function
\begin{equation} G(\vec{x},t)= \langle \Omega | \phi(\vec{x},t)\phi^\dagger (0,0)|\Omega\rangle \end{equation}
and the imaginary time Green's function
\begin{equation} \mathcal{G}(\vec{x},\tau)= \frac{1}{Z}\text{Tr}\Big[e^{-\beta H} \phi(\vec{x},\tau)\phi^\dagger (0,0)\Big] \end{equation}
are related by
\begin{equation} G(\vec{x},t)=\mathcal{G}(\vec{x},i\tau) \end{equation}
Meaning that we could basically define just one function $G(\vec{x},z)$ with $z\in\mathcal{C}$ that is equal to the Green Function of QM for real $z$ and equal to the thermodynamic average for imaginary $z$.
My question is the following
In the Path integral formalism, there were to things we needed to do to go from one average to the other; we need to go to imaginary time and we need to do something about the trace. In the Green's functions, however, it seems that going to imaginary time is enough, as if the trace gets automatically taken care of. How is that so?