generated from xmidt-org/.go-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tracingFactory.go
54 lines (47 loc) · 1.57 KB
/
tracingFactory.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
// SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package candlelight
import (
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
)
// New creates a structure with components that apps can use to initialize OpenTelemetry
// tracing instrumentation code.
func New(config Config) (Tracing, error) {
var tracing = Tracing{
propagator: propagation.TraceContext{},
}
tracerProvider, err := ConfigureTracerProvider(config)
if err != nil {
return Tracing{}, err
}
tracing.tracerProvider = tracerProvider
return tracing, nil
}
// Tracing contains the core dependencies to make tracing possible across an
// application.
type Tracing struct {
tracerProvider trace.TracerProvider
propagator propagation.TextMapPropagator
}
// IsNoop returns true if the tracer provider component is a noop. False otherwise.
func (t Tracing) IsNoop() bool {
return t.TracerProvider() == noop.NewTracerProvider()
}
// TracerProvider returns the tracer provider component. By default, the noop
// tracer provider is returned.
func (t Tracing) TracerProvider() trace.TracerProvider {
if t.tracerProvider == nil {
return noop.NewTracerProvider()
}
return t.tracerProvider
}
// Propagator returns the component that helps propagate trace context across
// API boundaries. By default, a W3C Trace Context format propagator is returned.
func (t Tracing) Propagator() propagation.TextMapPropagator {
if t.propagator == nil {
return propagation.TraceContext{}
}
return t.propagator
}