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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
from .segment import Segment
from ..exceptions.exceptions import FacadeSegmentMutationException
MUTATION_UNSUPPORTED_MESSAGE = 'FacadeSegments cannot be mutated.'
class FacadeSegment(Segment):
"""
This type of segment should only be used in an AWS Lambda environment.
It holds the same id, traceid and sampling decision as
the segment generated by Lambda service but its properties cannot
be mutated except for its subsegments. If this segment is created
before Lambda worker finishes initializatioin, all the child
subsegments will be discarded.
"""
def __init__(self, name, entityid, traceid, sampled):
self.initializing = self._is_initializing(
entityid=entityid,
traceid=traceid,
sampled=sampled,
)
super(FacadeSegment, self).__init__(
name=name,
entityid=entityid,
traceid=traceid,
sampled=sampled,
)
def close(self, end_time=None):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def put_http_meta(self, key, value):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def put_annotation(self, key, value):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def put_metadata(self, key, value, namespace='default'):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def set_aws(self, aws_meta):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def set_user(self, user):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def add_throttle_flag(self):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def add_fault_flag(self):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def add_error_flag(self):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def add_exception(self, exception, stack, remote=False):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def apply_status_code(self, status_code):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def serialize(self):
"""
Unsupported operation. Will raise an exception.
"""
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE)
def ready_to_send(self):
"""
Facade segment should never be sent out. This always
return False.
"""
return False
def increment(self):
"""
Increment total subsegments counter by 1.
"""
self._subsegments_counter.increment()
def decrement_ref_counter(self):
"""
No-op
"""
pass
def _is_initializing(self, entityid, traceid, sampled):
return not entityid or not traceid or sampled is None
|