Configure and initialise tracer
Includes config options for the tracer and sets up JaegerClient.pull/5544/head
parent
160c52d0d4
commit
5afd89a546
|
@ -278,6 +278,9 @@ def start(hs, listeners=None):
|
||||||
# Load the certificate from disk.
|
# Load the certificate from disk.
|
||||||
refresh_certificate(hs)
|
refresh_certificate(hs)
|
||||||
|
|
||||||
|
# Start the tracer
|
||||||
|
synapse.config.tracer.init_tracing(hs.config)
|
||||||
|
|
||||||
# It is now safe to start your Synapse.
|
# It is now safe to start your Synapse.
|
||||||
hs.start_listening(listeners)
|
hs.start_listening(listeners)
|
||||||
hs.get_datastore().start_profiling()
|
hs.get_datastore().start_profiling()
|
||||||
|
|
|
@ -40,6 +40,7 @@ from .spam_checker import SpamCheckerConfig
|
||||||
from .stats import StatsConfig
|
from .stats import StatsConfig
|
||||||
from .third_party_event_rules import ThirdPartyRulesConfig
|
from .third_party_event_rules import ThirdPartyRulesConfig
|
||||||
from .tls import TlsConfig
|
from .tls import TlsConfig
|
||||||
|
from .tracer import TracerConfig
|
||||||
from .user_directory import UserDirectoryConfig
|
from .user_directory import UserDirectoryConfig
|
||||||
from .voip import VoipConfig
|
from .voip import VoipConfig
|
||||||
from .workers import WorkerConfig
|
from .workers import WorkerConfig
|
||||||
|
@ -75,5 +76,6 @@ class HomeServerConfig(
|
||||||
ServerNoticesConfig,
|
ServerNoticesConfig,
|
||||||
RoomDirectoryConfig,
|
RoomDirectoryConfig,
|
||||||
ThirdPartyRulesConfig,
|
ThirdPartyRulesConfig,
|
||||||
|
TracerConfig,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright 2018 New Vector Ltd
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
from ._base import Config
|
||||||
|
from jaeger_client import Config as JaegerConfig
|
||||||
|
from synapse.util.scopecontextmanager import LogContextScopeManager
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class TracerConfig(Config):
|
||||||
|
def read_config(self, config):
|
||||||
|
self.tracer_config = config.get("tracer")
|
||||||
|
|
||||||
|
if self.tracer_config is None:
|
||||||
|
# If the tracer is not configured we assume it is disabled
|
||||||
|
self.tracer_config = {
|
||||||
|
"tracer_enabled": False,
|
||||||
|
}
|
||||||
|
|
||||||
|
if not self.tracer_config.get("tracer_enabled", False):
|
||||||
|
# The tracer is enabled so sanitize the config
|
||||||
|
# If no whitelists are given
|
||||||
|
self.tracer_config.setdefault("user_whitelist", ["*"])
|
||||||
|
self.tracer_config.setdefault("homeserver_whitelist", ["*"])
|
||||||
|
|
||||||
|
if type(self.tracer_config.get("user_whitelist")) != list:
|
||||||
|
raise RuntimeError("Tracer user_whitelist config is malformed")
|
||||||
|
if type(self.tracer_config.get("homeserver_whitelist")) != list:
|
||||||
|
raise RuntimeError("Tracer homesererver_whitelist config is malformed")
|
||||||
|
|
||||||
|
def default_config(self, **kwargs):
|
||||||
|
return """\
|
||||||
|
## Tracert ##
|
||||||
|
|
||||||
|
tracer:
|
||||||
|
# The list of users who's requests will be traced
|
||||||
|
# The list is a list of regex which is matched against the user_id
|
||||||
|
user_whitelist:
|
||||||
|
- "*"
|
||||||
|
# The list of homeservers we wish to trace across
|
||||||
|
# The list is a list of regex which is matched against the homeserver name
|
||||||
|
homeserver_whitelist:
|
||||||
|
- "*"
|
||||||
|
"""
|
||||||
|
|
||||||
|
def init_tracing(config):
|
||||||
|
"""Initialise the JaegerClient tracer
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config (Config)
|
||||||
|
The config used by the homserver. Here it's used to set the service
|
||||||
|
name to the homeserver's.
|
||||||
|
"""
|
||||||
|
|
||||||
|
jaeger_config = JaegerConfig(
|
||||||
|
config={
|
||||||
|
'sampler': {
|
||||||
|
'type': 'const',
|
||||||
|
'param': 1,
|
||||||
|
},
|
||||||
|
'logging': True,
|
||||||
|
},
|
||||||
|
service_name=config.server_name + "_new",
|
||||||
|
scope_manager=LogContextScopeManager(config),
|
||||||
|
)
|
||||||
|
|
||||||
|
return jaeger_config.initialize_tracer()
|
Loading…
Reference in New Issue