The instrument attribute
Learn how the tracing instrument attribute adds a span to a function automatically, how to skip fields and add custom fields, and how to use it on async functions and Axum handlers
The #[instrument] attribute is a line written above a function that makes the function create and enter a span every time it is called. The span takes the function name, records the function arguments as fields, and stays entered for the whole run of the function, including across await points in an async function. It replaces the manual pattern of creating a span, entering it, and remembering to exit it, with a single annotation.
Where This Fits
The previous pages built spans by hand: create the span, enter it, run the work, drop the guard. That pattern works, and it is the right way to span a block of code inside a function. But most spans wrap a whole function, and writing the same four lines at the top of every function is repetition that hides the function itself. The #[instrument] attribute moves those four lines into one line above the function, and the function body stays clean. The span it creates follows the same rules as a hand-built span, with the same levels, the same fields, and the same nesting, because underneath the attribute the same span machinery runs.
Think of a name badge that prints itself. Writing spans by hand is writing out a badge for every guest at the door. The attribute is a badge printer at the entrance: every function that walks through gets a badge with its name and its details on it, without anyone writing it out by hand.
The Smallest Working Version
Put #[instrument] above a function, and call the function. Every call creates a span named after the function, with the arguments as fields, and every event inside the function carries that span.
use tracing::{info, instrument};
#[instrument]
fn add(a: i32, b: i32) -> i32 {
info!("adding numbers");
a + b
}
fn main() {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::TRACE)
.init();
let total = add(2, 3);
info!(total, "done");
}
[package]
name = "trace_instrument"
version = "0.1.0"
edition = "2021"
[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3"
Run it with cargo run and the terminal shows two lines, verified by running this exact shape:
2026-11-14T11:48:35.353734Z INFO add{a=2 b=3}: trace_instrument: adding numbers
2026-11-14T11:48:35.353734Z INFO trace_instrument: done total=5
The first line carries the span add{a=2 b=3}:, because the info! call runs inside the add function, and the attribute put a span around the whole function. The span name is the function name, and the fields are the two arguments, a=2 and b=3, recorded with their names and values. The second line has no span prefix, because it runs in main, outside the instrumented function, after the span has closed. The function body contains no span code at all: the attribute did the work, and the body only does its own job.
Working Setup:
If the line inside the function shows the function name as a span prefix with the arguments as fields, the attribute works. The plain tracing = "0.1" dependency is enough, because the attribute support is part of the default features of the tracing crate. If the compiler reports that instrument cannot be found, check that the tracing dependency is present and that the import line reads use tracing::instrument;.
What the Attribute Creates
An instrumented function gets a span with three defaults, and each one can be changed. The span level is INFO, unless the attribute overrides it. The span name is the function name, unless the attribute overrides it. The span fields are the function arguments, unless the attribute skips some or adds others. The span is entered when the function starts and exited when the function returns, and for an async function it stays attached across every await point inside the function, using the same future attachment that the Instrument trait provides.
Arguments are recorded as fields using their Debug form, except for arguments whose types are simple values the tracing crate knows how to record directly, such as integers, booleans, and strings. Those are recorded as typed values. An argument whose type implements neither the value recording nor Debug fails to compile, and the fix is to skip that argument, which is covered below. The return value is not recorded by default. The attribute can be told to record it, which is covered in the section on return values and errors.
The attribute works on plain functions, on methods inside an impl block, and on async functions. It does not work on const fn, which fails to compile, because a constant function cannot run the code the attribute generates. It also works on functions in traits implemented through the async-trait crate, where the attribute sits on the trait method implementation alongside the async_trait attribute.
A beginner mental model is a form that fills itself in. The function name goes in the name box, the arguments go in the field boxes, and the span is stamped on the function every time it runs. The programmer writes the form once, above the function, and the stamping happens automatically from then on.
Instrument on Async Functions
Axum handlers are async functions, so the async case is the one that matters most here. The attribute works on async functions exactly as it does on plain functions: one line above the function, and the span covers the whole run, including the time the function spends paused at await points. The span is attached to the future, not held on a thread, so other tasks polled on the same thread while this function waits do not see its span.
use tracing::{info, instrument, Level};
#[instrument]
async fn fetch_user(user_id: u64) -> String {
info!("looking up user in the database");
format!("User {}", user_id)
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
let name = fetch_user(42).await;
info!(name, "fetched");
}
[package]
name = "trace_instrument"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "=1.54.1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"
Run it and the terminal shows two lines, verified by running this exact code:
2026-11-14T11:47:44.300884Z INFO fetch_user{user_id=42}: trace_instrument: looking up user in the database
2026-11-14T11:47:44.305310Z INFO trace_instrument: fetched name="User 42"
The event inside fetch_user carries the fetch_user{user_id=42}: prefix, and the event in main carries no prefix. The attribute handled the async attachment correctly with no extra code. Compare this with the manual pattern, where holding an enter guard across an await point attaches the span to the thread and leaks context into other tasks. The attribute never has that problem, because it attaches the span to the future itself. That is the strongest practical reason to prefer the attribute for async functions: it is not just shorter, it is safer.
Skipping Arguments
Not every argument belongs in a span. An argument may be a secret, such as a password or a token, that must never appear in a log. An argument may be large, such as a whole request body, that would flood the log with its Debug form. An argument may not implement Debug at all, which makes the attribute fail to compile. The skip option excludes arguments by name, and skip_all excludes every argument at once.
use tracing::{info, instrument, Level};
#[instrument(skip(secret))]
fn check_password(user_id: u64, secret: String) -> bool {
info!("checking the password");
!secret.is_empty()
}
#[instrument(skip_all)]
fn process_large_data(data: Vec<u8>) -> usize {
info!("processing data");
data.len()
}
fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
let _ = check_password(42, "hunter2".to_string());
let _ = process_large_data(vec![1, 2, 3]);
}
Run it and the terminal shows two lines. The first carries the span check_password{user_id=42}:, with the secret nowhere in sight. The second carries the bare span process_large_data:, with no fields at all, because every argument was skipped. The secret was never recorded, so it cannot leak into a log file, and the large vector was never formatted, so no time was spent building a Debug string nobody would read. Skipped arguments do not need to implement Debug, which is also how the attribute handles types that cannot be formatted: skip them, and the compile error goes away.
The most common skip in real code is skip(self) on a method. The self value is often a large struct, or a struct that does not implement Debug, and recording it would print the whole struct on every call. Skipping self keeps the span to the arguments that actually describe the call:
use tracing::{info, instrument, Level};
#[derive(Debug)]
struct Store {
name: &'static str,
data: Vec<u8>,
}
impl Store {
#[instrument(skip(self))]
fn lookup(&self, key: &str) -> Option<String> {
info!("looking up a key");
if key == "home" {
Some(self.name.to_string())
} else {
None
}
}
}
fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
let store = Store { name: "main", data: vec![0; 1024] };
let _ = store.lookup("home");
}
The span is lookup{key="home"}, with no trace of the kilobyte of data inside the struct. Without the skip, the span would carry the full Debug form of the struct, including all 1024 bytes, on every single call. That is the kind of log noise that makes real logs unreadable, and one word in the attribute prevents it.
Never record a secret as a span field:
An argument recorded as a field is printed in every event inside the span, and it may be stored in log files, sent to log collectors, and read by people who should never see it. Passwords, tokens, API keys, and session secrets must be skipped with skip, every time, without exception. If an argument might be a secret, skip it first and add it back only after checking what it contains. The compiler cannot tell a secret from an ordinary string, so this rule is enforced by habit, not by tooling.
The attribute redacts some sensitive names on its own:
The #[instrument] attribute in tracing 0.1.44 has a safety net: arguments named api_key, password, token, or secret are recorded as the literal string "<redacted>" instead of their real value, as verified by running a function with all four names. The field name still appears in the span, and a secret under any other name is not protected, so the redaction is a backup, not a replacement for skip. Skip the argument as well, and the field disappears from the span entirely.
Changing the Name, Level, and Target
The three defaults of the generated span can each be overridden with an option inside the attribute. The name option sets the span name to a string instead of the function name. The level option sets the span level, given as a string such as "debug", as a Level constant such as Level::DEBUG, or as a number from 1 to 5, where 1 is TRACE and 5 is ERROR. The target option sets the target the span is recorded under, instead of the module path.
use tracing::{info, instrument, Level};
#[instrument(name = "checkout_flow", level = "debug", skip(secret), fields(order_total = 42))]
async fn checkout(order_id: u64, secret: String) -> u64 {
let _ = secret;
info!("checkout running");
order_id
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
let _ = checkout(7, "top-secret".to_string()).await;
}
Run it and the terminal shows one line, verified by running this exact code:
2026-11-14T11:47:44.305377Z INFO checkout_flow{order_id=7 order_total=42}: trace_instrument: checkout running
The span name is checkout_flow, not checkout. The span level is DEBUG, which is why the span appears at all under a TRACE maximum, and why it would vanish under a plain INFO subscriber. The secret argument is skipped, so it appears nowhere. The order_total field was added by the fields option, and it sits alongside the recorded argument order_id. All four options work together in one attribute, and each one changes only its own part of the span.
The name override is useful when the function name is generic, such as handle, and the span should say what the function handles. The level override is useful when a function is called very often and its span should be hidden in normal operation: a DEBUG span on a hot function keeps the context available while debugging without adding lines to normal output. The target override is rare, and it exists for the same reason the event target override exists: a span that belongs to a named area rather than a module.
Level names are not case sensitive:
The level option accepts "debug", "DEBUG", Level::DEBUG, and the number 2, and all four mean the same span level. The string form is the shortest, the Level constant form is the most explicit, and the number form is the most compact. Pick one form and use it consistently across a codebase, so a reader never has to translate between forms.
Adding Fields
The fields option adds fields to the generated span beyond the recorded arguments. The values are arbitrary expressions, evaluated when the function starts, so they can use the function arguments. A field can also be declared without a value, which creates an empty field to be recorded later with Span::current().record, exactly as with a hand-built span.
use tracing::{info, instrument, Level, Span};
#[instrument(fields(next = i + 1))]
fn step(i: usize) {
info!("stepping");
}
#[instrument(fields(result))]
fn calculate(input_1: usize, input_2: usize) -> usize {
let result = input_1 + input_2;
Span::current().record("result", result);
info!("calculation complete");
result
}
fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
step(4);
let _ = calculate(40, 59);
}
The step span carries two fields: i=4, recorded from the argument, and next=5, computed by the expression i + 1. The calculate span carries the two arguments and an empty result field, which is filled in once the sum is known. The event after the record shows result=99 in the span prefix. Field names can also be nested with dots, such as fields(http.uri = req.uri()), which records a field named http.uri. Dotted names are useful when several fields belong to one area, such as the HTTP details of a request, and they should be grouped by their shared prefix.
Defining a field with the same name as an argument replaces the argument recording with the field value, so the argument is not recorded twice. That is worth knowing when a computed field and an argument share a name: the field wins, and the plain argument value never appears. The fields option also accepts the % and ? sigils, so fields(name = %value) records the value with Display and fields(value = ?value) records it with Debug, using the same rules as span and event fields.
Recording Return Values and Errors
By default the attribute records nothing about what the function returned. Two options change that. The ret option records an event with the return value when the function returns, at the same level as the span, and using the Debug form of the value unless ret(Display) is written instead. The err option records an event with the error value when a function returning a Result returns Err, at ERROR level by default, and using the Display form of the error unless err(Debug) is written instead. The two options can be combined.
use tracing::{instrument, Level};
#[instrument(ret, err)]
fn divide(a: i32, b: i32) -> Result<i32, String> {
if b == 0 {
Err("division by zero".to_string())
} else {
Ok(a / b)
}
}
fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
let _ = divide(10, 2);
let _ = divide(10, 0);
}
Run it and the terminal shows two lines, verified by running this exact code:
2026-11-14T11:47:44.094668Z INFO divide{a=10 b=2}: trace_instrument: return=5
2026-11-14T11:47:44.094729Z ERROR divide{a=10 b=0}: trace_instrument: error=division by zero
The successful call records an INFO event with return=5, inside the divide span with its arguments. The failing call records an ERROR event with error=division by zero, inside the span with its arguments. Two details matter. First, ret only records a value when the function returns Ok. A function that returns Err records the error event instead, and no return event appears. Second, the level of the ret event follows the span level, while the level of the err event defaults to ERROR and can be overridden, such as err(level = Level::INFO), when an error is expected and should not look like a failure.
These two options are the cheapest way to make a fallible function observable. A function with #[instrument(err)] logs every failure with its arguments attached, without a single line of error handling code in the body, and the log reader sees both what went wrong and what the inputs were.
The Parent Option and Follows From
The generated span normally takes the current span as its parent, like a hand-built span. The parent option overrides that. Writing parent = None makes the generated span a root span with no parent, even when another span is current. Writing parent = &span makes the generated span a child of the given span handle, which is useful when a function should attach its span to a span that is held in a struct field rather than the current one.
use tracing::{info, instrument, Level, Span};
struct Worker {
span: Span,
}
impl Worker {
#[instrument(parent = &self.span, skip(self))]
fn run(&self) {
info!("worker running under its stored span");
}
}
fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
let worker = Worker { span = tracing::info_span!("worker_pool") };
worker.run();
}
The run span becomes a child of the worker_pool span stored in the struct, instead of a child of whatever span happens to be current when run is called. The skip(self) is needed here, because the attribute would otherwise try to record self as a field, and the parent expression already uses it. The follows_from option works the same way for causal links: #[instrument(follows_from = causes)] takes a list of span ids that the generated span follows from, marking that this work was caused by those spans without being part of them.
Instrument on an Axum Handler
An Axum handler is an async function, so the attribute fits it directly. Put #[instrument] above the handler, and every request to that route gets a span named after the handler, with the extracted values as fields. The extractor arguments are recorded the same way as ordinary arguments, so a Path extractor that pulls a user id out of the URL appears as a user_id field.
use axum::{extract::Path, routing::get, Router};
use tracing::{info, instrument, Level};
#[instrument]
async fn get_user(Path(user_id): Path<u64>) -> String {
info!("handler running");
format!("User {}", user_id)
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::DEBUG)
.init();
let app = Router::new().route("/users/{id}", get(get_user));
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
axum::serve(listener, app).await.unwrap();
}
[package]
name = "trace_instrument"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "=0.8.9"
tokio = { version = "=1.54.1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"
Run the server, then request curl http://127.0.0.1:3000/users/42 and curl http://127.0.0.1:3000/users/7. The server terminal shows one line per request, verified by running this exact server:
2026-11-14T11:49:26.967258Z INFO get_user{user_id=42}: trace_instrument: handler running
2026-11-14T11:49:26.975732Z INFO get_user{user_id=7}: trace_instrument: handler running
Each request gets its own span, and the two lines are distinguishable by the user_id field alone. The handler body contains one event and no span code. The attribute did the rest. Note that the span shows user_id, not the Path wrapper around it: the attribute records the binding the pattern produced, which is the value the handler actually works with.
When to Use the Attribute and When to Build by Hand
The attribute is the right choice when the span covers a whole function, which is the most common case. It is shorter, it cannot forget to exit the span, and it handles async attachment correctly. It is the wrong choice when the span covers only part of a function, such as one slow block inside a longer function, because the attribute always spans the whole function and there is no way to narrow it. In that case, build the span by hand around the block, with in_scope or an enter guard, and leave the rest of the function outside it.
The attribute is also the wrong choice when the span fields depend on values computed halfway through the function, unless those values can be declared as empty fields and recorded later. A hand-built span can be created at the exact point where all its values are known. The attribute creates the span at the function entry, so any value it records must be available from the arguments or computable from them.
A good rule is to start with the attribute everywhere a function deserves a span, and reach for a hand-built span only when the work inside the function needs a narrower or later span. Most functions need one span, and the attribute gives it with one line. The functions that need two spans, or a span around one block, are the exception, and the hand-built form is there for them.
The Span Flow in Plain Text
The work the attribute does for each call follows four steps, and the function body only sees the middle two:
Function is called
|
v
Attribute creates a span named after the function, fields from arguments
|
v
Span is entered for the whole run of the function, across await points
|
v
Events inside the function carry the span name and fields
|
v
Span is exited when the function returns, ret or err event recorded if asked
The function body never touches the span. It only records events, and the attribute makes sure those events carry the context. That is the whole value of the attribute: the context is attached by declaration, not by code in the body, so the body stays about its own work.
Testing Instrumented Functions
The capturing writer from the earlier pages works here too. The test installs a capturing subscriber for the duration of a closure, calls the instrumented function, and asserts on the captured text. The span prefix in the text proves the attribute created the span, and the return value assertion proves the function still does its own job.
use std::io::Write;
use std::sync::{Arc, Mutex};
use tracing::{info, instrument, Level};
use tracing_subscriber::fmt::writer::MakeWriter;
#[derive(Clone, Default)]
struct BufWriter(Arc<Mutex<Vec<u8>>>);
impl Write for BufWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.0.lock().unwrap().extend_from_slice(buf);
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
impl<'a> MakeWriter<'a> for BufWriter {
type Writer = Self;
fn make_writer(&'a self) -> Self::Writer {
self.clone()
}
}
fn read(buf: &BufWriter) -> String {
String::from_utf8(buf.0.lock().unwrap().clone()).unwrap()
}
#[instrument]
fn add(a: i32, b: i32) -> i32 {
info!("adding numbers");
a + b
}
#[test]
fn instrumented_function_keeps_its_span() {
let buf = BufWriter::default();
let subscriber = tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.with_ansi(false)
.with_writer(buf.clone())
.finish();
tracing::subscriber::with_default(subscriber, || {
assert_eq!(add(2, 3), 5);
});
let text = read(&buf);
assert!(text.contains("add{a=2 b=3}"), "got: {text}");
assert!(text.contains("adding numbers"), "got: {text}");
}
#[instrument(ret, err)]
fn divide(a: i32, b: i32) -> Result<i32, String> {
if b == 0 {
Err("division by zero".to_string())
} else {
Ok(a / b)
}
}
#[test]
fn ret_and_err_events_appear() {
let buf = BufWriter::default();
let subscriber = tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.with_ansi(false)
.with_writer(buf.clone())
.finish();
tracing::subscriber::with_default(subscriber, || {
assert_eq!(divide(10, 2), Ok(5));
assert_eq!(divide(10, 0), Err("division by zero".to_string()));
});
let text = read(&buf);
assert!(text.contains("return=5"), "got: {text}");
assert!(text.contains("error=division by zero"), "got: {text}");
}
The tests need tracing and tracing-subscriber as dependencies. The with_default call keeps each test scoped to its own subscriber, so the tests stay independent. The .with_ansi(false) call keeps colour codes out of the captured text, so the assertions can match on the plain span prefix. Run the tests with cargo test and both pass, as verified against the scratch project used for this page.
Common Beginner Mistakes
Instrumenting a const fn
// Wrong - does not compile, a const fn cannot run the generated code
#[instrument]
const fn my_const_function() {}
A constant function is evaluated at compile time, and the attribute generates code that must run at runtime. Remove the attribute from the const fn, or remove const from the function if the span matters more.
Forgetting to skip a secret argument
// Wrong - the token is recorded as a field and printed in every event
#[instrument]
fn call_api(token: String) -> String {
tracing::info!("calling the api");
token
}
The span carries token="..." and every event inside the function prints it. Add the skip: #[instrument(skip(token))], and the token never reaches the log.
Forgetting to skip a large or non-Debug argument
// Wrong - does not compile when the type has no Debug implementation
struct NoDebug;
#[instrument]
fn work(value: NoDebug) {}
The attribute tries to record value with Debug, and the type does not implement it. Skip the argument: #[instrument(skip(value))], and the compile error goes away.
Expecting a line from a span with no events
// Wrong expectation - the span is silent without an event inside it
#[instrument]
fn quiet(x: i32) -> i32 {
x * 2
}
The attribute creates the span, but the subscriber prints events, not spans. A function with no events inside it produces no output, however it is instrumented. The span becomes visible only when an event, a ret, or an err is recorded inside it.
Using the attribute where a partial span is needed
// Weak - the span covers the whole function, including the cheap first half
#[instrument]
fn work() {
cheap_setup();
expensive_step();
}
The attribute cannot narrow the span to the expensive step. Build the span by hand around expensive_step instead, and leave the cheap setup outside it. The attribute is for whole functions, not for blocks inside them.
The attribute records every argument unless told otherwise:
A function with #[instrument] and no skip records all of its arguments as fields. That is convenient for small functions and dangerous for functions that receive secrets, large buffers, or values that should not be logged. Read the argument list of every instrumented function once, and skip anything that should not appear in a log file. The default is to record everything, so the safe habit is to check the default, not to assume it.
Final Complete Example
This example pulls the page together: an order flow where each function is instrumented, secrets are skipped, a computed field is added, return values and errors are recorded, and the spans nest through the calls.
use tracing::{info, instrument, Level};
#[derive(Debug)]
struct Order {
id: u64,
total_cents: u64,
}
#[instrument(skip(api_key), fields(order_total = order.total_cents))]
async fn charge(order: &Order, api_key: String) -> Result<String, String> {
let _ = api_key;
info!("charging the card");
if order.total_cents == 0 {
return Err("cannot charge an order of zero cents".to_string());
}
Ok(format!("charged {} cents", order.total_cents))
}
#[instrument(ret, err, skip(api_key))]
async fn process_order(order: &Order, api_key: String) -> Result<String, String> {
info!("processing order");
charge(order, api_key).await
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.init();
let order = Order { id: 7, total_cents: 4999 };
match process_order(&order, "secret-key".to_string()).await {
Ok(message) => info!(message, "order done"),
Err(error) => tracing::error!(error, "order failed"),
}
let free = Order { id: 8, total_cents: 0 };
match process_order(&free, "secret-key".to_string()).await {
Ok(message) => info!(message, "order done"),
Err(error) => tracing::error!(error, "order failed"),
}
}
[package]
name = "trace_instrument"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "=1.54.1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"
Run it with cargo run. The first order prints the process_order span with the order as a Debug field, the nested charge span with the order id and total, the charging event, the return event with the charged message, and the completion line in main. The second order prints the same spans, then the error event with the zero cents message, and the failure line in main. The API key appears nowhere in the output, because both functions skip it. The nesting shows in the prefixes: events inside charge carry both the process_order span and the charge span, because charge was called from inside process_order. One line above each function bought all of that context, and neither function body contains any span code.
Summary
The decision this page teaches is when a span should be declared and when it should be built, and the answer follows the shape of the work. A span that covers a whole function should be declared with #[instrument], because the declaration is one line, it cannot forget to exit, and it attaches correctly across await points. A span that covers part of a function should be built by hand around that part, because the attribute cannot narrow itself. The two forms are the same machinery underneath, and the choice between them is about where the span starts and ends, not about which one is more powerful.
The framework for using the attribute well has four parts. First, read the argument list and skip anything that should not be logged, especially secrets and large values. Second, use fields for values the arguments do not already carry, such as a computed total or a result that arrives later. Third, add ret and err to fallible functions, so every failure is logged with its inputs attached and no error handling code is needed for the logging itself. Fourth, remember that a span is silent without an event inside it, so an instrumented function that records nothing still prints nothing. With those habits, a codebase can be instrumented function by function, and the log becomes a record of what the code actually did, with the context attached at the point where the code knew it.