-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathoption.go
60 lines (51 loc) · 1.58 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package otelgorm
import (
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
"go.opentelemetry.io/otel/trace"
)
type Option func(p *otelPlugin)
// WithTracerProvider configures a tracer provider that is used to create a tracer.
func WithTracerProvider(provider trace.TracerProvider) Option {
return func(p *otelPlugin) {
p.provider = provider
}
}
// WithAttributes configures attributes that are used to create a span.
func WithAttributes(attrs ...attribute.KeyValue) Option {
return func(p *otelPlugin) {
p.attrs = append(p.attrs, attrs...)
}
}
// WithDBName configures a db.name attribute.
func WithDBName(name string) Option {
return func(p *otelPlugin) {
p.attrs = append(p.attrs, semconv.DBNameKey.String(name))
}
}
// WithoutQueryVariables configures the db.statement attribute to exclude query variables
func WithoutQueryVariables() Option {
return func(p *otelPlugin) {
p.excludeQueryVars = true
}
}
// WithQueryFormatter configures a query formatter
func WithQueryFormatter(queryFormatter func(query string) string) Option {
return func(p *otelPlugin) {
p.queryFormatter = queryFormatter
}
}
// WithoutMetrics prevents DBStats metrics from being reported.
func WithoutMetrics() Option {
return func(p *otelPlugin) {
p.excludeMetrics = true
}
}
// WithDryRunTx will add trace spans for "dry run" callback invocations from
// Gorm. "Dry Run" invocations occur when Gorm is just rendering SQL, but not
// actually executing it against a database.
func WithDryRunTx() Option {
return func(p *otelPlugin) {
p.includeDryRunSpans = true
}
}