Przeglądaj źródła

chore: reformat code (#2925)

Kevin Wan 2 lat temu
rodzic
commit
a5e5f04bcf

+ 1 - 5
core/stores/mon/trace.go

@@ -14,11 +14,7 @@ var mongoCmdAttributeKey = attribute.Key("mongo.cmd")
 
 func startSpan(ctx context.Context, cmd string) (context.Context, oteltrace.Span) {
 	tracer := trace.TracerFromContext(ctx)
-
-	ctx, span := tracer.Start(ctx,
-		spanName,
-		oteltrace.WithSpanKind(oteltrace.SpanKindClient),
-	)
+	ctx, span := tracer.Start(ctx, spanName, oteltrace.WithSpanKind(oteltrace.SpanKindClient))
 	span.SetAttributes(mongoCmdAttributeKey.String(cmd))
 
 	return ctx, span

+ 0 - 1
core/stores/redis/hook.go

@@ -14,7 +14,6 @@ import (
 	"github.com/zeromicro/go-zero/core/mapping"
 	"github.com/zeromicro/go-zero/core/timex"
 	"github.com/zeromicro/go-zero/core/trace"
-
 	"go.opentelemetry.io/otel/attribute"
 	"go.opentelemetry.io/otel/codes"
 	oteltrace "go.opentelemetry.io/otel/trace"

+ 1 - 5
core/stores/sqlx/trace.go

@@ -14,11 +14,7 @@ var sqlAttributeKey = attribute.Key("sql.method")
 
 func startSpan(ctx context.Context, method string) (context.Context, oteltrace.Span) {
 	tracer := trace.TracerFromContext(ctx)
-
-	start, span := tracer.Start(ctx,
-		spanName,
-		oteltrace.WithSpanKind(oteltrace.SpanKindClient),
-	)
+	start, span := tracer.Start(ctx, spanName, oteltrace.WithSpanKind(oteltrace.SpanKindClient))
 	span.SetAttributes(sqlAttributeKey.String(method))
 
 	return start, span

+ 19 - 19
core/trace/utils.go

@@ -22,25 +22,6 @@ var (
 	TraceIDFromContext = ztrace.TraceIDFromContext
 )
 
-// PeerFromCtx returns the peer from ctx.
-func PeerFromCtx(ctx context.Context) string {
-	p, ok := peer.FromContext(ctx)
-	if !ok || p == nil {
-		return ""
-	}
-
-	return p.Addr.String()
-}
-
-// SpanInfo returns the span info.
-func SpanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue) {
-	attrs := []attribute.KeyValue{RPCSystemGRPC}
-	name, mAttrs := ParseFullMethod(fullMethod)
-	attrs = append(attrs, mAttrs...)
-	attrs = append(attrs, PeerAttr(peerAddress)...)
-	return name, attrs
-}
-
 // ParseFullMethod returns the method name and attributes.
 func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) {
 	name := strings.TrimLeft(fullMethod, "/")
@@ -78,6 +59,25 @@ func PeerAttr(addr string) []attribute.KeyValue {
 	}
 }
 
+// PeerFromCtx returns the peer from ctx.
+func PeerFromCtx(ctx context.Context) string {
+	p, ok := peer.FromContext(ctx)
+	if !ok || p == nil {
+		return ""
+	}
+
+	return p.Addr.String()
+}
+
+// SpanInfo returns the span info.
+func SpanInfo(fullMethod, peerAddress string) (string, []attribute.KeyValue) {
+	attrs := []attribute.KeyValue{RPCSystemGRPC}
+	name, mAttrs := ParseFullMethod(fullMethod)
+	attrs = append(attrs, mAttrs...)
+	attrs = append(attrs, PeerAttr(peerAddress)...)
+	return name, attrs
+}
+
 // TracerFromContext returns a tracer in ctx, otherwise returns a global tracer.
 func TracerFromContext(ctx context.Context) (tracer trace.Tracer) {
 	if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {