Debian Codegraph @

bridge/opencensus/config.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package opencensus // import "go.opentelemetry.io/otel/bridge/opencensus"
5
6 import (
7 "go.opentelemetry.io/otel"
8 "go.opentelemetry.io/otel/trace"
9 )
10
11 const scopeName = "go.opentelemetry.io/otel/bridge/opencensus"
12
13 // newTraceConfig returns a config configured with options.
14 func newTraceConfig(options []TraceOption) traceConfig {
15 conf := traceConfig{tp: otel.GetTracerProvider()}
16 for _, o := range options {
17 conf = o.apply(conf)
18 }
19 return conf
20 }
21
22 type traceConfig struct {
23 tp trace.TracerProvider
24 }
25
26 // TraceOption applies a configuration option value to an OpenCensus bridge
27 // Tracer.
28 type TraceOption interface {
29 apply(traceConfig) traceConfig
30 }
31
32 // traceOptionFunc applies a set of options to a config.
33 type traceOptionFunc func(traceConfig) traceConfig
34
35 // apply returns a config with option(s) applied.
36 func (o traceOptionFunc) apply(conf traceConfig) traceConfig {
37 return o(conf)
38 }
39
40 // WithTracerProvider specifies a tracer provider to use for creating a tracer.
41 func WithTracerProvider(tp trace.TracerProvider) TraceOption {
42 return traceOptionFunc(func(conf traceConfig) traceConfig {
43 conf.tp = tp
44 return conf
45 })
46 }
47
48 type metricConfig struct{}
49
50 // MetricOption applies a configuration option value to an OpenCensus bridge
51 // MetricProducer.
52 type MetricOption interface {
53 apply(metricConfig) metricConfig
54 }