Detect N+1 Query Patterns
When this applies
A parent span has many child spans with the same operation name and similar duration, typically database queries or RPC calls.
Procedure
- Find candidate traces with
search_traces. - Pull the span tree with
get_trace_topology; group child spans by operation name under each parent. - Flag any group with more than 10 near-identical siblings as a potential N+1 pattern. Check that children have similar durations (within 2x of the median).
- Inspect repeated siblings with
get_span_detailsto confirm they target the same downstream service and carry similar attributes. - Report: the parent span (service, operation), the repeated child operation, the count, total wall-clock time consumed, and whether children run sequentially or in parallel.
Gotchas
- Parallel fan-out can look like N+1 but is intentional — check whether children overlap in time before flagging.
- Batch operations may share an operation name but carry different payloads — check span attributes to distinguish.