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.
 
 
 
 
 
 

92 lines
3.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 synapse.python_dependencies import DependencyException, check_requirements
  15. from ._base import Config, ConfigError
  16. class TracerConfig(Config):
  17. section = "tracing"
  18. def read_config(self, config, **kwargs):
  19. opentracing_config = config.get("opentracing")
  20. if opentracing_config is None:
  21. opentracing_config = {}
  22. self.opentracer_enabled = opentracing_config.get("enabled", False)
  23. self.jaeger_config = opentracing_config.get(
  24. "jaeger_config",
  25. {"sampler": {"type": "const", "param": 1}, "logging": False},
  26. )
  27. if not self.opentracer_enabled:
  28. return
  29. try:
  30. check_requirements("opentracing")
  31. except DependencyException as e:
  32. raise ConfigError(
  33. e.message # noqa: B306, DependencyException.message is a property
  34. )
  35. # The tracer is enabled so sanitize the config
  36. self.opentracer_whitelist = opentracing_config.get("homeserver_whitelist", [])
  37. if not isinstance(self.opentracer_whitelist, list):
  38. raise ConfigError("Tracer homeserver_whitelist config is malformed")
  39. def generate_config_section(cls, **kwargs):
  40. return """\
  41. ## Opentracing ##
  42. # These settings enable opentracing, which implements distributed tracing.
  43. # This allows you to observe the causal chains of events across servers
  44. # including requests, key lookups etc., across any server running
  45. # synapse or any other other services which supports opentracing
  46. # (specifically those implemented with Jaeger).
  47. #
  48. opentracing:
  49. # tracing is disabled by default. Uncomment the following line to enable it.
  50. #
  51. #enabled: true
  52. # The list of homeservers we wish to send and receive span contexts and span baggage.
  53. # See docs/opentracing.rst
  54. # This is a list of regexes which are matched against the server_name of the
  55. # homeserver.
  56. #
  57. # By default, it is empty, so no servers are matched.
  58. #
  59. #homeserver_whitelist:
  60. # - ".*"
  61. # Jaeger can be configured to sample traces at different rates.
  62. # All configuration options provided by Jaeger can be set here.
  63. # Jaeger's configuration mostly related to trace sampling which
  64. # is documented here:
  65. # https://www.jaegertracing.io/docs/1.13/sampling/.
  66. #
  67. #jaeger_config:
  68. # sampler:
  69. # type: const
  70. # param: 1
  71. # Logging whether spans were started and reported
  72. #
  73. # logging:
  74. # false
  75. """