newrelic / go-agent

New Relic Go Agent
Apache License 2.0
768 stars 295 forks source link

nrpgx - support functions like stdlib.RegisterConnConfig that only operate on the default pgx driver #435

Open bschoch-transcarent opened 2 years ago

bschoch-transcarent commented 2 years ago

Summary

stdlib.RegisterConnConfig allows you to use a *pgx.ConnConfig object to instantiate a sql.DB object

In our use case we were not writing the certificates to a file and were just adding them to the *pgx.ConnConfig object which is not possible with a connection string.

stdlib.RegisterConnConfig only updates the stdlib.GetDefaultDriver()

nrpgx does not wrap the stdlib.GetDefaultDriver() but rather an empty &stdlib.Driver{}, if it wrapped the default driver than all of the advanced pgx configuration options can be used

Desired Behaviour

Be able to use the strings returned from stdlib.RegisterConnConfig when opening the nrpgx driver

Possible Solution

https://github.com/newrelic/go-agent/blob/master/v3/integrations/nrpgx/nrpgx.go#L88 When I replaced the above line with sql.Register("nrpgx", newrelic.InstrumentSQLDriver(stdlib.GetDefaultDriver(), baseBuilder))

I was able to instrument new relic and instantiate my db with this line

db, err := sql.Open("nrpgx", stdlib.RegisterConnConfig(pgConfig.ConnConfig))

Additional context

If this was ported from https://github.com/newrelic/go-agent/tree/master/v3/integrations/nrpq lib/pq did not have these configuration options so this may have been over looked

Ak-x commented 2 years ago

This will be resolved by the completion of: https://github.com/newrelic/go-agent/issues/396