Example #1
0
def test_convert_spans_v2_json_to_v2_json():
    spans, _, _, _ = generate_list_of_spans(Encoding.V2_JSON)

    converted_spans = convert_spans(spans=spans,
                                    output_encoding=Encoding.V2_JSON)

    assert detect_span_version_and_encoding(
        converted_spans) == Encoding.V2_JSON
Example #2
0
def test_detect_span_version_and_encoding(encoding):
    spans, _, _, _ = generate_list_of_spans(encoding)
    old_type = type(spans)

    assert detect_span_version_and_encoding(spans) == encoding

    if encoding in [Encoding.V1_JSON, Encoding.V2_JSON]:
        assert type(spans) == old_type
        spans = spans.encode()
        assert detect_span_version_and_encoding(spans) == encoding
Example #3
0
def test_encoding():
    thrift_spans, zipkin_attrs, inner_span_id, ts = \
        generate_list_of_spans(Encoding.V1_THRIFT)

    json_spans = convert_spans(thrift_spans, Encoding.V2_JSON)

    inner_span, root_span = json.loads(json_spans)

    assert root_span == {
        'traceId': zipkin_attrs.trace_id,
        'name': 'test_span_name',
        'parentId': zipkin_attrs.parent_span_id,
        'id': zipkin_attrs.span_id,
        'timestamp': us(ts),
        'duration': us(10),
        'kind': 'CLIENT',
        'shared': True,
        'localEndpoint': {
            'ipv4': '10.0.0.0',
            'port': 8080,
            'serviceName': 'test_service_name',
        },
        'remoteEndpoint': {
            'ipv6': '2001:db8:85a3::8a2e:370:7334',
            'port': 8888,
            'serviceName': 'sa_service',
        },
        'tags': {
            'some_key': 'some_value'
        },
    }

    assert inner_span == {
        'traceId': zipkin_attrs.trace_id,
        'name': 'inner_span',
        'parentId': zipkin_attrs.span_id,
        'id': inner_span_id,
        'timestamp': us(ts),
        'duration': us(5),
        'localEndpoint': {
            'ipv4': '10.0.0.0',
            'port': 8080,
            'serviceName': 'test_service_name',
        },
        'annotations': [{
            'timestamp': us(ts),
            'value': 'ws'
        }],
    }
Example #4
0
def test_encoding():
    thrift_spans, zipkin_attrs, inner_span_id, ts = generate_list_of_spans(
        Encoding.V1_THRIFT)

    json_spans = convert_spans(thrift_spans, Encoding.V2_JSON)

    inner_span, root_span = json.loads(json_spans)

    assert root_span == {
        "traceId": zipkin_attrs.trace_id,
        "name": "test_span_name",
        "parentId": zipkin_attrs.parent_span_id,
        "id": zipkin_attrs.span_id,
        "timestamp": us(ts),
        "duration": us(10),
        "kind": "CLIENT",
        "localEndpoint": {
            "ipv4": "10.0.0.0",
            "port": 8080,
            "serviceName": "test_service_name",
        },
        "remoteEndpoint": {
            "ipv6": "2001:db8:85a3::8a2e:370:7334",
            "port": 8888,
            "serviceName": "sa_service",
        },
        "tags": {
            "some_key": "some_value"
        },
    }

    assert inner_span == {
        "traceId": zipkin_attrs.trace_id,
        "name": "inner_span",
        "parentId": zipkin_attrs.span_id,
        "id": inner_span_id,
        "timestamp": us(ts),
        "duration": us(5),
        "localEndpoint": {
            "ipv4": "10.0.0.0",
            "port": 8080,
            "serviceName": "test_service_name",
        },
        "annotations": [{
            "timestamp": us(ts),
            "value": "ws"
        }],
    }
Example #5
0
 def test_decode_spans_list(self):
     spans, _, _, _ = generate_list_of_spans(Encoding.V1_THRIFT)
     decoder = _V1ThriftDecoder()
     with mock.patch.object(decoder, '_decode_thrift_span') as mock_decode:
         decoder.decode_spans(spans)
         assert mock_decode.call_count == 2