Ejemplo n.º 1
0
    def get_shorten_id(self, uuid_id):
        """Return shorten id of a uuid that will be used in OpenTracing drivers

        :param uuid_id: A string of uuid that was generated by uuidutils
        :returns: A shorter 64-bit long id
        """
        return format(utils.shorten_id(uuid_id), "x")
Ejemplo n.º 2
0
    def get_shorten_id(self, uuid_id):
        """Return shorten id of a uuid that will be used in OpenTracing drivers

        :param uuid_id: A string of uuid that was generated by uuidutils
        :returns: A shorter 64-bit long id
        """
        return format(utils.shorten_id(uuid_id), "x")
Ejemplo n.º 3
0
    def test_shorten_id_with_invalid_uuid(self, mock_gen_uuid):
        invalid_id = "invalid"
        mock_gen_uuid.return_value = "1c089ea8-28fe-4f3d-8c00-f6daa2bc32f1"

        result = utils.shorten_id(invalid_id)
        expected = 10088334584203457265

        self.assertEqual(expected, result)
Ejemplo n.º 4
0
    def notify(self, payload):
        if payload["name"].endswith("start"):
            timestamp = datetime.datetime.strptime(payload["timestamp"],
                                                   "%Y-%m-%dT%H:%M:%S.%f")
            epoch = datetime.datetime.utcfromtimestamp(0)
            start_time = (timestamp - epoch).total_seconds()

            # Create parent span
            child_of = self.jaeger_client.SpanContext(
                trace_id=utils.shorten_id(payload["base_id"]),
                span_id=utils.shorten_id(payload["parent_id"]),
                parent_id=None,
                flags=self.jaeger_client.span.SAMPLED_FLAG
            )

            # Create Jaeger Tracing span
            span = self.tracer.start_span(
                operation_name=payload["name"].rstrip("-start"),
                child_of=child_of,
                tags=self.create_span_tags(payload),
                start_time=start_time
            )

            # Replace Jaeger Tracing span_id (random id) to OSProfiler span_id
            span.context.span_id = utils.shorten_id(payload["trace_id"])
            self.spans.append(span)
        else:
            span = self.spans.pop()

            # Store result of db call and function call
            for call in ("db", "function"):
                if payload.get("info", {}).get(call) is not None:
                    span.set_tag("result", payload["info"][call]["result"])

            # Span error tag and log
            if payload["info"].get("etype") is not None:
                span.set_tag("error", True)
                span.log_kv({"error.kind": payload["info"]["etype"]})
                span.log_kv({"message": payload["info"]["message"]})

            span.finish(finish_time=time.time())
Ejemplo n.º 5
0
    def notify(self, payload):
        if payload["name"].endswith("start"):
            timestamp = datetime.datetime.strptime(payload["timestamp"],
                                                   "%Y-%m-%dT%H:%M:%S.%f")
            epoch = datetime.datetime.utcfromtimestamp(0)
            start_time = (timestamp - epoch).total_seconds()

            # Create parent span
            child_of = self.jaeger_client.SpanContext(
                trace_id=utils.shorten_id(payload["base_id"]),
                span_id=utils.shorten_id(payload["parent_id"]),
                parent_id=None,
                flags=self.jaeger_client.span.SAMPLED_FLAG
            )

            # Create Jaeger Tracing span
            span = self.tracer.start_span(
                operation_name=payload["name"].rstrip("-start"),
                child_of=child_of,
                tags=self.create_span_tags(payload),
                start_time=start_time
            )

            # Replace Jaeger Tracing span_id (random id) to OSProfiler span_id
            span.context.span_id = utils.shorten_id(payload["trace_id"])
            self.spans.append(span)
        else:
            span = self.spans.pop()

            # Store result of db call and function call
            for call in ("db", "function"):
                if payload.get("info", {}).get(call) is not None:
                    span.set_tag("result", payload["info"][call]["result"])

            # Span error tag and log
            if payload["info"].get("etype") is not None:
                span.set_tag("error", True)
                span.log_kv({"error.kind": payload["info"]["etype"]})
                span.log_kv({"message": payload["info"]["message"]})

            span.finish(finish_time=time.time())
Ejemplo n.º 6
0
    def test_shorten_id_with_valid_uuid(self):
        valid_id = "4e3e0ec6-2938-40b1-8504-09eb1d4b0dee"

        uuid_obj = uuid.UUID(valid_id)

        with mock.patch("uuid.UUID") as mock_uuid:
            mock_uuid.return_value = uuid_obj

            result = utils.shorten_id(valid_id)
            expected = 9584796812364680686

            self.assertEqual(expected, result)