@@ -65,8 +65,7 @@ func Open(dialector gorm.Dialector, cfg *gorm.Config, opts ...Option) (*gorm.DB,
6565}
6666
6767func withCallbacks (db * gorm.DB , opts ... Option ) (* gorm.DB , error ) {
68- cfg := new (config )
69- defaults (cfg )
68+ cfg := newConfigWithDefaults ()
7069 for _ , fn := range opts {
7170 fn .apply (cfg )
7271 }
@@ -151,12 +150,6 @@ func before(db *gorm.DB, operationName string, cfg *config) {
151150 if ! math .IsNaN (cfg .analyticsRate ) {
152151 opts = append (opts , tracer .Tag (ext .EventSampleRate , cfg .analyticsRate ))
153152 }
154- for key , tagFn := range cfg .tagFns {
155- if tagFn != nil {
156- opts = append (opts , tracer .Tag (key , tagFn (db )))
157- }
158- }
159-
160153 _ , ctx := tracer .StartSpanFromContext (db .Statement .Context , operationName , opts ... )
161154 db .Statement .Context = ctx
162155}
@@ -175,6 +168,15 @@ func after(db *gorm.DB, cfg *config) {
175168 dbErr = db .Error
176169 }
177170 span .SetTag (ext .ResourceName , db .Statement .SQL .String ())
171+
172+ // process tagFns after setting the resource name to allow the resource
173+ // name to be overridden
174+ for key , tagFn := range cfg .tagFns {
175+ if tagFn != nil {
176+ span .SetTag (key , tagFn (db ))
177+ }
178+ }
179+
178180 span .Finish (tracer .WithError (dbErr ))
179181 }
180182}
0 commit comments