Stuck spans
A span is sent only when it ends. A query waiting on a lock, or a call to a service that never answers, can stay open for minutes. A span that never ends is never seen. Stuck Span Detection reports a span while it’s still open, once it has been open longer than a Stuck Span Timeout.
Timeouts and handlers
Section titled “Timeouts and handlers”- A Stuck Span Timeout is how long a span can stay open before it counts as stuck. You set it in seconds or minutes. New projects have no timeouts, so nothing is checked until you add one.
- Each timeout has an ordered list of handlers. A handler has conditions, and an action for a span that matches them. A handler with no conditions matches every span that’s stuck for that long.
A stuck span hasn’t ended, so its duration, error status and end attributes aren’t known yet. Handlers use the same conditions as rules, with the fields known while a span is open: Service Name, Span Name, Library Name, Span Kind, Span Attribute (as set so far), Resource Attribute, Is Root Span and Is Child Span.
As with rules, you set timeouts per service or as project defaults, and switch them on per environment. A service’s handlers are tried before the project’s.
What a handler does
Section titled “What a handler does”- Report once, then drop (the default) takes one snapshot at the timeout. The span is dropped when it ends.
- Report then… takes one snapshot at the timeout. Report after… repeating N times, then… takes N snapshots, one
at each timeout. After that, the handler does one of these:
- Continue reporting indefinitely: a snapshot at each timeout for as long as the span stays open. The span is kept.
- Continue reporting N more times: N more snapshots. The span is dropped when it ends.
- Stop reporting, then drop: no more snapshots. The span is dropped when it ends.
- Silently drop: no snapshot. The span is dropped when it ends.
When a span is dropped, its children move up to its parent, as with Drop Span. SpanSlice checks open spans every 5 seconds, so a snapshot can arrive up to 5 seconds after its timeout.
Snapshots
Section titled “Snapshots”A snapshot is a copy of the span as it looks right now. It’s named <span name> (incomplete), ends when it’s taken, and
has its own span ID, so it never collides with the real span. It carries the span’s attributes, with
redactions applied, plus these:
| Attribute | Meaning |
|---|---|
spanslice.stuck.is_snapshot |
true |
spanslice.stuck.duration_ms |
how long the span had been open |
spanslice.stuck.reported_count |
1 on the first snapshot, 2 on the next, … |
spanslice.stuck.source_span_id |
the real span’s ID, to find it once it ends |
spanslice.stuck_by |
the handler that took the span; the real span carries it too |
SpanSlice sends snapshots as it takes them, outside the trace. Rules and sampling don’t apply to them, and they carry no
SampleRate. In Live Tail, the Stuck filter shows them.
Several timeouts
Section titled “Several timeouts”SpanSlice checks timeouts from shortest to longest. When a span reaches a timeout, that timeout’s handlers are tried in order. The first handler that matches takes the span over from the handler in charge so far, and it counts its own snapshots from one. If nothing matches, the earlier handler stays in charge. A span that no handler ever matches is kept and never reported. The handler in charge reports once per its own timeout.
For example, take a 30-second timeout whose handler reports pg.query indefinitely, and a 5-minute timeout whose handler
reports any span once and drops it. A query open for six minutes is reported at 30 seconds, then every 30 seconds up to
4½ minutes. At 5 minutes, the second handler reports it once more, and the span is dropped when it ends.
A trace with a stuck span open is held like any other trace. It’s sent early once it’s 120 seconds old.