Skip to content

Commit 021e54e

Browse files
authored
fix: set grpc useragent (#1847)
* fix: set grpc useragent * fix: review comments
1 parent dd9d505 commit 021e54e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/common-grpc/service.ts

+6
Original file line numberDiff line numberDiff 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;

test/common/service.ts

+12
Original file line numberDiff line numberDiff 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),

0 commit comments

Comments
 (0)