mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
chore: reformat code (#2925)
This commit is contained in:
parent
3bc40d9eaf
commit
a5e5f04bcf
@ -14,11 +14,7 @@ var mongoCmdAttributeKey = attribute.Key("mongo.cmd")
|
|||||||
|
|
||||||
func startSpan(ctx context.Context, cmd string) (context.Context, oteltrace.Span) {
|
func startSpan(ctx context.Context, cmd string) (context.Context, oteltrace.Span) {
|
||||||
tracer := trace.TracerFromContext(ctx)
|
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))
|
span.SetAttributes(mongoCmdAttributeKey.String(cmd))
|
||||||
|
|
||||||
return ctx, span
|
return ctx, span
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/mapping"
|
"github.com/zeromicro/go-zero/core/mapping"
|
||||||
"github.com/zeromicro/go-zero/core/timex"
|
"github.com/zeromicro/go-zero/core/timex"
|
||||||
"github.com/zeromicro/go-zero/core/trace"
|
"github.com/zeromicro/go-zero/core/trace"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/codes"
|
"go.opentelemetry.io/otel/codes"
|
||||||
oteltrace "go.opentelemetry.io/otel/trace"
|
oteltrace "go.opentelemetry.io/otel/trace"
|
||||||
|
@ -14,11 +14,7 @@ var sqlAttributeKey = attribute.Key("sql.method")
|
|||||||
|
|
||||||
func startSpan(ctx context.Context, method string) (context.Context, oteltrace.Span) {
|
func startSpan(ctx context.Context, method string) (context.Context, oteltrace.Span) {
|
||||||
tracer := trace.TracerFromContext(ctx)
|
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))
|
span.SetAttributes(sqlAttributeKey.String(method))
|
||||||
|
|
||||||
return start, span
|
return start, span
|
||||||
|
@ -22,25 +22,6 @@ var (
|
|||||||
TraceIDFromContext = ztrace.TraceIDFromContext
|
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.
|
// ParseFullMethod returns the method name and attributes.
|
||||||
func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) {
|
func ParseFullMethod(fullMethod string) (string, []attribute.KeyValue) {
|
||||||
name := strings.TrimLeft(fullMethod, "/")
|
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.
|
// TracerFromContext returns a tracer in ctx, otherwise returns a global tracer.
|
||||||
func TracerFromContext(ctx context.Context) (tracer trace.Tracer) {
|
func TracerFromContext(ctx context.Context) (tracer trace.Tracer) {
|
||||||
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
|
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
|
||||||
|
Loading…
Reference in New Issue
Block a user