Tracking down slow queries in Ecto

It really isn’t. As I said we make thousands of ecto queries per second and setting stacktrace: true has been perfectly fine.

People should definitely set top level traces, but that doesn’t help if you get a trace for an ecto query that happens outside of any top level trace. In a large code base it’s difficult to get 100% coverage of all entry points and so it can be tricky to sort out where a given ecto query is coming from. If you can at least get a stacktrace for where in the code the query came from you can work your way back up.

Top level traces also don’t help if you make many queries that have the same SQL but in different places have very different arguments.

Tl;DR: stacktraces rock, it’s useful to use them in combination with top level traces.

2 Likes