feat: add trace.SpanIDFromContext and trace.TraceIDFromContext (#2654)

This commit is contained in:
Kevin Wan
2022-12-02 11:00:44 +08:00
committed by GitHub
parent 10fd9131a1
commit 9941055eaa
4 changed files with 68 additions and 21 deletions

View File

@@ -5,6 +5,7 @@ import (
"net"
"strings"
ztrace "github.com/zeromicro/go-zero/internal/trace"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"google.golang.org/grpc/peer"
@@ -12,6 +13,13 @@ import (
const localhost = "127.0.0.1"
var (
// SpanIDFromContext returns the span id from ctx.
SpanIDFromContext = ztrace.SpanIDFromContext
// TraceIDFromContext returns the trace id from ctx.
TraceIDFromContext = ztrace.TraceIDFromContext
)
// PeerFromCtx returns the peer from ctx.
func PeerFromCtx(ctx context.Context) string {
p, ok := peer.FromContext(ctx)