def test_server_extra_annotations_are_included( thrift_obj, default_trace_id_generator ): settings = { 'zipkin.tracing_percent': 100, 'zipkin.trace_id_generator': default_trace_id_generator, } WebTestApp(main({}, **settings)).get('/sample_v2', status=200) assert thrift_obj.call_count == 1 server_spans = thrift_obj.call_args[0][0] assert len(server_spans) == 1 server_span = server_spans[0] # Assert that the annotations logged via debug statements exist test_helper.assert_extra_annotations( server_span, {'bar': 1000000, 'foo': 2000000}, ) test_helper.assert_extra_binary_annotations( server_span, {'ping': 'pong'}, )
def test_server_extra_annotations_are_included(thrift_obj, sampled_trace_id_generator): settings = {"zipkin.trace_id_generator": sampled_trace_id_generator} TestApp(main({}, **settings)).get("/sample_v2", status=200) assert thrift_obj.call_count == 1 server_span = thrift_obj.call_args[0][0] # Assert that the annotations logged via debug statements exist test_helper.assert_extra_annotations(server_span, {"bar": 1000000, "foo": 2000000}) test_helper.assert_extra_binary_annotations(server_span, {"ping": "pong"})
def test_decorator(thrift_obj, default_trace_id_generator): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = {"zipkin.tracing_percent": 100, "zipkin.trace_id_generator": default_trace_id_generator} WebTestApp(main({}, **settings)).get("/decorator_context", status=200) # Two spans are logged - child span, then server span child_span_args, server_span_args = thrift_obj.call_args_list child_span = child_span_args[0][0] server_span = server_span_args[0][0] # Assert proper hierarchy and annotations assert child_span.parent_id == server_span.id assert_extra_binary_annotations(child_span, {"a": "1"}) assert child_span.name == "my_span"
def test_decorator(thrift_obj, default_trace_id_generator): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.tracing_percent': 100, 'zipkin.trace_id_generator': default_trace_id_generator, } WebTestApp(main({}, **settings)).get('/decorator_context', status=200) # Two spans are logged - child span, then server span child_span_args, server_span_args = thrift_obj.call_args_list child_span = child_span_args[0][0] server_span = server_span_args[0][0] # Assert proper hierarchy and annotations assert child_span.parent_id == server_span.id assert_extra_binary_annotations(child_span, {'a': '1'}) assert child_span.name == 'my_span'
def test_decorator( thrift_obj, sampled_trace_id_generator ): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.trace_id_generator': sampled_trace_id_generator, } TestApp(main({}, **settings)).get('/decorator_context', status=200) # Two spans are logged - child span, then server span child_span_args, server_span_args = thrift_obj.call_args_list child_span = child_span_args[0][0] server_span = server_span_args[0][0] # Assert proper hierarchy and annotations assert child_span.parent_id == server_span.id assert_extra_binary_annotations(child_span, {'a': '1'}) assert child_span.name == 'my_span'
def test_span_context(default_trace_id_generator): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.tracing_percent': 100, 'zipkin.trace_id_generator': default_trace_id_generator, } app_main, transport, _ = generate_app_main(settings) WebTestApp(app_main).get('/span_context', status=200) # Spans are batched # The order of span logging goes from innermost (grandchild) up. assert len(transport.output) == 1 span_list = decode_thrift(transport.output[0]) assert len(span_list) == 3 grandchild_span = span_list[0] child_span = span_list[1] server_span = span_list[2] # Assert proper hierarchy assert child_span.parent_id == server_span.id assert grandchild_span.parent_id == child_span.id # Assert annotations are properly assigned assert_extra_annotations(child_span, {'child_annotation': 1000000}) assert_extra_binary_annotations( child_span, {'foo': 'bar', 'child': 'true'}) assert_extra_annotations( grandchild_span, {'grandchild_annotation': 1000000}) assert_extra_binary_annotations(grandchild_span, {'grandchild': 'true'}) # For the span produced by SpanContext, assert cs==sr and ss==cr # Initialize them all so the equalities won't be true. annotations = { 'cs': 0, 'sr': 1, 'ss': 2, 'cr': 3 } for annotation in child_span.annotations: if annotation.value in annotations: annotations[annotation.value] = annotation.timestamp assert annotations['cs'] == annotations['sr'] assert annotations['ss'] == annotations['cr']
def test_server_extra_annotations_are_included( thrift_obj, sampled_trace_id_generator ): settings = { 'zipkin.trace_id_generator': sampled_trace_id_generator, } TestApp(main({}, **settings)).get('/sample_v2', status=200) assert thrift_obj.call_count == 1 server_span = thrift_obj.call_args[0][0] # Assert that the annotations logged via debug statements exist test_helper.assert_extra_annotations( server_span, {'bar': 1000000, 'foo': 2000000}, ) test_helper.assert_extra_binary_annotations( server_span, {'ping': 'pong'}, )
def test_span_context(thrift_obj, default_trace_id_generator): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = {"zipkin.tracing_percent": 100, "zipkin.trace_id_generator": default_trace_id_generator} WebTestApp(main({}, **settings)).get("/span_context", status=200) # Ugly extraction of spans from mock thrift_obj call args # The order of span logging goes from innermost (grandchild) up. gc_span_args, child_span_args, server_span_args = thrift_obj.call_args_list child_span = child_span_args[0][0] grandchild_span = gc_span_args[0][0] server_span = server_span_args[0][0] # Assert proper hierarchy assert child_span.parent_id == server_span.id assert grandchild_span.parent_id == child_span.id # Assert annotations are properly assigned assert_extra_annotations(server_span, {"server_annotation": 1000000}) assert_extra_binary_annotations(server_span, {"server": "true"}) assert_extra_annotations(child_span, {"child_annotation": 1000000}) assert_extra_binary_annotations(child_span, {"foo": "bar", "child": "true"}) assert_extra_annotations(grandchild_span, {"grandchild_annotation": 1000000}) assert_extra_binary_annotations(grandchild_span, {"grandchild": "true"}) # For the span produced by SpanContext, assert cs==sr and ss==cr # Initialize them all so the equalities won't be true. annotations = {"cs": 0, "sr": 1, "ss": 2, "cr": 3} for annotation in child_span.annotations: if annotation.value in annotations: annotations[annotation.value] = annotation.timestamp assert annotations["cs"] == annotations["sr"] assert annotations["ss"] == annotations["cr"]
def test_client_context( thrift_obj, sampled_trace_id_generator ): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.trace_id_generator': sampled_trace_id_generator, } TestApp(main({}, **settings)).get('/client_context', status=200) # Ugly extraction of spans from mock thrift_obj call args # The order of span logging goes from innermost (grandchild) up. gc_span_args, child_span_args, server_span_args = thrift_obj.call_args_list child_span = child_span_args[0][0] grandchild_span = gc_span_args[0][0] server_span = server_span_args[0][0] # Assert proper hierarchy assert child_span.parent_id == server_span.id assert grandchild_span.parent_id == child_span.id # Assert annotations are properly assigned assert_extra_annotations(server_span, {'server_annotation': 1000000}) assert_extra_binary_annotations(server_span, {'server': 'true'}) assert_extra_annotations(child_span, {'child_annotation': 1000000}) assert_extra_binary_annotations(child_span, {'foo': 'bar', 'child': 'true'}) assert_extra_annotations(grandchild_span, {'grandchild_annotation': 1000000}) assert_extra_binary_annotations(grandchild_span, {'grandchild': 'true'})
def test_decorator(default_trace_id_generator): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.tracing_percent': 100, 'zipkin.trace_id_generator': default_trace_id_generator, } app_main, transport, _ = generate_app_main(settings) WebTestApp(app_main).get('/decorator_context', status=200) # Two spans are logged - child span, then server span assert len(transport.output) == 1 span_list = decode_thrift(transport.output[0]) assert len(span_list) == 2 child_span = span_list[0] server_span = span_list[1] # Assert proper hierarchy and annotations assert child_span.parent_id == server_span.id assert_extra_binary_annotations(child_span, {'a': '1'}) assert child_span.name == 'my_span'
def test_decorator( thrift_obj, default_trace_id_generator ): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.tracing_percent': 100, 'zipkin.trace_id_generator': default_trace_id_generator, } WebTestApp(main({}, **settings)).get('/decorator_context', status=200) # Two spans are logged - child span, then server span assert thrift_obj.call_count == 1 span_list = thrift_obj.call_args[0][0] assert len(span_list) == 2 child_span = span_list[0] server_span = span_list[1] # Assert proper hierarchy and annotations assert child_span.parent_id == server_span.id assert_extra_binary_annotations(child_span, {'a': '1'}) assert child_span.name == 'my_span'
def test_span_context( thrift_obj, default_trace_id_generator ): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.tracing_percent': 100, 'zipkin.trace_id_generator': default_trace_id_generator, } WebTestApp(main({}, **settings)).get('/span_context', status=200) # Spans are batched # The order of span logging goes from innermost (grandchild) up. assert thrift_obj.call_count == 1 span_list = thrift_obj.call_args[0][0] assert len(span_list) == 3 grandchild_span = span_list[0] child_span = span_list[1] server_span = span_list[2] # Assert proper hierarchy assert child_span.parent_id == server_span.id assert grandchild_span.parent_id == child_span.id # Assert annotations are properly assigned assert_extra_annotations(server_span, {'server_annotation': 1000000}) assert_extra_binary_annotations(server_span, {'server': 'true'}) assert_extra_annotations(child_span, {'child_annotation': 1000000}) assert_extra_binary_annotations( child_span, {'foo': 'bar', 'child': 'true'}) assert_extra_annotations( grandchild_span, {'grandchild_annotation': 1000000}) assert_extra_binary_annotations(grandchild_span, {'grandchild': 'true'}) # For the span produced by SpanContext, assert cs==sr and ss==cr # Initialize them all so the equalities won't be true. annotations = { 'cs': 0, 'sr': 1, 'ss': 2, 'cr': 3 } for annotation in child_span.annotations: if annotation.value in annotations: annotations[annotation.value] = annotation.timestamp assert annotations['cs'] == annotations['sr'] assert annotations['ss'] == annotations['cr']
def test_span_context( thrift_obj, sampled_trace_id_generator ): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.trace_id_generator': sampled_trace_id_generator, } TestApp(main({}, **settings)).get('/span_context', status=200) # Ugly extraction of spans from mock thrift_obj call args # The order of span logging goes from innermost (grandchild) up. gc_span_args, child_span_args, server_span_args = thrift_obj.call_args_list child_span = child_span_args[0][0] grandchild_span = gc_span_args[0][0] server_span = server_span_args[0][0] # Assert proper hierarchy assert child_span.parent_id == server_span.id assert grandchild_span.parent_id == child_span.id # Assert annotations are properly assigned assert_extra_annotations(server_span, {'server_annotation': 1000000}) assert_extra_binary_annotations(server_span, {'server': 'true'}) assert_extra_annotations(child_span, {'child_annotation': 1000000}) assert_extra_binary_annotations( child_span, {'foo': 'bar', 'child': 'true'}) assert_extra_annotations( grandchild_span, {'grandchild_annotation': 1000000}) assert_extra_binary_annotations(grandchild_span, {'grandchild': 'true'}) # For the span produced by SpanContext, assert cs==sr and ss==cr # Initialize them all so the equalities won't be true. annotations = { 'cs': 0, 'sr': 1, 'ss': 2, 'cr': 3 } for annotation in child_span.annotations: if annotation.value in annotations: annotations[annotation.value] = annotation.timestamp assert annotations['cs'] == annotations['sr'] assert annotations['ss'] == annotations['cr']
def test_span_context(thrift_obj, default_trace_id_generator): # Tests that log lines with 'service_name' keys are logged as # new client spans. settings = { 'zipkin.tracing_percent': 100, 'zipkin.trace_id_generator': default_trace_id_generator, } WebTestApp(main({}, **settings)).get('/span_context', status=200) # Ugly extraction of spans from mock thrift_obj call args # The order of span logging goes from innermost (grandchild) up. gc_span_args, child_span_args, server_span_args = thrift_obj.call_args_list child_span = child_span_args[0][0] grandchild_span = gc_span_args[0][0] server_span = server_span_args[0][0] # Assert proper hierarchy assert child_span.parent_id == server_span.id assert grandchild_span.parent_id == child_span.id # Assert annotations are properly assigned assert_extra_annotations(server_span, {'server_annotation': 1000000}) assert_extra_binary_annotations(server_span, {'server': 'true'}) assert_extra_annotations(child_span, {'child_annotation': 1000000}) assert_extra_binary_annotations(child_span, { 'foo': 'bar', 'child': 'true' }) assert_extra_annotations(grandchild_span, {'grandchild_annotation': 1000000}) assert_extra_binary_annotations(grandchild_span, {'grandchild': 'true'}) # For the span produced by SpanContext, assert cs==sr and ss==cr # Initialize them all so the equalities won't be true. annotations = {'cs': 0, 'sr': 1, 'ss': 2, 'cr': 3} for annotation in child_span.annotations: if annotation.value in annotations: annotations[annotation.value] = annotation.timestamp assert annotations['cs'] == annotations['sr'] assert annotations['ss'] == annotations['cr']