-
Notifications
You must be signed in to change notification settings - Fork 678
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
Check for None result in gRPC (#3380) #3381
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR, could you please write a test for this to avoid regressions in the future? |
That was an adventure! Added a test that counts |
@@ -43,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
### Fixed | |||
|
|||
- `opentelemetry-instrumentation-grpc` Check for None result in gRPC |
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.
This need to be moved to the unreleased version
def counting_span_end(original_end): | ||
def wrapper(*args, **kwargs): | ||
nonlocal span_end_count | ||
span_end_count += 1 | ||
return original_end(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
def patched_start_span(*args, **kwargs): | ||
span = original_start_span(*args, **kwargs) | ||
span.end = counting_span_end(span.end) | ||
return span | ||
|
||
tracer.start_span = patched_start_span |
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.
Have you tried patching the end method of Span instead? something like with mock.patch.object(Span, "end") as span_end_mock:
and then self.assertEqual(span_end_mock.call_count, 1)
?
Description
This is a fix for #3380 that checks explicitly for a
None
result rather than evaluating truthiness. PubSub results with zero messages evaluate toFalse
, causingspan.end()
to be called twice.Fixes #3380
Type of change
How Has This Been Tested?
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.