You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That is, given a counter (or other metric) that has labels 'a', 'b', 'c' (AKA Counter<'a'|'b'|'c'>), then counter.curry({a: 'hello'}) would return a Counter<'b'|'c'> and counter.curry({a: 'hello', c: 'world'}) would return a Counter<'b'>, and counter.curry({d: 'oh dear'}) would be a compile/runtime error (depending on if one is using TypeScript and with what strictness settings).
Notably the returned object should support all the same methods as a full metric object (labels, curry, etc.), not just the observe or inc methods.
This feature would be much more compelling if we could work out how to avoid storing the defaults with each result. I've been reworking storage but without this in mind, since the registry supports global defaults, and applies them late - I have an open PR to make that code about 25% faster #683.
If you're adding something like hostname, appinstance, region, I would strongly recommend you use that feature as much as you possibly can. Right now adding defaults to every metric would make already slow metrics even slower, particularly at get(), which some people have complained is already gumming up the event loop.
Also as has been pointed out elsewhere, sometimes it might be useful to assign certain well known labels, like instance and host and service name in an aggregator running as a sidecar.
That did not drop the first argument but did an Object.assign(), but for chained calls of depth > 2 you'd also have to somehow access the previous values in order to merge them together, which could be a bit weird to plumb. The default bind() hides the bound variables in a symbol so you won't be looking it up that way.
And you'd have to change getLabels() to not throw on an incomplete list.
Activity
zbjornson commentedon Jan 23, 2021
I'm neutral on this because it's easy enough to do it in user-space, but if you want to submit a PR, I'm happy to review it.
mgabeler-lee-6rs commentedon Jan 26, 2021
Happy to take a stab at it -- I indeed did implement it in "user space" for my use case, can make a more generic version of that code to submit.
jdmarshall commentedon Jul 9, 2025
This feature would be much more compelling if we could work out how to avoid storing the defaults with each result. I've been reworking storage but without this in mind, since the registry supports global defaults, and applies them late - I have an open PR to make that code about 25% faster #683.
If you're adding something like hostname, appinstance, region, I would strongly recommend you use that feature as much as you possibly can. Right now adding defaults to every metric would make already slow metrics even slower, particularly at get(), which some people have complained is already gumming up the event loop.
jdmarshall commentedon Jul 2, 2026
Also as has been pointed out elsewhere, sometimes it might be useful to assign certain well known labels, like instance and host and service name in an aggregator running as a sidecar.
jdmarshall commentedon Jul 3, 2026
If anyone is still interested in working on this, the trick would be that you'd have to bind a special version of inc() and friends
That did not drop the first argument but did an
Object.assign(), but for chained calls of depth > 2 you'd also have to somehow access the previous values in order to merge them together, which could be a bit weird to plumb. The defaultbind()hides the bound variables in a symbol so you won't be looking it up that way.And you'd have to change
getLabels()to not throw on an incomplete list.jdmarshall commentedon Aug 20, 2026
This request can be fulfilled by #812