-
Notifications
You must be signed in to change notification settings - Fork 711
Exit the lock before logging #1317
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
Conversation
Before this change, the following would cause unintended behaviour in the Span API's add_event, update_name and set_status methods: - thread A calls set_status, locks to check if a span has ended, and releases the lock - thread B obtains the lock and ends a span - thread A continues its call of set_status This change ensures that the update operations are done with the lock being held. It's done in a decorator, but that is completely optional.
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.
I think the try/catch is worth trying to remove, otherwise LGTM!
logger.warning("Calling %s on an ended span.", func.__name__) | ||
return | ||
func(self, *args, **kwargs) | ||
try: |
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.
I might consider re-writing this try/catch as an if/else instead. A good way to do this is to set a value inside the lock, and use that to determine if the logging call is needed outside.
Exception handling has a lot of overhead aside from branching.
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.
Good point, this just seemed like the cleanest way to implement. Have reworked to use if/else, please take a look
raise _SpanEndedException | ||
func(self, *args, **kwargs) | ||
except _SpanEndedException: | ||
logger.warning("Calling %s on an ended span.", func.__name__) |
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.
would it be good time to fix this message? I feel like this implies the cal occurs, even if the span has already ended.
@@ -371,13 +371,21 @@ def _create_immutable_attributes(attributes): | |||
return MappingProxyType(attributes.copy() if attributes else {}) | |||
|
|||
|
|||
class _SpanEndedException(Exception): |
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 is unescessary, correct?
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.
correct, forgot to clean it up
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.
approving, have one comment that's worth a look though. Thanks!
Description
Avoid logging inside a lock.
Fixes #1316
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Checklist: