This repository was archived by the owner on Mar 4, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -417,6 +417,12 @@ export class GrpcService extends Service {
417417
418418 this . maxRetries = options . maxRetries ;
419419 this . userAgent = util . getUserAgentFromPackageJson ( config . packageJson ) ;
420+
421+ if ( this . providedUserAgent ) {
422+ this . userAgent = `${ this . providedUserAgent } ${ this . userAgent } ` ;
423+ }
424+ options [ 'grpc.primary_user_agent' ] = this . userAgent ;
425+
420426 this . activeServiceMap_ = new Map ( ) ;
421427 this . protos = { } ;
422428 const protoServices = config . protoServices ;
Original file line number Diff line number Diff line change @@ -402,6 +402,18 @@ describe('GrpcService', () => {
402402 assert . strictEqual ( grpcService . userAgent , userAgent ) ;
403403 } ) ;
404404
405+ it ( 'should set the primary_user_agent from user-agent' , ( ) => {
406+ const userAgent = 'user-agent/0.0.0' ;
407+
408+ getUserAgentFromPackageJsonOverride = packageJson => {
409+ assert . strictEqual ( packageJson , CONFIG . packageJson ) ;
410+ return userAgent ;
411+ } ;
412+
413+ new GrpcService ( CONFIG , OPTIONS ) ;
414+ assert . strictEqual ( OPTIONS [ 'grpc.primary_user_agent' ] , userAgent ) ;
415+ } ) ;
416+
405417 it ( 'should localize the service' , ( ) => {
406418 assert . deepStrictEqual (
407419 Object . keys ( grpcService . protos ) ,
You can’t perform that action at this time.
0 commit comments