def test_set_tag_manual_drop(self): ctx = Context() s = Span(tracer=None, name='root.span', service='s', resource='r', context=ctx) assert s.context == ctx assert ctx.sampling_priority != priority.USER_REJECT assert s.context.sampling_priority != priority.USER_REJECT assert s.meta == dict() s.set_tag('manual.drop') assert ctx.sampling_priority == priority.USER_REJECT assert s.context.sampling_priority == priority.USER_REJECT assert s.meta == dict() ctx.sampling_priority = priority.AUTO_REJECT assert ctx.sampling_priority == priority.AUTO_REJECT assert s.context.sampling_priority == priority.AUTO_REJECT assert s.meta == dict() s.set_tag('manual.drop') assert ctx.sampling_priority == priority.USER_REJECT assert s.context.sampling_priority == priority.USER_REJECT assert s.meta == dict()
def test_context_priority(self): # a context is sampled if the spans are sampled ctx = Context() for priority in [USER_REJECT, AUTO_REJECT, AUTO_KEEP, USER_KEEP, None, 999]: ctx.sampling_priority = priority span = Span(tracer=None, name=('fake_span_%s' % repr(priority))) ctx.add_span(span) # It's "normal" to have sampled be true even when priority sampling is # set to 0 or -1. It would stay false even even with priority set to 2. # The only criteria to send (or not) the spans to the agent should be # this "sampled" attribute, as it's tightly related to the trace weight. ok_(ctx._sampled is True, 'priority has no impact on sampled status') eq_(priority, ctx.sampling_priority)
def test_context_priority(self): # a context is sampled if the spans are sampled ctx = Context() for priority in [USER_REJECT, AUTO_REJECT, AUTO_KEEP, USER_KEEP, None, 999]: ctx.sampling_priority = priority span = Span(tracer=None, name=('fake_span_%s' % repr(priority))) ctx.add_span(span) # It's "normal" to have sampled be true even when priority sampling is # set to 0 or -1. It would stay false even even with priority set to 2. # The only criteria to send (or not) the spans to the agent should be # this "sampled" attribute, as it's tightly related to the trace weight. ok_(ctx._sampled is True, 'priority has no impact on sampled status') eq_(priority, ctx.sampling_priority)
def test_clone(self): ctx = Context() ctx.sampling_priority = 2 # manually create a root-child trace root = Span(tracer=None, name='root') child = Span(tracer=None, name='child_1', trace_id=root.trace_id, parent_id=root.span_id) child._parent = root ctx.add_span(root) ctx.add_span(child) cloned_ctx = ctx.clone() assert cloned_ctx._parent_trace_id == ctx._parent_trace_id assert cloned_ctx._parent_span_id == ctx._parent_span_id assert cloned_ctx._sampling_priority == ctx._sampling_priority assert cloned_ctx._dd_origin == ctx._dd_origin assert cloned_ctx._current_span == ctx._current_span assert cloned_ctx._trace == []
def test_clone(self): ctx = Context() ctx.sampling_priority = 2 # manually create a root-child trace root = Span(tracer=None, name='root') child = Span(tracer=None, name='child_1', trace_id=root.trace_id, parent_id=root.span_id) child._parent = root ctx.add_span(root) ctx.add_span(child) cloned_ctx = ctx.clone() eq_(cloned_ctx._parent_trace_id, ctx._parent_trace_id) eq_(cloned_ctx._parent_span_id, ctx._parent_span_id) eq_(cloned_ctx._sampled, ctx._sampled) eq_(cloned_ctx._sampling_priority, ctx._sampling_priority) eq_(cloned_ctx._current_span, ctx._current_span) eq_(cloned_ctx._trace, []) eq_(cloned_ctx._finished_spans, 0)
def test_clone(self): ctx = Context() ctx.sampling_priority = 2 # manually create a root-child trace root = Span(tracer=None, name='root') child = Span(tracer=None, name='child_1', trace_id=root.trace_id, parent_id=root.span_id) child._parent = root ctx.add_span(root) ctx.add_span(child) cloned_ctx = ctx.clone() eq_(cloned_ctx._parent_trace_id, ctx._parent_trace_id) eq_(cloned_ctx._parent_span_id, ctx._parent_span_id) eq_(cloned_ctx._sampled, ctx._sampled) eq_(cloned_ctx._sampling_priority, ctx._sampling_priority) eq_(cloned_ctx._dd_origin, ctx._dd_origin) eq_(cloned_ctx._current_span, ctx._current_span) eq_(cloned_ctx._trace, []) eq_(cloned_ctx._finished_spans, 0)
def test_set_tag_manual_keep(self): ctx = Context() s = Span(tracer=None, name="root.span", service="s", resource="r", context=ctx) assert s.context == ctx assert ctx.sampling_priority != priority.USER_KEEP assert s.context.sampling_priority != priority.USER_KEEP assert s.meta == dict() s.set_tag("manual.keep") assert ctx.sampling_priority == priority.USER_KEEP assert s.context.sampling_priority == priority.USER_KEEP assert s.meta == dict() ctx.sampling_priority = priority.AUTO_REJECT assert ctx.sampling_priority == priority.AUTO_REJECT assert s.context.sampling_priority == priority.AUTO_REJECT assert s.meta == dict() s.set_tag("manual.keep") assert ctx.sampling_priority == priority.USER_KEEP assert s.context.sampling_priority == priority.USER_KEEP assert s.meta == dict()