<!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="Checks whether a span or event is enabled based on the provided metadata."><title>enabled in tracing - 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"data-themes=""data-resource-suffix=""data-rustdoc-version="1.77.2 (25ef9e3d8 2024-04-09)"data-channel="1.77.2"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 macro"><!--[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/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/index.html"><imgsrc="https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png"alt="logo"></a><h2><ahref="../tracing/index.html">tracing</a><spanclass="version">0.1.40</span></h2></div><divclass="sidebar-elems"></div></nav><divclass="sidebar-resizer"></div>
<main><divclass="width-limiter"><navclass="sub"><formclass="search-form"><span></span><divid="sidebar-button"tabindex="-1"><ahref="../tracing/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>Macro <ahref="index.html">tracing</a>::<wbr><aclass="macro"href="#">enabled</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/macros.rs.html#1184-1264">source</a> · <buttonid="toggle-all-docs"title="collapse all docs">[<span>−</span>]</button></span></div><preclass="rust item-decl"><spanclass="macro">macro_rules! </span>enabled {
}</pre><detailsclass="toggle top-doc"open><summaryclass="hideme"><span>Expand description</span></summary><divclass="docblock"><p>Checks whether a span or event is <ahref="trait.Subscriber.html#tymethod.enabled"title="method tracing::Subscriber::enabled">enabled</a> based on the provided <ahref="struct.Metadata.html"title="struct tracing::Metadata">metadata</a>.</p>
<p>This macro is a specialized tool: it is intended to be used prior
to an expensive computation required <em>just</em> for that event, but
<em>cannot</em> be done as part of an argument to that event, such as
when multiple events are emitted (e.g., iterating over a collection
<p><ahref="trait.Subscriber.html"title="trait tracing::Subscriber">Subscribers</a> can make filtering decisions based all the data included in a
span or event’s <ahref="struct.Metadata.html"title="struct tracing::Metadata"><code>Metadata</code></a>. This means that it is possible for <code>enabled!</code>
to return a <em>false positive</em> (indicating that something would be enabled
when it actually would not be) or a <em>false negative</em> (indicating that
something would be disabled when it would actually be enabled).</p>
<p>This occurs when a subscriber is using a <em>more specific</em> filter than the
metadata provided to the <code>enabled!</code> macro. Some situations that can result
in false positives or false negatives include:</p>
<ul>
<li>If a subscriber is using a filter which may enable a span or event based
on field names, but <code>enabled!</code> is invoked without listing field names,
<code>enabled!</code> may return a false negative if a specific field name would
cause the subscriber to enable something that would otherwise be disabled.</li>
<li>If a subscriber is using a filter which enables or disables specific events by
file path and line number, a particular event may be enabled/disabled
even if an <code>enabled!</code> invocation with the same level, target, and fields
indicated otherwise.</li>
<li>The subscriber can choose to enable <em>only</em> spans or <em>only</em> events, which <code>enabled</code>
will not reflect.</li>
</ul>
<p><code>enabled!()</code> requires a <ahref="struct.Level.html"title="struct tracing::Level">level</a> argument, an optional <code>target:</code>
argument, and an optional set of field names. If the fields are not provided,
they are considered to be unknown. <code>enabled!</code> attempts to match the
syntax of <code>event!()</code> as closely as possible, which can be seen in the
<p><code>enabled!</code> queries subscribers with <ahref="struct.Metadata.html"title="struct tracing::Metadata"><code>Metadata</code></a> where
<ahref="struct.Metadata.html#method.is_event"title="method tracing::Metadata::is_event"><code>is_event</code></a> and <ahref="struct.Metadata.html#method.is_span"title="method tracing::Metadata::is_span"><code>is_span</code></a> both return <code>false</code>. Alternatively,
use <ahref="macro.event_enabled.html"title="macro tracing::event_enabled"><code>event_enabled!</code></a> or <ahref="macro.span_enabled.html"title="macro tracing::span_enabled"><code>span_enabled!</code></a> to ensure one of these