Exemplo n.º 1
0
def test_custom_msgpack_encode():
    encoder = MsgpackEncoder()
    refencoder = RefMsgpackEncoder()

    trace = gen_trace(nspans=50)

    # Note that we assert on the decoded versions because the encoded
    # can vary due to non-deterministic map key/value positioning
    assert decode(refencoder.encode_trace(trace)) == decode(
        encoder.encode_trace(trace))

    ref_encoded = refencoder.encode_traces([trace, trace])
    encoded = encoder.encode_traces([trace, trace])
    assert decode(encoded) == decode(ref_encoded)

    # Empty trace (not that this should be done in practice)
    assert decode(refencoder.encode_trace([])) == decode(
        encoder.encode_trace([]))

    s = Span(None, None)
    # Need to .finish() to have a duration since the old implementation will not encode
    # duration_ns, the new one will encode as None
    s.finish()
    assert decode(refencoder.encode_trace([s])) == decode(
        encoder.encode_trace([s]))
Exemplo n.º 2
0
    def test_encode_traces_msgpack(self):
        # test encoding for MsgPack format
        traces = []
        traces.append([
            Span(name="client.testing", tracer=None),
            Span(name="client.testing", tracer=None),
        ])
        traces.append([
            Span(name="client.testing", tracer=None),
            Span(name="client.testing", tracer=None),
        ])

        encoder = MsgpackEncoder()
        spans = encoder.encode_traces(traces)
        items = encoder._decode(spans)

        # test the encoded output that should be a string
        # and the output must be flatten
        assert isinstance(spans, msgpack_type)
        assert len(items) == 2
        assert len(items[0]) == 2
        assert len(items[1]) == 2
        for i in range(2):
            for j in range(2):
                assert b"client.testing" == items[i][j][b"name"]