-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
143 lines (127 loc) · 4.74 KB
/
options.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package sdk
import (
"time"
"go.bryk.io/pkg/log"
"go.bryk.io/pkg/otel"
"go.opentelemetry.io/otel/propagation"
sdkMetric "go.opentelemetry.io/otel/sdk/metric"
sdkTrace "go.opentelemetry.io/otel/sdk/trace"
)
// Option provide a functional style configuration mechanism
// to instrument an application.
type Option func(*Instrumentation)
// WithServiceName adjust the `service.name` attribute.
func WithServiceName(name string) Option {
return func(op *Instrumentation) {
op.attrs.Set(lblSvcName, name)
}
}
// WithServiceVersion adjust the `service.version` attribute.
func WithServiceVersion(version string) Option {
return func(op *Instrumentation) {
op.attrs.Set(lblSvcVer, version)
}
}
// WithSpanLimits allows to adjust the limits bound any Span created by
// the tracer.
// https://pkg.go.dev/go.opentelemetry.io/otel/sdk/trace#SpanLimits
func WithSpanLimits(sl sdkTrace.SpanLimits) Option {
return func(op *Instrumentation) {
op.spanLimits = sl
}
}
// WithPropagator add a new propagator to the application. OpenTelemetry
// propagators are used to extract and inject context data from and into
// messages exchanged by applications. The application supports the following
// propagation mechanisms by default:
// - W3C Trace Context (https://www.w3.org/TR/trace-context/)
// - W3C Baggage (https://www.w3.org/TR/baggage/)
func WithPropagator(mp propagation.TextMapPropagator) Option {
return func(op *Instrumentation) {
op.props = append(op.props, mp)
}
}
// WithSpanProcessor registers a new span processor in the trace provider
// processing chain.
func WithSpanProcessor(sp sdkTrace.SpanProcessor) Option {
return func(op *Instrumentation) {
op.spanProcessors = append(op.spanProcessors, sp)
}
}
// WithResourceAttributes allows extending (or overriding) the core
// attributes used globally by the application. The core attributes must
// provide information at the resource level. These attributes are used
// to configure the application's tracer and logger instances.
func WithResourceAttributes(fields otel.Attributes) Option {
return func(op *Instrumentation) {
op.attrs = join(op.attrs, fields)
}
}
// WithBaseLogger set the output handler. If not provided, all output is
// discarded by default. The application will create an extended logger
// using all the attributes discovered/provided during the setup process.
func WithBaseLogger(ll log.Logger) Option {
return func(op *Instrumentation) {
op.log = ll
}
}
// WithExporter enables a trace (i.e. span) exporter as data sink for the
// application. If no exporter is set, all traces are discarded by default.
func WithExporter(exp sdkTrace.SpanExporter) Option {
return func(op *Instrumentation) {
op.traceExporter = exp
}
}
// WithSampler adjust the sampling strategy used by the application.
// All traces are sampled by default.
//
// https://opentelemetry.io/docs/instrumentation/go/exporting_data/#sampling
func WithSampler(ss sdkTrace.Sampler) Option {
return func(op *Instrumentation) {
op.sampler = ss
}
}
// WithMetricReader configures the application's meter provider to export
// the measured data. Readers take two forms: ones that push to an endpoint
// (NewPeriodicReader), and ones that an endpoint pulls from. See the
// `go.opentelemetry.io/otel/exporters` package for exporters that can be
// used as or with these Readers.
func WithMetricReader(exp sdkMetric.Reader) Option {
return func(op *Instrumentation) {
op.metricExporter = exp
}
}
// WithHostMetrics enables the application to capture the conventional host
// metric instruments specified by OpenTelemetry. Host metric events are
// sometimes collected through the OpenTelemetry Collector `host metrics`
// receiver running as an agent; this instrumentation option provides an
// alternative for processes that want to record the same information without
// an agent.
func WithHostMetrics() Option {
return func(op *Instrumentation) {
op.hostMetrics = true
}
}
// WithRuntimeMetrics enables the application to capture the conventional runtime
// metrics specified by OpenTelemetry. The provided interval value sets the
// minimum interval between calls to runtime.ReadMemStats(), which is a relatively
// expensive call to make frequently. The default interval value is 10 seconds,
// passing a value <= 0 uses the default.
func WithRuntimeMetrics(interval time.Duration) Option {
return func(op *Instrumentation) {
if interval.Seconds() <= 0 {
interval = 10 * time.Second
}
op.runtimeMetrics = true
op.runtimeMetricsInt = interval
}
}
// WithExemplars enable experimental support for exemplars by settings
// the adequate ENV variables
//
// https://github.com/open-telemetry/opentelemetry-go/blob/main/sdk/metric/internal/x/README.md
func WithExemplars() Option {
return func(op *Instrumentation) {
op.exemplars = true
}
}