micrometer icon indicating copy to clipboard operation
micrometer copied to clipboard

[Question] Does MeterBinder needs to be thread safe?

Open kkocel opened this issue 1 year ago • 2 comments

Should I make my MeterBinder implementations thread-safe? Docs do not specify that...

kkocel avatar Sep 02 '24 11:09 kkocel

Thank you for the question. It has sparked some discussion among the team. We will update documentation on this.

MeterBinder instances generally aren't expected to have bindTo called often. Typically it would be expected that it is called on MeterRegistry instances at configuration time for an application. However, I think even our own MeterBinder implementations may not be consistent on whether the implementation is done in such a way that the same MeterBinder instance can be bound to multiple registries without issue. So I think that's a question/expectation to decide on before answering about thread safety. By thread safe, do you mean when bindTo is called concurrently for the same MeterBinder instance? Do you have a use case in which you expect this to happen with some MeterBinder, or is it just a general question about implementation concerns?

shakuzen avatar Sep 12 '24 08:09 shakuzen

It's more about implementation concerns - I've seen bindTo methods in some libraries that use synchronized keywords or ReentrantLock and micrometer implementations that do not use such mechanisms.

kkocel avatar Sep 12 '24 08:09 kkocel