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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # OpenTracing
  2. ## Background
  3. OpenTracing is a semi-standard being adopted by a number of distributed
  4. tracing platforms. It is a common api for facilitating vendor-agnostic
  5. tracing instrumentation. That is, we can use the OpenTracing api and
  6. select one of a number of tracer implementations to do the heavy lifting
  7. in the background. Our current selected implementation is Jaeger.
  8. OpenTracing is a tool which gives an insight into the causal
  9. relationship of work done in and between servers. The servers each track
  10. events and report them to a centralised server - in Synapse's case:
  11. Jaeger. The basic unit used to represent events is the span. The span
  12. roughly represents a single piece of work that was done and the time at
  13. which it occurred. A span can have child spans, meaning that the work of
  14. the child had to be completed for the parent span to complete, or it can
  15. have follow-on spans which represent work that is undertaken as a result
  16. of the parent but is not depended on by the parent to in order to
  17. finish.
  18. Since this is undertaken in a distributed environment a request to
  19. another server, such as an RPC or a simple GET, can be considered a span
  20. (a unit or work) for the local server. This causal link is what
  21. OpenTracing aims to capture and visualise. In order to do this metadata
  22. about the local server's span, i.e the 'span context', needs to be
  23. included with the request to the remote.
  24. It is up to the remote server to decide what it does with the spans it
  25. creates. This is called the sampling policy and it can be configured
  26. through Jaeger's settings.
  27. For OpenTracing concepts see
  28. <https://opentracing.io/docs/overview/what-is-tracing/>.
  29. For more information about Jaeger's implementation see
  30. <https://www.jaegertracing.io/docs/>
  31. ## Setting up OpenTracing
  32. To receive OpenTracing spans, start up a Jaeger server. This can be done
  33. using docker like so:
  34. ```sh
  35. docker run -d --name jaeger \
  36. -p 6831:6831/udp \
  37. -p 6832:6832/udp \
  38. -p 5778:5778 \
  39. -p 16686:16686 \
  40. -p 14268:14268 \
  41. jaegertracing/all-in-one:1
  42. ```
  43. By default, Synapse will publish traces to Jaeger on localhost.
  44. If Jaeger is hosted elsewhere, point Synapse to the correct host by setting
  45. `opentracing.jaeger_config.local_agent.reporting_host` [in the Synapse configuration](usage/configuration/config_documentation.md#opentracing-1)
  46. or by setting the `JAEGER_AGENT_HOST` environment variable to the desired address.
  47. Latest documentation is probably at
  48. https://www.jaegertracing.io/docs/latest/getting-started.
  49. ## Enable OpenTracing in Synapse
  50. OpenTracing is not enabled by default. It must be enabled in the
  51. homeserver config by adding the `opentracing` option to your config file. You can find
  52. documentation about how to do this in the [config manual under the header 'Opentracing'](usage/configuration/config_documentation.md#opentracing).
  53. See below for an example Opentracing configuration:
  54. ```yaml
  55. opentracing:
  56. enabled: true
  57. homeserver_whitelist:
  58. - "mytrustedhomeserver.org"
  59. - "*.myotherhomeservers.com"
  60. ```
  61. ## Homeserver whitelisting
  62. The homeserver whitelist is configured using regular expressions. A list
  63. of regular expressions can be given and their union will be compared
  64. when propagating any spans contexts to another homeserver.
  65. Though it's mostly safe to send and receive span contexts to and from
  66. untrusted users since span contexts are usually opaque ids it can lead
  67. to two problems, namely:
  68. - If the span context is marked as sampled by the sending homeserver
  69. the receiver will sample it. Therefore two homeservers with wildly
  70. different sampling policies could incur higher sampling counts than
  71. intended.
  72. - Sending servers can attach arbitrary data to spans, known as
  73. 'baggage'. For safety this has been disabled in Synapse but that
  74. doesn't prevent another server sending you baggage which will be
  75. logged to OpenTracing's logs.
  76. ## Configuring Jaeger
  77. Sampling strategies can be set as in this document:
  78. <https://www.jaegertracing.io/docs/latest/sampling/>.