Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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)
     )
Exemplo n.º 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)
Exemplo n.º 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)
     )
Exemplo n.º 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)
     )
Exemplo n.º 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)
     )
Exemplo n.º 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)
     )
Exemplo n.º 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)
     )
Exemplo n.º 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)
     )
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 17
0
 def test_logging_recorder_setup(self):
     client = make_client("test-service")
     baseplate_observer = TraceBaseplateObserver(client)
     self.assertEqual(type(baseplate_observer.recorder), LoggingRecorder)
Exemplo n.º 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))
Exemplo n.º 19
0
 def test_null_recorder_setup(self):
     baseplate_observer = TraceBaseplateObserver(
         'test-service',
         log_if_unconfigured=False,
     )
     self.assertEqual(type(baseplate_observer.recorder), NullRecorder)
Exemplo n.º 20
0
 def test_sets_hostname(self):
     baseplate_observer = TraceBaseplateObserver('test-service')
     self.assertIsNotNone(baseplate_observer.hostname)
Exemplo n.º 21
0
 def test_null_recorder_setup(self):
     baseplate_observer = TraceBaseplateObserver('test-service')
     self.assertEqual(type(baseplate_observer.recorder), NullRecorder)
Exemplo n.º 22
0
 def test_logging_recorder_setup(self):
     baseplate_observer = TraceBaseplateObserver('test-service')
     self.assertEqual(type(baseplate_observer.recorder), LoggingRecorder)
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 25
0
 def test_sets_hostname(self):
     client = make_client("test-service")
     baseplate_observer = TraceBaseplateObserver(client)
     self.assertIsNotNone(baseplate_observer.hostname)
Exemplo n.º 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))