Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contrib/gorm.io/gorm.v1: fix orchestrion aspect #3121

Merged
merged 5 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
contrib/gorm.io/gorm.v1: fix orchestrion aspect
rarguelloF committed Jan 27, 2025
commit 831131e355075152d406071521afd415c545d9b6
16 changes: 15 additions & 1 deletion contrib/gorm.io/gorm.v1/orchestrion.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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{}))
@@ -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",
},
},
},
},
},