Skip to content

Expose driverInstance and driverInstanceNoProcess or processQueryText for APM tracing #774

Open
@nacho692

Description

@nacho692

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions