Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set grpc useragent #1847

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
surbhigarg92 marked this conversation as resolved.
Show resolved Hide resolved

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