Skip to content

Commit f211614

Browse files
committed
fix(contrib/gorm.io): allow resource name to be overridden by custom tags
1 parent 35e1174 commit f211614

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

contrib/gorm.io/gorm.v1/gorm.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ func before(db *gorm.DB, operationName string, cfg *config) {
151151
if !math.IsNaN(cfg.analyticsRate) {
152152
opts = append(opts, tracer.Tag(ext.EventSampleRate, cfg.analyticsRate))
153153
}
154-
for key, tagFn := range cfg.tagFns {
155-
if tagFn != nil {
156-
opts = append(opts, tracer.Tag(key, tagFn(db)))
157-
}
158-
}
159-
160154
_, ctx := tracer.StartSpanFromContext(db.Statement.Context, operationName, opts...)
161155
db.Statement.Context = ctx
162156
}
@@ -175,6 +169,15 @@ func after(db *gorm.DB, cfg *config) {
175169
dbErr = db.Error
176170
}
177171
span.SetTag(ext.ResourceName, db.Statement.SQL.String())
172+
173+
// process tagFns after setting the resource name to allow the resource
174+
// name to be overridden
175+
for key, tagFn := range cfg.tagFns {
176+
if tagFn != nil {
177+
span.SetTag(key, tagFn(db))
178+
}
179+
}
180+
178181
span.Finish(tracer.WithError(dbErr))
179182
}
180183
}

0 commit comments

Comments
 (0)