1 Star 1 Fork 3

menuiis/gkit

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
stats_handler.go 1.02 KB
Copy Edit Raw Blame History
SongZhibin97 authored 2022-06-16 15:17 +08:00 . Update stats_handler.go
package trace
import (
"context"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/stats"
)
// ClientHandler 客户端追踪
type ClientHandler struct{}
// HandleConn exists to satisfy gRPC stats.Handler.
func (c *ClientHandler) HandleConn(ctx context.Context, cs stats.ConnStats) {}
// TagConn exists to satisfy gRPC stats.Handler.
func (c *ClientHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context {
return ctx
}
// HandleRPC implements per-RPC tracing and stats instrumentation.
func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
if _, ok := rs.(*stats.OutHeader); ok {
if p, ok := peer.FromContext(ctx); ok {
remoteAddr := p.Addr.String()
if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
span.SetAttributes(peerAttr(remoteAddr)...)
}
}
}
}
// TagRPC implements per-RPC context management.
func (c *ClientHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context {
return ctx
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/menciis/gkit.git
git@gitee.com:menciis/gkit.git
menciis
gkit
gkit
d3f65ed26d21

Search