<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../../tracing_core/all.html"title="show sidebar"></a></div><inputclass="search-input"name="search"aria-label="Run search in the documentation"autocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"><divid="help-button"tabindex="-1"><ahref="../../help.html"title="help">?</a></div><divid="settings-menu"tabindex="-1"><ahref="../../settings.html"title="settings"><imgwidth="22"height="22"alt="Change settings"src="../../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><sectionid="main-content"class="content"><divclass="main-heading"><h1>Module <ahref="../index.html">tracing_core</a>::<wbr><aclass="mod"href="#">callsite</a><buttonid="copy-path"title="Copy item path to clipboard"><imgsrc="../../static.files/clipboard-7571035ce49a181d.svg"width="19"height="18"alt="Copy item path"></button></h1><spanclass="out-of-band"><aclass="src"href="../../src/tracing_core/callsite.rs.html#1-619">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>Callsites represent the source locations from which spans or events
<p>Every span or event in <code>tracing</code> is associated with a <ahref="../trait.Callsite.html"title="trait tracing_core::Callsite"><code>Callsite</code></a>. A
callsite is a small <code>static</code> value that is responsible for the following:</p>
<ul>
<li>Storing the span or event’s <ahref="../struct.Metadata.html"title="struct tracing_core::Metadata"><code>Metadata</code></a>,</li>
<li>Uniquely <ahref="struct.Identifier.html"title="struct tracing_core::callsite::Identifier">identifying</a> the span or event definition,</li>
<li>Caching the subscriber’s <ahref="../subscriber/struct.Interest.html"title="struct tracing_core::subscriber::Interest"><code>Interest</code></a><supid="fnref1"><ahref="#fn1">1</a></sup> in that span or event, to avoid
<p>When a span or event is recorded for the first time, its callsite
<ahref="fn.register.html"title="fn tracing_core::callsite::register"><code>register</code></a>s itself with the global callsite registry. Registering a
callsite calls the <ahref="../trait.Subscriber.html#method.register_callsite"title="method tracing_core::Subscriber::register_callsite"><code>Subscriber::register_callsite</code></a>
method with that callsite’s <ahref="../struct.Metadata.html"title="struct tracing_core::Metadata"><code>Metadata</code></a> on every currently active
subscriber. This serves two primary purposes: informing subscribers of the
callsite’s existence, and performing static filtering.</p>
<p>If a <ahref="../trait.Subscriber.html"title="trait tracing_core::Subscriber"><code>Subscriber</code></a> implementation wishes to allocate storage for each
unique span/event location in the program, or pre-compute some value
that will be used to record that span or event in the future, it can
do so in its <ahref="../trait.Subscriber.html#method.register_callsite"title="method tracing_core::Subscriber::register_callsite"><code>register_callsite</code></a> method.</p>
<p>The <ahref="../trait.Subscriber.html#method.register_callsite"title="method tracing_core::Subscriber::register_callsite"><code>register_callsite</code></a> method returns an <ahref="../subscriber/struct.Interest.html"title="struct tracing_core::subscriber::Interest"><code>Interest</code></a> value,
which indicates that the subscriber either <ahref="../subscriber/struct.Interest.html#method.always"title="associated function tracing_core::subscriber::Interest::always">always</a> wishes to record
that span or event, <ahref="../subscriber/struct.Interest.html#method.sometimes"title="associated function tracing_core::subscriber::Interest::sometimes">sometimes</a> wishes to record it based on a
dynamic filter evaluation, or <ahref="../subscriber/struct.Interest.html#method.never"title="associated function tracing_core::subscriber::Interest::never">never</a> wishes to record it.</p>
<p>When registering a new callsite, the <ahref="../subscriber/struct.Interest.html"title="struct tracing_core::subscriber::Interest"><code>Interest</code></a>s returned by every
currently active subscriber are combined, and the result is stored at
each callsite. This way, when the span or event occurs in the
future, the cached <ahref="../subscriber/struct.Interest.html"title="struct tracing_core::subscriber::Interest"><code>Interest</code></a> value can be checked efficiently
to determine if the span or event should be recorded, without
needing to perform expensive filtering (i.e. calling the
<ahref="../trait.Subscriber.html#tymethod.enabled"title="method tracing_core::Subscriber::enabled"><code>Subscriber::enabled</code></a> method every time a span or event occurs).</p>
<p>When a new <ahref="crate::dispatch::Dispatch"><code>Dispatch</code></a> is created (i.e. a new subscriber becomes
active), any previously cached <ahref="../subscriber/struct.Interest.html"title="struct tracing_core::subscriber::Interest"><code>Interest</code></a> values are re-evaluated
for all callsites in the program. This way, if the new subscriber
will enable a callsite that was not previously enabled, the
<ahref="../subscriber/struct.Interest.html"title="struct tracing_core::subscriber::Interest"><code>Interest</code></a> in that callsite is updated. Similarly, when a
subscriber is dropped, the interest cache is also re-evaluated, so
that any callsites enabled only by that subscriber are disabled.</p>
<p>In addition, the <ahref="fn.rebuild_interest_cache.html"title="fn tracing_core::callsite::rebuild_interest_cache"><code>rebuild_interest_cache</code></a> function in this module can be
used to manually invalidate all cached interest and re-register those
callsites. This function is useful in situations where a subscriber’s
interest can change, but it does so relatively infrequently. The subscriber
may wish for its interest to be cached most of the time, and return
<ahref="../subscriber/struct.Interest.html#method.always"title="associated function tracing_core::subscriber::Interest::always"><code>Interest::always</code></a> or <ahref="../subscriber/struct.Interest.html#method.never"title="associated function tracing_core::subscriber::Interest::never"><code>Interest::never</code></a> in its
<ahref="../trait.Subscriber.html#method.register_callsite"title="method tracing_core::Subscriber::register_callsite"><code>register_callsite</code></a> method, so that its <ahref="../trait.Subscriber.html#tymethod.enabled"title="method tracing_core::Subscriber::enabled"><code>Subscriber::enabled</code></a> method
doesn’t need to be evaluated every time a span or event is recorded.
However, when the configuration changes, the subscriber can call
<ahref="fn.rebuild_interest_cache.html"title="fn tracing_core::callsite::rebuild_interest_cache"><code>rebuild_interest_cache</code></a> to re-evaluate the entire interest cache with its
new configuration. This is a relatively costly operation, but if the
configuration changes infrequently, it may be more efficient than calling
<p>In most cases, instrumenting code using <code>tracing</code> should <em>not</em> require
implementing the <ahref="../trait.Callsite.html"title="trait tracing_core::Callsite"><code>Callsite</code></a> trait directly. When using the <ahref="https://docs.rs/tracing/latest/tracing/#macros"><code>tracing</code>
crate’s macros</a> or the <ahref="https://docs.rs/tracing/latest/tracing/attr.instrument.html"><code>#[instrument]</code> attribute</a>, a
<code>Callsite</code> is automatically generated.</p>
<p>However, code which provides alternative forms of <code>tracing</code> instrumentation
may need to interact with the callsite system directly. If
instrumentation-side code needs to produce a <code>Callsite</code> to emit spans or
events, the <ahref="struct.DefaultCallsite.html"title="struct tracing_core::callsite::DefaultCallsite"><code>DefaultCallsite</code></a> struct provided in this module is a
ready-made <code>Callsite</code> implementation that is suitable for most uses. When
possible, the use of <code>DefaultCallsite</code> should be preferred over implementing
<ahref="../trait.Callsite.html"title="trait tracing_core::Callsite"><code>Callsite</code></a> for user types, as <code>DefaultCallsite</code> may benefit from
additional performance optimizations.</p>
<divclass="footnotes"><hr><ol><liid="fn1"><p>Returned by the <ahref="crate::subscriber::Subscriber::register_callsite"><code>Subscriber::register_callsite</code></a>
method. <ahref="#fnref1">↩</a></p></li></ol></div></div></details><h2id="structs"class="section-header">Structs<ahref="#structs"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="struct"href="struct.DefaultCallsite.html"title="struct tracing_core::callsite::DefaultCallsite">DefaultCallsite</a></div><divclass="desc docblock-short">A default <ahref="../trait.Callsite.html"title="trait tracing_core::Callsite"><code>Callsite</code></a> implementation.</div></li><li><divclass="item-name"><aclass="struct"href="struct.Identifier.html"title="struct tracing_core::callsite::Identifier">Identifier</a></div><divclass="desc docblock-short">Uniquely identifies a <ahref="../trait.Callsite.html"title="trait tracing_core::Callsite"><code>Callsite</code></a></div></li></ul><h2id="traits"class="section-header">Traits<ahref="#traits"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="trait"href="trait.Callsite.html"title="trait tracing_core::callsite::Callsite">Callsite</a></div><divclass="desc docblock-short">Trait implemented by callsites.</div></li></ul><h2id="functions"class="section-header">Functions<ahref="#functions"class="anchor">§</a></h2><ulclass="item-table"><li><divclass="item-name"><aclass="fn"href="fn.rebuild_interest_cache.html"title="fn tracing_core::callsite::rebuild_interest_cache">rebuild_interest_cache</a></div><divclass="desc docblock-short">Clear and reregister interest on every <ahref="../trait.Callsite.html"title="trait tracing_core::Callsite"><code>Callsite</code></a></div></li><li><divclass="item-name"><aclass="fn"href="fn.register.html"title="fn tracing_core::callsite::register">register</a></div><divclass="desc docblock-short">Register a new <ahref="../trait.Callsite.html"title="trait tracing_core::Callsite"><code>Callsite</code></a> with the global registry.</div></li></ul></section></div></main></body></html>