Ejemplo 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))
Ejemplo n.º 2
0
    def extract(self, carrier):  # noqa
        trace_id = None
        span_id = None
        level = 1

        try:
            if type(carrier) is dict or hasattr(carrier, "__getitem__"):
                dc = carrier
            elif hasattr(carrier, "__dict__"):
                dc = carrier.__dict__
            elif type(carrier) is list:
                dc = dict(carrier)
            else:
                raise ot.SpanContextCorruptedException()

            for key in dc.keys():
                if self.HEADER_KEY_T == key:
                    trace_id = header_to_id(dc[key])
                elif self.HEADER_KEY_S == key:
                    span_id = header_to_id(dc[key])
                elif self.HEADER_KEY_L == key:
                    level = dc[key]

            ctx = None
            if trace_id is not None and span_id is not None:
                ctx = SpanContext(span_id=span_id,
                                  trace_id=trace_id,
                                  level=level,
                                  baggage={},
                                  sampled=True)
            return ctx

        except Exception:
            logger.debug("extract error:", exc_info=True)
Ejemplo n.º 3
0
    def extract(self, carrier):  # noqa
        trace_id = None
        span_id = None
        level = 1
        synthetic = False

        try:
            if type(carrier) is dict or hasattr(carrier, "__getitem__"):
                dc = carrier
            elif hasattr(carrier, "__dict__"):
                dc = carrier.__dict__
            elif type(carrier) is list:
                dc = dict(carrier)
            else:
                raise ot.SpanContextCorruptedException()

            # Headers can exist in the standard X-Instana-T/S format or the alternate HTTP_X_INSTANA_T/S style
            # We do a case insensitive search to cover all possible variations of incoming headers.
            for key in dc.keys():
                lc_key = key.lower()

                if self.LC_HEADER_KEY_T == lc_key:
                    trace_id = header_to_id(dc[key])
                elif self.LC_HEADER_KEY_S == lc_key:
                    span_id = header_to_id(dc[key])
                elif self.LC_HEADER_KEY_L == lc_key:
                    level = dc[key]
                elif self.LC_HEADER_KEY_SYNTHETIC == lc_key:
                    synthetic = dc[key] == "1"

                elif self.ALT_LC_HEADER_KEY_T == lc_key:
                    trace_id = header_to_id(dc[key])
                elif self.ALT_LC_HEADER_KEY_S == lc_key:
                    span_id = header_to_id(dc[key])
                elif self.ALT_LC_HEADER_KEY_L == lc_key:
                    level = dc[key]
                elif self.ALT_LC_HEADER_KEY_SYNTHETIC == lc_key:
                    synthetic = dc[key] == "1"

            ctx = None
            if trace_id is not None and span_id is not None:
                ctx = SpanContext(span_id=span_id,
                                  trace_id=trace_id,
                                  level=level,
                                  baggage={},
                                  sampled=True,
                                  synthetic=synthetic)
            elif synthetic:
                ctx = SpanContext(synthetic=synthetic)

            return ctx

        except Exception:
            logger.debug("extract error:", exc_info=True)
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
 def test_apply_tracing_corrupted(self):
     tracer = PyramidTracer(
         DummyTracer(opentracing.SpanContextCorruptedException()))
     tracer._apply_tracing(DummyRequest(), [])