/usr/lib/python2.7/dist-packages/aws_xray_sdk/core/models/segment.py is in python-aws-xray-sdk 0.95-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | import copy
from .entity import Entity
from .traceid import TraceId
from ..utils.atomic_counter import AtomicCounter
from ..exceptions.exceptions import SegmentNameMissingException
class Segment(Entity):
"""
The compute resources running your application logic send data
about their work as segments. A segment provides the resource's name,
details about the request, and details about the work done.
"""
def __init__(self, name, entityid=None, traceid=None,
parent_id=None, sampled=True):
"""
Create a segment object.
:param str name: segment name. If not specified a
SegmentNameMissingException will be thrown.
:param str entityid: hexdigits segment id.
:param str traceid: The trace id of the segment.
:param str parent_id: The parent id of the segment. It comes
from id of an upstream segment or subsegment.
:param bool sampled: If False this segment will not be sent
to the X-Ray daemon.
"""
if not name:
raise SegmentNameMissingException("Segment name is required.")
super(Segment, self).__init__(name)
if not traceid:
traceid = TraceId().to_id()
self.trace_id = traceid
if entityid:
self.id = entityid
self.in_progress = True
self.sampled = sampled
self.ref_counter = AtomicCounter()
self._subsegments_counter = AtomicCounter()
if parent_id:
self.parent_id = parent_id
def add_subsegment(self, subsegment):
"""
Add input subsegment as a child subsegment and increment
reference counter and total subsegments counter.
"""
super(Segment, self).add_subsegment(subsegment)
self.increment()
def increment(self):
"""
Increment reference counter to track on open subsegments
and total subsegments counter to track total size of subsegments
it currently hold.
"""
self.ref_counter.increment()
self._subsegments_counter.increment()
def decrement_ref_counter(self):
"""
Decrement reference counter by 1 when a subsegment is closed.
"""
self.ref_counter.decrement()
def ready_to_send(self):
"""
Return True if the segment doesn't have any open subsegments
and itself is not in progress.
"""
return self.ref_counter.get_current() <= 0 and not self.in_progress
def get_total_subsegments_size(self):
"""
Return the number of total subsegments regardless of open or closed.
"""
return self._subsegments_counter.get_current()
def decrement_subsegments_size(self):
"""
Decrement total subsegments by 1. This usually happens when
a subsegment is streamed out.
"""
return self._subsegments_counter.decrement()
def remove_subsegment(self, subsegment):
"""
Remove the reference of input subsegment.
"""
super(Segment, self).remove_subsegment(subsegment)
self.decrement_subsegments_size()
def __getstate__(self):
"""
Used by jsonpikle to remove unwanted fields.
"""
properties = copy.copy(self.__dict__)
super(Segment, self)._delete_empty_properties(properties)
del properties['ref_counter']
del properties['_subsegments_counter']
return properties
|