| <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Instruments a function to create and enter a `tracing` span every time the function is called."><meta name="keywords" content="rust, rustlang, rust-lang, instrument"><title>instrument in tracing_attributes - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc attr"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../tracing_attributes/index.html"><div class="logo-container"><img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../tracing_attributes/index.html"><div class="logo-container"> |
| <img src="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png" alt="logo"></div></a><div class="sidebar-elems"><h2><a href="index.html">In tracing_attributes</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Attribute Macro <a href="index.html">tracing_attributes</a>::<wbr><a class="attr" href="#">instrument</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/tracing_attributes/lib.rs.html#563-571">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust attr"><code>#[instrument]</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Instruments a function to create and enter a <code>tracing</code> <a href="https://docs.rs/tracing/latest/tracing/span/index.html">span</a> every time |
| the function is called.</p> |
| <p>Unless overriden, a span with the <a href="https://docs.rs/tracing/latest/tracing/struct.Level.html#associatedconstant.INFO"><code>INFO</code></a> <a href="https://docs.rs/tracing/latest/tracing/struct.Level.html">level</a> will be generated. |
| The generated span’s name will be the name of the function. |
| By default, all arguments to the function are included as fields on the |
| span. Arguments that are <code>tracing</code> <a href="https://docs.rs/tracing/latest/tracing/field/trait.Value.html#foreign-impls">primitive types</a> implementing the |
| <a href="https://docs.rs/tracing/latest/tracing/field/trait.Value.html."><code>Value</code> trait</a> will be recorded as fields of that type. Types which do |
| not implement <code>Value</code> will be recorded using <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="std::fmt::Debug"><code>std::fmt::Debug</code></a>.</p> |
| <h2 id="overriding-span-attributes"><a href="#overriding-span-attributes">Overriding Span Attributes</a></h2> |
| <p>To change the <a href="https://docs.rs/tracing/latest/tracing/struct.Metadata.html#method.name">name</a> of the generated span, add a <code>name</code> argument to the |
| <code>#[instrument]</code> macro, followed by an equals sign and a string literal. For |
| example:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> |
| <span class="comment">// The generated span's name will be "my_span" rather than "my_function". |
| </span><span class="attribute">#[instrument(name = <span class="string">"my_span"</span>)] |
| </span><span class="kw">pub fn </span>my_function() { |
| <span class="comment">// ... do something incredibly interesting and important ... |
| </span>}</code></pre></div> |
| <p>To override the <a href="https://docs.rs/tracing/latest/tracing/struct.Metadata.html#method.target">target</a> of the generated span, add a <code>target</code> argument to |
| the <code>#[instrument]</code> macro, followed by an equals sign and a string literal |
| for the new target. The <a href="https://docs.rs/tracing/latest/tracing/struct.Metadata.html#method.module_path">module path</a> is still recorded separately. For |
| example:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">pub mod </span>my_module { |
| <span class="comment">// The generated span's target will be "my_crate::some_special_target", |
| // rather than "my_crate::my_module". |
| </span><span class="attribute">#[instrument(target = <span class="string">"my_crate::some_special_target"</span>)] |
| </span><span class="kw">pub fn </span>my_function() { |
| <span class="comment">// ... all kinds of neat code in here ... |
| </span>} |
| }</code></pre></div> |
| <p>Finally, to override the <a href="https://docs.rs/tracing/latest/tracing/struct.Level.html">level</a> of the generated span, add a <code>level</code> |
| argument, followed by an equals sign and a string literal with the name of |
| the desired level. Level names are not case sensitive. For example:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// The span's level will be TRACE rather than INFO. |
| </span><span class="attribute">#[instrument(level = <span class="string">"trace"</span>)] |
| </span><span class="kw">pub fn </span>my_function() { |
| <span class="comment">// ... I have written a truly marvelous implementation of this function, |
| // which this example is too narrow to contain ... |
| </span>}</code></pre></div> |
| <h2 id="skipping-fields"><a href="#skipping-fields">Skipping Fields</a></h2> |
| <p>To skip recording one or more arguments to a function or method, pass |
| the argument’s name inside the <code>skip()</code> argument on the <code>#[instrument]</code> |
| macro. This can be used when an argument to an instrumented function does |
| not implement <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html"><code>fmt::Debug</code></a>, or to exclude an argument with a verbose or |
| costly <code>Debug</code> implementation. Note that:</p> |
| <ul> |
| <li>multiple argument names can be passed to <code>skip</code>.</li> |
| <li>arguments passed to <code>skip</code> do <em>not</em> need to implement <code>fmt::Debug</code>.</li> |
| </ul> |
| <p>You can also use <code>skip_all</code> to skip all arguments.</p> |
| <h3 id="examples"><a href="#examples">Examples</a></h3> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// This type doesn't implement `fmt::Debug`! |
| </span><span class="kw">struct </span>NonDebug; |
| |
| <span class="comment">// `arg` will be recorded, while `non_debug` will not. |
| </span><span class="attribute">#[instrument(skip(non_debug))] |
| </span><span class="kw">fn </span>my_function(arg: usize, non_debug: NonDebug) { |
| <span class="comment">// ... |
| </span>} |
| |
| <span class="comment">// These arguments are huge |
| </span><span class="attribute">#[instrument(skip_all)] |
| </span><span class="kw">fn </span>my_big_data_function(large: Vec<u8>, also_large: HashMap<String, String>) { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Skipping the <code>self</code> parameter:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[derive(Debug)] |
| </span><span class="kw">struct </span>MyType { |
| data: Vec<u8>, <span class="comment">// Suppose this buffer is often quite long... |
| </span>} |
| |
| <span class="kw">impl </span>MyType { |
| <span class="comment">// Suppose we don't want to print an entire kilobyte of `data` |
| // every time this is called... |
| </span><span class="attribute">#[instrument(skip(<span class="self">self</span>))] |
| </span><span class="kw">pub fn </span>my_method(<span class="kw-2">&mut </span><span class="self">self</span>, an_interesting_argument: usize) { |
| <span class="comment">// ... do something (hopefully, using all that `data`!) |
| </span>} |
| }</code></pre></div> |
| <h2 id="adding-fields"><a href="#adding-fields">Adding Fields</a></h2> |
| <p>Additional fields (key-value pairs with arbitrary data) can be passed to |
| to the generated span through the <code>fields</code> argument on the |
| <code>#[instrument]</code> macro. Strings, integers or boolean literals are accepted values |
| for each field. The name of the field must be a single valid Rust |
| identifier, nested (dotted) field names are not supported. Any |
| Rust expression can be used as a field value in this manner. These |
| expressions will be evaluated at the beginning of the function’s body, so |
| arguments to the function may be used in these expressions. Field names may |
| also be specified <em>without</em> values. Doing so will result in an <a href="https://docs.rs/tracing/latest/tracing/field/struct.Empty.html">empty field</a> |
| whose value may be recorded later within the function body.</p> |
| <p>Note that overlap between the names of fields and (non-skipped) arguments |
| will result in a compile error.</p> |
| <h3 id="examples-1"><a href="#examples-1">Examples</a></h3> |
| <p>Adding a new field based on the value of an argument:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> |
| <span class="comment">// This will record a field named "i" with the value of `i` *and* a field |
| // named "next" with the value of `i` + 1. |
| </span><span class="attribute">#[instrument(fields(next = i + <span class="number">1</span>))] |
| </span><span class="kw">pub fn </span>my_function(i: usize) { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Recording specific properties of a struct as their own fields:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> |
| <span class="comment">// This will record the request's URI and HTTP method as their own separate |
| // fields. |
| </span><span class="attribute">#[instrument(fields(http.uri = req.uri(), http.method = req.method()))] |
| </span><span class="kw">pub fn </span>handle_request<B>(req: http::Request<B>) -> http::Response<B> { |
| <span class="comment">// ... handle the request ... |
| </span>}</code></pre></div> |
| <p>This can be used in conjunction with <code>skip</code> or <code>skip_all</code> to record only |
| some fields of a struct:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// Remember the struct with the very large `data` field from the earlier |
| // example? Now it also has a `name`, which we might want to include in |
| // our span. |
| </span><span class="attribute">#[derive(Debug)] |
| </span><span class="kw">struct </span>MyType { |
| name: <span class="kw-2">&</span><span class="lifetime">'static </span>str, |
| data: Vec<u8>, |
| } |
| |
| <span class="kw">impl </span>MyType { |
| <span class="comment">// This will skip the `data` field, but will include `self.name`, |
| // formatted using `fmt::Display`. |
| </span><span class="attribute">#[instrument(skip(<span class="self">self</span>), fields(<span class="self">self</span>.name = %<span class="self">self</span>.name))] |
| </span><span class="kw">pub fn </span>my_method(<span class="kw-2">&mut </span><span class="self">self</span>, an_interesting_argument: usize) { |
| <span class="comment">// ... do something (hopefully, using all that `data`!) |
| </span>} |
| }</code></pre></div> |
| <p>Adding an empty field to be recorded later:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code> |
| <span class="comment">// This function does a very interesting and important mathematical calculation. |
| // Suppose we want to record both the inputs to the calculation *and* its result... |
| </span><span class="attribute">#[instrument(fields(result))] |
| </span><span class="kw">pub fn </span>do_calculation(input_1: usize, input_2: usize) -> usize { |
| <span class="comment">// Rerform the calculation. |
| </span><span class="kw">let </span>result = input_1 + input_2; |
| |
| <span class="comment">// Record the result as part of the current span. |
| </span>tracing::Span::current().record(<span class="string">"result"</span>, <span class="kw-2">&</span>result); |
| |
| <span class="comment">// Now, the result will also be included on this event! |
| </span><span class="macro">tracing::info!</span>(<span class="string">"calculation complete!"</span>); |
| |
| <span class="comment">// ... etc ... |
| </span>}</code></pre></div> |
| <h2 id="examples-2"><a href="#examples-2">Examples</a></h2> |
| <p>Instrumenting a function:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument] |
| </span><span class="kw">pub fn </span>my_function(my_arg: usize) { |
| <span class="comment">// This event will be recorded inside a span named `my_function` with the |
| // field `my_arg`. |
| </span><span class="macro">tracing::info!</span>(<span class="string">"inside my_function!"</span>); |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Setting the level for the generated span:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(level = Level::DEBUG)] |
| </span><span class="kw">pub fn </span>my_function() { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Levels can be specified either with <a href="https://docs.rs/tracing/latest/tracing/struct.Level.html"><code>Level</code></a> constants, literal strings |
| (e.g., <code>"debug"</code>, <code>"info"</code>) or numerically (1—5, corresponding to <a href="https://docs.rs/tracing/latest/tracing/struct.Level.html#associatedconstant.TRACE"><code>Level::TRACE</code></a>—<a href="https://docs.rs/tracing/latest/tracing/struct.Level.html#associatedconstant.ERROR"><code>Level::ERROR</code></a>).</p> |
| <p>Overriding the generated span’s name:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(name = <span class="string">"my_name"</span>)] |
| </span><span class="kw">pub fn </span>my_function() { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Overriding the generated span’s target:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(target = <span class="string">"my_target"</span>)] |
| </span><span class="kw">pub fn </span>my_function() { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Overriding the generated span’s parent:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(parent = <span class="prelude-val">None</span>)] |
| </span><span class="kw">pub fn </span>my_function() { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="comment">// A struct which owns a span handle. |
| </span><span class="kw">struct </span>MyStruct |
| { |
| span: tracing::Span |
| } |
| |
| <span class="kw">impl </span>MyStruct |
| { |
| <span class="comment">// Use the struct's `span` field as the parent span |
| </span><span class="attribute">#[instrument(parent = <span class="kw-2">&</span><span class="self">self</span>.span, skip(<span class="self">self</span>))] |
| </span><span class="kw">fn </span>my_method(<span class="kw-2">&</span><span class="self">self</span>) {} |
| }</code></pre></div> |
| <p>Specifying <a href="https://docs.rs/tracing/latest/tracing/struct.Span.html#method.follows_from"><code>follows_from</code></a> relationships:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(follows_from = causes)] |
| </span><span class="kw">pub fn </span>my_function(causes: <span class="kw-2">&</span>[tracing::Id]) { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Any expression of type <code>impl IntoIterator<Item = impl Into<Option<Id>>></code> |
| may be provided to <code>follows_from</code>; e.g.:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(follows_from = [cause]</span>)] |
| <span class="kw">pub fn </span>my_function(cause: <span class="kw-2">&</span>tracing::span::EnteredSpan) { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>To skip recording an argument, pass the argument’s name to the <code>skip</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">struct </span>NonDebug; |
| |
| <span class="attribute">#[instrument(skip(non_debug))] |
| </span><span class="kw">fn </span>my_function(arg: usize, non_debug: NonDebug) { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>To add additional context to the span, pass key-value pairs to <code>fields</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(fields(foo=<span class="string">"bar"</span>, id=<span class="number">1</span>, show=<span class="bool-val">true</span>))] |
| </span><span class="kw">fn </span>my_function(arg: usize) { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>Adding the <code>ret</code> argument to <code>#[instrument]</code> will emit an event with the function’s |
| return value when the function returns:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(ret)] |
| </span><span class="kw">fn </span>my_function() -> i32 { |
| <span class="number">42 |
| </span>}</code></pre></div> |
| <p>The return value event will have the same level as the span generated by <code>#[instrument]</code>. |
| By default, this will be <a href="https://docs.rs/tracing/latest/tracing/struct.Level.html#associatedconstant.INFO"><code>INFO</code></a>, but if the level is overridden, the event will be at the same |
| level.</p> |
| <p>It’s also possible to override the level for the <code>ret</code> event independently:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(ret(level = Level::WARN))] |
| </span><span class="kw">fn </span>my_function() -> i32 { |
| <span class="number">42 |
| </span>}</code></pre></div> |
| <p><strong>Note</strong>: if the function returns a <code>Result<T, E></code>, <code>ret</code> will record returned values if and |
| only if the function returns <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Ok" title="Result::Ok"><code>Result::Ok</code></a>.</p> |
| <p>By default, returned values will be recorded using their <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="std::fmt::Debug"><code>std::fmt::Debug</code></a> implementations. |
| If a returned value implements <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="std::fmt::Display"><code>std::fmt::Display</code></a>, it can be recorded using its <code>Display</code> |
| implementation instead, by writing <code>ret(Display)</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(ret(Display))] |
| </span><span class="kw">fn </span>my_function() -> i32 { |
| <span class="number">42 |
| </span>}</code></pre></div> |
| <p>If the function returns a <code>Result<T, E></code> and <code>E</code> implements <code>std::fmt::Display</code>, adding |
| <code>err</code> or <code>err(Display)</code> will emit error events when the function returns <code>Err</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(err)] |
| </span><span class="kw">fn </span>my_function(arg: usize) -> <span class="prelude-ty">Result</span><(), std::io::Error> { |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p>The level of the error value event defaults to <code>ERROR</code>.</p> |
| <p>Similarly, overriding the level of the <code>err</code> event :</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(err(level = Level::INFO))] |
| </span><span class="kw">fn </span>my_function(arg: usize) -> <span class="prelude-ty">Result</span><(), std::io::Error> { |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p>By default, error values will be recorded using their <code>std::fmt::Display</code> implementations. |
| If an error implements <code>std::fmt::Debug</code>, it can be recorded using its <code>Debug</code> implementation |
| instead by writing <code>err(Debug)</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(err(Debug))] |
| </span><span class="kw">fn </span>my_function(arg: usize) -> <span class="prelude-ty">Result</span><(), std::io::Error> { |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p>If a <code>target</code> is specified, both the <code>ret</code> and <code>err</code> arguments will emit outputs to |
| the declared target (or the default channel if <code>target</code> is not specified).</p> |
| <p>The <code>ret</code> and <code>err</code> arguments can be combined in order to record an event if a |
| function returns <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Ok" title="Result::Ok"><code>Result::Ok</code></a> or <a href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html#variant.Err" title="Result::Err"><code>Result::Err</code></a>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument(err, ret)] |
| </span><span class="kw">fn </span>my_function(arg: usize) -> <span class="prelude-ty">Result</span><(), std::io::Error> { |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p><code>async fn</code>s may also be instrumented:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument] |
| </span><span class="kw">pub async fn </span>my_function() -> <span class="prelude-ty">Result</span><(), ()> { |
| <span class="comment">// ... |
| </span>}</code></pre></div> |
| <p>It also works with <a href="https://crates.io/crates/async-trait">async-trait</a> |
| (a crate that allows defining async functions in traits, |
| something not currently possible in Rust), |
| and hopefully most libraries that exhibit similar behaviors:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>async_trait::async_trait; |
| |
| <span class="attribute">#[async_trait] |
| </span><span class="kw">pub trait </span>Foo { |
| <span class="kw">async fn </span>foo(<span class="kw-2">&</span><span class="self">self</span>, arg: usize); |
| } |
| |
| <span class="attribute">#[derive(Debug)] |
| </span><span class="kw">struct </span>FooImpl(usize); |
| |
| <span class="attribute">#[async_trait] |
| </span><span class="kw">impl </span>Foo <span class="kw">for </span>FooImpl { |
| <span class="attribute">#[instrument(fields(value = <span class="self">self</span>.<span class="number">0</span>, tmp = std::any::type_name::<<span class="self">Self</span>>()))] |
| </span><span class="kw">async fn </span>foo(<span class="kw-2">&</span><span class="self">self</span>, arg: usize) {} |
| }</code></pre></div> |
| <p><code>const fn</code> cannot be instrumented, and will result in a compilation failure:</p> |
| |
| <div class="example-wrap compile_fail"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="attribute">#[instrument] |
| </span><span class="kw">const fn </span>my_const_function() {}</code></pre></div> |
| </div></details></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="tracing_attributes" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html> |