A custom span should represent one meaningful operation with a clear start, end, and owner.

Choose a boundary

Good candidates include a business transaction, validation stage, cache lookup, internal queue wait, or other operation whose duration or failure helps explain a request. Prefer boundaries that answer a diagnostic question; avoid a span for every helper method.

Start and end the span

Use the OpenTelemetry tracer API for the application’s language. A language-neutral outline is:

start a span named "inventory.reserve"
make it the active context while the operation runs
record relevant attributes and events
set error status if the operation fails
end the span on every exit path

SDK syntax varies. Use scope-management or finally/deferred cleanup patterns so exceptions and cancellations do not leave spans open. Use an appropriate span kind for the operation and preserve the active parent context when the work is causally nested.

Name and review spans

Use a stable operation name such as inventory.reserve, not a name containing a request ID, user ID, or other per-call value. Put approved, queryable dimensions in attributes instead. Confirm that the resulting span appears in the intended service and trace before rolling out broadly.