File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
src/Grpc.Net.Client/Internal
test/Grpc.Net.Client.Tests Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -58,18 +58,21 @@ static GrpcProtocolConstants()
5858 {
5959 var userAgent = "grpc-dotnet" ;
6060
61+ // Use the assembly file version in the user agent.
62+ // We are not using `AssemblyInformationalVersionAttribute` because Source Link appends
63+ // the git hash to it, and sending a long user agent has perf implications.
6164 var assemblyVersion = typeof ( GrpcProtocolConstants )
6265 . Assembly
63- . GetCustomAttributes < AssemblyInformationalVersionAttribute > ( )
66+ . GetCustomAttributes < AssemblyFileVersionAttribute > ( )
6467 . FirstOrDefault ( ) ;
6568
6669 Debug . Assert ( assemblyVersion != null ) ;
6770
68- // assembly version attribute should always be present
69- // but in case it isn't then don't include version in user-agent
71+ // Assembly file version attribute should always be present,
72+ // but in case it isn't then don't include version in user-agent.
7073 if ( assemblyVersion != null )
7174 {
72- userAgent += "/" + assemblyVersion . InformationalVersion ;
75+ userAgent += "/" + assemblyVersion . Version ;
7376 }
7477
7578 UserAgentHeader = ProductInfoHeaderValue . Parse ( userAgent ) ;
Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ public async Task AsyncUnaryCall_Success_HttpRequestMessagePopulated()
7575 Assert . AreEqual ( GrpcProtocolConstants . UserAgentHeader , userAgent ) ;
7676 Assert . AreEqual ( "grpc-dotnet" , userAgent . Product . Name ) ;
7777 Assert . IsTrue ( ! string . IsNullOrEmpty ( userAgent . Product . Version ) ) ;
78+
79+ // Santity check that the user agent doesn't have the git hash in it and isn't too long.
80+ // Sending a long user agent with each call has performance implications.
81+ Assert . IsTrue ( ! userAgent . Product . Version . Contains ( '+' ) ) ;
82+ Assert . IsTrue ( userAgent . Product . Version . Length <= 10 ) ;
7883 }
7984
8085 [ Test ]
You can’t perform that action at this time.
0 commit comments