def test_log_debug_for_new_span(mock_logger):
    mock_transport_handler, mock_logs = mock_logger
    with zipkin.zipkin_span(
        service_name='test_service_name',
        span_name='test_span_name',
        transport_handler=mock_transport_handler,
        sample_rate=100.0,
        binary_annotations={'some_key': 'some_value'},
        add_logging_annotation=True,
    ):
        zipkin_logger.debug({
            'annotations': {
                'cs': 7,
                'cr': 8,
            },
            'binary_annotations': {
                'logged_binary_annotation': 'logged_value',
            },
            'name': 'logged_name',
            'service_name': 'logged_service_name',
        })
        pass

    logged_span = _decode_binary_thrift_obj(mock_logs[0])
    root_span = _decode_binary_thrift_obj(mock_logs[1])
    assert logged_span.name == 'logged_name'
    assert logged_span.annotations[0].host.service_name == 'logged_service_name'
    assert logged_span.parent_id == root_span.id
    assert logged_span.binary_annotations[0].key == 'logged_binary_annotation'
    assert logged_span.binary_annotations[0].value == 'logged_value'
    assert set([ann.value for ann in logged_span.annotations]) == set(['cs', 'cr'])
예제 #2
0
def sample_v2(dummy_request):
    zipkin_logger.debug({
        'annotations': {'foo': 2},
        'binary_annotations': {'ping': 'pong'},
        'name': 'v2',
    })
    zipkin_logger.debug({'annotations': {'bar': 1}, 'name': 'v2'})
    return {}
예제 #3
0
def sample_v2_client(dummy_request):
    zipkin_logger.debug({
        'annotations': {'foo_client': 2},
        'name': 'v2_client',
        'service_name': 'foo_service',
    })
    zipkin_logger.debug({
        'annotations': {'bar_client': 1},
        'name': 'v2_client',
        'service_name': 'bar_service',
    })
    return {}
예제 #4
0
def test_log_debug_for_existing_span(default_annotations):
    mock_transport_handler, mock_logs = mock_logger()
    mock_firehose_handler, mock_firehose_logs = mock_logger()
    with zipkin.zipkin_span(
        service_name='test_service_name',
        span_name='test_span_name',
        transport_handler=mock_transport_handler,
        sample_rate=100.0,
        binary_annotations={'some_key': 'some_value'},
        add_logging_annotation=True,
        firehose_handler=mock_firehose_handler,
    ):
        zipkin_logger.debug({
            'annotations': {
                'test_annotation': 42,
            },
            'binary_annotations': {
                'extra_binary_annotation': 'extra_value',
            }
        })
        pass

    def check_span(span):
        assert span.name == 'test_span_name'
        assert span.annotations[0].host.service_name == 'test_service_name'
        assert span.parent_id is None
        assert len(span.annotations) == 4
        annotations = sorted(span.annotations, key=lambda ann: ann.value)
        assert annotations[3].value == 'test_annotation'
        assert annotations[3].timestamp == 42 * USECS
        default_annotations.add('test_annotation')
        assert set([ann.value for ann in annotations]) == default_annotations
        assert len(span.binary_annotations) == 2
        binary_annotations = sorted(
            span.binary_annotations, key=lambda bin_ann: bin_ann.key)
        assert binary_annotations[0].key == 'extra_binary_annotation'
        assert binary_annotations[0].value == 'extra_value'
        assert binary_annotations[1].key == 'some_key'
        assert binary_annotations[1].value == 'some_value'

    assert len(mock_logs) == 1
    check_span(_decode_binary_thrift_obj(mock_logs[0]))
    check_span(_decode_binary_thrift_obj(mock_firehose_logs[0]))
예제 #5
0
def test_log_debug_for_existing_span(mock_logger):
    mock_transport_handler, mock_logs = mock_logger
    with zipkin.zipkin_span(
        service_name='test_service_name',
        span_name='test_span_name',
        transport_handler=mock_transport_handler,
        sample_rate=100.0,
        binary_annotations={'some_key': 'some_value'},
    ):
        zipkin_logger.debug({
            'annotations': {
                'test_annotation': 42,
            },
            'binary_annotations': {
                'extra_binary_annotation': 'extra_value',
            }
        })
        pass

    assert len(mock_logs) == 1
    span = _decode_binary_thrift_obj(mock_logs[0])
    assert span.name == 'test_span_name'
    assert span.annotations[0].host.service_name == 'test_service_name'
    assert span.parent_id is None
    assert len(span.annotations) == 3
    annotations = sorted(span.annotations, key=lambda ann: ann.value)
    assert annotations[2].value == 'test_annotation'
    assert annotations[2].timestamp == 42000000
    assert set([ann.value for ann in annotations]) == set([
        'ss', 'sr', 'test_annotation',
    ])
    assert len(span.binary_annotations) == 2
    binary_annotations = sorted(
        span.binary_annotations, key=lambda bin_ann: bin_ann.key)
    assert binary_annotations[0].key == 'extra_binary_annotation'
    assert binary_annotations[0].value == 'extra_value'
    assert binary_annotations[1].key == 'some_key'
    assert binary_annotations[1].value == 'some_value'
예제 #6
0
def span_context(dummy_request):
    # These annotations should go to the server span
    zipkin_logger.debug({
        'annotations': {
            'server_annotation': 1
        },
        'binary_annotations': {
            'server': 'true'
        },
    })
    # Creates a new span, a child of the server span
    with zipkin_span(
            service_name='child',
            span_name='get',
            binary_annotations={'foo': 'bar'},
    ):
        # These annotations go to the child span
        zipkin_logger.debug({
            'annotations': {
                'child_annotation': 1
            },
            'binary_annotations': {
                'child': 'true'
            },
        })
        # This should log a new span with `child` as its parent
        zipkin_logger.debug({
            'annotations': {
                'grandchild_annotation': 1
            },
            'binary_annotations': {
                'grandchild': 'true'
            },
            'service_name': 'grandchild',
            'name': 'put',
        })
    return {}
예제 #7
0
def span_context(dummy_request):
    # These annotations should go to the server span
    zipkin_logger.debug({
        'annotations': {'server_annotation': 1},
        'binary_annotations': {'server': 'true'},
    })
    # Creates a new span, a child of the server span
    with zipkin_span(
        service_name='child', span_name='get',
        binary_annotations={'foo': 'bar'},
    ):
        # These annotations go to the child span
        zipkin_logger.debug({
            'annotations': {'child_annotation': 1},
            'binary_annotations': {'child': 'true'},
        })
        # This should log a new span with `child` as its parent
        zipkin_logger.debug({
            'annotations': {'grandchild_annotation': 1},
            'binary_annotations': {'grandchild': 'true'},
            'service_name': 'grandchild',
            'name': 'put',
        })
    return {}