diff --git a/database/gdb/gdb_core_tracing.go b/database/gdb/gdb_core_tracing.go index 484c76838..b0d3b0c1a 100644 --- a/database/gdb/gdb_core_tracing.go +++ b/database/gdb/gdb_core_tracing.go @@ -20,14 +20,14 @@ import ( // addSqlToTracing adds sql information to tracer if it's enabled. func (c *Core) addSqlToTracing(ctx context.Context, sql *Sql) { - if gtrace.IsActivated(ctx) { + if !gtrace.IsActivated(ctx) { return } tr := otel.GetTracerProvider().Tracer( "github.com/gogf/gf/database/gdb", trace.WithInstrumentationVersion(fmt.Sprintf(`%s`, gf.VERSION)), ) - ctx, span := tr.Start(ctx, sql.Type) + ctx, span := tr.Start(ctx, sql.Type, trace.WithSpanKind(trace.SpanKindInternal)) defer span.End() if sql.Error != nil { diff --git a/database/gredis/gredis_conn.go b/database/gredis/gredis_conn.go index aaafd44c5..1162599ac 100644 --- a/database/gredis/gredis_conn.go +++ b/database/gredis/gredis_conn.go @@ -66,7 +66,7 @@ func (c *Conn) do(timeout time.Duration, commandName string, args ...interface{} timestampMilli2 := gtime.TimestampMilli() // Tracing. - if gtrace.IsActivated(c.ctx) { + if !gtrace.IsActivated(c.ctx) { return } tr := otel.GetTracerProvider().Tracer( @@ -77,7 +77,7 @@ func (c *Conn) do(timeout time.Duration, commandName string, args ...interface{} if ctx == nil { ctx = context.Background() } - _, span := tr.Start(ctx, "Redis."+commandName) + _, span := tr.Start(ctx, "Redis."+commandName, trace.WithSpanKind(trace.SpanKindInternal)) defer span.End() if err != nil { span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, err)) diff --git a/net/ghttp/ghttp_middleware_tracing.go b/net/ghttp/ghttp_middleware_tracing.go index afb8d38a4..8cc26cd3f 100644 --- a/net/ghttp/ghttp_middleware_tracing.go +++ b/net/ghttp/ghttp_middleware_tracing.go @@ -43,7 +43,7 @@ func MiddlewareServerTracing(r *Request) { propagation.Baggage{}, ) ctx := propagator.Extract(r.Context(), r.Header) - ctx, span := tr.Start(ctx, r.URL.String()) + ctx, span := tr.Start(ctx, r.URL.String(), trace.WithSpanKind(trace.SpanKindServer)) defer span.End() span.SetAttributes(gtrace.CommonLabels()...) @@ -59,7 +59,7 @@ func MiddlewareServerTracing(r *Request) { reqBodyContent = string(reqBodyContentBytes) } else { reqBodyContent = fmt.Sprintf( - "[Request Body Too Large For Logging, Max: %d bytes]", + "[Request Body Too Large For Tracing, Max: %d bytes]", tracingMaxContentLogSize, ) } @@ -80,7 +80,10 @@ func MiddlewareServerTracing(r *Request) { if r.Response.BufferLength() <= tracingMaxContentLogSize { resBodyContent = r.Response.BufferString() } else { - resBodyContent = fmt.Sprintf("[Response Body Too Large For Logging, Max: %d bytes]", tracingMaxContentLogSize) + resBodyContent = fmt.Sprintf( + "[Response Body Too Large For Tracing, Max: %d bytes]", + tracingMaxContentLogSize, + ) } span.AddEvent("http.response", trace.WithAttributes( label.Any(`http.response.headers`, httputil.HeaderToMap(r.Response.Header())), diff --git a/net/ghttp/internal/client/client_tracing.go b/net/ghttp/internal/client/client_tracing.go index 516f0396f..274bfce2f 100644 --- a/net/ghttp/internal/client/client_tracing.go +++ b/net/ghttp/internal/client/client_tracing.go @@ -32,7 +32,7 @@ func MiddlewareTracing(c *Client, r *http.Request) (response *Response, err erro "github.com/gogf/gf/net/ghttp.Client", trace.WithInstrumentationVersion(fmt.Sprintf(`%s`, gf.VERSION)), ) - ctx, span := tr.Start(r.Context(), r.URL.String()) + ctx, span := tr.Start(r.Context(), r.URL.String(), trace.WithSpanKind(trace.SpanKindClient)) defer span.End() span.SetAttributes(gtrace.CommonLabels()...) @@ -64,7 +64,10 @@ func MiddlewareTracing(c *Client, r *http.Request) (response *Response, err erro resBodyContent = string(reqBodyContentBytes) response.Body = utils.NewReadCloser(reqBodyContentBytes, false) } else { - resBodyContent = fmt.Sprintf("[Response Body Too Large For Logging, Max: %d bytes]", tracingMaxContentLogSize) + resBodyContent = fmt.Sprintf( + "[Response Body Too Large For Tracing, Max: %d bytes]", + tracingMaxContentLogSize, + ) } span.AddEvent("http.response", trace.WithAttributes(