1
1
# Tracing
2
2
3
- The feature "otel" can be used when building rustup to turn on Opentelemetry
4
- tracing with an OLTP GRPC exporter .
3
+ Similar to other tools in the Rust ecosystem like Rustc and Cargo,
4
+ Rustup also provides observability/logging features via the ` tracing ` crate .
5
5
6
- This can be very useful for diagnosing performance or correctness issues in more
7
- complicated scenarios.
6
+ The verbosity of logs is controlled via the ` RUSTUP_LOG ` environment
7
+ variable using ` tracing_subscriber ` 's [ directive syntax] .
8
+
9
+ [ directive syntax ] : https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
10
+
11
+ ## Console-based tracing
12
+
13
+ A ` tracing_subscriber ` that prints log lines directly to ` stderr ` is directly
14
+ available in the prebuilt version of Rustup since v1.28.0.
15
+
16
+ For historical reasons, if ` RUSTUP_LOG ` is not set, this subscriber will print
17
+ the log lines in a format that mimics the "legacy" ` stderr ` output in older
18
+ versions of Rustup:
19
+
20
+ ``` console
21
+ > rustup default stable
22
+ info: using existing install for 'stable-aarch64-apple-darwin'
23
+ info: default toolchain set to 'stable-aarch64-apple-darwin'
24
+
25
+ stable-aarch64-apple-darwin unchanged - rustc 1.79.0 (129f3b996 2024-06-10)
26
+ ```
27
+
28
+ However, once ` RUSTUP_LOG ` is set to any value, Rustup's "custom logging mode" will
29
+ be activated, and ` tracing_subscriber ` 's builtin output format will be used instead:
30
+
31
+ ``` console
32
+ > RUSTUP_LOG=trace rustup default stable
33
+ 2024-06-16T12:08:48.732894Z INFO rustup::cli::common: using existing install for 'stable-aarch64-apple-darwin'
34
+ 2024-06-16T12:08:48.739232Z INFO rustup::cli::common: default toolchain set to 'stable-aarch64-apple-darwin'
35
+
36
+ stable-aarch64-apple-darwin unchanged - rustc 1.79.0 (129f3b996 2024-06-10)
37
+ ```
38
+
39
+ Please note that since ` RUSTUP_LOG=trace ` essentially accepts log lines from
40
+ all possible sources, you might sometimes see log lines coming from Rustup's
41
+ dependencies, such as ` hyper_util ` in the following example:
42
+
43
+ ``` console
44
+ > RUSTUP_LOG=trace rustup update
45
+ [..]
46
+ 2024-06-16T12:12:45.569428Z TRACE hyper_util::client::legacy::client: http1 handshake complete, spawning background dispatcher task
47
+ 2024-06-16T12:12:45.648682Z TRACE hyper_util::client::legacy::pool: pool dropped, dropping pooled (("https", static.rust-lang.org))
8
48
9
- ## Prerequisites
49
+ stable-aarch64-apple-darwin unchanged - rustc 1.79.0 (129f3b996 2024-06-10)
50
+ nightly-aarch64-apple-darwin unchanged - rustc 1.81.0-nightly (3cf924b93 2024-06-15)
10
51
11
- ` protoc ` must be installed, which can be downloaded from GitHub or installed via package manager.
52
+ 2024-06-16T12:12:45.693350Z INFO rustup::cli::rustup_mode: cleaning up downloads & tmp directories
53
+ ```
54
+
55
+ ### Caveats
56
+
57
+ Due to historical reasons, the names of logging levels in Rustup's "legacy" ` stderr `
58
+ output and the names being used in the ` tracing ` crate are slightly different:
59
+
60
+ | Legacy | ` tracing ` |
61
+ | ---------- | --------- |
62
+ | ` debug: ` | ` TRACE ` |
63
+ | ` verbose: ` | ` DEBUG ` |
64
+ | ` info: ` | ` INFO ` |
65
+ | ` warning: ` | ` WARN ` |
66
+ | ` error: ` | ` ERROR ` |
67
+
68
+ When specifying a particular logging level using the ` RUSTUP_LOG ` environment variable,
69
+ the ` tracing ` version should be used in all cases.
70
+ For example, set ` RUSTUP_LOG=rustup=DEBUG ` to receive log lines from ` rustup ` itself
71
+ with a maximal verbosity of ` DEBUG ` .
72
+
73
+ ## Opentelemetry tracing
74
+
75
+ > ** Prerequisites:** Before following the instructions in this section,
76
+ > ` protoc ` must be installed, which can be downloaded from GitHub
77
+ > or installed via a package manager.
78
+
79
+ The feature ` otel ` can be used when building rustup to turn on Opentelemetry
80
+ tracing with an OLTP GRPC exporter.
12
81
13
- ## Usage
82
+ This can be very useful for diagnosing performance or correctness issues in more
83
+ complicated scenarios.
14
84
15
85
The normal [ OTLP environment
16
86
variables] ( https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md )
@@ -21,31 +91,24 @@ run a Jaeger docker container on the same host:
21
91
docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 -e COLLECTOR_OTLP_ENABLED=true -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 14269:14269 -p 9411:9411 jaegertracing/all-in-one:latest
22
92
```
23
93
24
- Then build rustup-init with tracing:
94
+ Then build ` rustup-init ` with tracing:
25
95
26
96
``` sh
27
97
cargo build --features=otel
28
98
```
29
99
30
- Run the operation you want to analyze:
100
+ Run the operation you want to analyze. For example, we can now run ` rustup show ` with tracing :
31
101
32
102
``` sh
33
103
RUSTUP_FORCE_ARG0=" rustup" ./target/debug/rustup-init show
34
104
```
35
105
36
106
And [ look in Jaeger for a trace] ( http://localhost:16686/search?service=rustup ) .
37
107
38
- ## Tracing and tests
39
-
40
108
Tracing can also be used in tests to get a trace of the operations taken during the test.
109
+ To use this feature, build the project with ` --features=otel,test ` .
41
110
42
- The custom macro ` rustup_macros::test ` adds a prelude and suffix to each test to
43
- ensure that there is a tracing context setup, that the test function is a span,
44
- and that the spans from the test are flushed.
45
-
46
- Build with features=otel,test to use this feature.
47
-
48
- ## Adding instrumentation
111
+ ### Adding instrumentation
49
112
50
113
The ` otel ` feature uses conditional compilation to only add function instrument
51
114
when enabled. Instrumenting a currently uninstrumented function is mostly simply
@@ -71,11 +134,3 @@ Some good general heuristics:
71
134
- Be way of debug build timing - release optimisations make a huge difference,
72
135
though debug is a lot faster to iterate on. If something isn't a problem in
73
136
release don't pay it too much heed in debug.
74
-
75
- ## Caveats
76
-
77
- Cross-thread propagation isn't connected yet. This will cause instrumentation in
78
- a thread to make a new root span until it is fixed. If any Tokio runtime-related
79
- code gets added in those threads this will also cause a panic. We have a couple
80
- of threadpools in use today; if you need to instrument within that context, use
81
- a thunk to propagate the tokio runtime into those threads.
0 commit comments