stats: add client side user agent to outgoing header (#3331)

This commit is contained in:
Piotr Kowalczuk
2020-01-31 12:34:44 -06:00
committed by GitHub
parent b88d2d7465
commit 7621679bee
2 changed files with 11 additions and 5 deletions

View File

@ -680,14 +680,15 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
}
}
if t.statsHandler != nil {
header, _, _ := metadata.FromOutgoingContextRaw(ctx)
header, _ := metadata.FromOutgoingContext(ctx)
header.Set("user-agent", t.userAgent)
outHeader := &stats.OutHeader{
Client: true,
FullMethod: callHdr.Method,
RemoteAddr: t.remoteAddr,
LocalAddr: t.localAddr,
Compression: callHdr.SendCompress,
Header: header.Copy(),
Header: header,
}
t.statsHandler.HandleRPC(s.ctx, outHeader)
}

View File

@ -48,6 +48,7 @@ var (
testMetadata = metadata.MD{
"key1": []string{"value1"},
"key2": []string{"value2"},
"user-agent": []string{fmt.Sprintf("test/0.0.1 grpc-go/%s", grpc.Version)},
}
// For headers sent from server:
testHeaderMetadata = metadata.MD{
@ -220,7 +221,11 @@ func (te *test) clientConn() *grpc.ClientConn {
if te.cc != nil {
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" {
opts = append(opts,
grpc.WithCompressor(grpc.NewGZIPCompressor()),