opentracing.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ===========
  2. OpenTracing
  3. ===========
  4. Background
  5. ----------
  6. OpenTracing is a semi-standard being adopted by a number of distributed tracing
  7. platforms. It is a common api for facilitating vendor-agnostic tracing
  8. instrumentation. That is, we can use the OpenTracing api and select one of a
  9. number of tracer implementations to do the heavy lifting in the background.
  10. Our current selected implementation is Jaeger.
  11. OpenTracing is a tool which gives an insight into the causal relationship of
  12. work done in and between servers. The servers each track events and report them
  13. to a centralised server - in Synapse's case: Jaeger. The basic unit used to
  14. represent events is the span. The span roughly represents a single piece of work
  15. that was done and the time at which it occurred. A span can have child spans,
  16. meaning that the work of the child had to be completed for the parent span to
  17. complete, or it can have follow-on spans which represent work that is undertaken
  18. as a result of the parent but is not depended on by the parent to in order to
  19. finish.
  20. Since this is undertaken in a distributed environment a request to another
  21. server, such as an RPC or a simple GET, can be considered a span (a unit or
  22. work) for the local server. This causal link is what OpenTracing aims to
  23. capture and visualise. In order to do this metadata about the local server's
  24. span, i.e the 'span context', needs to be included with the request to the
  25. remote.
  26. It is up to the remote server to decide what it does with the spans
  27. it creates. This is called the sampling policy and it can be configured
  28. through Jaeger's settings.
  29. For OpenTracing concepts see
  30. https://opentracing.io/docs/overview/what-is-tracing/.
  31. For more information about Jaeger's implementation see
  32. https://www.jaegertracing.io/docs/
  33. =====================
  34. Seting up OpenTracing
  35. =====================
  36. To receive OpenTracing spans, start up a Jaeger server. This can be done
  37. using docker like so:
  38. .. code-block:: bash
  39. docker run -d --name jaeger
  40. -p 6831:6831/udp \
  41. -p 6832:6832/udp \
  42. -p 5778:5778 \
  43. -p 16686:16686 \
  44. -p 14268:14268 \
  45. jaegertracing/all-in-one:1.13
  46. Latest documentation is probably at
  47. https://www.jaegertracing.io/docs/1.13/getting-started/
  48. Enable OpenTracing in Synapse
  49. -----------------------------
  50. OpenTracing is not enabled by default. It must be enabled in the homeserver
  51. config by uncommenting the config options under ``opentracing`` as shown in
  52. the `sample config <./sample_config.yaml>`_. For example:
  53. .. code-block:: yaml
  54. opentracing:
  55. tracer_enabled: true
  56. homeserver_whitelist:
  57. - "mytrustedhomeserver.org"
  58. - "*.myotherhomeservers.com"
  59. Homeserver whitelisting
  60. -----------------------
  61. The homeserver whitelist is configured using regular expressions. A list of regular
  62. expressions can be given and their union will be compared when propagating any
  63. spans contexts to another homeserver.
  64. Though it's mostly safe to send and receive span contexts to and from
  65. untrusted users since span contexts are usually opaque ids it can lead to
  66. two problems, namely:
  67. - If the span context is marked as sampled by the sending homeserver the receiver will
  68. sample it. Therefore two homeservers with wildly different sampling policies
  69. could incur higher sampling counts than intended.
  70. - Sending servers can attach arbitrary data to spans, known as 'baggage'. For safety this has been disabled in Synapse
  71. but that doesn't prevent another server sending you baggage which will be logged
  72. to OpenTracing's logs.
  73. ==========
  74. EDU FORMAT
  75. ==========
  76. EDUs can contain tracing data in their content. This is not specced but
  77. it could be of interest for other homeservers.
  78. EDU format (if you're using jaeger):
  79. .. code-block:: json
  80. {
  81. "edu_type": "type",
  82. "content": {
  83. "org.matrix.opentracing_context": {
  84. "uber-trace-id": "fe57cf3e65083289"
  85. }
  86. }
  87. }
  88. Though you don't have to use jaeger you must inject the span context into
  89. `org.matrix.opentracing_context` using the opentracing `Format.TEXT_MAP` inject method.
  90. ==================
  91. Configuring Jaeger
  92. ==================
  93. Sampling strategies can be set as in this document:
  94. https://www.jaegertracing.io/docs/1.13/sampling/