I won't be able to give any references, so I hope some more experts can help me out, as there is much work on traces of functors. In general, there are two reasonable notions of "trace" of a functor, and they can be different. Throughout, I let $F$ denote an endofunctor of a nice-enough ($\mathbb C$-linear, etc.) category $\mathcal C$, and $\DeclareMathOperator\id{id}\id$ the identity functor.
Then one notion of "trace" is:
$$ \operatorname{trace}(F) = \hom(\id,F)$$
where the $\hom$ is taken in the (monoidal) category $\operatorname{End}(\mathcal C)$ of endofunctors of $\mathcal C$, i.e. it is the space of natural transformations. For this definition to make sense, we need only that $\mathcal C$ is small enough for $\operatorname{End}(\mathcal C)$ to be locally small (otherwise, for generic categories, the hom spaces between functors can be proper classes), or at least for $\hom(\id,F)$ to be small. In the $\mathbb C$-linear setting, one expects that $\hom(\id,F) \in \mathrm{Vect}$, and in fact it is a $\hom(\id,\id)$-module. Note that $\hom(\id,\id)$ is always an algebra. In fact, since $\operatorname{End}(\mathcal C)$ is a monoidal category, $\hom(\id,\id)$ is always a commutative algebra.
For example, when choose a $\mathbb C$-algebra $A$, and let $\mathcal C$ denote the category of left $A$-modules. Then $\hom(\id,\id)$ is the center of $A$.
There is an important generalization: work not with categories but $(\infty,1)$-categories. Then one can set $\mathcal C$ to be an appropriate "derived" category of chain complexes of $A$-modules, and $\hom(\id,\id)$ is then the Hochschild cochain complex of $A$.
There is another important notion of "trace", which is given by an end (or is it a coend?) of the functor $\hom(-,F-)$. This notion is slightly closer to the idea of "adding up the diagonal entries of a matrix for $F$". In the $A$-module case, this version gives $\operatorname{trace}(\id) = A / [A,A]$, where $[A,A]$ is the subvector space of commutators (and not an ideal or anything), so that the quotient is simply a vector space (with a distinugished element, namely the image of $1\in A$). In the derived setting, one gets the Hochschild chains of $A$.
The two constructions must give canonically-the-same answer if $\mathcal C$ is the image of an oriented but otherwise unframed 2-TQFT. But if you work with framed TQFTs, they can give different answers. Recall that a 2-framing of a 1-manifold $S$ is a framing of $S\times \mathbb R$, and that a framing of an $n$-manifold is a collection of $n$ vector fields which are at every point linearly independent.
The first "trace" corresponds to the circle with "outward" framing, i.e. it has a "2-framing" inherited from embedding the circle as a simple closed curve in $\mathbb R^2$. The second trace corresponds to the "product" framing, i.e. the framed circle where one of the two vector fields is parallel to the circle and the other is orthogonal.
When thought of in this geometric picture, the "Deligne conjecture" that Hochschild chains has a homotopy-$S^1$-action becomes natural, and Hochschild cochains have their $E_2$-algebra structure coming from embedding two disks into a larger disk.
Actually, if you have a complete framed 2-dimensional TQFT which assigns $\mathcal C$ to a point, then the two notions of trace must agree for $\id$, at least in dimension. I mean, if you look at the torus (with its unique framing), the value of the torus must be the dimension of each $\operatorname{trace}(\id)$, by cutting the framed torus into an annulus in two different ways. A framed 2-TQFT does not pick out a chosen isomorphism between the two different traces, and I believe that any choice of such an isomorphism is pretty much enough to extend the framed TQFT to an unframed one. Algebras with such a choice are called "Calabi–Yau", at least by some people, because the data of such an isomorphism is roughly the same (when $A$ is commutative) as a trivialization of the canonical line of $\operatorname{Spec}(A)$.