Example #1
0
 def test_callproc_and_commit_are_not_traced(self):
     connection = ConnectionTracing(self.dbapi_connection,
                                    self.tracer,
                                    trace_callproc=False,
                                    trace_commit=False)
     with connection as cursor:
         cursor.callproc('my_procedure')
     assert not self.tracer.finished_spans()
Example #2
0
 def test_executemany_and_commit_are_not_traced(self):
     connection = ConnectionTracing(self.dbapi_connection,
                                    self.tracer,
                                    trace_executemany=False,
                                    trace_commit=False)
     with connection as cursor:
         cursor.executemany('INSERT INTO some_table VALUES (%s, %s, %s)')
     assert not self.tracer.finished_spans()
Example #3
0
 def test_execute_and_commit_are_not_traced(self):
     connection = ConnectionTracing(self.dbapi_connection,
                                    self.tracer,
                                    trace_execute=False,
                                    trace_commit=False)
     with connection as cursor:
         cursor.execute('SELECT * FROM SOME_TABLE')
     assert not self.tracer.finished_spans()
Example #4
0
 def test_callproc_and_rollback_are_not_traced(self):
     connection = ConnectionTracing(self.dbapi_connection,
                                    self.tracer,
                                    trace_callproc=False,
                                    trace_rollback=False)
     with connection as cursor:
         with patch.object(MockDBAPICursor,
                           'callproc',
                           side_effect=SomeException()) as callproc:
             callproc.__name__ = 'callproc'
             cursor.callproc('my_procedure')
     assert not self.tracer.finished_spans()
Example #5
0
 def test_execute_and_rollback_are_not_traced(self):
     connection = ConnectionTracing(self.dbapi_connection,
                                    self.tracer,
                                    trace_execute=False,
                                    trace_rollback=False)
     with connection as cursor:
         with patch.object(MockDBAPICursor,
                           'execute',
                           side_effect=SomeException()) as execute:
             execute.__name__ = 'execute'
             cursor.execute('SELECT * FROM some_table')
     assert not self.tracer.finished_spans()
Example #6
0
 def test_executemany_and_rollback_are_not_traced(self):
     connection = ConnectionTracing(self.dbapi_connection,
                                    self.tracer,
                                    trace_executemany=False,
                                    trace_rollback=False)
     with connection as cursor:
         with patch.object(MockDBAPICursor,
                           'executemany',
                           side_effect=SomeException()) as executemany:
             executemany.__name__ = 'executemany'
             cursor.executemany(
                 'INSERT INTO some_table VALUES (%s, %s, %s)')
     assert not self.tracer.finished_spans()
Example #7
0
    def test_custom_span_tags(self):
        span_tags = dict(one=123, two=234)
        tracer = MockTracer()
        connection = ConnectionTracing(MockDBAPIConnection(),
                                       tracer,
                                       span_tags=span_tags)

        with connection as cursor:
            cursor.execute('insert')
            cursor.executemany('insert', [1, 2])
            cursor.callproc('procedure')

        spans = tracer.finished_spans()
        assert len(spans) == 4
        for span in spans:
            assert span.tags[tags.DATABASE_TYPE] == 'sql'
            assert span.tags[tags.SPAN_KIND] == tags.SPAN_KIND_RPC_CLIENT
            assert span.tags['one'] == 123
            assert span.tags['two'] == 234
Example #8
0
 def setup(self):
     self.tracer = MockTracer()
     self.dbapi_connection = MockDBAPIConnection()
     self.connection = ConnectionTracing(self.dbapi_connection, self.tracer)