|
|
|
@ -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() {
|
|
|
|
|