|
|
@ -1,6 +1,7 @@
|
|
|
|
package trace
|
|
|
|
package trace
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
|
@ -23,6 +24,7 @@ const (
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
agents = make(map[string]lang.PlaceholderType)
|
|
|
|
agents = make(map[string]lang.PlaceholderType)
|
|
|
|
lock sync.Mutex
|
|
|
|
lock sync.Mutex
|
|
|
|
|
|
|
|
tp *sdktrace.TracerProvider
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// StartAgent starts a opentelemetry agent.
|
|
|
|
// StartAgent starts a opentelemetry agent.
|
|
|
@ -43,6 +45,11 @@ func StartAgent(c Config) {
|
|
|
|
agents[c.Endpoint] = lang.Placeholder
|
|
|
|
agents[c.Endpoint] = lang.Placeholder
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StopAgent shuts down the span processors in the order they were registered.
|
|
|
|
|
|
|
|
func StopAgent() {
|
|
|
|
|
|
|
|
_ = tp.Shutdown(context.Background())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|
|
|
func createExporter(c Config) (sdktrace.SpanExporter, error) {
|
|
|
|
// Just support jaeger and zipkin now, more for later
|
|
|
|
// Just support jaeger and zipkin now, more for later
|
|
|
|
switch c.Batcher {
|
|
|
|
switch c.Batcher {
|
|
|
@ -74,7 +81,7 @@ func startAgent(c Config) error {
|
|
|
|
opts = append(opts, sdktrace.WithBatcher(exp))
|
|
|
|
opts = append(opts, sdktrace.WithBatcher(exp))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tp := sdktrace.NewTracerProvider(opts...)
|
|
|
|
tp = sdktrace.NewTracerProvider(opts...)
|
|
|
|
otel.SetTracerProvider(tp)
|
|
|
|
otel.SetTracerProvider(tp)
|
|
|
|
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
|
|
|
|
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
|
|
|
|
propagation.TraceContext{}, propagation.Baggage{}))
|
|
|
|
propagation.TraceContext{}, propagation.Baggage{}))
|
|
|
|