<!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><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-46f98efaafac5295.ttf.woff2,FiraSans-Regular-018c141bf0843ffd.woff2,FiraSans-Medium-8f9a781e4970d388.woff2,SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2,SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><linkrel="stylesheet"href="../static.files/normalize-76eba96aa4d2e634.css"><linkrel="stylesheet"href="../static.files/rustdoc-dd39b87e5fcfba68.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.80.0 (051478957 2024-07-21)"data-channel="1.80.0"data-search-js="search-d52510db62a78183.js"data-settings-js="settings-4313503d2e1961c2.js"><scriptsrc="../static.files/storage-118b08c4c78b968e.js"></script><scriptdefersrc="sidebar-items.js"></script><scriptdefersrc="../static.files/main-20a3ad099b048cf2.js"></script><noscript><linkrel="stylesheet"href="../static.files/noscript-df360f571f6edeae.css"></noscript><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"><rustdoc-search></rustdoc-search><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">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