The Ngram says here that both expressions are used; however, I think "the history" is the correct expression because there is one history like when you write "the sun". On the other hand, my gut is telling me that "in history" is the word. I think only a native English speaker can tell which one I should use in formal situation.
It depends on whether you mean "history" as the broad concept, or as a concrete example with a narrower focus. Both are fine in a formal context.
He is the greatest general in history
He is the greatest general in the history of Europe
Additionally, you can still reference the concept, but limit to a particular subset:
He is the greatest general in European history.
Note there are many English nouns that act in the same way, for example "cuisine":
It is the most difficult dish in all cuisine.
It is the most difficult dish in all of the cuisine of India.
It is the most difficult dish in all Indian cuisine.