|
| 1 | ++++ |
| 2 | +title = "Tracing" |
| 3 | ++++ |
| 4 | + |
| 5 | +Tracing is a powerful tool for observing system behavior across multiple components, making it especially |
| 6 | +useful for debugging and performance analysis in complex environments. |
| 7 | + |
| 8 | +By integrating OpenTelemetry (a standard that unifies OpenTracing and OpenCensus) and the Zipkin v2 protocol, |
| 9 | +XAPI enables efficient tracking and visualization of operations across internal and external systems. |
| 10 | +This facilitates detailed analysis and improves collaboration between teams. |
| 11 | + |
| 12 | +Tracing is commonly used in high-level applications such as web services. As a result, less widely-used or |
| 13 | +non-web-oriented languages may lack dedicated libraries for distributed tracing (An OCaml implementation |
| 14 | +has been developed specifically for XenAPI). |
| 15 | + |
| 16 | +# How tracing works in XAPI |
| 17 | + |
| 18 | +## Spans and Trace Context |
| 19 | + |
| 20 | +- A *span* is the core unit of a trace, representing a single operation with a defined start and end time. |
| 21 | + Spans can contain sub-spans that represent child tasks. This helps identify bottlenecks or areas that |
| 22 | + can be parallelized. |
| 23 | + - A span can contain several contextual elements such as *tags* (key-value pairs), |
| 24 | + *events* (time-based data), and *errors*. |
| 25 | +- The *TraceContext* HTTP standard defines how trace IDs and span contexts are propagated across systems, |
| 26 | + enabling full traceability of operations. |
| 27 | + |
| 28 | +This data enables the creation of relationships between tasks and supports visualizations such as |
| 29 | +architecture diagrams or execution flows. These help in identifying root causes of issues and bottlenecks, |
| 30 | +and also assist newcomers in onboarding to the project. |
| 31 | + |
| 32 | +## Configuration |
| 33 | + |
| 34 | +- To enable tracing, you need to create an *Observer* object in XAPI. This can be done using the *xe* CLI: |
| 35 | + ```sh |
| 36 | + xe observer-create \ |
| 37 | + name-label=<name> \ |
| 38 | + enabled=true \ |
| 39 | + components=xapi,xenopsd \ |
| 40 | + ``` |
| 41 | +- By default, if you don't specify `enabled=true`, the observer will be disabled. |
| 42 | +- To add an HTTP endpoint, make sure the server is up and running, then run: |
| 43 | + ```sh |
| 44 | + xe observer-param-set uuid=<OBSERVER_UUID> endpoints=bugtool,http://<jaeger-ip>:9411/api/v2/spans |
| 45 | + ``` |
| 46 | + If you specify an invalid or unreachable HTTP endpoint, the configuration will fail. |
| 47 | +- **components**: Specify which internal components (e.g., *xapi*, *xenopsd*) should be traced. |
| 48 | + Additional components are expected to be supported in future releases. An experimental *smapi* component |
| 49 | + is also available and requires additional configuration (explained below). |
| 50 | + |
| 51 | +- **endpoints**: The observer can collect traces locally in */var/log/dt* or forward them to external |
| 52 | + visualization tools such as [Jaeger](https://www.jaegertracing.io/). Currently, only HTTP/S endpoints |
| 53 | + are supported, and they require additional configuration steps (see next section). |
| 54 | + |
| 55 | +- To disable tracing you just need to set *enabled* to false: |
| 56 | + ```sh |
| 57 | + xe observer-param-set uuid=<OBSERVER_UUID> enabled=false |
| 58 | + ``` |
| 59 | + |
| 60 | +### Enabling smapi component |
| 61 | + |
| 62 | +- *smapi* component is currently considered experimental and is filtered by default. To enable it, you must |
| 63 | + explicitly configure the following in **xapi.conf**: |
| 64 | + ```ini |
| 65 | + observer-experimental-components="" |
| 66 | + ``` |
| 67 | + This tells XAPI that no components are considered experimental, thereby allowing *smapi* to be traced. |
| 68 | + A modification to **xapi.conf** requires a restart of the XAPI toolstack. |
| 69 | + |
| 70 | +### Enabling HTTP/S endpoints |
| 71 | + |
| 72 | +- By default HTTP and HTTPS endpoints are disabled. To enable them, add the following lines to **xapi.conf**: |
| 73 | + ```ini |
| 74 | + observer-endpoint-http-enabled=true |
| 75 | + observer-endpoint-https-enabled=true |
| 76 | + ``` |
| 77 | + As with enabling *smapi* component, modifying **xapi.conf** requires a restart of the XAPI toolstack. |
| 78 | + *Note*: HTTPS endpoint support is available but not tested and may not work. |
| 79 | + |
| 80 | +### Sending local trace to endpoint |
| 81 | + |
| 82 | +By default, traces are generated locally in the `/var/log/dt` directory. You can copy or forward |
| 83 | +these traces to another location or endpoint using the `xs-trace` tool. For example, if you have |
| 84 | +a *Jaeger* server running locally, you can run: |
| 85 | + |
| 86 | +```sh |
| 87 | +xs-trace /var/log/dt/ http://127.0.0.1:9411/api/v2/spans |
| 88 | +``` |
| 89 | + |
| 90 | +You will then be able to visualize the traces in Jaeger. |
| 91 | + |
| 92 | +### Tagging Trace Sessions for Easier Search |
| 93 | + |
| 94 | +#### Specific attributes |
| 95 | +To make trace logs easier to locate and analyze, it can be helpful to add custom attributes around the |
| 96 | +execution of specific commands. For example: |
| 97 | + |
| 98 | +```sh |
| 99 | +# xe observer-param-set uuid=<OBSERVER_UUID> attributes:custom.random=1234 |
| 100 | +# xe vm-start ... |
| 101 | +# xe observer-param-clear uuid=<OBSERVER_UUID> param-name=attributes param-key=custom.random |
| 102 | +``` |
| 103 | + |
| 104 | +This technique adds a temporary attribute, *custom.random=1234*, which will appear in the generated trace |
| 105 | +spans, making it easier to search for specific activity in trace visualisation tools. It may also be possible |
| 106 | +to achieve similar tagging using baggage parameters directly in individual *xe* commands, but this approach |
| 107 | +is currently undocumented. |
| 108 | + |
| 109 | +#### Baggage |
| 110 | + |
| 111 | +*Baggage*, contextual information that resides alongside the context, is supported. This means you can run |
| 112 | +the following command: |
| 113 | + |
| 114 | +```sh |
| 115 | +BAGGAGE="mybaggage=apples" xe vm-list |
| 116 | +``` |
| 117 | + |
| 118 | +You will be able to search for tags `mybaggage=apples`. |
| 119 | + |
| 120 | +#### Traceparent |
| 121 | + |
| 122 | +Another way to assist in trace searching is to use the `TRACEPARENT` HTTP header. It is an HTTP header field that |
| 123 | +identifies the incoming request. It has a [specific format](https://www.w3.org/TR/trace-context/#traceparent-header) |
| 124 | +and it is supported by **XAPI**. Once generated you can run command as: |
| 125 | + |
| 126 | +```sh |
| 127 | +TRACEPARENT="00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" xe vm-list |
| 128 | +``` |
| 129 | + |
| 130 | +And you will be able to look for trace *4bf92f3577b34da6a3ce929d0e0e4736*. |
| 131 | + |
| 132 | +### Links |
| 133 | + |
| 134 | +- [Opentelemetry](https://opentelemetry.io/) |
| 135 | +- [Trace Context](https://www.w3.org/TR/trace-context/) |
| 136 | +- [Baggage](https://opentelemetry.io/docs/concepts/signals/baggage/) |
| 137 | +- [Ocaml opentelemetry module](https://ocaml.org/p/opentelemetry/latest) |
0 commit comments