rest otel support (#943)

This commit is contained in:
zhoushuguang
2021-08-24 10:04:12 +08:00
committed by GitHub
parent f669e1226c
commit 280e837c9e
8 changed files with 103 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import (
"github.com/tal-tech/go-zero/core/logx"
"github.com/tal-tech/go-zero/core/syncx"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/propagation"
@@ -53,7 +54,17 @@ func StartAgent(c Config) {
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
otel.SetErrorHandler(otelErrHandler{})
enabled.Set(true)
})
}
// errHandler handing otel errors.
type otelErrHandler struct{}
var _ otel.ErrorHandler = otelErrHandler{}
func (o otelErrHandler) Handle(err error) {
logx.Errorf("[otel] error: %v", err)
}

View File

@@ -1,8 +1,6 @@
package opentelemetry
const (
TraceName = "go-zero"
)
const TraceName = "go-zero"
// A Config is a opentelemetry config.
type Config struct {

View File

@@ -45,6 +45,9 @@ func (sc ServiceConf) SetUp() error {
if len(sc.Log.ServiceName) == 0 {
sc.Log.ServiceName = sc.Name
}
if len(sc.OpenTelemetry.Name) == 0 {
sc.OpenTelemetry.Name = sc.Name
}
if err := logx.SetUp(sc.Log); err != nil {
return err
}