-
Notifications
You must be signed in to change notification settings - Fork 415
/
option.go
83 lines (72 loc) · 2.03 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2022 Datadog, Inc.
package pgx
import "github.com/DataDog/dd-trace-go/v2/internal/namingschema"
type config struct {
serviceName string
traceQuery bool
traceBatch bool
traceCopyFrom bool
tracePrepare bool
traceConnect bool
}
func defaultConfig() *config {
return &config{
serviceName: namingschema.ServiceName(defaultServiceName),
traceQuery: true,
traceBatch: true,
traceCopyFrom: true,
tracePrepare: true,
traceConnect: true,
}
}
type Option func(*config)
// WithService sets the service name to use for all spans.
func WithService(name string) Option {
return func(c *config) {
c.serviceName = name
}
}
// WithTraceQuery enables tracing query operations.
func WithTraceQuery(enabled bool) Option {
return func(c *config) {
c.traceQuery = enabled
}
}
// WithTraceBatch enables tracing batched operations (i.e. pgx.Batch{}).
func WithTraceBatch(enabled bool) Option {
return func(c *config) {
c.traceBatch = enabled
}
}
// WithTraceCopyFrom enables tracing pgx.CopyFrom calls.
func WithTraceCopyFrom(enabled bool) Option {
return func(c *config) {
c.traceCopyFrom = enabled
}
}
// WithTracePrepare enables tracing prepared statements.
//
// conn, err := pgx.Connect(ctx, "postgres://user:pass@example.com:5432/dbname", pgx.WithTraceConnect())
// if err != nil {
// // handle err
// }
// defer conn.Close(ctx)
//
// _, err := conn.Prepare(ctx, "stmt", "select $1::integer")
// row, err := conn.QueryRow(ctx, "stmt", 1)
func WithTracePrepare(enabled bool) Option {
return func(c *config) {
c.tracePrepare = enabled
}
}
// WithTraceConnect enables tracing calls to Connect and ConnectConfig.
//
// pgx.Connect(ctx, "postgres://user:pass@example.com:5432/dbname", pgx.WithTraceConnect())
func WithTraceConnect(enabled bool) Option {
return func(c *config) {
c.traceConnect = enabled
}
}