Skip to content

Commit

Permalink
fix(injector: builtin: gorm.io/gorm): do not replace with a function …
Browse files Browse the repository at this point in the history
…with a different signature
  • Loading branch information
rarguelloF committed Jan 27, 2025
1 parent e64a9d5 commit 2bc212f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 17 additions & 1 deletion _integration-tests/tests/gorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type TestCase struct {

func (tc *TestCase) Setup(_ context.Context, t *testing.T) {
var err error
tc.DB, err = gorm.Open(sqlite.Open("file::memory:"), &gorm.Config{})
tc.DB, err = gorm.Open(sqlite.Open("file::memory:"))
require.NoError(t, err)

require.NoError(t, tc.DB.AutoMigrate(&Note{}))
Expand Down Expand Up @@ -64,6 +64,22 @@ func (*TestCase) ExpectedTraces() trace.Traces {
},
Meta: map[string]string{
"component": "gorm.io/gorm.v1",
"span.kind": "client",
},
Children: trace.Traces{
{
Tags: map[string]any{
"resource": "SELECT * FROM `notes` WHERE user_id = ? AND `notes`.`deleted_at` IS NULL ORDER BY `notes`.`id` LIMIT 1",
"type": "sql",
"name": "sqlite3.query",
"service": "sqlite3.db",
},
Meta: map[string]string{
"component": "database/sql",
"span.kind": "client",
"db.system": "other_sql",
},
},
},
},
},
Expand Down
16 changes: 15 additions & 1 deletion internal/injector/builtin/yaml/databases/gorm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ aspects:
join-point:
function-call: gorm.io/gorm.Open
advice:
- replace-function: gopkg.in/DataDog/dd-trace-go.v1/contrib/gorm.io/gorm.v1.Open
- wrap-expression:
imports:
gorm: gorm.io/gorm
gormtrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/gorm.io/gorm.v1
template: |-
func() (*gorm.DB, error) {
db, err := {{ . }}
if err != nil {
return nil, err
}
if err := db.Use(gormtrace.NewTracePlugin()); err != nil {
return nil, err
}
return db, nil
}()
##############################################################################
# jinzhu/gorm
Expand Down

0 comments on commit 2bc212f

Please sign in to comment.