  The trace of the canonical module (the canonical trace) determines the
non-Gorenstein locus of a local Cohen--Macaulay ring. We call a local
Cohen--Macaulay ring nearly Gorenstein, if its canonical trace contains the
maximal ideal. Similar definitions can be made for positively graded
Cohen--Macaulay $K$-algebras. We study the canonical trace for tensor products
and Segre products of algebras, as well as of (squarefree) Veronese
subalgebras. The results are used to classify the nearly Gorenstein Hibi rings.
We study connections between the class of nearly Gorenstein rings and that of
almost Gorenstein rings. We show that in dimension one, the former class
includes the latter.
