<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="Callsites represent the source locations from which spans or events originate."><title>tracing_core::callsite - Rust</title><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><linkrel="preload"as="font"type="font/woff2"crossoriginhref="../../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><linkrel="stylesheet"href="../../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../../static.files/rustdoc-5bc39a1768837dd0.css"><metaname="rustdoc-vars"data-root-path="../../"data-static-root-path="../../static.files/"data-current-crate="tracing_core"data-themes=""data-resource-suffix=""data-rustdoc-version="1.77.0 (aedd173a2 2024-03-17)"data-channel="1.77.0"data-search-js="search-dd67cee4cfa65049.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../../static.files/storage-4c98445ec4002617.js"></script><scriptdefersrc="../sidebar-items.js"></script><scriptdefersrc="../../static.files/main-48f368f3872407c8.js"></script><noscript><linkrel="stylesheet"href="../../static.files/noscript-04d5337699b92874.css"></noscript><linkrel="alternate icon"type="image/png"href="../../static.files/favicon-16x16-8b506e7a72182f1c.png"><linkrel="alternate icon"type="image/png"href="../../static.files/favicon-32x32-422f7d1d52889060.png"><linkrel="icon"type="image/svg+xml"href="../../static.files/favicon-2c020d218678b618.svg"></head><bodyclass="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="mobile-topbar"><buttonclass="sidebar-menu-toggle"title="show sidebar"></button><aclass="logo-container"href="../../tracing_core/index.html"><imgsrc="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png"alt=""></a></nav><navclass="sidebar"><divclass="sidebar-crate"><aclass="logo-container"href="../../tracing_core/index.html"><imgsrc="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png"alt="logo"></a><h2><ahref="../../tracing_core/index.html">tracing_core</a><spanclass="version">0.1.32</span></h2></div><h2class="location"><ahref="#">Module callsite</a></h2><divclass="sidebar-elems"><section><ulclass="block"><li><ahref="#structs">Structs</a></li><li><ahref="#traits">Traits</a></li><li><ahref="#functions">Functions</a></li></ul></section><h2><ahref="../index.html">In crate tracing_core</a></h2></div></nav><divclass="sidebar-resizer"></div>
<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>