Beispiel #1
0
    def test_sample_rate_fallback(self):
        client = tracing_client_from_config({
            "tracing.service_name": "example_name",
            "tracing.sample_rate": "30%",
        })
        self.assertAlmostEqual(client.sample_rate, .3)

        client = tracing_client_from_config({
            "tracing.service_name": "example_name",
            "tracing.sample_rate": ".4",
        })
        self.assertAlmostEqual(client.sample_rate, .4)
Beispiel #2
0
    def test_most_simple_config_without_logging(self):
        client = tracing_client_from_config(
            {"tracing.service_name": "example_name"},
            log_if_unconfigured=False)

        self.assertEqual(client.service_name, "example_name")
        self.assertIsInstance(client.recorder, NullRecorder)
Beispiel #3
0
    def test_most_simple_config(self):
        client = tracing_client_from_config({
            "tracing.service_name":
            "example_name",
        })

        self.assertEqual(client.service_name, "example_name")
        self.assertIsInstance(client.recorder, LoggingRecorder)
def make_processor(app_config):  # pragma: nocover
    cfg = config.parse_config(app_config, {
        "activity": {
            "window": config.Timespan,
        },
        "tracing": {
            "endpoint": config.Optional(config.Endpoint),
            "service_name": config.String,
        },
        "redis": {
            "url": config.String,
            "max_connections": config.Optional(config.Integer, default=100),
        },
    })

    metrics_client = metrics_client_from_config(app_config)
    tracing_client = tracing_client_from_config(app_config)
    error_reporter = error_reporter_from_config(app_config, __name__)
    redis_pool = redis.BlockingConnectionPool.from_url(
        cfg.redis.url,
        max_connections=cfg.redis.max_connections,
        timeout=0.1,
    )

    baseplate = Baseplate()
    baseplate.configure_logging()
    baseplate.configure_metrics(metrics_client)
    baseplate.configure_tracing(tracing_client)
    baseplate.configure_error_reporting(error_reporter)
    baseplate.add_to_context("redis", RedisContextFactory(redis_pool))

    counter = ActivityCounter(cfg.activity.window.total_seconds())
    handler = Handler(counter=counter)
    processor = ActivityService.ContextProcessor(handler)
    event_handler = BaseplateProcessorEventHandler(logger, baseplate)
    processor.setEventHandler(event_handler)

    return processor
Beispiel #5
0
 def test_not_configured_at_all(self):
     with self.assertRaises(ConfigurationError):
         tracing_client_from_config({})