# Traces and Spans — OpenTelemetry

Source: https://www.skillbyai.com/en/opentelemetry/t-spans

> A tree of timed operations.

## Parent and child spans

A **trace** represents one end-to-end request and is identified by a 16-byte **trace ID**. It consists of **spans**: named, timed operations (an HTTP request handled, a database query, a call to another service), each with an 8-byte **span ID** and the ID of its parent span. The first span is the root. **Span kind** describes the role: SERVER (handles an incoming request), CLIENT (makes an outgoing call), INTERNAL, PRODUCER and CONSUMER (messaging). Backends draw traces as waterfall timelines.

## Following one request

Spans, their attributes and propagated context make it possible to follow a request across services.

![Three ideas: traces and spans, span details, context propagation.](assets/figures/opentelemetry/section-2-map.svg) — Figure 2.1 — Spans, attributes and propagation.

## A checkout trace as a waterfall

Illustrative timings.

```text
trace 4bf92f3577b34da6a3ce929d0e0e4736                       0ms        500ms       1000ms
POST /checkout            [SERVER] frontend          |==========================================| 980 ms
  GET /cart               [CLIENT] frontend          |===|                                         70 ms
    GET /cart             [SERVER] cart-service      |==|                                          55 ms
  POST /payments          [CLIENT] frontend              |==================================|      780 ms
    POST /payments        [SERVER] payment-service       |=================================|       760 ms
      SELECT accounts     [CLIENT] payment-service       |=|                                       20 ms
      POST /charge        [CLIENT] payment-service          |=============================|        700 ms  <- slow
```

## A parcel tracking history

Each scan of a parcel at a depot is a span; the full tracking history from sender to recipient is the trace.

**Quiz:** Which span kind describes a service making an outgoing HTTP call?

- [ ] SERVER
- [x] CLIENT
- [ ] INTERNAL
- [ ] CONSUMER

*Answer:* CLIENT. The receiving side records a SERVER span.
