Esempio n. 1
0
    def extract(self, carrier):  # noqa
        try:
            if type(carrier) is dict or hasattr(carrier, "__dict__"):
                dc = carrier
            elif type(carrier) is list:
                dc = dict(carrier)
            else:
                raise ot.SpanContextCorruptedException()

            # Look for standard X-Instana-T/S format
            if self.HEADER_KEY_T in dc and self.header_key_s in dc:
                trace_id = util.header_to_id(dc[self.HEADER_KEY_T])
                span_id = util.header_to_id(dc[self.HEADER_KEY_S])

            # Alternatively check for alternate HTTP_X_INSTANA_T/S style
            elif self.ALT_HEADER_KEY_T in dc and self.ALT_HEADER_KEY_S in dc:
                trace_id = util.header_to_id(dc[self.ALT_HEADER_KEY_T])
                span_id = util.header_to_id(dc[self.ALT_HEADER_KEY_S])

            return SpanContext(span_id=span_id,
                               trace_id=trace_id,
                               baggage={},
                               sampled=True)

        except Exception as e:
            log.debug("extract error: ", str(e))
Esempio n. 2
0
    def extract(self, carrier):  # noqa
        try:
            if type(carrier) is dict or hasattr(carrier, "__dict__"):
                dc = carrier
            elif type(carrier) is list:
                dc = dict(carrier)
            else:
                raise ot.SpanContextCorruptedException()

            if field_name_trace_id in dc and field_name_span_id in dc:
                trace_id = util.header_to_id(dc[field_name_trace_id])
                span_id = util.header_to_id(dc[field_name_span_id])

            return SpanContext(span_id=span_id,
                               trace_id=trace_id,
                               baggage={},
                               sampled=True)

        except Exception as e:
            log.debug("extract error: ", str(e))
            return SpanContext()