improve tracing feature

This commit is contained in:
jianchenma
2021-01-27 13:28:12 +08:00
parent f5ba665c59
commit f2fe084988
3 changed files with 36 additions and 12 deletions

View File

@ -11,6 +11,7 @@ import (
"context"
"fmt"
"github.com/gogf/gf"
"github.com/gogf/gf/net/gtrace"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
@ -19,11 +20,7 @@ import (
// addSqlToTracing adds sql information to tracer if it's enabled.
func (c *Core) addSqlToTracing(ctx context.Context, sql *Sql) {
if ctx == nil {
return
}
spanCtx := trace.SpanContextFromContext(ctx)
if traceId := spanCtx.TraceID; !traceId.IsValid() {
if gtrace.IsActivated(ctx) {
return
}

View File

@ -13,6 +13,7 @@ import (
"github.com/gogf/gf"
"github.com/gogf/gf/container/gvar"
"github.com/gogf/gf/internal/json"
"github.com/gogf/gf/net/gtrace"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"github.com/gomodule/redigo/redis"
@ -65,11 +66,7 @@ func (c *Conn) do(timeout time.Duration, commandName string, args ...interface{}
timestampMilli2 := gtime.TimestampMilli()
// Tracing.
if c.ctx == nil {
return
}
spanCtx := trace.SpanContextFromContext(c.ctx)
if traceId := spanCtx.TraceID; !traceId.IsValid() {
if gtrace.IsActivated(c.ctx) {
return
}
tr := otel.GetTracerProvider().Tracer(