예제 #1
0
 def test_register_server_span_observer(self):
     baseplate_observer = TraceBaseplateObserver("test-service")
     context_mock = mock.Mock()
     span = ServerSpan("test-id", "test-parent-id", "test-span-id", True, 0, "test")
     baseplate_observer.on_server_span_created(context_mock, span)
     self.assertEqual(len(span.observers), 1)
     self.assertEqual(type(span.observers[0]), TraceServerSpanObserver)
예제 #2
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)
예제 #3
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)
예제 #4
0
 def test_should_sample_utilizes_sample_rate(self):
     client = make_client("test-service", sample_rate=1)
     baseplate_observer = TraceBaseplateObserver(client)
     span = Span('test-id',
                 'test-parent',
                 'test-span-id',
                 None,
                 0,
                 "test",
                 self.mock_context)
     self.assertTrue(baseplate_observer.should_sample(span))
     baseplate_observer.sample_rate = 0
     self.assertFalse(baseplate_observer.should_sample(span))
예제 #5
0
 def test_should_sample_utilizes_sampled_setting(self):
     client = make_client("test-service", sample_rate=0)
     baseplate_observer = TraceBaseplateObserver(client)
     span_with_sampled_flag = Span('test-id',
                                   'test-parent',
                                   'test-span-id',
                                   True,
                                   0,
                                   "test",
                                   self.mock_context)
     self.assertTrue(
         baseplate_observer.should_sample(span_with_sampled_flag)
     )
예제 #6
0
    def setUp(self):
        thread_patch = mock.patch("threading.Thread", autospec=True)
        thread_patch.start()
        self.addCleanup(thread_patch.stop)
        configurator = Configurator()
        configurator.add_route("example", "/example", request_method="GET")
        configurator.add_view(example_application,
                              route_name="example",
                              renderer="json")

        configurator.add_route("local_test",
                               "/local_test",
                               request_method="GET")
        configurator.add_view(local_parent_trace_within_context,
                              route_name="local_test",
                              renderer="json")

        self.client = make_client("test-service")
        self.observer = TraceBaseplateObserver(self.client)

        self.baseplate = Baseplate()
        self.baseplate.register(self.observer)

        self.baseplate_configurator = BaseplateConfigurator(
            self.baseplate, trust_trace_headers=True)
        configurator.include(self.baseplate_configurator.includeme)
        app = configurator.make_wsgi_app()
        self.local_span_ids = []
        self.local_span_observers = []
        self.test_app = webtest.TestApp(app)
예제 #7
0
 def test_remote_recorder_setup(self):
     client = make_client(
         "test-service", tracing_endpoint=Endpoint("test:1111"))
     baseplate_observer = TraceBaseplateObserver(client)
     self.assertTrue(
         isinstance(baseplate_observer.recorder,
                    RemoteRecorder)
     )
예제 #8
0
 def test_remote_recorder_setup(self):
     baseplate_observer = TraceBaseplateObserver(
         'test-service',
         tracing_endpoint=Endpoint("test:1111"),
     )
     self.assertTrue(
         isinstance(baseplate_observer.recorder,
                    RemoteRecorder)
     )
예제 #9
0
 def test_force_sampling(self):
     span_with_debug_flag = Span('test-id',
                                 'test-parent',
                                 'test-span-id',
                                 True,
                                 1,
                                 "test",
                                 self.mock_context)
     span_without_debug_flag = Span('test-id',
                                    'test-parent',
                                    'test-span-id',
                                    True,
                                    0,
                                    "test",
                                    self.mock_context)
     self.assertTrue(
         TraceBaseplateObserver.force_sampling(span_with_debug_flag)
     )
     self.assertFalse(
         TraceBaseplateObserver.force_sampling(span_without_debug_flag)
     )
예제 #10
0
 def test_force_sampling(self):
     span_with_debug_flag = Span('test-id',
                                 'test-parent',
                                 'test-span-id',
                                 True,
                                 1,
                                 "test",
                                 self.mock_context)
     span_without_debug_flag = Span('test-id',
                                    'test-parent',
                                    'test-span-id',
                                    True,
                                    0,
                                    "test",
                                    self.mock_context)
     self.assertTrue(
         TraceBaseplateObserver.force_sampling(span_with_debug_flag)
     )
     self.assertFalse(
         TraceBaseplateObserver.force_sampling(span_without_debug_flag)
     )
예제 #11
0
 def test_should_sample_utilizes_force_sampling(self):
     client = make_client("test-service", sample_rate=0)
     baseplate_observer = TraceBaseplateObserver(client)
     span_with_forced = Span('test-id',
                             'test-parent',
                             'test-span-id',
                             False,
                             1,
                             "test",
                             self.mock_context)
     span_without_forced = Span('test-id',
                                'test-parent',
                                'test-span-id',
                                False,
                                0,
                                "test",
                                self.mock_context)
     self.assertTrue(
         baseplate_observer.should_sample(span_with_forced)
     )
     self.assertFalse(
         baseplate_observer.should_sample(span_without_forced)
     )
예제 #12
0
 def test_should_sample_utilizes_force_sampling(self):
     client = make_client("test-service", sample_rate=0)
     baseplate_observer = TraceBaseplateObserver(client)
     span_with_forced = Span('test-id',
                             'test-parent',
                             'test-span-id',
                             False,
                             1,
                             "test",
                             self.mock_context)
     span_without_forced = Span('test-id',
                                'test-parent',
                                'test-span-id',
                                False,
                                0,
                                "test",
                                self.mock_context)
     self.assertTrue(
         baseplate_observer.should_sample(span_with_forced)
     )
     self.assertFalse(
         baseplate_observer.should_sample(span_without_forced)
     )
