option.go (898B)
1 package bunotel 2 3 import ( 4 "go.opentelemetry.io/otel/attribute" 5 semconv "go.opentelemetry.io/otel/semconv/v1.12.0" 6 ) 7 8 type Option func(h *QueryHook) 9 10 // WithAttributes configures attributes that are used to create a span. 11 func WithAttributes(attrs ...attribute.KeyValue) Option { 12 return func(h *QueryHook) { 13 h.attrs = append(h.attrs, attrs...) 14 } 15 } 16 17 // WithDBName configures a db.name attribute. 18 func WithDBName(name string) Option { 19 return func(h *QueryHook) { 20 h.attrs = append(h.attrs, semconv.DBNameKey.String(name)) 21 } 22 } 23 24 // WithFormattedQueries enables formatting of the query that is added 25 // as the statement attribute to the trace. 26 // This means that all placeholders and arguments will be filled first 27 // and the query will contain all information as sent to the database. 28 func WithFormattedQueries(format bool) Option { 29 return func(h *QueryHook) { 30 h.formatQueries = format 31 } 32 }