On a Riemannian manifold, the trace $X$ of a tensor $X_{\mu\nu}$ is defined as $$X=g^{\mu\nu}X_{\mu\nu}.$$ In linear algebra, the trace is the sum of the diagonal elements, so a traceless matrix has the diagonal elements sum to zero. For a traceless tensor $X_{\mu\nu}$, the sum of the diagonal elements in the matrix $[X_{\mu\nu}]$ will in general not be zero.
Why then do we use the concept of 'trace' for tensors if the diagonal elements don't sum to zero? Is there some sort of connection between the concept of trace for linear algebra & tensors?