-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.go
54 lines (46 loc) · 1.86 KB
/
init.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
package goagent // import "github.com/Traceableai/goagent"
import (
"os"
"github.com/Traceableai/goagent/config"
internalconfig "github.com/Traceableai/goagent/internal/config"
"github.com/Traceableai/goagent/internal/logger"
internalstate "github.com/Traceableai/goagent/internal/state"
"github.com/Traceableai/goagent/version"
"github.com/hypertrace/goagent/instrumentation/opentelemetry"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
)
var versionInfoAttributes = []attribute.KeyValue{
semconv.TelemetrySDKNameKey.String("traceable"),
semconv.TelemetrySDKVersionKey.String(version.Version),
}
// Init initializes Traceable tracing and returns a shutdown function to flush data immediately
// on a termination signal.
func Init(cfg *config.AgentConfig) func() {
loggerCloser := logger.InitLogger(os.Getenv("TA_LOG_LEVEL"))
internalstate.AppendCloser(loggerCloser)
return InitWithAttributesAndZap(cfg, versionInfoAttributes, logger.GetLogger())
}
func InitWithAttributesAndZap(cfg *config.AgentConfig, attributes []attribute.KeyValue, logger *zap.Logger) func() {
if cfg.Tracing.Enabled.Value {
internalstate.InitConfig(cfg)
} else {
internalstate.InitConfig(internalconfig.DisabledConfig)
}
tracingCloser := opentelemetry.InitWithSpanProcessorWrapperAndZap(cfg.Tracing, &traceableSpanProcessorWrapper{}, attributes, logger)
internalstate.AppendCloser(tracingCloser)
return internalstate.CloserFn()
}
func RegisterService(
serviceName string,
resourceAttributes map[string]string,
) (SpanStarter, trace.TracerProvider, error) {
s, tp, err := opentelemetry.RegisterServiceWithSpanProcessorWrapper(serviceName, resourceAttributes, &traceableSpanProcessorWrapper{},
versionInfoAttributes)
if err != nil {
return nil, tp, err
}
return translateSpanStarter(s), tp, nil
}