diff options
-rw-r--r-- | src/node/src/client.js | 6 | ||||
-rw-r--r-- | src/node/test/surface_test.js | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/node/src/client.js b/src/node/src/client.js index b7bad949d4..06a0f3637f 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -47,6 +47,7 @@ var Readable = stream.Readable; var Writable = stream.Writable; var Duplex = stream.Duplex; var util = require('util'); +var version = require('../package.json').version; util.inherits(ClientWritableStream, Writable); @@ -517,7 +518,10 @@ function makeClientConstructor(methods, serviceName) { callback(null, metadata); }; } - + if (!options) { + options = {}; + } + options.GRPC_ARG_PRIMARY_USER_AGENT_STRING = 'grpc-node/' + version; this.server_address = address.replace(/\/$/, ''); this.channel = new grpc.Channel(address, options); this.auth_uri = this.server_address + '/' + serviceName; diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 18178e49e4..3cb68f8cd8 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -258,6 +258,16 @@ describe('Echo metadata', function() { }); call.end(); }); + it('shows the correct user-agent string', function(done) { + var version = require('../package.json').version; + var call = client.unary({}, function(err, data) { + assert.ifError(err); + }, {key: ['value']}); + call.on('metadata', function(metadata) { + assert(_.startsWith(metadata['user-agent'], 'grpc-node/' + version)); + done(); + }); + }); }); describe('Other conditions', function() { var client; |