Make the scope current when needed for grpc server instrumentation by ttddyy · Pull Request #3806 · micrometer-metrics/micrometer (original) (raw)
When grpc client uses non-blocking requests, the server calls
interceptor#interceptCall multiple times first, then proceed to the
listener#on... methods. It is different from blocking requests that call
those methods sequentially per request. The behavior causes multiple scopes to
be opened on the same thread in interceptCall and wrongly consumes them in
on... methods.
This change compares the current scope held by the ObservationRegistry
against the withheld scope. When they are different, make the withheld scope
current; then, the subsequent logic can pick the proper target observation.
Closes micrometer-metricsgh-3805