Skip to content
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

Expose driverInstance and driverInstanceNoProcess or processQueryText for APM tracing #774

Open
nacho692 opened this issue Nov 10, 2022 · 2 comments

Comments

@nacho692
Copy link

nacho692 commented Nov 10, 2022

I'm enabling dd-trace-go over "mssql" driver.

It works by creating a tracing wrapping over the driver. In order to do this, you have to initialize a Driver and register it in the datadog package.

sqltrace.Register(driverName, &mssql.Driver{})

The issue i'm having is that statements with variables stopped working:

Incorrect syntax near '?'."

I know "?" for placeholder is not mssql standard but it used to work before tracing. After some digging I found that defining processQueryText as true correctly fixes this issue.

As I cannot change every statement in the codebase, I am enabling tracing with the help of reflection:

driver := &mssql.Driver{}
dv := reflect.ValueOf(driver).Elem().FieldByName("processQueryText")
dv = reflect.NewAt(dv.Type(), unsafe.Pointer(dv.UnsafeAddr())).Elem()

if dv.IsValid() && dv.CanSet() {
    dv.SetBool(true)
}
sqltrace.Register("mssql", driver)

Maybe it makes sense to expose the driver instances?

@NikitaDef
Copy link
Contributor

I guess, by that.
https://github.com/denisenkom/go-mssqldb#query-parameter-token-replace-driver-mssql

Can you show your query?

@nacho692
Copy link
Author

nacho692 commented Nov 11, 2022

Yep, that's exactly it!
I know I can change the query, but I would like to trace the "mssql" driver instead of the "sqlserver" one

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

No branches or pull requests

2 participants