diff --git a/src/common-grpc/service.ts b/src/common-grpc/service.ts index 24e84b884..08f5642d7 100644 --- a/src/common-grpc/service.ts +++ b/src/common-grpc/service.ts @@ -417,6 +417,12 @@ export class GrpcService extends Service { this.maxRetries = options.maxRetries; this.userAgent = util.getUserAgentFromPackageJson(config.packageJson); + + if (this.providedUserAgent) { + this.userAgent = `${this.providedUserAgent} ${this.userAgent}`; + } + options['grpc.primary_user_agent'] = this.userAgent; + this.activeServiceMap_ = new Map(); this.protos = {}; const protoServices = config.protoServices; diff --git a/test/common/service.ts b/test/common/service.ts index bb5d417df..293f98d0f 100644 --- a/test/common/service.ts +++ b/test/common/service.ts @@ -402,6 +402,18 @@ describe('GrpcService', () => { assert.strictEqual(grpcService.userAgent, userAgent); }); + it('should set the primary_user_agent from user-agent', () => { + const userAgent = 'user-agent/0.0.0'; + + getUserAgentFromPackageJsonOverride = packageJson => { + assert.strictEqual(packageJson, CONFIG.packageJson); + return userAgent; + }; + + new GrpcService(CONFIG, OPTIONS); + assert.strictEqual(OPTIONS['grpc.primary_user_agent'], userAgent); + }); + it('should localize the service', () => { assert.deepStrictEqual( Object.keys(grpcService.protos),