instrumentedsql icon indicating copy to clipboard operation
instrumentedsql copied to clipboard

Does this library work with sqlx?

Open pavelnikolov opened this issue 7 years ago • 2 comments

I tried using this library with sqlx, but I cannot get it working. Any ideas how to solve this problem? My goal is to make instrumentedsql work with named queries.

My code bebfore:

db, err := sqlx.Open("postgres", config.DB.URL)

after:

	sql.Register("instrumented-postgres", instrumentedsql.WrapDriver(&pq.Driver{}, instrumentedsql.WithTracer(opentracingsql.NewTracer())))
	db, err := sql.Open("instrumented-postgres", config.DB.URL)

Tracing works just fine, but now I get "pq: syntax error at end of input" errors.

pavelnikolov avatar Dec 09 '17 07:12 pavelnikolov

I managed to get sqlx working with the pq driver and instrumentedsql using the following code:

	sql.Register("instrumented-postgres", instrumentedsql.WrapDriver(&pq.Driver{}, instrumentedsql.WithTracer(opentracingsql.NewTracer())))
	db, err := sql.Open("instrumented-postgres", config.DB.URL)
        ...
        dbx := sqlx.NewDb(db, "postgres")

pavelnikolov avatar Dec 13 '17 20:12 pavelnikolov

Thanks @pavelnikolov! you saved my day!

A-Kamaee avatar Oct 29 '21 14:10 A-Kamaee