예제 #1
0
 def on_server_span_created(self, context: RequestContext, server_span: ServerSpan) -> None:
     timeout = self.config.by_endpoint.get(server_span.name, self.config.default)
     if timeout is not config.InfiniteTimespan:
         observer = TimeoutServerSpanObserver(
             server_span, timeout.total_seconds(), self.config.debug
         )
         server_span.register(observer)
예제 #2
0
 def on_server_span_created(self, context: RequestContext,
                            server_span: ServerSpan) -> None:
     timeout = self.config.by_endpoint.get(server_span.name,
                                           self.config.default)
     observer = TimeoutServerSpanObserver(server_span, timeout,
                                          self.config.debug)
     server_span.register(observer)
예제 #3
0
    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)
예제 #4
0
    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))
예제 #5
0
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
예제 #6
0
 def setUp(self):
     super().setUp()
     self.recorder = NullRecorder()
     self.mock_context = mock.Mock()
     self.span = ServerSpan("test-id", "test-parent-id", "test-span-id",
                            None, 0, "test", self.mock_context)
     self.test_server_span_observer = TraceServerSpanObserver(
         "test-service", "test-hostname", self.span, self.recorder)
예제 #7
0
 def test_no_tracing_without_sampling(self):
     client = make_client("test-service", sample_rate=0)
     baseplate_observer = TraceBaseplateObserver(client)
     context_mock = mock.Mock()
     span = ServerSpan("test-id", "test-parent-id", "test-span-id", False,
                       0, "test", self.mock_context)
     baseplate_observer.on_server_span_created(context_mock, span)
     self.assertEqual(len(span.observers), 0)
예제 #8
0
    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))
예제 #9
0
 def test_register_server_span_observer(self):
     client = make_client("test-service")
     baseplate_observer = TraceBaseplateObserver(client)
     context_mock = mock.Mock()
     span = ServerSpan("test-id", "test-parent-id", "test-span-id", True, 0,
                       "test", self.mock_context)
     baseplate_observer.on_server_span_created(context_mock, span)
     self.assertEqual(len(span.observers), 1)
     self.assertEqual(type(span.observers[0]), TraceServerSpanObserver)
예제 #10
0
    def on_server_span_created(self, context: RequestContext,
                               server_span: ServerSpan) -> None:
        timeout = self.config.by_endpoint.get(server_span.name,
                                              self.config.default)

        min_timeout = None
        if timeout is not config.InfiniteTimespan:
            min_timeout = timeout.total_seconds()

        try:
            deadline_budget = context.deadline_budget
            if deadline_budget:
                if not min_timeout or deadline_budget < min_timeout:
                    min_timeout = deadline_budget
        except AttributeError:
            # no deadline budget in request header
            pass

        if min_timeout:
            observer = TimeoutServerSpanObserver(server_span, min_timeout,
                                                 self.config.debug)
            server_span.register(observer)
예제 #11
0
def make_test_server_span(context=None):
    if not context:
        context = mock.Mock()
    return ServerSpan(1, 2, 3, None, 0, "name", context)
예제 #12
0
 def on_server_span_created(self, context: RequestContext,
                            server_span: ServerSpan) -> None:
     observer = _ActiveRequestsServerSpanObserver(self,
                                                  server_span.trace_id)
     server_span.register(observer)
예제 #13
0
 def setUp(self):
     super().setUp()
     self.recorder = NullRecorder()
     self.mock_context = mock.Mock()
     self.span = ServerSpan("test-id", "test-parent-id", "test-span-id",
                            None, 0, "test", self.mock_context)