def test_instrumented_sanity(self, connection_tracing): tracer, conn = connection_tracing with tracer.start_active_span('Parent'): with conn.cursor() as cursor: cursor.execute('insert into table_one values (%s, %s, %s, %s)', (random_string(), random_string(), datetime.now(), datetime.now())) cursor.execute('insert into table_two values (%s, %s, %s, %s)', (random_int(0, 100000), random_int( 0, 100000), random_float(), random_float())) conn.commit() spans = tracer.finished_spans() assert len(spans) == 4 for span in spans[:3]: assert span.tags['some'] == 'tag' assert span.tags[tags.DATABASE_TYPE] == 'MySQL' assert span.tags[tags.DATABASE_INSTANCE] == 'test_db' first, second, commit, parent = spans for span in (first, second): assert span.operation_name == 'DictCursor.execute(insert)' assert span.tags['db.rows_produced'] == 1 assert span.parent_id == parent.context.span_id assert tags.ERROR not in span.tags assert first.tags[ tags. DATABASE_STATEMENT] == 'insert into table_one values (%s, %s, %s, %s)' assert second.tags[ tags. DATABASE_STATEMENT] == 'insert into table_two values (%s, %s, %s, %s)' assert commit.operation_name == 'Connection.commit()' assert parent.operation_name == 'Parent'
def test_instrumented_sanity(self, connection_tracing): tracer, conn = connection_tracing # C arg validation assert isinstance(conn, psycopg2.extensions.connection) psycopg2.extensions.register_type(psycopg2.extensions.UNICODE, conn) with tracer.start_active_span('Parent'): with conn.cursor(cursor_factory=DictCursor) as cursor: # C arg validation assert isinstance(cursor, psycopg2.extensions.cursor) psycopg2.extras.register_uuid(None, cursor) cursor.execute('insert into table_one values (%s, %s, %s, %s)', (random_string(), random_string(), datetime.now(), datetime.now())) cursor.execute('insert into table_two values (%s, %s, %s, %s)', (random_int(0, 100000), random_int( 0, 100000), random_float(), random_float())) conn.commit() spans = tracer.finished_spans() assert len(spans) == 4 for span in spans[:3]: assert span.tags['some'] == 'tag' assert span.tags[tags.DATABASE_TYPE] == 'PostgreSQL' assert span.tags[tags.DATABASE_INSTANCE] == 'test_db' first, second, commit, parent = spans for span in (first, second): assert span.operation_name == 'DictCursor.execute(insert)' assert span.tags['db.rows_produced'] == 1 assert span.parent_id == parent.context.span_id assert tags.ERROR not in span.tags assert first.tags[ tags. DATABASE_STATEMENT] == 'insert into table_one values (%s, %s, %s, %s)' assert second.tags[ tags. DATABASE_STATEMENT] == 'insert into table_two values (%s, %s, %s, %s)' assert commit.operation_name == 'connection.commit()' assert parent.operation_name == 'Parent'