Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow using span name from query comment rather than sql #100

Open
BusyByte opened this issue Apr 21, 2023 · 1 comment
Open

allow using span name from query comment rather than sql #100

BusyByte opened this issue Apr 21, 2023 · 1 comment

Comments

@BusyByte
Copy link

BusyByte commented Apr 21, 2023

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.

@BusyByte BusyByte changed the title allow using span name from query comment rather than allow using span name from query comment rather than sql Apr 26, 2023
@BusyByte
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant