def assert_conn_is_traced(self, db, service):
    try:
        db.execute("select 'foobar'")
    except AttributeError:
        pass
    q = "select 'foobarblah'"
    start = time.time()
    cursor = db.cursor()
    res = cursor.execute(q)
    self.assertIsNone(res)
    rows = cursor.fetchall()
    end = time.time()
    self.assertEquals(rows, [('foobarblah',)])
    self.assert_structure(dict(name='postgres.query', resource=q, service=service, error=0, span_type='sql'))
    root = self.get_root_span()
    self.assertIsNone(root.get_tag('sql.query'))
    assert (start <= root.start <= end)
    assert (root.duration <= (end - start))
    self.reset()
    q = 'select * from some_non_existant_table'
    cur = db.cursor()
    try:
        cur.execute(q)
    except Exception:
        pass
    else:
        assert 0, 'should have an error'
    self.assert_structure(dict(name='postgres.query', resource=q, service=service, error=1, span_type='sql', meta={'out.host': '127.0.0.1'}, metrics={'out.port': TEST_PORT}))
    root = self.get_root_span()
    assert_is_measured(root)
    self.assertIsNone(root.get_tag('sql.query'))
    self.reset()
def assert_conn_is_traced(self, db, service):
    try:
        db.execute("select 'foobar'")
    except AttributeError:
        pass
    q = "select 'foobarblah'"
    start = time.time()
    cursor = db.cursor()
    res = cursor.execute(q)
    self.assertIsNone(res)
    rows = cursor.fetchall()
    end = time.time()
    self.assertEquals(rows, [('foobarblah',)])
    self.assert_structure(dict(name='postgres.query', resource=q, service=service, error=0, span_type='sql'))
    root = self.get_root_span()
    self.assertIsNone(root.get_tag('sql.query'))
    assert (start <= root.start <= end)
    assert (root.duration <= (end - start))
    self.reset()
    q = 'select * from some_non_existant_table'
    cur = db.cursor()
    try:
        cur.execute(q)
    except Exception:
        pass
    else:
        assert 0, 'should have an error'
    self.assert_structure(dict(name='postgres.query', resource=q, service=service, error=1, span_type='sql', meta={'out.host': '127.0.0.1'}, metrics={'out.port': TEST_PORT}))
    root = self.get_root_span()
    assert_is_measured(root)
    self.assertIsNone(root.get_tag('sql.query'))
    self.reset()