Exemplo n.º 1
0
    def test_join_encoded_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()

        # Encode each individual trace on its own
        encoded_traces = [encoder.encode_trace(trace) for trace in traces]
        # Join the encoded traces together
        data = encoder.join_encoded(encoded_traces)

        # Parse the encoded data
        items = encoder._decode(data)

        # test the encoded output that should be a string
        # and the output must be flatten
        assert isinstance(data, 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"]
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"]
Exemplo n.º 3
0
def test_msgpack_span_property_variations(span):
    refencoder = RefMsgpackEncoder()
    encoder = MsgpackEncoder()

    # Finish the span to ensure a duration exists.
    span.finish()

    trace = [span]
    assert decode(refencoder.encode_trace(trace)) == decode(
        encoder.encode_trace(trace))
Exemplo n.º 4
0
def test_span_types(span, tags):
    refencoder = RefMsgpackEncoder()
    encoder = MsgpackEncoder()

    span.set_tags(tags)

    # Finish the span to ensure a duration exists.
    span.finish()

    trace = [span]
    assert decode(refencoder.encode_trace(trace)) == decode(
        encoder.encode_trace(trace))
Exemplo n.º 5
0
def test_custom_msgpack_encode_trace_size(name, service, resource, meta,
                                          metrics, error, span_type):
    encoder = MsgpackEncoder(1 << 20, 1 << 20)
    span = Span(tracer=None, name=name, service=service, resource=resource)
    span.meta = meta
    span.metrics = metrics
    span.error = error
    span.span_type = span_type
    trace = [span, span, span]

    encoder.put(trace)
    assert encoder.size + 1 == len(encoder.encode())
Exemplo n.º 6
0
def test_encoder_propagates_dd_origin():
    tracer = DummyTracer()
    encoder = MsgpackEncoder(1 << 20, 1 << 20)
    with tracer.trace("Root") as root:
        root.context.dd_origin = CI_APP_TEST_ORIGIN
        for _ in range(999):
            with tracer.trace("child"):
                pass
    # Ensure encoded trace contains dd_origin tag in all spans
    trace = tracer.writer.pop()
    encoder.put(trace)
    decoded_trace = decode(encoder.encode())[0]
    for span in decoded_trace:
        assert span[b"meta"][b"_dd.origin"] == b"ciapp-test"
Exemplo n.º 7
0
def test_encoder_buffer_size_limit():
    buffer_size = 1 << 10
    encoder = MsgpackEncoder(buffer_size, buffer_size)

    trace = [Span(tracer=None, name="test")]
    encoder.put(trace)
    trace_size = encoder.size

    for _ in range(1, int(buffer_size / trace_size)):
        encoder.put(trace)

    with pytest.raises(BufferFull):
        encoder.put(trace)

    with pytest.raises(BufferFull):
        encoder.put(trace)
Exemplo n.º 8
0
def test_custom_msgpack_encode():
    encoder = MsgpackEncoder(1 << 20, 1 << 20)
    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
    encoder.put(trace)
    assert decode(refencoder.encode_traces([trace
                                            ])) == decode(encoder.encode())

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

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

    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()
    encoder.put([s])
    assert decode(refencoder.encode_traces([[s]])) == decode(encoder.encode())
Exemplo n.º 9
0
def test_encoder_buffer_item_size_limit():
    max_item_size = 1 << 10
    encoder = MsgpackEncoder(max_item_size << 1, max_item_size)

    span = Span(tracer=None, name="test")
    trace = [span]
    encoder.put(trace)
    trace_size = encoder.size - 1  # This includes the global msgpack array size prefix

    with pytest.raises(BufferItemTooLarge):
        encoder.put([span] * (int(max_item_size / trace_size) + 1))
Exemplo n.º 10
0
def test_encoder_buffer_size_limit():
    buffer_size = 1 << 10
    encoder = MsgpackEncoder(buffer_size, buffer_size)

    trace = [Span(tracer=None, name="test")]
    encoder.put(trace)
    trace_size = encoder.size - 1  # This includes the global msgpack array size prefix

    for _ in range(1, int(buffer_size / trace_size)):
        encoder.put(trace)

    with pytest.raises(BufferFull):
        encoder.put(trace)

    with pytest.raises(BufferFull):
        encoder.put(trace)
Exemplo n.º 11
0
def test_encoder_buffer_item_size_limit():
    buffer_size = 1 << 10
    encoder = MsgpackEncoder(buffer_size, buffer_size)

    span = Span(tracer=None, name="test")
    trace = [span]
    encoder.put(trace)
    trace_size = encoder.size

    with pytest.raises(BufferItemTooLarge):
        encoder.put([span] * (int(buffer_size / trace_size) + 1))
Exemplo n.º 12
0
    def test_list_buffered_encoder(self):
        # test encoding for MsgPack format
        encoder = MsgpackEncoder(2 << 10, 2 << 10)
        encoder.put([
            Span(name="client.testing", tracer=None),
        ])

        trace = encoder.get()
        assert len(trace) == 1

        assert isinstance(trace[0], msgpack_type)
        items = encoder._decode(trace[0])
        assert len(items) == 1
Exemplo n.º 13
0
def test_custom_msgpack_join_encoded():
    encoder = MsgpackEncoder()
    refencoder = RefMsgpackEncoder()

    trace = gen_trace(nspans=50)

    ref = refencoder.join_encoded(
        [refencoder.encode_trace(trace) for _ in range(10)])
    custom = encoder.join_encoded(
        [encoder.encode_trace(trace) for _ in range(10)])
    assert decode(ref) == decode(custom)

    ref = refencoder.join_encoded(
        [refencoder.encode_trace(trace) for _ in range(1)])
    custom = encoder.join_encoded(
        [encoder.encode_trace(trace) for _ in range(1)])
    assert decode(ref) == decode(custom)
Exemplo n.º 14
0
import msgpack
from msgpack.fallback import Packer
import pytest

from ddtrace.internal.encoding import MsgpackEncoder
from ddtrace.internal.encoding import _EncoderBase
from tests.tracer.test_encoders import RefMsgpackEncoder
from tests.tracer.test_encoders import gen_trace


msgpack_encoder = RefMsgpackEncoder()
trace_encoder = MsgpackEncoder()


class PPMsgpackEncoder(_EncoderBase):
    content_type = "application/msgpack"

    @staticmethod
    def encode(obj):
        return Packer().pack(obj)

    @staticmethod
    def decode(data):
        return msgpack.unpackb(data, raw=True)


trace_large = gen_trace(nspans=1000)
trace_small = gen_trace(nspans=50, key_size=10, ntags=5, nmetrics=4)


@pytest.mark.benchmark(group="encoding.join_encoded", min_time=0.005)
Exemplo n.º 15
0
import msgpack
from msgpack.fallback import Packer
import pytest

from ddtrace.ext.ci import CI_APP_TEST_ORIGIN
from ddtrace.internal.encoding import MsgpackEncoder
from ddtrace.internal.encoding import _EncoderBase
from tests.tracer.test_encoders import RefMsgpackEncoder
from tests.tracer.test_encoders import gen_trace
from tests.utils import DummyTracer

msgpack_encoder = RefMsgpackEncoder()
trace_encoder = MsgpackEncoder(4 << 20, 4 << 20)


class PPMsgpackEncoder(_EncoderBase):
    content_type = "application/msgpack"

    @staticmethod
    def encode(obj):
        return Packer().pack(obj)

    @staticmethod
    def decode(data):
        return msgpack.unpackb(data, raw=True)


trace_large = gen_trace(nspans=1000)
trace_small = gen_trace(nspans=50, key_size=10, ntags=5, nmetrics=4)