This repository was archived by the owner on May 29, 2026. It is now read-only.
Description EnableController is available on the CommenterConfig struct (
), however, the code that outputs the SQL comment does not output a comment for the
controller context key (
func (conn * sqlCommenterConn ) withComment (ctx context.Context , query string ) string {
var commentsMap = map [string ]string {}
query = strings .TrimSpace (query )
config := conn .options .Config
// Sorted alphabetically
if config .EnableAction && (ctx .Value (core .Action ) != nil ) {
commentsMap [core .Action ] = ctx .Value (core .Action ).(string )
}
// `driver` information should not be coming from framework.
// So, explicitly adding that here.
if config .EnableDBDriver {
commentsMap [core .Driver ] = fmt .Sprintf ("database/sql:%s" , conn .options .Tags .DriverName )
}
if config .EnableFramework && (ctx .Value (core .Framework ) != nil ) {
commentsMap [core .Framework ] = ctx .Value (core .Framework ).(string )
}
if config .EnableRoute && (ctx .Value (core .Route ) != nil ) {
commentsMap [core .Route ] = ctx .Value (core .Route ).(string )
}
if config .EnableTraceparent {
carrier := core .ExtractTraceparent (ctx )
if val , ok := carrier ["traceparent" ]; ok {
commentsMap [core .Traceparent ] = val
}
}
if config .EnableApplication {
if ! attemptedToAutosetApplication && conn .options .Tags .Application == "" {
attemptedToAutosetApplication = true
bi , ok := debug .ReadBuildInfo ()
if ok {
conn .options .Tags .Application = bi .Path
}
}
if conn .options .Tags .Application != "" {
commentsMap [core .Application ] = conn .options .Tags .Application
}
}
var commentsString string = ""
if len (commentsMap ) > 0 { // Converts comments map to string and appends it to query
commentsString = fmt .Sprintf ("/*%s*/" , core .ConvertMapToComment (commentsMap ))
}
// A semicolon at the end of the SQL statement means the query ends there.
// We need to insert the comment before that to be considered as part of the SQL statemtent.
if query [len (query )- 1 :] == ";" {
return fmt .Sprintf ("%s%s;" , strings .TrimSuffix (query , ";" ), commentsString )
}
return fmt .Sprintf ("%s%s" , query , commentsString )
}
).
I will plan to open a PR for this.
Reactions are currently unavailable
EnableControlleris available on theCommenterConfigstruct (sqlcommenter/go/core/core.go
Line 48 in c447d21
controllercontext key (sqlcommenter/go/database/sql/connection.go
Lines 94 to 149 in c447d21
I will plan to open a PR for this.