tracer.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.d
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from synapse.python_dependencies import DependencyException, check_requirements
  16. from ._base import Config, ConfigError
  17. class TracerConfig(Config):
  18. section = "tracing"
  19. def read_config(self, config, **kwargs):
  20. opentracing_config = config.get("opentracing")
  21. if opentracing_config is None:
  22. opentracing_config = {}
  23. self.opentracer_enabled = opentracing_config.get("enabled", False)
  24. self.jaeger_config = opentracing_config.get(
  25. "jaeger_config",
  26. {"sampler": {"type": "const", "param": 1}, "logging": False},
  27. )
  28. if not self.opentracer_enabled:
  29. return
  30. try:
  31. check_requirements("opentracing")
  32. except DependencyException as e:
  33. raise ConfigError(e.message)
  34. # The tracer is enabled so sanitize the config
  35. self.opentracer_whitelist = opentracing_config.get("homeserver_whitelist", [])
  36. if not isinstance(self.opentracer_whitelist, list):
  37. raise ConfigError("Tracer homeserver_whitelist config is malformed")
  38. def generate_config_section(cls, **kwargs):
  39. return """\
  40. ## Opentracing ##
  41. # These settings enable opentracing, which implements distributed tracing.
  42. # This allows you to observe the causal chains of events across servers
  43. # including requests, key lookups etc., across any server running
  44. # synapse or any other other services which supports opentracing
  45. # (specifically those implemented with Jaeger).
  46. #
  47. opentracing:
  48. # tracing is disabled by default. Uncomment the following line to enable it.
  49. #
  50. #enabled: true
  51. # The list of homeservers we wish to send and receive span contexts and span baggage.
  52. # See docs/opentracing.rst
  53. # This is a list of regexes which are matched against the server_name of the
  54. # homeserver.
  55. #
  56. # By defult, it is empty, so no servers are matched.
  57. #
  58. #homeserver_whitelist:
  59. # - ".*"
  60. # Jaeger can be configured to sample traces at different rates.
  61. # All configuration options provided by Jaeger can be set here.
  62. # Jaeger's configuration mostly related to trace sampling which
  63. # is documented here:
  64. # https://www.jaegertracing.io/docs/1.13/sampling/.
  65. #
  66. #jaeger_config:
  67. # sampler:
  68. # type: const
  69. # param: 1
  70. # Logging whether spans were started and reported
  71. #
  72. # logging:
  73. # false
  74. """