Skip to content

Commit

Permalink
contrib/gorm.io/gorm.v1: fix orchestrion aspect
Browse files Browse the repository at this point in the history
  • Loading branch information
rarguelloF committed Jan 27, 2025
1 parent 9f1ce94 commit 831131e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
16 changes: 15 additions & 1 deletion contrib/gorm.io/gorm.v1/orchestrion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@ 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
}()
18 changes: 17 additions & 1 deletion internal/orchestrion/_integration/gorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 @@ -62,6 +62,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

0 comments on commit 831131e

Please sign in to comment.