Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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))
Beispiel #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
Beispiel #6
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))
Beispiel #7
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)
Beispiel #8
0
 def on_server_span_created(self, context: RequestContext,
                            server_span: ServerSpan) -> None:
     observer = _ActiveRequestsServerSpanObserver(self,
                                                  server_span.trace_id)
     server_span.register(observer)