allow using span name from query comment rather than sql
BusyByte opened this issue · comments
Given a comment on the first line could we have our span name be or have selectLatestFooBar
in it?
-- Name: selectLatestFooBar
select
foo,
bar
from baz;
Currently we do this for metrics and would be nice for traces as well.
We parse the sql like so:
private val re = """--\s*Name:\s*(\w+)""".r
def extractQueryNameOrSql(sql: String): String = {
re.findFirstMatchIn(sql).flatMap(m => Option(m.group(1))).getOrElse(sql)
}
If it happened to not have a comment in it then you could default back to your current way you display the sql (com.ovoenergy.natchez.extras.doobie.TracedTransactor$#formatQuery)
We are currently on 6.25 of natchez-extras-doobie but would likely upgrade to newer version if we need newer version of natchez.
This could also be generalized to a qualifier function from Sql => Span Name but this is not binary compatible unless you wanted a default on another parameter. We are using the trace function on TracedTransctor currently but I think this would also need to be added on the apply as well. Let me know if you want me to go down that route. I didn't think there was any harm to doing this as it's probably not a common thing. But an addition parameter would let people opt into this behavior.