You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I'm trying to use the otelsql instrumentation and running into a problem when I begin a transaction.
Describe the solution you'd like
Currently stdDriver only implements driver.Conn https://pkg.go.dev/database/sql/driver#Conn e.g. It exposes a BeginTx method, which is allegedly deprecated:
typeConninterface {
...// Begin starts and returns a new transaction.//// Deprecated: Drivers should implement ConnBeginTx instead (or additionally).Begin() ([Tx](https://pkg.go.dev/database/sql/driver#Tx), [error](https://pkg.go.dev/builtin#error))
According to the interface definition, we'll need to check the txn options argument and return some errors if ReadOnly and some Isolation levels aren't supported. Here's how the standard library does these checks, so we can do something similar. https://github.com/golang/go/blob/master/src/database/sql/ctxutil.go#L110
i.e. add something like this:
func (std*stdDriver) BeginTx(ctx context.Context, optsTxOptions) (Tx, error) {
ifopts!=nil {
// Check the transaction level. If the transaction level is non-default// then return an error here as the BeginTx driver value is not supported.ifopts.Isolation!=LevelDefault {
returnnil, errors.New("sql: driver does not support non-default isolation level")
}
// If a read-only transaction is requested return an error as the// BeginTx driver value is not supported.ifopts.ReadOnly {
returnnil, errors.New("sql: driver does not support read-only transactions")
}
}
ifctx.Done() ==nil {
returnstd.Begin()
}
}
Describe alternatives you've considered
If we don't want to implement this interface, maybe I can get the otelsql to support using the deprecated Begin method
Additional context
std library calling BeginTx on otConn
otConn returning the err cause stdDriver doesn't implement BeginTx
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I'm trying to use the otelsql instrumentation and running into a problem when I begin a transaction.
otelsql's driver.Conn implementation does implement ConnBeginTx, so golang will call it's BeginTx method
https://github.com/golang/go/blob/master/src/database/sql/ctxutil.go#L98
otelsql expects it's connection to also implement the ConnBeginTx interface, so this will return an err
https://github.com/XSAM/otelsql/blob/main/conn.go#L170
Describe the solution you'd like
Currently stdDriver only implements driver.Conn https://pkg.go.dev/database/sql/driver#Conn e.g. It exposes a BeginTx method, which is allegedly deprecated:
We could add an additional BeginTx method to the struct so it will implement ConnBeginTx
https://pkg.go.dev/database/sql/driver#ConnBeginTx
According to the interface definition, we'll need to check the txn options argument and return some errors if ReadOnly and some Isolation levels aren't supported. Here's how the standard library does these checks, so we can do something similar.
https://github.com/golang/go/blob/master/src/database/sql/ctxutil.go#L110
i.e. add something like this:
Describe alternatives you've considered
If we don't want to implement this interface, maybe I can get the otelsql to support using the deprecated Begin method
Additional context
std library calling BeginTx on otConn

otConn returning the err cause stdDriver doesn't implement BeginTx

The text was updated successfully, but these errors were encountered: