Esempio n. 1
0
 def test_not_recording(self):
     with mock.patch("opentelemetry.trace.INVALID_SPAN") as mock_span:
         URLLibInstrumentor().uninstrument()
         URLLibInstrumentor().instrument(
             tracer_provider=trace._DefaultTracerProvider())
         mock_span.is_recording.return_value = False
         result = self.perform_request(self.URL)
         self.assertEqual(result.read(), b"Hello!")
         self.assert_span(None, 0)
         self.assertFalse(mock_span.is_recording())
         self.assertTrue(mock_span.is_recording.called)
         self.assertFalse(mock_span.set_attribute.called)
         self.assertFalse(mock_span.set_status.called)
        def test_not_recording(self):
            with mock.patch("opentelemetry.trace.INVALID_SPAN") as mock_span:
                transport = self.create_transport(
                    tracer_provider=trace._DefaultTracerProvider())
                client = self.create_client(transport)
                mock_span.is_recording.return_value = False
                result = self.perform_request(self.URL, client=client)

                self.assertEqual(result.text, "Hello!")
                self.assert_span(None, 0)
                self.assertFalse(mock_span.is_recording())
                self.assertTrue(mock_span.is_recording.called)
                self.assertFalse(mock_span.set_attribute.called)
                self.assertFalse(mock_span.set_status.called)
 def test_default_tracer(self):
     # pylint: disable=protected-access
     tracer_provider = trace._DefaultTracerProvider()
     tracer = tracer_provider.get_tracer(__name__)
     with tracer.start_span("test") as span:
         self.assertEqual(span.get_span_context(),
                          trace.INVALID_SPAN_CONTEXT)
         self.assertEqual(span, trace.INVALID_SPAN)
         self.assertIs(span.is_recording(), False)
         with tracer.start_span("test2") as span2:
             self.assertEqual(span2.get_span_context(),
                              trace.INVALID_SPAN_CONTEXT)
             self.assertEqual(span2, trace.INVALID_SPAN)
             self.assertIs(span2.is_recording(), False)