Exemple #1
0
    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'
Exemple #3
0
    def test_uninstrumented_not_traced(self, instrumented_elasticsearch,
                                       tracer_and_uninstrumented_client):
        tracer, es = tracer_and_uninstrumented_client

        doc_id = random_int(0)
        body = dict(lorem='ipsum' * 1024)
        index = es.index(index='some-index',
                         doc_type='some-doc-type',
                         id=doc_id,
                         body=body,
                         params={'refresh': 'true'})
        doc_id = str(doc_id)
        assert index['_id'] == doc_id
        assert index.get('result') == 'created' or index.get('created')
        lorem = es.get(index='some-index', doc_type='some-doc-type', id=doc_id)
        assert lorem['_id'] == doc_id
        assert lorem['_source'] == body

        assert not tracer.finished_spans()
Exemple #4
0
    def test_add_and_get_document(self, tracer_and_client):
        tracer, es = tracer_and_client

        doc_id = random_int(0)
        body = dict(lorem='ipsum' * 1024)
        index = es.index(index='some-index',
                         doc_type='some-doc-type',
                         id=doc_id,
                         body=body,
                         params={'refresh': 'true'})
        doc_id = str(doc_id)
        assert index['_id'] == doc_id
        assert index.get('result') == 'created' or index.get('created')
        lorem = es.get(index='some-index', doc_type='some-doc-type', id=doc_id)
        assert lorem['_id'] == doc_id
        assert lorem['_source'] == body

        spans = tracer.finished_spans()
        assert len(spans) == 2
        expected_url = '/some-index/some-doc-type/{}'.format(doc_id)
        for span in spans:
            assert span.operation_name == 'MyPrefix{}'.format(expected_url)
            assert span.tags['elasticsearch.url'] == expected_url
            assert span.tags['component'] == 'elasticsearch-py'