| 1 |
from .segment import Segment |
| 2 |
from ..exceptions.exceptions import FacadeSegmentMutationException |
| 3 |
|
| 4 |
|
| 5 |
MUTATION_UNSUPPORTED_MESSAGE = 'FacadeSegments cannot be mutated.' |
| 6 |
|
| 7 |
|
| 8 |
class FacadeSegment(Segment): |
| 9 |
""" |
| 10 |
This type of segment should only be used in an AWS Lambda environment. |
| 11 |
It holds the same id, traceid and sampling decision as |
| 12 |
the segment generated by Lambda service but its properties cannot |
| 13 |
be mutated except for its subsegments. If this segment is created |
| 14 |
before Lambda worker finishes initializatioin, all the child |
| 15 |
subsegments will be discarded. |
| 16 |
""" |
| 17 |
def __init__(self, name, entityid, traceid, sampled): |
| 18 |
|
| 19 |
self.initializing = self._is_initializing( |
| 20 |
entityid=entityid, |
| 21 |
traceid=traceid, |
| 22 |
sampled=sampled, |
| 23 |
) |
| 24 |
|
| 25 |
super(FacadeSegment, self).__init__( |
| 26 |
name=name, |
| 27 |
entityid=entityid, |
| 28 |
traceid=traceid, |
| 29 |
sampled=sampled, |
| 30 |
) |
| 31 |
|
| 32 |
def close(self, end_time=None): |
| 33 |
""" |
| 34 |
Unsupported operation. Will raise an exception. |
| 35 |
""" |
| 36 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 37 |
|
| 38 |
def put_http_meta(self, key, value): |
| 39 |
""" |
| 40 |
Unsupported operation. Will raise an exception. |
| 41 |
""" |
| 42 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 43 |
|
| 44 |
def put_annotation(self, key, value): |
| 45 |
""" |
| 46 |
Unsupported operation. Will raise an exception. |
| 47 |
""" |
| 48 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 49 |
|
| 50 |
def put_metadata(self, key, value, namespace='default'): |
| 51 |
""" |
| 52 |
Unsupported operation. Will raise an exception. |
| 53 |
""" |
| 54 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 55 |
|
| 56 |
def set_aws(self, aws_meta): |
| 57 |
""" |
| 58 |
Unsupported operation. Will raise an exception. |
| 59 |
""" |
| 60 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 61 |
|
| 62 |
def set_user(self, user): |
| 63 |
""" |
| 64 |
Unsupported operation. Will raise an exception. |
| 65 |
""" |
| 66 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 67 |
|
| 68 |
def add_throttle_flag(self): |
| 69 |
""" |
| 70 |
Unsupported operation. Will raise an exception. |
| 71 |
""" |
| 72 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 73 |
|
| 74 |
def add_fault_flag(self): |
| 75 |
""" |
| 76 |
Unsupported operation. Will raise an exception. |
| 77 |
""" |
| 78 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 79 |
|
| 80 |
def add_error_flag(self): |
| 81 |
""" |
| 82 |
Unsupported operation. Will raise an exception. |
| 83 |
""" |
| 84 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 85 |
|
| 86 |
def add_exception(self, exception, stack, remote=False): |
| 87 |
""" |
| 88 |
Unsupported operation. Will raise an exception. |
| 89 |
""" |
| 90 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 91 |
|
| 92 |
def apply_status_code(self, status_code): |
| 93 |
""" |
| 94 |
Unsupported operation. Will raise an exception. |
| 95 |
""" |
| 96 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 97 |
|
| 98 |
def serialize(self): |
| 99 |
""" |
| 100 |
Unsupported operation. Will raise an exception. |
| 101 |
""" |
| 102 |
raise FacadeSegmentMutationException(MUTATION_UNSUPPORTED_MESSAGE) |
| 103 |
|
| 104 |
def ready_to_send(self): |
| 105 |
""" |
| 106 |
Facade segment should never be sent out. This always |
| 107 |
return False. |
| 108 |
""" |
| 109 |
return False |
| 110 |
|
| 111 |
def increment(self): |
| 112 |
""" |
| 113 |
Increment total subsegments counter by 1. |
| 114 |
""" |
| 115 |
self._subsegments_counter.increment() |
| 116 |
|
| 117 |
def decrement_ref_counter(self): |
| 118 |
""" |
| 119 |
No-op |
| 120 |
""" |
| 121 |
pass |
| 122 |
|
| 123 |
def _is_initializing(self, entityid, traceid, sampled): |
| 124 |
return not entityid or not traceid or sampled is None |