diff --git a/_integration-tests/tests/sql/sql.go b/_integration-tests/tests/sql/sql.go index b65e5224..a85b425e 100644 --- a/_integration-tests/tests/sql/sql.go +++ b/_integration-tests/tests/sql/sql.go @@ -24,22 +24,28 @@ 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')), @@ -47,7 +53,7 @@ func (tc *TestCase) Setup(t *testing.T) { (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) } diff --git a/internal/injector/builtin/yaml/stdlib/database-sql.yml b/internal/injector/builtin/yaml/stdlib/database-sql.yml index 27ecf5cb..3b41469d 100644 --- a/internal/injector/builtin/yaml/stdlib/database-sql.yml +++ b/internal/injector/builtin/yaml/stdlib/database-sql.yml @@ -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: