/
otel_exporter_options.go
100 lines (82 loc) · 2.62 KB
/
otel_exporter_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
package otelog
import (
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/resource"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)
type logExporterOptions struct {
conn *grpc.ClientConn
endpoint string
credential credentials.TransportCredentials
resource *resource.Resource
scope instrumentation.Scope
processor LogProcessor
}
// LogExporterOption is an option to use with NewLogExporter().
type LogExporterOption interface {
apply(*logExporterOptions)
}
type logExporterOptionFunc func(*logExporterOptions)
func (f logExporterOptionFunc) apply(opts *logExporterOptions) {
f(opts)
}
// Sets the resource associated with the LogExporter
func WithResource(r *resource.Resource) LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.resource = r
})
}
type scopeOption instrumentation.Scope
// Sets the scope associated with the LogExporter
func WithScope(s instrumentation.Scope) LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.scope = s
})
}
// Sets a LogProcessor that sends every event immediatly. It
// should be avoided in production.
func WithSyncer() LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.processor = &syncProcessor{}
})
}
// Sets a LogProcessor that batches logs before exporting them.
func WithBatchLogProcessor(options ...BatchLogProcessorOption) LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.processor = newBatchProcessor(options...)
})
}
// Sets the Open Telemetry collector endpoint to export logs to.
func WithEndpoint(endpoint string) LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.endpoint = endpoint
})
}
// Sets no credential for the OpenTelemetry endpoint.
func WithInsecure() LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.credential = insecure.NewCredentials()
})
}
// Sets the gRPC TLS credential to use for the OpenTelemetry endpoint.
func WithTLSCredentials(c credentials.TransportCredentials) LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.credential = c
})
}
func WithGRPCConn(conn *grpc.ClientConn) LogExporterOption {
return logExporterOptionFunc(func(opts *logExporterOptions) {
opts.conn = conn
})
}
func newOtelLogExporterOptions(options ...LogExporterOption) logExporterOptions {
opts := logExporterOptions{
processor: newBatchProcessor(),
}
for _, o := range options {
o.apply(&opts)
}
return opts
}