-
Notifications
You must be signed in to change notification settings - Fork 147
Description
The problem
Wrong typehints
The docstring for end_time in the following sections seems to be wrong, it should be in float but docstring says int
aws-xray-sdk-python/aws_xray_sdk/core/models/entity.py
Lines 62 to 76 in 692a439
| def close(self, end_time=None): | |
| """ | |
| Close the trace entity by setting `end_time` | |
| and flip the in progress flag to False. | |
| :param int end_time: Epoch in seconds. If not specified | |
| current time will be used. | |
| """ | |
| self._check_ended() | |
| if end_time: | |
| self.end_time = end_time | |
| else: | |
| self.end_time = time.time() | |
| self.in_progress = False |
aws-xray-sdk-python/aws_xray_sdk/core/models/subsegment.py
Lines 130 to 140 in 692a439
| def close(self, end_time=None): | |
| """ | |
| Close the trace entity by setting `end_time` | |
| and flip the in progress flag to False. Also decrement | |
| parent segment's ref counter by 1. | |
| :param int end_time: Epoch in seconds. If not specified | |
| current time will be used. | |
| """ | |
| super().close(end_time) | |
| self.parent_segment.decrement_ref_counter() |
aws-xray-sdk-python/aws_xray_sdk/core/context.py
Lines 43 to 57 in 692a439
| def end_segment(self, end_time=None): | |
| """ | |
| End the current active segment. | |
| :param int end_time: epoch in seconds. If not specified the current | |
| system time will be used. | |
| """ | |
| entity = self.get_trace_entity() | |
| if not entity: | |
| log.warning("No segment to end") | |
| return | |
| if self._is_subsegment(entity): | |
| entity.parent_segment.close(end_time) | |
| else: | |
| entity.close(end_time) |
aws-xray-sdk-python/aws_xray_sdk/core/context.py
Lines 73 to 88 in 692a439
| def end_subsegment(self, end_time=None): | |
| """ | |
| End the current active segment. Return False if there is no | |
| subsegment to end. | |
| :param int end_time: epoch in seconds. If not specified the current | |
| system time will be used. | |
| """ | |
| subsegment = self.get_trace_entity() | |
| if self._is_subsegment(subsegment): | |
| subsegment.close(end_time) | |
| self._local.entities.pop() | |
| return True | |
| else: | |
| log.warning("No subsegment to end.") | |
| return False |
Correct typehints (on top of wrong ones)
And you can find the following code calling the function above using the correct type hint float
aws-xray-sdk-python/aws_xray_sdk/core/recorder.py
Lines 342 to 347 in 692a439
| def end_subsegment(self, end_time=None): | |
| """ | |
| End the current active subsegment. If this is the last one open | |
| under its parent segment, the entire segment will be sent. | |
| :param float end_time: subsegment compeletion in unix epoch in seconds. |
aws-xray-sdk-python/aws_xray_sdk/core/recorder.py
Lines 247 to 254 in 692a439
| def end_segment(self, end_time=None): | |
| """ | |
| End the current segment and send it to X-Ray daemon | |
| if it is ready to send. Ready means segment and | |
| all its subsegments are closed. | |
| :param float end_time: segment completion in unix epoch in seconds. | |
| """ |
Fix
Verify this issue and Change typehint for end_time in Wrong typehints section from int to float