fix:trace graceful stop,pre loss trace (#2358)

This commit is contained in:
maizige
2022-09-07 10:33:01 +08:00
committed by GitHub
parent 6078bf1a04
commit cfda972d50
8 changed files with 22 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package trace
import (
"context"
"fmt"
"sync"
@@ -23,6 +24,7 @@ const (
var (
agents = make(map[string]lang.PlaceholderType)
lock sync.Mutex
tp *sdktrace.TracerProvider
)
// StartAgent starts a opentelemetry agent.
@@ -43,6 +45,11 @@ func StartAgent(c Config) {
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) {
// Just support jaeger and zipkin now, more for later
switch c.Batcher {
@@ -74,7 +81,7 @@ func startAgent(c Config) error {
opts = append(opts, sdktrace.WithBatcher(exp))
}
tp := sdktrace.NewTracerProvider(opts...)
tp = sdktrace.NewTracerProvider(opts...)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{}, propagation.Baggage{}))