Taking a trace using a continuous spectrum of eigenstates This may be a simple question, but I have not been able to find an adequate discussion in any source that quite answers it.  
In many cases in quantum mechanics, traces are evaluated using the discrete spectrum of the Hamiltonian: $Tr[A] = \sum \langle n|A|n\rangle$. Is there a generalization for a Hamiltonian with a continuous spectrum? As a specific example, take $H=\frac{p^2}{2}$, the non-relativistic free particle Hamiltonian. The eigenvalues of the Hamiltonian are just momentum eigenstates, with corresponding energies $E(p) = p^2/2$. So we could write the energy eigenstates as $|E,\pm\rangle$, where $E$ ranges from 0 to $\infty$ and plus/minus denotes right/left moving particles. 
Say I want to calculate the partition function, $Z(\beta) = Tr[e^{-\beta H}]$. If I try this naively by expanding the trace in the momentum basis, I get $$Z(\beta) = \int_{\mathbb{R}} dp \langle p | e^{-\beta p^2/2} | p \rangle = \int dp e^{-\beta p^2 /2} \delta(0) = \delta(0)\sqrt{\frac{2\pi}{\beta}}.$$ 
On the other hand, if I expand in the energy eigenbasis, I would naively get $$Z(\beta) = \sum\limits_{s\in\{+,-\}}\int_{\mathbb{R}\geq0} dE \langle E,s| e^{-\beta H} | E,s \rangle = 2\int dE e^{-\beta E} \delta(0) = \frac{2}{\beta}\delta(0),$$ which is not the same as above. 
My suspicion of what went wrong in this particular calculation is that the measure for evaluating the trace in the energy basis was incorrect (it might be possible to see this by changing variables in the momentum basis integral), but I am not sure. My second suspicion is that rigged Hilbert space formalism may be able to clear up the ambiguity. Regardless, it would be useful to see under what conditions an integral-type trace as above exists and is well-defined.  
 A: The momentum eigenvalue density of states is $dp/2\pi$ per unit volume. The momentum-density-of-states   partition function for $H=\hat p^2$ is therefore 
$$
{\rm Vol} \int_{-\infty}^{\infty} \frac{dp}{2\pi} e^{-\beta p^2} ={\rm Vol} \frac 1{2\pi}\sqrt{\frac{\pi}{\beta}}. 
$$
Since $dE = dp^2 = 2p dp= 2\sqrt E \,dp$ the energy eigenvalue density of states per unit volume is 
$ dE/\sqrt E$. This is twice  as big as one would expect from the expression for $dE $. This doubling is  because  the energy range $E=(0,\infty)$ is covered twice as $p$ rangers from $-\infty$ to $\infty$. The energy
trace per unit volume  is therefore 
$$
\int_0^\infty e^{-\beta E}  E^{-1/2} \frac{dE}{2\pi}= \frac{1}{2\pi \sqrt\beta} \Gamma(1/2)= \frac{1}{2\pi \sqrt \beta}\sqrt \pi,  
$$
which is the same as the momentum calculation. 
A useful observation is   that  $\delta(0)$ in position space, while not mathematically well  defined,  has the physical interpretatation  density of momentum states per unit spatial volume. Meanwhile  the equation 
$$
\int_{-\infty}^\infty e^{ikx} dx=2\pi \delta(k)
$$ s
shows that 
$2\pi \delta(0)$ in momentum space is the volume of the system. 
