def init_tracer(hs: "HomeServer"): """Set the whitelists and initialise the JaegerClient tracer""" global opentracing if not hs.config.opentracer_enabled: # We don't have a tracer opentracing = None return if not opentracing or not JaegerConfig: raise ConfigError( "The server has been configured to use opentracing but opentracing is not " "installed.") # Pull out the jaeger config if it was given. Otherwise set it to something sensible. # See https://github.com/jaegertracing/jaeger-client-python/blob/master/jaeger_client/config.py set_homeserver_whitelist(hs.config.opentracer_whitelist) from jaeger_client.metrics.prometheus import PrometheusMetricsFactory config = JaegerConfig( config=hs.config.jaeger_config, service_name=f"{hs.config.server_name} {hs.get_instance_name()}", scope_manager=LogContextScopeManager(hs.config), metrics_factory=PrometheusMetricsFactory(), ) # If we have the rust jaeger reporter available let's use that. if RustReporter: logger.info("Using rust_python_jaeger_reporter library") tracer = config.create_tracer(RustReporter(), config.sampler) opentracing.set_global_tracer(tracer) else: config.initialize_tracer()
def init_tracer(config): """Set the whitelists and initialise the JaegerClient tracer Args: config (HomeserverConfig): The config used by the homeserver """ global opentracing if not config.opentracer_enabled: # We don't have a tracer opentracing = None return if not opentracing or not JaegerConfig: raise ConfigError( "The server has been configured to use opentracing but opentracing is not " "installed.") # Include the worker name name = config.worker_name if config.worker_name else "master" # Pull out the jaeger config if it was given. Otherwise set it to something sensible. # See https://github.com/jaegertracing/jaeger-client-python/blob/master/jaeger_client/config.py set_homeserver_whitelist(config.opentracer_whitelist) JaegerConfig( config=config.jaeger_config, service_name="{} {}".format(config.server_name, name), scope_manager=LogContextScopeManager(config), ).initialize_tracer()
def setUp(self) -> None: # since this is a unit test, we don't really want to mess around with the # global variables that power opentracing. We create our own tracer instance # and test with it. scope_manager = LogContextScopeManager({}) config = jaeger_client.config.Config( config={}, service_name="test", scope_manager=scope_manager ) self._reporter = jaeger_client.reporter.InMemoryReporter() self._tracer = config.create_tracer( sampler=jaeger_client.ConstSampler(True), reporter=self._reporter, )
def init_tracer(config): """Set the whitelists and initialise the JaegerClient tracer Args: config (HomeserverConfig): The config used by the homeserver """ global opentracing if not config.opentracer_enabled: # We don't have a tracer opentracing = None return if not opentracing or not JaegerConfig: raise ConfigError( "The server has been configured to use opentracing but opentracing is not " "installed.") # Include the worker name name = config.worker_name if config.worker_name else "master" set_homeserver_whitelist(config.opentracer_whitelist) jaeger_config = JaegerConfig( config={ "sampler": { "type": "const", "param": 1 }, "logging": True }, service_name="{} {}".format(config.server_name, name), scope_manager=LogContextScopeManager(config), ) jaeger_config.initialize_tracer() # Set up tags to be opentracing's tags global tags tags = opentracing.tags