-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup_http.go
47 lines (40 loc) · 1.29 KB
/
setup_http.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
package otelKit
import (
"github.com/richelieu-yang/chimera/v3/src/core/strKit"
"github.com/richelieu-yang/chimera/v3/src/log/logrusKit"
"github.com/sirupsen/logrus"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/propagation"
"time"
)
func MustSetUpWithHttp(httpEndpoint, serviceName string, attributeMap map[string]string, opts ...otlptracehttp.Option) {
err := SetUpWithHttp(httpEndpoint, serviceName, attributeMap, opts...)
if err != nil {
logrusKit.DisableQuote(nil)
logrus.Fatalf("%+v", err)
}
}
func SetUpWithHttp(httpEndpoint, serviceName string, attributeMap map[string]string, opts ...otlptracehttp.Option) (err error) {
defer func() {
if err == nil {
setupFlag.Store(true)
}
}()
if err = strKit.AssertNotEmpty(serviceName, "serviceName"); err != nil {
return
}
/* TracerProvider */
tp, err := NewHttpTracerProvider(httpEndpoint, serviceName, attributeMap, opts...)
if err != nil {
return
}
otel.SetTracerProvider(tp)
/* TextMapPropagator */
textMapPropagator := propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})
otel.SetTextMapPropagator(textMapPropagator)
logrus.RegisterExitHandler(func() {
ShutdownTracerProvider(tp, time.Second*3)
})
return
}