Skip to content

Commit

Permalink
fix(injector: builtin: sql): driver is not registered from non-instru…
Browse files Browse the repository at this point in the history
…mented sql calls

Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Nov 20, 2024
1 parent 49288e7 commit b5f19dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
24 changes: 15 additions & 9 deletions _integration-tests/tests/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,36 @@ type TestCase struct {

func (tc *TestCase) Setup(t *testing.T) {
var err error
tc.DB, err = sql.Open("sqlite3", "file::memory:")
tc.DB, err = sql.Open("sqlite3", "file::memory:?cache=shared")
require.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, tc.DB.Close())
})

_, err = tc.DB.ExecContext(context.Background(),
//orchestrion:ignore
prepareConn, err := sql.Open("sqlite3", "file::memory:?cache=shared")
require.NoError(t, err)

defer prepareConn.Close()

_, err = prepareConn.ExecContext(context.Background(),
`CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
userid INTEGER,
content STRING,
created STRING
)`)
id INTEGER PRIMARY KEY AUTOINCREMENT,
userid INTEGER,
content STRING,
created STRING
)`)
require.NoError(t, err)

_, err = tc.DB.ExecContext(context.Background(),
_, err = prepareConn.ExecContext(context.Background(),
`INSERT OR REPLACE INTO notes(userid, content, created) VALUES
(1, 'Hello, John. This is John. You are leaving a note for yourself. You are welcome and thank you.', datetime('now')),
(1, 'Hey, remember to mow the lawn.', datetime('now')),
(2, 'Reminder to submit that report by Thursday.', datetime('now')),
(2, 'Opportunities don''t happen, you create them.', datetime('now')),
(3, 'Pick up cabbage from the store on the way home.', datetime('now')),
(3, 'Review PR #1138', datetime('now')
);`)
)`)
require.NoError(t, err)
}

Expand Down
10 changes: 9 additions & 1 deletion internal/injector/builtin/yaml/stdlib/database-sql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ aspects:
join-point:
function-call: database/sql.Register
advice:
- replace-function: gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql.Register
- wrap-expression:
imports:
sqltrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql
sql: database/sql
template: |-
func(driverName string, driver driver.Driver) {
sql.Register(driverName, driver)
sqltrace.Register(driverName, driver)
}({{ .Args.0 }}, {{ .Args.1 }})
- id: Open
join-point:
Expand Down

0 comments on commit b5f19dc

Please sign in to comment.