Skip to content

Add support for 'traceQueries' DSN configuration parameter #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

gm42
Copy link

@gm42 gm42 commented Apr 8, 2016

Description

This is a proposal for a way to trace each and every SQL query being executed by the driver. I do not expect it to be merged in its current form but rather please give me some feedback about how to achieve the purpose:

  • being able to trace the SQL connections executed by a single goroutine

Right now I am printing them to errLog, although I'd possibly use a separate logger (as these are not really errors). It's also a common desire to be able to turn on/off the feature at runtime, which would require yet another mutex (I am not particularly happy about the one introduced here either).

Checklist

  • Code compiles correctly
  • Created tests which fail without the change
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

Edit: renamed the parameter from debugQueries to traceQueries

@gm42 gm42 force-pushed the feature/debug-queries branch 2 times, most recently from a653cba to 72940f5 Compare April 8, 2016 12:18
@methane
Copy link
Member

methane commented Apr 8, 2016

Why do you want to do this in driver level instead of higher level?

@gm42 gm42 force-pushed the feature/debug-queries branch from 72940f5 to 3260325 Compare April 8, 2016 12:20
@gm42
Copy link
Author

gm42 commented Apr 8, 2016

@methane I am using packages that wrap the driver and I am using the driver itself; by printing the information I need just before it's actually being executed I have a convenient central location from where to collect it; but I think that's obvious already?

@gm42 gm42 force-pushed the feature/debug-queries branch 2 times, most recently from 97fb693 to ee2f46b Compare April 8, 2016 12:31
@methane
Copy link
Member

methane commented Apr 8, 2016

For example, gorp have logging feature.
You can also custom (hand made) query through gorp. https://godoc.org/github.com/coopernurse/gorp#DbMap.Exec

Since DSN limitation, it's difficult to configure logging. (format, logger, etc...)
I think database/sql package or package wraps it should provide more flexible logging support.

@gm42
Copy link
Author

gm42 commented Apr 8, 2016

I agree, this should better be at database/sql level. Here in this proposal I was piggybacking on the existing logging feature of this driver.

I am looking at a general solution that allows me to capture all interactions of my Go application with the MySQL server.

Alternatively, one could write a shim package for go-sql-driver/mysql and wrap the methods there.

@methane
Copy link
Member

methane commented Apr 8, 2016

FYI: This pull request doesn't log query executed without prepared statement.

@gm42
Copy link
Author

gm42 commented Apr 8, 2016

@methane I will fix that, thanks for reporting

@gm42 gm42 force-pushed the feature/debug-queries branch from f62309e to 4c088bd Compare April 8, 2016 13:17
@gm42 gm42 changed the title Add support for 'debugQueries' DSN configuration parameter Add support for 'traceQueries' DSN configuration parameter May 13, 2016
@gm42 gm42 force-pushed the feature/debug-queries branch from 3e4d431 to 15a568f Compare March 31, 2017 12:24
@gm42
Copy link
Author

gm42 commented Mar 31, 2017

FYI I have just re-based & squashed this PR

Add some missing debugging for query/exec methods
Print information about MySQL connection involved
@bgaifullin
Copy link
Contributor

@gm42 https://github.com/mailru/dbr has instruments to trace queries and it is driver agnostic.

@dolmen
Copy link
Contributor

dolmen commented Jun 15, 2018

Use https://github.com/luna-duclos/instrumentedsql which is able to wrap any driver for logging or other use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants