-
Notifications
You must be signed in to change notification settings - Fork 417
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
contrib/database/sql: prevent DBM propagation full mode with incompatible dbs #2328
Changes from 4 commits
b8a0110
0fb5df6
02ae892
2154437
34d61b3
b8f8bda
b0096c4
4c9ef99
e13e2c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,9 +123,7 @@ func Register(driverName string, driver driver.Driver, opts ...RegisterOption) { | |
|
||
cfg := new(config) | ||
defaults(cfg, driverName, nil) | ||
for _, fn := range opts { | ||
fn(cfg) | ||
} | ||
processOptions(cfg, driverName, opts...) | ||
log.Debug("contrib/database/sql: Registering driver: %s %#v", driverName, cfg) | ||
registeredDrivers.add(driverName, driver, cfg) | ||
} | ||
|
@@ -196,9 +194,7 @@ func OpenDB(c driver.Connector, opts ...Option) *sql.DB { | |
driverName = reflect.TypeOf(c.Driver()).String() | ||
defaults(cfg, driverName, nil) | ||
} | ||
for _, fn := range opts { | ||
fn(cfg) | ||
} | ||
processOptions(cfg, driverName, opts...) | ||
tc := &tracedConnector{ | ||
connector: c, | ||
driverName: driverName, | ||
|
@@ -236,3 +232,29 @@ func Open(driverName, dataSourceName string, opts ...Option) (*sql.DB, error) { | |
} | ||
return OpenDB(&dsnConnector{dsn: dataSourceName, driver: d}, opts...), nil | ||
} | ||
|
||
func processOptions(cfg *config, driverName string, opts ...Option) { | ||
for _, fn := range opts { | ||
fn(cfg) | ||
} | ||
checkDBMPropagation(cfg, driverName) | ||
} | ||
|
||
func checkDBMPropagation(cfg *config, driverName string) { | ||
fullModeSupported := func() bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious about style: why make this an inner anonymous function rather than a named function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it was just a matter of namespacing (this way I could use a shorter function name instead of |
||
unsupportedDrivers := []string{"sqlserver", "oracle"} | ||
for _, dr := range unsupportedDrivers { | ||
if dr == driverName { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks a bit brittle, tell me if I'm wrong, but it looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obviously take my perspective with a grain of salt since I'm not an owner/maintainer for the go tracer but I agree that the driverName based logic is somewhat brittle. I know it's done in other places but I wonder if we could still consider doing type checking on the Something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree! I've added a new way to detect the driver, following this logic:
please let me know what you think @vandonr @alexandre-normand |
||
return false | ||
} | ||
} | ||
return true | ||
} | ||
if cfg.dbmPropagationMode == tracer.DBMPropagationModeFull && !fullModeSupported() { | ||
log.Warn("Using DBM_PROPAGATION_MODE in 'full' mode is not supported for %s. See "+ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might make sense here to state that we're downgrading to |
||
"https://docs.datadoghq.com/database_monitoring/connect_dbm_and_apm/ for more info.", | ||
driverName, | ||
) | ||
cfg.dbmPropagationMode = tracer.DBMPropagationModeService | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to have a test that goes through the implicit driver registration (i.e. when a user doesn't call
Register
and usesOpen
directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch! adding it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