Skip to content

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, not GET /orders/84213.

What a span contains

FieldMeaningExample
Trace IDThe request this span belongs to4bf92f3577b34da6a3ce929d0e0e4736
Span IDThis span’s own identifier00f067aa0ba902b7
Parent span IDThe span that caused this one (empty for the root)a3ce929d0e0e4736
NameWhat the work is, in low-cardinality formSELECT orders
KindRole: SERVER, CLIENT, INTERNAL, PRODUCER, CONSUMERCLIENT
Start and end timeWhen the work began and finished15:10:02.114 to 15:10:02.149
StatusUNSET, OK or ERRORERROR
AttributesKey-value contexthttp.route=/checkout, db.system=postgresql
EventsTimestamped notes inside the span, such as an exceptionexception: TimeoutError

An annotated example

Here is a simplified span as an OpenTelemetry SDK might export it:

json
{
  "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 noticeWhy it matters
35 ms durationMultiply by how many times it repeats inside the parent
Kind CLIENTThis service called the database; the time includes the network
Statement has ? placeholdersValues 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 /checkout or GET /orders/:id.
  • Database spans: operation plus table, such as SELECT order_items.
  • Custom spans: a verb phrase for the business step, such as calculate tax or render 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:

price-cart.tstypescript
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();
    }
  });
}

Frequently asked questions

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.

  • 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.