def test_make_local_span_copies_context(self, mock_getrandbits): mock_getrandbits.return_value = 0xCAFE mock_observer = mock.Mock(spec=ServerSpanObserver) mock_context = mock.Mock() mock_cloned_context = mock.Mock() mock_context.clone.return_value = mock_cloned_context server_span = ServerSpan("trace", "parent", "id", None, 0, "name", mock_context) server_span.register(mock_observer) local_span = server_span.make_child("test_op", local=True, component_name="test_component") self.assertNotEqual(local_span.context, mock_context)
def test_make_child(self, mock_getrandbits): mock_getrandbits.return_value = 0xCAFE mock_observer = mock.Mock(spec=ServerSpanObserver) mock_context = mock.Mock() server_span = ServerSpan("trace", "parent", "id", None, 0, "name", mock_context) server_span.register(mock_observer) child_span = server_span.make_child("child_name") self.assertEqual(child_span.name, "child_name") self.assertEqual(child_span.id, 0xCAFE) self.assertEqual(child_span.trace_id, "trace") self.assertEqual(child_span.parent_id, "id") self.assertEqual(mock_observer.on_child_span_created.call_count, 1) self.assertEqual(mock_observer.on_child_span_created.call_args, mock.call(child_span))
def test_nested(): batch = FakeBatch() span = ServerSpan( trace_id=1234, parent_id=2345, span_id=3456, sampled=None, flags=None, name="fancy.span", context=RequestContext({}), ) observer = TaggedMetricsLocalSpanObserver(batch, span, {"client", "endpoint"}) span.register(observer) with span.make_child("foo", local=True, component_name="foo") as child_span: assert len(child_span.observers) == 1
def test_make_local_span(self, mock_getrandbits): mock_getrandbits.return_value = 0xCAFE mock_observer = mock.Mock(spec=ServerSpanObserver) mock_context = mock.Mock() mock_cloned_context = mock.Mock() mock_context.clone.return_value = mock_cloned_context server_span = ServerSpan("trace", "parent", "id", None, 0, "name", mock_context) server_span.register(mock_observer) local_span = server_span.make_child("test_op", local=True, component_name="test_component") self.assertEqual(local_span.name, "test_op") self.assertEqual(local_span.id, 0xCAFE) self.assertEqual(local_span.trace_id, "trace") self.assertEqual(local_span.parent_id, "id") self.assertEqual(mock_observer.on_child_span_created.call_count, 1) self.assertEqual(mock_observer.on_child_span_created.call_args, mock.call(local_span))