25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

70 lines
2.5 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 DependencyException, 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. try:
  33. check_requirements("opentracing")
  34. except DependencyException as e:
  35. raise ConfigError(
  36. e.message # noqa: B306, DependencyException.message is a property
  37. )
  38. # The tracer is enabled so sanitize the config
  39. self.opentracer_whitelist: List[str] = opentracing_config.get(
  40. "homeserver_whitelist", []
  41. )
  42. if not isinstance(self.opentracer_whitelist, list):
  43. raise ConfigError("Tracer homeserver_whitelist config is malformed")
  44. force_tracing_for_users = opentracing_config.get("force_tracing_for_users", [])
  45. if not isinstance(force_tracing_for_users, list):
  46. raise ConfigError(
  47. "Expected a list", ("opentracing", "force_tracing_for_users")
  48. )
  49. for i, u in enumerate(force_tracing_for_users):
  50. if not isinstance(u, str):
  51. raise ConfigError(
  52. "Expected a string",
  53. ("opentracing", "force_tracing_for_users", f"index {i}"),
  54. )
  55. self.force_tracing_for_users.add(u)