1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-02-09 13:36:57 +02:00
kratos/middleware/tracing/statsHandler.go
Kagaya f7588a47de
fix: ci lint error (#1391)
* fix lint check

* fix lll lint error

* fix build error

* fix gomnd

* fix shadow declaration

* add make test command

* update
2021-08-31 10:14:57 +08:00

39 lines
1.0 KiB
Go

package tracing
import (
"context"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/stats"
)
// ClientHandler is tracing 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
}