Exemplo n.º 1
0
def test_store_span_adds_to_current_entry_if_span_name_already_present():
    handler = logging_helper.ZipkinLoggerHandler('foo')
    handler.spans = {
        ('a', False): {
            'annotations': {
                'a': 2
            },
            'binary_annotations': {
                'asdf': 'qwe'
            },
            'span_name': 'a',
            'is_client': False
        }
    }
    handler.store_span('a', False, {'foo': 3}, {'bar': 'baz'})
    assert handler.spans == {
        ('a', False): {
            'annotations': {
                'a': 2,
                'foo': 3
            },
            'binary_annotations': {
                'asdf': 'qwe',
                'bar': 'baz'
            },
            'span_name': 'a',
            'is_client': False
        }
    }
def test_zipkin_handler_raises_exception_if_ann_and_bann_not_provided(
        sampled_zipkin_attr):
    record = mock.Mock(msg={'name': 'foo'})
    handler = logging_helper.ZipkinLoggerHandler(sampled_zipkin_attr)
    with pytest.raises(ZipkinError) as excinfo:
        handler.emit(record)
    assert ("Atleast one of annotation/binary annotation has to be provided"
            " for foo span" == str(excinfo.value))
def test_store_span_appends_to_span():
    handler = logging_helper.ZipkinLoggerHandler('foo')
    handler.store_span('a', False, {'foo': 2}, {'bar': 'baz'}, None)
    assert handler.spans == [{'annotations': {'foo': 2},
                              'binary_annotations': {'bar': 'baz'},
                              'span_name': 'a',
                              'is_client': False,
                              'service_name': None}]
def test_zipkin_handler_successfully_emits_sampled_record(
        store_sp, sampled_zipkin_attr):
    record = mock.Mock()
    record.msg = {'annotations': 'ann1', 'binary_annotations': 'bann1',
                  'name': 'foo', 'type': 'service',
                  'service_name': 'blargh'}
    handler = logging_helper.ZipkinLoggerHandler(sampled_zipkin_attr)
    handler.emit(record)
    store_sp.assert_called_once_with('foo', False, 'ann1', 'bann1', 'blargh')
Exemplo n.º 5
0
def test_store_span_creates_a_new_entry_to_dict_if_span_name_not_present():
    handler = logging_helper.ZipkinLoggerHandler('foo')
    handler.store_span('a', False, {'foo': 2}, {'bar': 'baz'})
    assert handler.spans == {
        ('a', False): {
            'annotations': {
                'foo': 2
            },
            'binary_annotations': {
                'bar': 'baz'
            },
            'span_name': 'a',
            'is_client': False
        }
    }
def test_zipkin_handler_does_not_emit_unsampled_record(unsampled_zipkin_attr):
    handler = logging_helper.ZipkinLoggerHandler(unsampled_zipkin_attr)
    assert not handler.emit('bla')
def test_zipkin_handler_init():
    handler = logging_helper.ZipkinLoggerHandler('foo')
    assert handler.zipkin_attrs == 'foo'