示例#1
0
    def test_with_baggage_item(self):
        """Should allow immutable extension of new span contexts."""
        baggage = {
            '1': 1,
        }

        first_ctx = SpanContext(baggage=baggage)

        second_ctx = first_ctx.with_baggage_item('2', 2)

        assert '2' not in first_ctx.baggage
        assert second_ctx.baggage is not first_ctx.baggage
示例#2
0
    def test_baggage(self):
        """Ensure baggage passed is the resulting baggage of the span context."""
        baggage = {
            'some': 'stuff',
        }

        span_ctx = SpanContext(baggage=baggage)

        assert span_ctx.baggage == baggage
示例#3
0
    def test_http_headers_base(self, ot_tracer):
        """extract should undo inject for http headers."""

        span_ctx = SpanContext(trace_id=123, span_id=456)
        carrier = {}

        ot_tracer.inject(span_ctx, Format.HTTP_HEADERS, carrier)
        assert len(carrier.keys()) > 0

        ext_span_ctx = ot_tracer.extract(Format.HTTP_HEADERS, carrier)
        assert ext_span_ctx._dd_context.trace_id == 123
        assert ext_span_ctx._dd_context.span_id == 456
示例#4
0
    def test_text(self, ot_tracer):
        """extract should undo inject for http headers"""
        span_ctx = SpanContext(trace_id=123, span_id=456, baggage={"test": 4, "test2": "string"})
        carrier = {}

        ot_tracer.inject(span_ctx, Format.TEXT_MAP, carrier)
        assert len(carrier.keys()) > 0

        ext_span_ctx = ot_tracer.extract(Format.TEXT_MAP, carrier)
        assert ext_span_ctx._dd_context.trace_id == 123
        assert ext_span_ctx._dd_context.span_id == 456
        assert ext_span_ctx.baggage == span_ctx.baggage
示例#5
0
    def test_corrupted_propagated_context(self, ot_tracer):
        """Corrupted context should raise a SpanContextCorruptedException."""
        span_ctx = SpanContext(trace_id=123, span_id=456, baggage={"test": 4, "test2": "string"})
        carrier = {}

        ot_tracer.inject(span_ctx, Format.TEXT_MAP, carrier)
        assert len(carrier.keys()) > 0

        # manually alter a key in the carrier baggage
        del carrier[HTTP_HEADER_TRACE_ID]
        corrupted_key = HTTP_HEADER_TRACE_ID[2:]
        carrier[corrupted_key] = 123

        with pytest.raises(SpanContextCorruptedException):
            ot_tracer.extract(Format.TEXT_MAP, carrier)
示例#6
0
    def test_distributed_trace_propagation(self, ot_tracer, dd_tracer, writer):
        """Ensure that a propagated span context is properly activated."""
        span_ctx = SpanContext(trace_id=123, span_id=456)
        carrier = {}
        ot_tracer.inject(span_ctx, Format.HTTP_HEADERS, carrier)

        # extract should activate the span so that a subsequent start_span
        # will inherit from the propagated span context
        ot_tracer.extract(Format.HTTP_HEADERS, carrier)

        with dd_tracer.trace('test') as span:
            pass

        assert span.parent_id == 456
        assert span.trace_id == 123

        spans = writer.pop()
        assert len(spans) == 1
示例#7
0
def nop_span_ctx():

    return SpanContext(sampling_priority=AUTO_KEEP)
示例#8
0
def nop_span_ctx():
    from ddtrace.ext.priority import AUTO_KEEP
    from ddtrace.opentracer.span_context import SpanContext

    return SpanContext(sampling_priority=AUTO_KEEP)
示例#9
0
 def test_init(self):
     """Make sure span context creation is fine."""
     span_ctx = SpanContext()
     assert span_ctx
示例#10
0
 def test_span_context_immutable_baggage(self):
     """Ensure that two different span contexts do not share baggage."""
     ctx1 = SpanContext()
     ctx1.set_baggage_item('test', 3)
     ctx2 = SpanContext()
     assert 'test' not in ctx2._baggage