Skip to content

Commit 5def238

Browse files
committed
[doc] add documentation about tracing
It is a quick overview of tracing and how to enable it in XAPI. Signed-off-by: Guillaume <[email protected]> Signed-off-by: Mathieu Labourier <[email protected]>
1 parent bef6739 commit 5def238

File tree

1 file changed

+132
-0
lines changed
  • doc/content/toolstack/features/Tracing

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
endpoints=bugtool,http://<jaeger-ip>:9411/api/v2/spans
41+
```
42+
- **components**: Specify which internal components (e.g., *xapi*, *xenopsd*) should be traced.
43+
Additional components are expected to be supported in future releases. An experimental *smapi* component
44+
is also available and requires additional configuration (explained below).
45+
46+
- **endpoints**: The observer can collect traces locally in */var/log/dt* or forward them to external
47+
visualization tools such as [Jaeger](https://www.jaegertracing.io/). Currently, only HTTP/S endpoints
48+
are supported, and they require additional configuration steps (see next section).
49+
50+
- To disable tracing you just need to set *enabled* to false:
51+
```sh
52+
xe observer-param-set uuid=<OBSERVER_UUID> enabled=false
53+
```
54+
55+
### Enabling smapi component
56+
57+
- *smapi* component is currently considered experimental and is filtered by default. To enable it, you must
58+
explicitly configure the following in **xapi.conf**:
59+
```ini
60+
observer-experimental-components=""
61+
```
62+
This tells XAPI that no components are considered experimental, thereby allowing *smapi* to be traced.
63+
A modification to **xapi.conf** requires a restart of the XAPI toolstack.
64+
65+
### Enabling HTTP/S endpoints
66+
67+
- By default HTTP and HTTPS endpoints are disabled. To enable them, add the following lines to **xapi.conf**:
68+
```ini
69+
observer-endpoint-http-enabled=true
70+
observer-endpoint-https-enabled=true
71+
```
72+
As with enabling *smapi* component, modifying **xapi.conf** requires a restart of the XAPI toolstack.
73+
*Note*: HTTPS endpoint support is available but not tested and may not work.
74+
75+
### Sending local trace to endpoint
76+
77+
By default, traces are generated locally in the `/var/log/dt` directory. You can copy or forward
78+
these traces to another location or endpoint using the `xs-trace` tool. For example, if you have
79+
a *Jaeger* server running locally, you can run:
80+
81+
```sh
82+
xs-trace /var/log/dt/ http://127.0.0.1:9411/api/v2/spans
83+
```
84+
85+
You will then be able to visualize the traces in Jaeger.
86+
87+
### Tagging Trace Sessions for Easier Search
88+
89+
#### Specific attributes
90+
To make trace logs easier to locate and analyze, it can be helpful to add custom attributes around the
91+
execution of specific commands. For example:
92+
93+
```sh
94+
# xe observer-param-set uuid=<OBSERVER_UUID> attributes:custom.random=1234
95+
# xe vm-start ...
96+
# xe observer-param-clear uuid=<OBSERVER_UUID> param-name=attributes param-key=custom.random
97+
```
98+
99+
This technique adds a temporary attribute, *custom.random=1234*, which will appear in the generated trace
100+
spans, making it easier to search for specific activity in trace visualisation tools. It may also be possible
101+
to achieve similar tagging using baggage parameters directly in individual *xe* commands, but this approach
102+
is currently undocumented.
103+
104+
#### Baggage
105+
106+
*Baggage*, contextual information that resides alongside the context, is supported. This means you can run
107+
the following command:
108+
109+
```sh
110+
mybaggage=apples xe vm-list
111+
```
112+
113+
You will be able to search for tags `mybaggage=apples`.
114+
115+
#### Traceparent
116+
117+
Another way to assist in trace searching is to use the `TRACEPARENT` HTTP header. It is an HTTP header field that
118+
identifies the incoming request. It has a [specific format](https://www.w3.org/TR/trace-context/#traceparent-header)
119+
and it is supported by **XAPI**. Once generated you can run command as:
120+
121+
```sh
122+
TRACEPARENT="00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" xe vm-list
123+
```
124+
125+
And you will be able to look for trace *4bf92f3577b34da6a3ce929d0e0e4736*.
126+
127+
### Links
128+
129+
- [Opentelemetry](https://opentelemetry.io/)
130+
- [Trace Context](https://www.w3.org/TR/trace-context/)
131+
- [Baggage](https://opentelemetry.io/docs/concepts/signals/baggage/)
132+
- [Ocaml opentelemetry module](https://ocaml.org/p/opentelemetry/latest)

0 commit comments

Comments
 (0)