stats: add client side user agent to outgoing header (#3331)
This commit is contained in:
@ -680,14 +680,15 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if t.statsHandler != nil {
|
if t.statsHandler != nil {
|
||||||
header, _, _ := metadata.FromOutgoingContextRaw(ctx)
|
header, _ := metadata.FromOutgoingContext(ctx)
|
||||||
|
header.Set("user-agent", t.userAgent)
|
||||||
outHeader := &stats.OutHeader{
|
outHeader := &stats.OutHeader{
|
||||||
Client: true,
|
Client: true,
|
||||||
FullMethod: callHdr.Method,
|
FullMethod: callHdr.Method,
|
||||||
RemoteAddr: t.remoteAddr,
|
RemoteAddr: t.remoteAddr,
|
||||||
LocalAddr: t.localAddr,
|
LocalAddr: t.localAddr,
|
||||||
Compression: callHdr.SendCompress,
|
Compression: callHdr.SendCompress,
|
||||||
Header: header.Copy(),
|
Header: header,
|
||||||
}
|
}
|
||||||
t.statsHandler.HandleRPC(s.ctx, outHeader)
|
t.statsHandler.HandleRPC(s.ctx, outHeader)
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,9 @@ type rpcCtxKey struct{}
|
|||||||
var (
|
var (
|
||||||
// For headers sent to server:
|
// For headers sent to server:
|
||||||
testMetadata = metadata.MD{
|
testMetadata = metadata.MD{
|
||||||
"key1": []string{"value1"},
|
"key1": []string{"value1"},
|
||||||
"key2": []string{"value2"},
|
"key2": []string{"value2"},
|
||||||
|
"user-agent": []string{fmt.Sprintf("test/0.0.1 grpc-go/%s", grpc.Version)},
|
||||||
}
|
}
|
||||||
// For headers sent from server:
|
// For headers sent from server:
|
||||||
testHeaderMetadata = metadata.MD{
|
testHeaderMetadata = metadata.MD{
|
||||||
@ -220,7 +221,11 @@ func (te *test) clientConn() *grpc.ClientConn {
|
|||||||
if te.cc != nil {
|
if te.cc != nil {
|
||||||
return te.cc
|
return te.cc
|
||||||
}
|
}
|
||||||
opts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithBlock()}
|
opts := []grpc.DialOption{
|
||||||
|
grpc.WithInsecure(),
|
||||||
|
grpc.WithBlock(),
|
||||||
|
grpc.WithUserAgent("test/0.0.1"),
|
||||||
|
}
|
||||||
if te.compress == "gzip" {
|
if te.compress == "gzip" {
|
||||||
opts = append(opts,
|
opts = append(opts,
|
||||||
grpc.WithCompressor(grpc.NewGZIPCompressor()),
|
grpc.WithCompressor(grpc.NewGZIPCompressor()),
|
||||||
|
Reference in New Issue
Block a user