Exemplo n.º 1
0
    def test_wrap_httplib_response_exporter_thread(self):
        mock_span = mock.Mock()
        span_id = '1234'
        mock_span.span_id = span_id
        mock_span.attributes = {}
        mock_tracer = MockTracer(mock_span)
        mock_response_func = mock.Mock()
        mock_result = mock.Mock()
        mock_result.status = '200'
        mock_response_func.return_value = mock_result

        patch_tracer = mock.patch(
            'opencensus.ext.requests.trace.execution_context.'
            'get_opencensus_tracer',
            return_value=mock_tracer)
        patch_attr = mock.patch(
            'opencensus.ext.httplib.trace.'
            'execution_context.get_opencensus_attr',
            return_value='1111')
        patch_thread = mock.patch(
            'opencensus.ext.requests.trace.execution_context.'
            'is_exporter',
            return_value=True)

        wrapped = trace.wrap_httplib_response(mock_response_func)

        with patch_tracer, patch_attr, patch_thread:
            wrapped(mock.Mock())

        expected_attributes = {}

        self.assertEqual(expected_attributes, mock_tracer.span.attributes)
Exemplo n.º 2
0
    def test_wrap_httplib_response_no_open_span(self):
        mock_span = mock.Mock()
        span_id = '1234'
        mock_span.span_id = span_id
        mock_span.attributes = {}
        mock_tracer = MockTracer(mock_span)
        mock_response_func = mock.Mock()
        mock_result = mock.Mock()
        mock_result.status = '200'
        mock_response_func.return_value = mock_result

        patch_tracer = mock.patch(
            'opencensus.ext.requests.trace.execution_context.'
            'get_opencensus_tracer',
            return_value=mock_tracer)
        patch_attr = mock.patch(
            'opencensus.ext.httplib.trace.'
            'execution_context.get_opencensus_attr',
            return_value='1111')

        wrapped = trace.wrap_httplib_response(mock_response_func)

        with patch_tracer, patch_attr:
            wrapped(mock.Mock())

        # Attribute should be empty as there is no matching span
        expected_attributes = {}

        self.assertEqual(expected_attributes, mock_tracer.span.attributes)