-
Notifications
You must be signed in to change notification settings - Fork 965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the scope current when needed for grpc server instrumentation #3806
Make the scope current when needed for grpc server instrumentation #3806
Conversation
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
} | ||
|
||
@Override | ||
public void onMessage(RespT message) { | ||
if (this.scope != this.registry.getCurrentObservationScope()) { | ||
this.scope.makeCurrent(); | ||
this.registry.setCurrentObservationScope(this.scope); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afair this is redundant cause scope will make itself current.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, makeCurrent
does not update the registry.getCurrentObservationScope()
.
Created a PR to fix it: #3808
listenerA.onHalfClose(); | ||
assertThat(registry.getCurrentObservation()).isSameAs(observationA); | ||
assertThat(registry.getCurrentObservationScope()).isSameAs(scopeA); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test to ensure that we're not leaving any unclosed scopes? I understand that after making all calls current scope should be null?
superseded by #3836 |
When grpc client uses non-blocking requests, the server calls
interceptor#interceptCall
multiple times first, then proceed to thelistener#on...
methods. It is different from blocking requests that call those methods sequentially per request. This behavior causes multiple scopes to be opened on the same thread ininterceptCall
and wrongly consumes them inon...
methods.This change compares the current scope held by the
ObservationRegistry
against the withheldscope
by the grpc listener callback. When they are different, make the withheld scope current; then, the subsequent logic can pick up the proper target observation.Closes gh-3805