def log_span( span_id, parent_span_id, trace_id, span_name, annotations, binary_annotations, registry_settings, ): """Creates a span and logs it. Uses the required registry setting of `zipkin.transport_handler` to log the span. """ span = create_span( span_id, parent_span_id, trace_id, span_name, annotations, binary_annotations, ) message = thrift_obj_in_bytes(span) scribe_stream = registry_settings.get('zipkin.stream_name', 'zipkin') if 'zipkin.transport_handler' in registry_settings: return registry_settings['zipkin.transport_handler'](scribe_stream, message) else: raise ZipkinError( "`zipkin.transport_handler` is a required config property, which" " is missing. It is a callback method which takes stream_name and" " a message as the params and logs message via scribe/kafka." )
def test_create_span(Span): # Not much logic here so this is just a smoke test. The only # substantive thing is that hex IDs get converted to ints. thrift_helper.create_span( span_id='0000000000000001', parent_span_id='0000000000000002', trace_id='000000000000000f', span_name='foo', annotations='ann', binary_annotations='binary_ann', ) Span.assert_called_once_with(**{ 'id': 1, 'parent_id': 2, 'name': 'foo', 'trace_id': 15, 'name': 'foo', 'annotations': 'ann', 'binary_annotations': 'binary_ann', })
def test_create_span_creates_a_default_span_object( Span, sampled_zipkin_attr): get_id = thrift_helper.get_id assert Span.return_value == thrift_helper.create_span( sampled_zipkin_attr, 'foo', 'ann', 'binary_ann') Span.assert_called_once_with( **{'name': 'foo', 'trace_id': 18, 'binary_annotations': 'binary_ann', 'annotations': 'ann', 'parent_id': get_id('34'), 'id': get_id('23')})
def test_create_span_creates_a_child_span_object_for_child( Span, gen_span, sampled_zipkin_attr): gen_span.return_value = '56' get_id = thrift_helper.get_id assert Span.return_value == thrift_helper.create_span( sampled_zipkin_attr, 'foo', 'ann', 'binary_ann', is_client=True) Span.assert_called_once_with( **{'name': 'foo', 'trace_id': 18, 'binary_annotations': 'binary_ann', 'annotations': 'ann', 'parent_id': get_id('23'), 'id': get_id('56')})
def test_create_span_creates_a_default_span_object(Span, sampled_zipkin_attr): get_id = thrift_helper.get_id assert Span.return_value == thrift_helper.create_span( sampled_zipkin_attr, 'foo', 'ann', 'binary_ann') Span.assert_called_once_with( **{ 'name': 'foo', 'trace_id': 18, 'binary_annotations': 'binary_ann', 'annotations': 'ann', 'parent_id': get_id('34'), 'id': get_id('23') })
def test_create_span_creates_a_default_span_object(Span, sampled_zipkin_attr): get_id = thrift_helper.get_id assert Span.return_value == thrift_helper.create_span(sampled_zipkin_attr, "foo", "ann", "binary_ann") Span.assert_called_once_with( **{ "name": "foo", "trace_id": 18, "binary_annotations": "binary_ann", "annotations": "ann", "parent_id": get_id("34"), "id": get_id("23"), } )
def test_create_span_creates_a_child_span_object_for_child(Span, gen_span, sampled_zipkin_attr): gen_span.return_value = "56" get_id = thrift_helper.get_id assert Span.return_value == thrift_helper.create_span( sampled_zipkin_attr, "foo", "ann", "binary_ann", is_client=True ) Span.assert_called_once_with( **{ "name": "foo", "trace_id": 18, "binary_annotations": "binary_ann", "annotations": "ann", "parent_id": get_id("23"), "id": get_id("56"), } )
def test_create_span_creates_a_child_span_object_for_child( Span, gen_span, sampled_zipkin_attr): gen_span.return_value = '56' get_id = thrift_helper.get_id assert Span.return_value == thrift_helper.create_span(sampled_zipkin_attr, 'foo', 'ann', 'binary_ann', is_client=True) Span.assert_called_once_with( **{ 'name': 'foo', 'trace_id': 18, 'binary_annotations': 'binary_ann', 'annotations': 'ann', 'parent_id': get_id('23'), 'id': get_id('56') })
def log_span(zipkin_attrs, span_name, registry_settings, annotations, binary_annotations, is_client): """Creates a span and logs it. If `zipkin.transport_handler` config is set, it is used to act as a callback and log message is sent as a parameter. """ span = create_span( zipkin_attrs, span_name, annotations, binary_annotations, is_client) message = thrift_obj_in_bytes(span) scribe_stream = registry_settings.get('zipkin.stream_name', 'zipkin') if 'zipkin.transport_handler' in registry_settings: return registry_settings['zipkin.transport_handler'](scribe_stream, message) else: raise ZipkinError( "`zipkin.transport_handler` is a required config property, which" " is missing. It is a callback method which takes stream_name and" " a message as the params and logs message via scribe/kafka.")