@@ -36,6 +36,7 @@ type otelPlugin struct {
3636 attrs []attribute.KeyValue
3737 excludeQueryVars bool
3838 excludeMetrics bool
39+ excludeServerAddress bool
3940 recordStackTraceInSpan bool
4041 queryFormatter func (query string ) string
4142}
@@ -112,26 +113,28 @@ func (p *otelPlugin) before(spanName string) gormHookFunc {
112113 ctx , span := p .tracer .Start (tx .Statement .Context , spanName , trace .WithSpanKind (trace .SpanKindClient ))
113114 tx .Statement .Context = ctx
114115
115- // `server.address` is required in the latest semconv
116- var serverAddrAttr attribute.KeyValue
117- switch dialector := tx .Config .Dialector .(type ) {
118- case * mysql.Dialector :
119- if dialector .Config .DSNConfig != nil && dialector .Config .DSNConfig .Addr != "" {
120- serverAddrAttr = semconv .ServerAddressKey .String (dialector .Config .DSNConfig .Addr )
121- span .SetAttributes (serverAddrAttr )
122- }
123- case * clickhouse.Dialector :
124- if dialector .Config .DSN != "" {
125- serverAddrAttr = semconv .ServerAddressKey .String (dialector .Config .DSN )
126- span .SetAttributes (serverAddrAttr )
127- }
128- case * postgres.Dialector :
129- if dialector .Config .DSN != "" {
130- serverAddrAttr = semconv .ServerAddressKey .String (dialector .Config .DSN )
131- span .SetAttributes (serverAddrAttr )
132- }
133- default :
116+ if ! p .excludeServerAddress {
117+ // `server.address` is required in the latest semconv
118+ var serverAddrAttr attribute.KeyValue
119+ switch dialector := tx .Config .Dialector .(type ) {
120+ case * mysql.Dialector :
121+ if dialector .Config .DSNConfig != nil && dialector .Config .DSNConfig .Addr != "" {
122+ serverAddrAttr = semconv .ServerAddressKey .String (dialector .Config .DSNConfig .Addr )
123+ span .SetAttributes (serverAddrAttr )
124+ }
125+ case * clickhouse.Dialector :
126+ if dialector .Config .DSN != "" {
127+ serverAddrAttr = semconv .ServerAddressKey .String (dialector .Config .DSN )
128+ span .SetAttributes (serverAddrAttr )
129+ }
130+ case * postgres.Dialector :
131+ if dialector .Config .DSN != "" {
132+ serverAddrAttr = semconv .ServerAddressKey .String (dialector .Config .DSN )
133+ span .SetAttributes (serverAddrAttr )
134+ }
135+ default :
134136
137+ }
135138 }
136139 }
137140}
0 commit comments