Add setTraceFunction() method to query

This allows the developer to track when a query starts and ends
for logging/timing/debugging purposes. There is also a global
Query.setGlobalTraceFunction() that applies the trace function
to all queries.

The trace function is passed information about the query, and is
expected to return a function that will be called with information
about the result.