yaorg/node-measured

Counter not working

megastef opened this issue · 3 comments

HI, I installed measured using this:

npm install measured@latest
measured@1.0.0 node_modules/measured
└── inherits@2.0.1

Then calling node console (0.12.1):

> var m = require ('measured')
undefined
> var counter = new m.Counter()
undefined
> counter
{ _count: 0 }
> util.inspect (counter)
'{ _count: 0 }'

The functions inc(), dec(), toJSON() are missing. I looked quickly into the source code in Github - but could not see where the problem is. Any idea?

The methods are there. They are not shown by util.inspect though.

This is how I tested using node 0.10.38:

$ npm i measured
measured@1.0.0 node_modules/measured
└── inherits@2.0.1
$ node
> var m = require('measured')
undefined
> var c = new m.Counter()
undefined
> c
{ _count: 0 }
> c.inc()
undefined
> c
{ _count: 1 }

Can you try the same thing on node 0.12.1 please?

All this works fine. The problem was somewhere else in my code I used "delegate" for different "Measured" metric types - my 'generic' function went wrong because counters don't return an Object when calling toJSON(). Added a type check for "Number" and handle it now correctly. Thanks for looking into it.

Thanks for updating the issue 👍