In fact, there are many examples where this happens. And as you suggested, it comes from an algebraic point of view; namely in the area of what are called fusion categories. These are categories which come with quite a bit of data to begin with. In particular, they are monoidal, there is some notion of simple objects, have duals and evaluation $$\epsilon:a\otimes a^*\longrightarrow 1$$ and coevaluation maps$$\hat{\epsilon}:\mathbb{1}\longrightarrow a\otimes a^*$$ associated to every object $a$. We can then define the trace of a morphism $f:a\longrightarrow a$ to be the composite $$1\xrightarrow{\epsilon}a\otimes a^* \xrightarrow{f\otimes id}a\otimes a^*\xrightarrow{\hat{\epsilon}}1$$
which is an element of the endomorphism ring of the unit object $1$ (this ring often happens to be a field). (For the sake of brevity I'll from here on assume that these categories are spherical, i.e. left trace agrees with right trace so we don't have to make any overly complicated distictions. If the category is not spherical we can still get some notion of dimension, called the squared norm of an object but I'm trying to keep this compact). The dimension of an object is then, as you suggested, defined to be $tr(id_a)$.
An example of such a category is the so-called Fibonnaci category. It has two simple objects, $X$ and $1$ with $X=X^* = $ $ ^{*}X$ and $X\otimes X= 1 \oplus X$. Using monoidality and additivity of all functors, we can then calculate $$dim(X) = (1+\sqrt{5})/2.$$
There is a plethora of such categories, this is just one example. I hope I could get the ideas across!