I'd like to add some logging\stats to all our DB calls and was wondering if there's an easy way to do it?
I was hoping I could write my own driver and somehow "wrap" the original (mySql or Postgres) driver, redirecting calls and keeping some stats but the drivers
hash is private in the database\sql package. Any other ideas?
评论:
themissedsymphony:
eyalpost:https://github.com/ExpansiveWorlds/instrumentedsql is quite good for wrapping and then logging!
monkey_that:Nice! I wasn't even aware that both the mysql and postgres drivers expose the Driver struct so I can reference it directly. Thanks!
eyalpost:You can wrap sql.DB in another struct, then implement needed interfaces such as Query, Exec that will pass all the arguments to an actual sql.DB, in the mean time you can measure and log.
For more advanced method look at this https://github.com/marcusolsson/goddd
fortytw2:That's a good direction, thanks! Although I was looking for something that can be done "behind the scenes" (i.e. just by adding a reference to my package).
AnimalMachine:Extra easy if you're using postgres - throw in a quick
db.Exec(`LOAD 'auto_explain';`) db.Exec(`SET auto_explain.log_min_duration = 0;`)
then check the logs of your postgres instance (running in the foreground, in docker makes this super easy for development)
GentooMonk:edit: i had supplied some profiling tips, but it was getting down voted. /r/golang is getting to be as good as the rest of reddit it seems. :(
zuzzas:sadly :(
AnimalMachine:i had supplied some profiling tips, but it was getting down voted
And you've removed your potentially useful advice, because a couple of imaginary internet points were taken from you?
skidooer:Community said it wasn't valuable. And it's probably my last act of protest on reddit.
Where did the community say it wasn't valuable?
A downvote doesn't say anything. For all we know someone accidentally clicked on the wrong button.
