You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
3 years ago
|
package tracing
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
3 years ago
|
"fmt"
|
||
3 years ago
|
|
||
|
"go.opentelemetry.io/otel/trace"
|
||
|
"google.golang.org/grpc/peer"
|
||
|
"google.golang.org/grpc/stats"
|
||
|
)
|
||
|
|
||
|
// ClientHandler is tracing ClientHandler
|
||
3 years ago
|
type ClientHandler struct{}
|
||
3 years ago
|
|
||
|
// HandleConn exists to satisfy gRPC stats.Handler.
|
||
2 years ago
|
func (c *ClientHandler) HandleConn(_ context.Context, _ stats.ConnStats) {
|
||
3 years ago
|
fmt.Println("Handle connection.")
|
||
3 years ago
|
}
|
||
|
|
||
|
// TagConn exists to satisfy gRPC stats.Handler.
|
||
2 years ago
|
func (c *ClientHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context {
|
||
3 years ago
|
return ctx
|
||
|
}
|
||
|
|
||
|
// HandleRPC implements per-RPC tracing and stats instrumentation.
|
||
|
func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
|
||
3 years ago
|
if _, ok := rs.(*stats.OutHeader); !ok {
|
||
|
return
|
||
|
}
|
||
|
p, ok := peer.FromContext(ctx)
|
||
|
if !ok {
|
||
|
return
|
||
|
}
|
||
2 years ago
|
span := trace.SpanFromContext(ctx)
|
||
|
if span.SpanContext().IsValid() {
|
||
|
span.SetAttributes(peerAttr(p.Addr.String())...)
|
||
3 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// TagRPC implements per-RPC context management.
|
||
2 years ago
|
func (c *ClientHandler) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context {
|
||
3 years ago
|
return ctx
|
||
|
}
|