You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 regels
2.3 KiB

  1. # Copyright 2019 The Matrix.org Foundation C.I.C.d
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import Any, List, Set
  15. from synapse.types import JsonDict
  16. from synapse.util.check_dependencies import check_requirements
  17. from ._base import Config, ConfigError
  18. class TracerConfig(Config):
  19. section = "tracing"
  20. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  21. opentracing_config = config.get("opentracing")
  22. if opentracing_config is None:
  23. opentracing_config = {}
  24. self.opentracer_enabled = opentracing_config.get("enabled", False)
  25. self.jaeger_config = opentracing_config.get(
  26. "jaeger_config",
  27. {"sampler": {"type": "const", "param": 1}, "logging": False},
  28. )
  29. self.force_tracing_for_users: Set[str] = set()
  30. if not self.opentracer_enabled:
  31. return
  32. check_requirements("opentracing")
  33. # The tracer is enabled so sanitize the config
  34. self.opentracer_whitelist: List[str] = opentracing_config.get(
  35. "homeserver_whitelist", []
  36. )
  37. if not isinstance(self.opentracer_whitelist, list):
  38. raise ConfigError("Tracer homeserver_whitelist config is malformed")
  39. force_tracing_for_users = opentracing_config.get("force_tracing_for_users", [])
  40. if not isinstance(force_tracing_for_users, list):
  41. raise ConfigError(
  42. "Expected a list", ("opentracing", "force_tracing_for_users")
  43. )
  44. for i, u in enumerate(force_tracing_for_users):
  45. if not isinstance(u, str):
  46. raise ConfigError(
  47. "Expected a string",
  48. ("opentracing", "force_tracing_for_users", f"index {i}"),
  49. )
  50. self.force_tracing_for_users.add(u)