liveBook · Manning

Span

As explained in Secure APIs

A span is a recorded unit of work representing a step in the processing of a request or operation.

A span is a recorded unit of work representing one step in processing a request or operation. Several spans can share a trace ID, allowing the request’s events to be reconstructed. section 11.3

Spans make API behavior easier to inspect. OpenTelemetry captures request details and exceptions automatically, while custom spans expose work inside the application, such as database operations, transformations, or external-service calls. section 11.3 section 11.4

A useful span record can provide:

  • A name, timing information, status, attributes, and identifiers such as trace ID, span ID, and parent ID. section 11.3
  • A connection between multiple processing events belonging to the same HTTP request. section 11.3
  • Context-specific attributes that make events easier to find and analyze. section 11.4

Tracing a cart operation

A POST /carts handler can create a custom span named cart.create, then attach the authenticated user’s sub claim and the cart payload with set_attribute(). The resulting internal span remains correlated with the request through its trace ID. section 11.4

Figure 11.10 Autoinstrumentation logs capture only events around the edges of our application, such as HTTP request events. To understand what happens inside our application, we must produce custom logs.
figure

Use the figure to distinguish automatically captured HTTP-edge events from custom spans that reveal work inside the application. section 11.4

How Secure APIs covers it

How deep it goes
Explains span structure, trace correlation, exception capture, and custom creation with attributes, without developing broader tracing internals.
Examples
Demonstrates GET /books request spans and a cart.create custom span containing user and cart attributes.
What it assumes
Assumes familiarity with API requests and token claims while introducing OpenTelemetry tracing and custom span creation.
What you can do after
Diagnose/debug with it by correlating request events, inspecting attributes, and reconstructing exceptions through trace IDs.
How it connects
Connects spans with traces, logs, metrics, OpenTelemetry, autoinstrumentation, exceptions, and HTTP requests.

Also explained in

Compare how 6 books explain span →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.