twitter/querulous — pull request #36 by johanoskarsson (2012-01-20 19:22:48+00:00)
Title: Annotations in the Query, sent as SQL comments

This patch allows key value annotations to be added to a particular Query. This is then serialized into a c-style comment block that is appended to the query before it is sent off to the database.

The other change in this patch uses the annotations to set the trace_id if the trace has been set to be sampled. This allows us to look at slow query logs and from the trace id there find out more about where the query came from and sometimes even the url hit that caused the slow query.

Things worth considering:
* had to delay creation of the prepared statement till when the query is executed. This is because the flow in using Querulous with tracing enabled is 1) create Query 2) add annotation 3) execute query. In the old code with this flow the extra annotations section in the sql could not be injected into the prepared statement since that had already been created in the SqlQuery constructor.
* one side effect of delaying statement creation is that validation of params doesn't happen until execution
* are there any multithreaded considerations to the above change?