Monitoring glossary
What is a span in tracing?
A span is one timed unit of work inside a trace: an HTTP request, a database query, a call to another service. Spans nest to tell the full story of a request.
3 min read8 sectionsUpdated
On this page
Key points
- Every span has a name, a start time, a duration, a status and attributes.
- Spans have parents: the tree of parent and child spans is the trace.
- Span kind tells you the role: server, client, internal, producer or consumer.
- Good span names are low cardinality:
GET /orders/:id, notGET /orders/84213.
| Field | Meaning | Example |
|---|---|---|
| Trace ID | The request this span belongs to | 4bf92f3577b34da6a3ce929d0e0e4736 |
| Span ID | This span’s own identifier | 00f067aa0ba902b7 |
| Parent span ID | The span that caused this one (empty for the root) | a3ce929d0e0e4736 |
| Name | What the work is, in low-cardinality form | SELECT orders |
| Kind | Role: SERVER, CLIENT, INTERNAL, PRODUCER, CONSUMER | CLIENT |
| Start and end time | When the work began and finished | 15:10:02.114 to 15:10:02.149 |
| Status | UNSET, OK or ERROR | ERROR |
| Attributes | Key-value context | http.route=/checkout, db.system=postgresql |
| Events | Timestamped notes inside the span, such as an exception | exception: TimeoutError |
{
"traceId": "4bf92f3577b34da6a3ce929d0e0e4736",
"spanId": "b7ad6b7169203331",
"parentSpanId": "00f067aa0ba902b7",
"name": "SELECT order_items",
"kind": "SPAN_KIND_CLIENT",
"startTimeUnixNano": "1761231002114000000",
"endTimeUnixNano": "1761231002149000000",
"attributes": [
{ "key": "db.system", "value": { "stringValue": "postgresql" } },
{ "key": "db.statement", "value": { "stringValue": "SELECT * FROM order_items WHERE order_id = ?" } }
],
"status": { "code": "STATUS_CODE_OK" }
}| What to notice | Why it matters |
|---|---|
| 35 ms duration | Multiply by how many times it repeats inside the parent |
| Kind CLIENT | This service called the database; the time includes the network |
| Statement has ? placeholders | Values are removed, which keeps secrets out and groups identical queries |
Naming spans well
Span names become rows in your APM tables, so they must group similar work together:
- HTTP server spans: method plus route template, such as
POST /checkoutorGET /orders/:id. - Database spans: operation plus table, such as
SELECT order_items. - Custom spans: a verb phrase for the business step, such as
calculate taxorrender invoice.
Never put IDs, emails or timestamps in names. Put them in attributes if you need them, and keep sensitive values out entirely.
Adding your own spans
Automatic instrumentation covers HTTP, databases and common clients. Add manual spans around the business logic you care about:
import { trace, SpanStatusCode } from '@opentelemetry/api';
const tracer = trace.getTracer('checkout');
export async function priceCart(cart: Cart) {
return tracer.startActiveSpan('price cart', async (span) => {
try {
span.setAttribute('cart.items', cart.items.length);
return await computePrices(cart);
} catch (err) {
span.recordException(err as Error);
span.setStatus({ code: SpanStatusCode.ERROR });
throw err;
} finally {
span.end();
}
});
}What is a root span?
The first span of a trace, with no parent. For a web request it is usually the server span at the edge, such as the API gateway or the first backend.
How many spans does a trace have?
Anything from one to thousands. A typical API request has a handful to a few dozen: the server span, database and cache calls, and calls to other services.
What makes a span an error?
Its status is set to ERROR, usually by instrumentation when an exception is thrown or an HTTP call returns a 5xx. In VitalRix, exceptions recorded on spans are grouped into error issues automatically.
Related reading
- OpenTelemetry for FastAPI: Trace a FastAPI service with OpenTelemetry: instrument the app, async database drivers and httpx, run uvicorn workers correctly and export.
- OpenTelemetry for Go: Instrument a Go service with OpenTelemetry: set up the tracer provider, wrap net/http with otelhttp, pass context everywhere and export the spans.
- OpenTelemetry for PHP and Laravel: Trace a Laravel app with OpenTelemetry: install the PHP extension and auto-instrumentation packages, configure PHP-FPM and trace queries.
- OpenTelemetry for NestJS: Trace a NestJS service with OpenTelemetry: load the SDK before Nest boots, instrument HTTP, Express and NestJS core, and export JSON to VitalRix.
- OpenTelemetry for Flask: Instrument a Flask app with OpenTelemetry, in code or with zero code: trace routes, SQLAlchemy and outgoing calls, and export to VitalRix.
- OpenTelemetry for Next.js: Trace a Next.js app with OpenTelemetry using instrumentation.ts: Node.js runtime setup, JSON export straight to VitalRix, fetch spans and Edge caveats.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.