Skip to content

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

@BusyByte

Description

@BusyByte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions