/
config.go
54 lines (43 loc) · 1.37 KB
/
config.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package opencensus // import "go.opentelemetry.io/otel/bridge/opencensus"
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)
const scopeName = "go.opentelemetry.io/otel/bridge/opencensus"
// newTraceConfig returns a config configured with options.
func newTraceConfig(options []TraceOption) traceConfig {
conf := traceConfig{tp: otel.GetTracerProvider()}
for _, o := range options {
conf = o.apply(conf)
}
return conf
}
type traceConfig struct {
tp trace.TracerProvider
}
// TraceOption applies a configuration option value to an OpenCensus bridge
// Tracer.
type TraceOption interface {
apply(traceConfig) traceConfig
}
// traceOptionFunc applies a set of options to a config.
type traceOptionFunc func(traceConfig) traceConfig
// apply returns a config with option(s) applied.
func (o traceOptionFunc) apply(conf traceConfig) traceConfig {
return o(conf)
}
// WithTracerProvider specifies a tracer provider to use for creating a tracer.
func WithTracerProvider(tp trace.TracerProvider) TraceOption {
return traceOptionFunc(func(conf traceConfig) traceConfig {
conf.tp = tp
return conf
})
}
type metricConfig struct{}
// MetricOption applies a configuration option value to an OpenCensus bridge
// MetricProducer.
type MetricOption interface {
apply(metricConfig) metricConfig
}