示例#1
0
    def test_span_info(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 123
        pin = Pin('my_service',
                  app='my_app',
                  tracer=tracer,
                  tags={'pin1': 'value_pin1'})
        traced_cursor = TracedCursor(cursor, pin, {})

        def method():
            pass

        traced_cursor._trace_method(method, 'my_name', 'my_resource',
                                    {'extra1': 'value_extra1'})
        span = tracer.writer.pop()[0]  # type: Span
        # Only measure if the name passed matches the default name (e.g. `sql.query` and not `sql.query.fetchall`)
        assert_is_not_measured(span)
        assert span.meta['pin1'] == 'value_pin1', 'Pin tags are preserved'
        assert span.meta[
            'extra1'] == 'value_extra1', 'Extra tags are merged into pin tags'
        assert span.name == 'my_name', 'Span name is respected'
        assert span.service == 'my_service', 'Service from pin'
        assert span.resource == 'my_resource', 'Resource is respected'
        assert span.span_type == 'sql', 'Span has the correct span type'
        # Row count
        assert span.get_metric(
            'db.rowcount') == 123, 'Row count is set as a metric'
        assert span.get_metric(
            'sql.rows'
        ) == 123, 'Row count is set as a tag (for legacy django cursor replacement)'
示例#2
0
    def test_django_traced_cursor_backward_compatibility(self):
        cursor = self.cursor
        tracer = self.tracer
        # Django integration used to have its own TracedCursor implementation. When we replaced such custom
        # implementation with the generic dbapi traced cursor, we had to make sure to add the tag 'sql.rows' that was
        # set by the legacy replaced implementation.
        cursor.rowcount = 123
        pin = Pin('my_service',
                  app='my_app',
                  tracer=tracer,
                  tags={'pin1': 'value_pin1'})
        traced_cursor = TracedCursor(cursor, pin, {})

        def method():
            pass

        traced_cursor._trace_method(method, 'my_name', 'my_resource',
                                    {'extra1': 'value_extra1'})
        span = tracer.writer.pop()[0]  # type: Span
        # Row count
        assert span.get_metric(
            'db.rowcount') == 123, 'Row count is set as a metric'
        assert span.get_metric(
            'sql.rows'
        ) == 123, 'Row count is set as a tag (for legacy django cursor replacement)'
示例#3
0
    def test_span_info(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 123
        pin = Pin("my_service",
                  app="my_app",
                  tracer=tracer,
                  tags={"pin1": "value_pin1"})
        traced_cursor = TracedCursor(cursor, pin, {})

        def method():
            pass

        traced_cursor._trace_method(method, "my_name", "my_resource",
                                    {"extra1": "value_extra1"})
        span = tracer.pop()[0]  # type: Span
        # Only measure if the name passed matches the default name (e.g. `sql.query` and not `sql.query.fetchall`)
        assert_is_not_measured(span)
        assert span.meta["pin1"] == "value_pin1", "Pin tags are preserved"
        assert span.meta[
            "extra1"] == "value_extra1", "Extra tags are merged into pin tags"
        assert span.name == "my_name", "Span name is respected"
        assert span.service == "my_service", "Service from pin"
        assert span.resource == "my_resource", "Resource is respected"
        assert span.span_type == "sql", "Span has the correct span type"
        # Row count
        assert span.get_metric(
            "db.rowcount") == 123, "Row count is set as a metric"
        assert span.get_metric(
            "sql.rows"
        ) == 123, "Row count is set as a tag (for legacy django cursor replacement)"
示例#4
0
    def test_default_service(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 123
        pin = Pin(None, app='my_app', tracer=tracer, tags={'pin1': 'value_pin1'})
        traced_cursor = TracedCursor(cursor, pin, None)

        def method():
            pass

        traced_cursor._trace_method(method, 'my_name', 'my_resource', {'extra1': 'value_extra1'})
        span = tracer.writer.pop()[0]  # type: Span
        assert span.service == "db"
示例#5
0
    def test_default_service(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 123
        pin = Pin(None, app="my_app", tracer=tracer, tags={"pin1": "value_pin1"})
        traced_cursor = TracedCursor(cursor, pin, None)

        def method():
            pass

        traced_cursor._trace_method(method, "my_name", "my_resource", {"extra1": "value_extra1"})
        span = tracer.pop()[0]  # type: Span
        assert span.service == "db"
示例#6
0
    def test_service_cfg_and_pin(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 123
        pin = Pin("pin-svc", app='my_app', tracer=tracer, tags={'pin1': 'value_pin1'})
        cfg = AttrDict(_default_service="cfg-svc")
        traced_cursor = TracedCursor(cursor, pin, cfg)

        def method():
            pass

        traced_cursor._trace_method(method, 'my_name', 'my_resource', {'extra1': 'value_extra1'})
        span = tracer.writer.pop()[0]  # type: Span
        assert span.service == "pin-svc"
示例#7
0
    def test_service_cfg_and_pin(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 123
        pin = Pin("pin-svc", app="my_app", tracer=tracer, tags={"pin1": "value_pin1"})
        cfg = AttrDict(_default_service="cfg-svc")
        traced_cursor = TracedCursor(cursor, pin, cfg)

        def method():
            pass

        traced_cursor._trace_method(method, "my_name", "my_resource", {"extra1": "value_extra1"})
        span = tracer.pop()[0]  # type: Span
        assert span.service == "pin-svc"
示例#8
0
    def test_cfg_service(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 123
        pin = Pin(None, tracer=tracer, tags={"pin1": "value_pin1"})
        cfg = IntegrationConfig(None, "db-test", service="cfg-service")
        traced_cursor = TracedCursor(cursor, pin, cfg)

        def method():
            pass

        traced_cursor._trace_method(method, "my_name", "my_resource",
                                    {"extra1": "value_extra1"})
        span = tracer.pop()[0]  # type: Span
        assert span.service == "cfg-service"
示例#9
0
    def test_django_traced_cursor_backward_compatibility(self):
        cursor = self.cursor
        tracer = self.tracer
        # Django integration used to have its own TracedCursor implementation. When we replaced such custom
        # implementation with the generic dbapi traced cursor, we had to make sure to add the tag 'sql.rows' that was
        # set by the legacy replaced implementation.
        cursor.rowcount = 123
        pin = Pin("my_service", tracer=tracer, tags={"pin1": "value_pin1"})
        cfg = IntegrationConfig(None, "db-test")
        traced_cursor = TracedCursor(cursor, pin, cfg)

        def method():
            pass

        traced_cursor._trace_method(method, "my_name", "my_resource",
                                    {"extra1": "value_extra1"})
        span = tracer.pop()[0]  # type: Span
        # Row count
        assert span.get_metric(
            "db.rowcount") == 123, "Row count is set as a metric"
        assert span.get_metric(
            "sql.rows"
        ) == 123, "Row count is set as a tag (for legacy django cursor replacement)"