SQLcommenter is a plugin/middleware/wrapper to augment application related information/tags with SQL Statements that can be used later to correlate user code with SQL statements.
- Clone the source
- In terminal go inside the client folder location where we need to import sqlcommenter go-sql module and enter the below commands
go mod edit -replace google.com/sqlcommenter=path/to/google/sqlcommenter/go-sql
go mod tiny
go get google.com/sqlcommenter/gosqlPlease use the sqlcommenter's default go-sql database driver to execute statements.
Due to inherent nature of Go, the safer way to pass information from framework to database driver is via context. So, it is recommended to use the context based methods of DB interface like QueryContext, ExecContext and PrepareContext.
db, err := sqlcommenter.Open("<driver>", "<connectionString>", sqlcommenter.CommenterOptions{<tag>:<bool>})Users are given control over what tags they want to append by using core.CommenterOptions struct.
type CommenterOptions struct {
EnableDBDriver bool
EnableTraceparent bool // OpenTelemetry trace information
EnableRoute bool // applicable for web frameworks
EnableFramework bool // applicable for web frameworks
EnableController bool // applicable for web frameworks
EnableAction bool // applicable for web frameworks
}With Go SqlCommenter, we have configuration to choose which tags to be appended to the comment.
| Options | Included by default? | go-sql-driver |
|---|---|---|
DBDriver |
go-sql-driver |