Conversation
Queries prefixed with a "-- name: ..." comment, such as sqlc emits, made the default operation-name parser return "--", which became the span name too once span names started defaulting to the operation name. Skip leading "--" line comments and "/* */" block comments before taking the first word. Fixes #63 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
go.mod requires go 1.25, so the "!go1.24" implementation could never compile and the "go1.24" tags were always satisfied. Consolidate into a single implementation and drop the now-meaningless build tags. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
do the string cuts cause a new allocation? I think they don't.
If that's the case, it may be a good idea to clone the string before returning, to avoid keeping a reference to the whole query. Otherwise we could keep large queries from being collected by the GC as long as the span is live.
I guess it depends if the string we see here is the "raw" query without template substitutions (from which we'd have a single copy in memory) or the templated query, from which we may have arbitrarily many. 🤔
Maybe it's premature optimization...
|
Spending 20-25 ns to get better span names seems worth it to me, and trying to optimize it should not be a blocker for getting this merged, in my opinion. :) |
|
FWiW, I pulled this fix into my project to test it, and it worked as described. Excited to see this land. |
|
I'd also say we merge this as is and see if we can further optimize this down the line, if needed. @costela any objections? Otherwise I'd merge it. |
Fixes #63.
Queries that start with a SQL comment (sqlc's
-- name: GetFoo :oneprefix is the common case) made the default operation-name parser return--fordb.operation.name, and since v0.12.0 for the span name as well. The default parser now skips leading--line comments and/* */block comments before taking the first word. A user-suppliedWithSpanNameFuncis unaffected and still sees the raw statement.Second commit removes the
go1.24build constraints:go.modrequires 1.25, so the!go1.24variant never compiled and the tags were always satisfied.Benchmark
BenchmarkDefaultSpanNameCtxFunc, Apple M-series,-count 3median. Zero allocations before and after.332afb9)SELECT ...SELECT-- name: GetFoo :one\nSELECT ...--(wrong)/* name: GetFoo :one */\nSELECT .../*(wrong)The plain case pays about 4 ns for the leading-whitespace trim and two prefix checks. The comment cases were only faster on main because they stopped at the wrong token.
Not in scope
/* /* */ */block comments are not handled and fall back toUNKNOWN. Documented on the helper.GetFoo) is a separate design question, sincespanNameCtxFunccurrently feeds both the span name anddb.operation.name.🤖 Generated with Claude Code