コード例 #1
0
    def test_correct_span_names(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 0
        pin = Pin('pin_name', tracer=tracer)
        traced_cursor = TracedCursor(cursor, pin, {})

        traced_cursor.execute('arg_1', kwarg1='kwarg1')
        self.assert_structure(dict(name='sql.query'))
        assert_is_measured(self.get_root_span())
        self.reset()

        traced_cursor.executemany('arg_1', kwarg1='kwarg1')
        self.assert_structure(dict(name='sql.query'))
        assert_is_measured(self.get_root_span())
        self.reset()

        traced_cursor.callproc('arg_1', 'arg2')
        self.assert_structure(dict(name='sql.query'))
        assert_is_measured(self.get_root_span())
        self.reset()

        traced_cursor.fetchone('arg_1', kwarg1='kwarg1')
        self.assert_has_no_spans()

        traced_cursor.fetchmany('arg_1', kwarg1='kwarg1')
        self.assert_has_no_spans()

        traced_cursor.fetchall('arg_1', kwarg1='kwarg1')
        self.assert_has_no_spans()
コード例 #2
0
    def test_correct_span_names(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 0
        pin = Pin("pin_name", tracer=tracer)
        traced_cursor = TracedCursor(cursor, pin, {})

        traced_cursor.execute("arg_1", kwarg1="kwarg1")
        self.assert_structure(dict(name="sql.query"))
        assert_is_measured(self.get_root_span())
        self.reset()

        traced_cursor.executemany("arg_1", kwarg1="kwarg1")
        self.assert_structure(dict(name="sql.query"))
        assert_is_measured(self.get_root_span())
        self.reset()

        traced_cursor.callproc("arg_1", "arg2")
        self.assert_structure(dict(name="sql.query"))
        assert_is_measured(self.get_root_span())
        self.reset()

        traced_cursor.fetchone("arg_1", kwarg1="kwarg1")
        self.assert_has_no_spans()

        traced_cursor.fetchmany("arg_1", kwarg1="kwarg1")
        self.assert_has_no_spans()

        traced_cursor.fetchall("arg_1", kwarg1="kwarg1")
        self.assert_has_no_spans()
コード例 #3
0
    def test_correct_span_names_can_be_overridden_by_pin(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 0
        pin = Pin('pin_name', app='changed', tracer=tracer)
        traced_cursor = TracedCursor(cursor, pin)

        traced_cursor.execute('arg_1', kwarg1='kwarg1')
        self.assert_structure(dict(name='changed.query'))
        self.reset()

        traced_cursor.executemany('arg_1', kwarg1='kwarg1')
        self.assert_structure(dict(name='changed.query'))
        self.reset()

        traced_cursor.callproc('arg_1', 'arg2')
        self.assert_structure(dict(name='changed.query'))
        self.reset()

        traced_cursor.fetchone('arg_1', kwarg1='kwarg1')
        self.assert_has_no_spans()

        traced_cursor.fetchmany('arg_1', kwarg1='kwarg1')
        self.assert_has_no_spans()

        traced_cursor.fetchall('arg_1', kwarg1='kwarg1')
        self.assert_has_no_spans()
コード例 #4
0
    def test_when_pin_disabled_then_no_tracing(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 0
        cursor.execute.return_value = '__result__'
        cursor.executemany.return_value = '__result__'

        tracer.enabled = False
        pin = Pin('pin_name', tracer=tracer)
        traced_cursor = TracedCursor(cursor, pin, {})

        assert '__result__' == traced_cursor.execute('arg_1', kwarg1='kwarg1')
        assert len(tracer.writer.pop()) == 0

        assert '__result__' == traced_cursor.executemany('arg_1',
                                                         kwarg1='kwarg1')
        assert len(tracer.writer.pop()) == 0

        cursor.callproc.return_value = 'callproc'
        assert 'callproc' == traced_cursor.callproc('arg_1', 'arg_2')
        assert len(tracer.writer.pop()) == 0

        cursor.fetchone.return_value = 'fetchone'
        assert 'fetchone' == traced_cursor.fetchone('arg_1', 'arg_2')
        assert len(tracer.writer.pop()) == 0

        cursor.fetchmany.return_value = 'fetchmany'
        assert 'fetchmany' == traced_cursor.fetchmany('arg_1', 'arg_2')
        assert len(tracer.writer.pop()) == 0

        cursor.fetchall.return_value = 'fetchall'
        assert 'fetchall' == traced_cursor.fetchall('arg_1', 'arg_2')
        assert len(tracer.writer.pop()) == 0
コード例 #5
0
    def test_when_pin_disabled_then_no_tracing(self):
        cursor = self.cursor
        tracer = self.tracer
        cursor.rowcount = 0
        cursor.execute.return_value = "__result__"
        cursor.executemany.return_value = "__result__"

        tracer.enabled = False
        pin = Pin("pin_name", tracer=tracer)
        traced_cursor = TracedCursor(cursor, pin, {})

        assert "__result__" == traced_cursor.execute("arg_1", kwarg1="kwarg1")
        assert len(tracer.pop()) == 0

        assert "__result__" == traced_cursor.executemany("arg_1", kwarg1="kwarg1")
        assert len(tracer.pop()) == 0

        cursor.callproc.return_value = "callproc"
        assert "callproc" == traced_cursor.callproc("arg_1", "arg_2")
        assert len(tracer.pop()) == 0

        cursor.fetchone.return_value = "fetchone"
        assert "fetchone" == traced_cursor.fetchone("arg_1", "arg_2")
        assert len(tracer.pop()) == 0

        cursor.fetchmany.return_value = "fetchmany"
        assert "fetchmany" == traced_cursor.fetchmany("arg_1", "arg_2")
        assert len(tracer.pop()) == 0

        cursor.fetchall.return_value = "fetchall"
        assert "fetchall" == traced_cursor.fetchall("arg_1", "arg_2")
        assert len(tracer.pop()) == 0
コード例 #6
0
    def test_execute_wrapped_is_called_and_returned(self):
        cursor = self.cursor
        cursor.rowcount = 0
        cursor.execute.return_value = '__result__'

        pin = Pin('pin_name', tracer=self.tracer)
        traced_cursor = TracedCursor(cursor, pin, {})
        # DEV: We always pass through the result
        assert '__result__' == traced_cursor.execute('__query__', 'arg_1', kwarg1='kwarg1')
        cursor.execute.assert_called_once_with('__query__', 'arg_1', kwarg1='kwarg1')
コード例 #7
0
    def test_execute_wrapped_is_called_and_returned(self):
        cursor = self.cursor
        cursor.rowcount = 0
        cursor.execute.return_value = "__result__"

        pin = Pin("pin_name", tracer=self.tracer)
        traced_cursor = TracedCursor(cursor, pin, {})
        # DEV: We always pass through the result
        assert "__result__" == traced_cursor.execute("__query__", "arg_1", kwarg1="kwarg1")
        cursor.execute.assert_called_once_with("__query__", "arg_1", kwarg1="kwarg1")
コード例 #8
0
 def test_execute_wrapped_is_called_and_returned(self):
     cursor = self.cursor
     cursor.rowcount = 0
     pin = Pin('pin_name', tracer=self.tracer)
     traced_cursor = TracedCursor(cursor, pin)
     assert traced_cursor is traced_cursor.execute(
         '__query__', 'arg_1', kwarg1='kwarg1')
     cursor.execute.assert_called_once_with('__query__',
                                            'arg_1',
                                            kwarg1='kwarg1')
コード例 #9
0
    def test_cursor_analytics_default(self):
        cursor = self.cursor
        cursor.rowcount = 0
        cursor.execute.return_value = '__result__'

        pin = Pin('pin_name', tracer=self.tracer)
        traced_cursor = TracedCursor(cursor, pin, {})
        # DEV: We always pass through the result
        assert '__result__' == traced_cursor.execute('__query__', 'arg_1', kwarg1='kwarg1')

        span = self.tracer.writer.pop()[0]
        self.assertIsNone(span.get_metric(ANALYTICS_SAMPLE_RATE_KEY))
コード例 #10
0
    def test_cursor_analytics_default(self):
        cursor = self.cursor
        cursor.rowcount = 0
        cursor.execute.return_value = "__result__"

        pin = Pin("pin_name", tracer=self.tracer)
        traced_cursor = TracedCursor(cursor, pin, {})
        # DEV: We always pass through the result
        assert "__result__" == traced_cursor.execute("__query__", "arg_1", kwarg1="kwarg1")

        span = self.pop_spans()[0]
        self.assertIsNone(span.get_metric(ANALYTICS_SAMPLE_RATE_KEY))
コード例 #11
0
    def test_cursor_analytics_without_rate(self):
        with self.override_config("dbapi2", dict(analytics_enabled=True)):
            cursor = self.cursor
            cursor.rowcount = 0
            cursor.execute.return_value = "__result__"

            pin = Pin("pin_name", tracer=self.tracer)
            traced_cursor = TracedCursor(cursor, pin, {})
            # DEV: We always pass through the result
            assert "__result__" == traced_cursor.execute("__query__", "arg_1", kwarg1="kwarg1")

            span = self.pop_spans()[0]
            self.assertEqual(span.get_metric(ANALYTICS_SAMPLE_RATE_KEY), 1.0)
コード例 #12
0
    def test_cursor_analytics_without_rate(self):
        with self.override_config('dbapi2', dict(analytics_enabled=True)):
            cursor = self.cursor
            cursor.rowcount = 0
            cursor.execute.return_value = '__result__'

            pin = Pin('pin_name', tracer=self.tracer)
            traced_cursor = TracedCursor(cursor, pin, {})
            # DEV: We always pass through the result
            assert '__result__' == traced_cursor.execute('__query__',
                                                         'arg_1',
                                                         kwarg1='kwarg1')

            span = self.tracer.writer.pop()[0]
            self.assertEqual(span.get_metric(ANALYTICS_SAMPLE_RATE_KEY), 1.0)