diff --git a/lib/statsd.js b/lib/statsd.js index f27383b..44ba752 100644 --- a/lib/statsd.js +++ b/lib/statsd.js @@ -73,7 +73,9 @@ Client.prototype.timing = function (stat, time, sampleRate, tags, callback) { * @param callback {Function=} Callback when message is done being delivered. Optional. */ Client.prototype.increment = function (stat, value, sampleRate, tags, callback) { - this.sendAll(stat, value || 1, 'c', sampleRate, tags, callback); + value = (value === undefined || value === null) ? 1 : value; + + this.sendAll(stat, value, 'c', sampleRate, tags, callback); }; /** @@ -85,7 +87,9 @@ Client.prototype.increment = function (stat, value, sampleRate, tags, callback) * @param callback {Function=} Callback when message is done being delivered. Optional. */ Client.prototype.decrement = function (stat, value, sampleRate, tags, callback) { - this.sendAll(stat, -value || -1, 'c', sampleRate, tags, callback); + value = (value === undefined || value === null) ? 1 : value; + + this.sendAll(stat, -value, 'c', sampleRate, tags, callback); }; /** diff --git a/test/test_statsd.js b/test/test_statsd.js index 0fbb314..fe0803f 100644 --- a/test/test_statsd.js +++ b/test/test_statsd.js @@ -527,6 +527,19 @@ describe('StatsD', function(){ it('should send no increment stat when a mock Client is used', function(finished){ assertMockClientMethod('increment', finished); }); + + it('should send 0 when value is 0', function(finished){ + udpTest(function(message, server){ + assert.equal(message, 'test:0|c'); + server.close(); + finished(); + }, function(server){ + var address = server.address(), + statsd = new StatsD(address.address, address.port); + + statsd.increment('test', 0); + }); + }); }); describe('#decrement', function(finished){ @@ -603,6 +616,19 @@ describe('StatsD', function(){ it('should send no decrement stat when a mock Client is used', function(finished){ assertMockClientMethod('decrement', finished); }); + + it('should send 0 when value is 0', function(finished){ + udpTest(function(message, server){ + assert.equal(message, 'test:0|c'); + server.close(); + finished(); + }, function(server){ + var address = server.address(), + statsd = new StatsD(address.address, address.port); + + statsd.decrement('test', 0); + }); + }); }); describe('#set', function(finished){