Skip to content

Commit

Permalink
fix: set grpc useragent (#1847)
Browse files Browse the repository at this point in the history
* fix: set grpc useragent

* fix: review comments
  • Loading branch information
surbhigarg92 authored May 17, 2023
1 parent dd9d505 commit 021e54e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/common-grpc/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/common/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 021e54e

Please sign in to comment.