@@ -94,18 +94,23 @@ And [look in Jaeger for a trace](http://localhost:16686/search?service=rustup).
94
94
Tracing can also be used in tests to get a trace of the operations taken during the test.
95
95
To use this feature, build the project with ` --features=otel,test ` .
96
96
97
- ### Adding instrumentation
97
+ ## Adding instrumentation
98
98
99
- The ` otel ` feature uses conditional compilation to only add function instrument
100
- when enabled. Instrumenting a currently uninstrumented function is mostly simply
101
- done like so:
99
+ Instrumenting a currently uninstrumented function is mostly simply done like so:
102
100
103
101
``` rust
104
102
#[tracing:: instrument(level = " trace" , err(level = " trace" ), skip_all)]
105
103
```
106
104
107
- ` skip_all ` is not required, but some core structs don't implement Debug yet, and
108
- others have a lot of output in Debug : tracing adds some overheads, so keeping
105
+ Sometimes you might want to instrument a function only when the ` otel ` feature is enabled.
106
+ In this case, you will need to use conditional compilation with ` cfg_attr ` :
107
+
108
+ ``` rust
109
+ #[cfg_attr(feature= " otel" , tracing:: instrument(level = " trace" , err(level = " trace" ), skip_all))]
110
+ ```
111
+
112
+ ` skip_all ` is not required, but some core structs don't implement ` Debug ` yet, and
113
+ others have a lot of output in ` Debug ` : tracing adds some overheads, so keeping
109
114
spans lightweight can help avoid frequency bias in the results - where
110
115
parameters with large debug in frequently called functions show up as much
111
116
slower than they are.
0 commit comments