예제 #13
0
    def setUp(self):
        configurator = Configurator()
        configurator.add_route("example", "/example", request_method="GET")
        configurator.add_view(example_application,
                              route_name="example",
                              renderer="json")

        self.observer = TraceBaseplateObserver('test-service')

        self.baseplate = Baseplate()
        self.baseplate.register(self.observer)

        self.baseplate_configurator = BaseplateConfigurator(
            self.baseplate,
            trust_trace_headers=True,
        )
        configurator.include(self.baseplate_configurator.includeme)
        app = configurator.make_wsgi_app()
        self.test_app = webtest.TestApp(app)
예제 #14
0
    def configure_tracing(self, tracing_client, *args, **kwargs):
        """Collect and send span information for request tracing.

        When configured, this will send tracing information automatically
        collected by Baseplate to the configured distributed tracing service.

        :param baseplate.diagnostics.tracing.TracingClient tracing_client: Tracing
            client to send request traces to.

        """
        # pylint: disable=cyclic-import
        from baseplate.diagnostics.tracing import make_client, TraceBaseplateObserver, TracingClient

        # the first parameter was service_name before, so if it's not a client
        # object we'll act like this is the old-style invocation and use the
        # first parameter as service_name instead, passing on the old arguments
        if not isinstance(tracing_client, TracingClient):
            warn_deprecated("Passing tracing configuration directly to "
                            "configure_tracing is deprecated in favor of "
                            "using baseplate.tracing_client_from_config and "
                            "passing the constructed client on.")
            tracing_client = make_client(tracing_client, *args, **kwargs)

        self.register(TraceBaseplateObserver(tracing_client))
예제 #15
0
 def test_no_tracing_without_sampling(self):
     baseplate_observer = TraceBaseplateObserver("test-service", sample_rate=0)
     context_mock = mock.Mock()
     span = ServerSpan("test-id", "test-parent-id", "test-span-id", False, 0, "test")
     baseplate_observer.on_server_span_created(context_mock, span)
     self.assertEqual(len(span.observers), 0)
예제 #16
0
 def test_should_sample_utilizes_sample_rate(self):
     baseplate_observer = TraceBaseplateObserver("test-service", sample_rate=1)
     span = Span("test-id", "test-parent", "test-span-id", None, 0, "test")
     self.assertTrue(baseplate_observer.should_sample(span))
     baseplate_observer.sample_rate = 0
     self.assertFalse(baseplate_observer.should_sample(span))
예제 #17
0
 def test_logging_recorder_setup(self):
     client = make_client("test-service")
     baseplate_observer = TraceBaseplateObserver(client)
     self.assertEqual(type(baseplate_observer.recorder), LoggingRecorder)
예제 #18
0
 def test_force_sampling(self):
     span_with_debug_flag = Span("test-id", "test-parent", "test-span-id", True, 1, "test")
     span_without_debug_flag = Span("test-id", "test-parent", "test-span-id", True, 0, "test")
     self.assertTrue(TraceBaseplateObserver.force_sampling(span_with_debug_flag))
     self.assertFalse(TraceBaseplateObserver.force_sampling(span_without_debug_flag))
예제 #19
0
 def test_null_recorder_setup(self):
     baseplate_observer = TraceBaseplateObserver(
         'test-service',
         log_if_unconfigured=False,
     )
     self.assertEqual(type(baseplate_observer.recorder), NullRecorder)
예제 #20
0
 def test_sets_hostname(self):
     baseplate_observer = TraceBaseplateObserver('test-service')
     self.assertIsNotNone(baseplate_observer.hostname)
예제 #21
0
 def test_null_recorder_setup(self):
     baseplate_observer = TraceBaseplateObserver('test-service')
     self.assertEqual(type(baseplate_observer.recorder), NullRecorder)
예제 #22
0
 def test_logging_recorder_setup(self):
     baseplate_observer = TraceBaseplateObserver('test-service')
     self.assertEqual(type(baseplate_observer.recorder), LoggingRecorder)
예제 #23
0
 def test_null_recorder_setup(self):
     client = make_client("test-service", log_if_unconfigured=False)
     baseplate_observer = TraceBaseplateObserver(client)
     self.assertEqual(type(baseplate_observer.recorder), NullRecorder)
예제 #24
0
 def test_should_sample_utilizes_sampled_setting(self):
     baseplate_observer = TraceBaseplateObserver("test-service", sample_rate=0)
     span_with_sampled_flag = Span("test-id", "test-parent", "test-span-id", True, 0, "test")
     self.assertTrue(baseplate_observer.should_sample(span_with_sampled_flag))
예제 #25
0
 def test_sets_hostname(self):
     client = make_client("test-service")
     baseplate_observer = TraceBaseplateObserver(client)
     self.assertIsNotNone(baseplate_observer.hostname)
예제 #26
0
 def test_should_sample_utilizes_force_sampling(self):
     baseplate_observer = TraceBaseplateObserver("test-service", sample_rate=0)
     span_with_forced = Span("test-id", "test-parent", "test-span-id", False, 1, "test")
     span_without_forced = Span("test-id", "test-parent", "test-span-id", False, 0, "test")
     self.assertTrue(baseplate_observer.should_sample(span_with_forced))
     self.assertFalse(baseplate_observer.should_sample(span_without_forced))