A trace can show that something retried, but it cannot tell you whether the attempts were counted correctly unless the spans are shaped to make counting possible. This hypothetical case study walks through one nightly job, three candidate span shapes, and an observation-based check for the failure mode that matters most: attempts nested under one another instead of siblings. This is illustrative; no implementation, query, or test was executed, and no production numbers are reported.
The problem: three spans, two possible stories
Imagine a nightly job that posts invoices to an upstream HTTP API and retries on timeouts and 5xx responses. On a bad night the trace view shows three spans with the same operation name, and the on-call engineer has to answer two questions quickly. Did the job make three attempts at one invoice, or did it sync three different invoices that each succeeded on the first try?
The trace alone often cannot answer that, because the answer depends on how the spans were shaped rather than on how many rows you can see. According to the OpenTelemetry documentation, a span describes a single operation with a trace ID, span ID, timestamps and optional attributes or events, and a parent span ID links a child to its parent inside the trace (OpenTelemetry traces documentation). That parent relationship is under your control and easy to get wrong in a retry wrapper.
You have this problem if any of the following sounds familiar:
- Your HTTP client library is auto-instrumented, so every wire request already emits a span.
- Your retry helper wraps the call, so a second span appears per attempt without a clear owner.
- Dashboards count spans by name, which silently mixes attempts, invoices and services.
Prerequisites and constraints
Before changing instrumentation, confirm you have the pieces below, because a span-shape decision is cheap only while the schema is still yours.
- The OpenTelemetry SDK initialised in the service that owns the retry loop, not just in the HTTP client.
- An exporter you can point at a console or an in-memory sink for local inspection, plus your normal backend for production.
- A stub upstream you can make fail deterministically two times and then succeed, so checks do not depend on the network.
- Agreement on what an attempt means: one call to the upstream, including the ones that time out with unknown outcomes.
One constraint deserves emphasis early. Traces are diagnostic data about instrumented work, and they are not a business ledger, so any claim about side effects needs a separate source of truth. The AWS Builders' Library makes the same point from the retry side: backoff spaces attempts and jitter avoids lockstep clients, but neither mechanism proves the preceding call had no side effects (AWS Builders' Library on timeouts, retries, and backoff with jitter).
The hypothetical project
The scenario is a small service called nightly-invoice-sync with one function, sync_invoice(invoice_id), guarded by a retry wrapper with a maximum of three attempts. The upstream is a stub that returns 503 twice and 200 on the third call, which makes the expected span count easy to reason about. The goal is narrow: make retry attempts countable, keep per-attempt latency visible, and keep retry-layer depth constant regardless of how many attempts occur.
Three candidate span shapes
Option A: one span per logical call, attempts as events
You open a single span for the invoice and add one event per attempt with the status code and timestamp. This keeps the trace flat and the cardinality low, but counting attempts requires reading events rather than children. One timestamp per attempt does not by itself give per-attempt duration; you would need start and end events, a duration attribute, or another explicit measure. Without that extra data, per-attempt latency is not native to this shape.
Option B: a parent span plus sibling attempt spans
The logical call becomes a parent span named invoice.sync, and every attempt becomes a child span named invoice.sync.attempt with an attempt.index attribute. Attempts are siblings under one parent, so counting is a filtered child count, latency is native if the attempt span closes before the backoff wait, and retry-layer depth stays constant at two: one parent plus its attempt children. If an auto-instrumented HTTP client adds a span beneath each attempt, total trace depth can be larger; count only the retry-layer spans when querying attempts.
Option C: each attempt as a child of the previous attempt
This is the tempting shape when you add the next span inside the previous attempt's scope. It produces a chain, so counting attempts means walking depth, the trace tree grows with every retry, and latency views start reading like nested calls rather than repeated ones.
| Layout | Attempts countable | Per-attempt latency | Retry-layer depth | Main risk |
|---|---|---|---|---|
| A: events | Event count | Not native; needs explicit start/end events or duration data | Flat | Tooling differences when aggregating events |
| B: sibling attempts | Filtered child count | Native if the attempt span excludes backoff | Constant at two; client spans may add depth | Requires wrapper-level instrumentation and naming discipline |
| C: chained attempts | Depth only | Native but misleading | Grows per attempt | Counting breaks once you add more nesting |
Option B is the layout this case study assumes for the retry layer. It survives the two changes that usually arrive later, a second retry layer and a shared HTTP client span, provided you name the layers and decide which one owns attempt counting. It does not make client spans disappear.
The shape in prose
The implementation sketch is deliberately prose, not executable code; it has not been run. Start a parent span for the logical call, named invoice.sync, and set the maximum attempt count. For each attempt index from one to three, create an attempt span as a child of the parent, not as a child of the previous attempt. Set the attempt index on that span. Make one upstream call inside the attempt span and record the response status code or a retry reason. If the response is one you will not retry, let the attempt finish with its actual outcome and return the response. If the attempt fails in a retryable way, mark that attempt span as failed. Close the attempt span before waiting. If more attempts remain, wait with backoff and jitter outside the attempt span; after the final failed attempt, raise exhaustion without waiting again. The parent status can reflect the final call outcome, but do not use parent status to hide which attempts failed.
Two details matter more than syntax. First, keep invoice identifiers out of attribute values unless you have decided that high-cardinality identifiers are acceptable in your backend. Second, mark the attempt span as failed when the attempt triggers a retry, not only the parent, so a later dashboard can distinguish a recovered call from a call that exhausted its budget.
How to verify the layout
Proposed check 1: confirm sibling structure
This check is proposed, not executed. Input: a deterministic stub that returns 503 on the first two calls and 200 on the third, an exporter pointed at an in-memory sink, and one job run for one invoice. Observe the finished spans. The criteria are: one parent span named invoice.sync; exactly three attempt spans named invoice.sync.attempt; all three attempt spans share the same parent span ID; attempt.index values are 1, 2 and 3; and no attempt span has another attempt span as its parent. If the second attempt's parent is the first attempt, you have the chained shape. If the attempt parent IDs differ, context was lost or there is more than one parent. If there are more than three attempt spans, look for duplicate client instrumentation, a prefetch, or another retry layer. If there are fewer, the retry may not be instrumented or the trace may have been sampled. If client spans appear beneath attempts, count only the named attempt spans.
Proposed check 2: inspect raw spans by hand for one local run
For one local run, inspect the exported spans as text and look for the same trace ID on the parent and attempt spans, plus one parent span ID shared by the attempts. Client spans may also appear; identify the retry layer by span name and attributes rather than by total span count. If attempts have different trace IDs, context propagation is missing. If an attempt's parent is an HTTP client span instead of the invoice.sync parent, the ownership of attempt counting is wrong. If attempt spans overlap in time when the retry loop is sequential, inspect where the span was opened and closed.
Proposed check 3: ask the same question in production terms
Before trusting a dashboard, write down the exact question and the exact aggregation, for example the distribution of direct child counts for invoice.sync per night, filtered to spans named invoice.sync.attempt. If the answer cannot be produced from attributes you actually set and names you control, the schema is missing a field or a naming rule rather than the backend missing a feature. If the count includes client spans, fix the filter before treating the number as an attempt count.
Failure modes to expect
- Double counting from client instrumentation. An auto-instrumented HTTP client emits its own span per attempt, so name your wrapper spans distinctly and document which layer owns the count.
- Chained attempts. Adding the next attempt inside the previous attempt's scope turns a flat structure into a chain and quietly breaks child-count queries.
- Unpropagated context. If the retry loop lives in another process or thread without context propagation, attempts land in separate traces and no parent relationship survives.
- Failed attempts marked as successes. Setting status only on the parent hides which attempt failed and makes error rates look better than they are.
- Sampling that hides the interesting trace. Verify with your own experiment whether error traces are retained by your sampler configuration, rather than assuming they are.
- Cardinality creep. Per-invoice or per-customer attributes inflate series counts quickly, so decide deliberately what belongs on a span and what belongs in logs.
What the trace still cannot tell you
A trace describes instrumented work, and it is not proof that an external system processed your request (OpenTelemetry traces documentation). A timeout on attempt two looks identical whether the upstream did nothing or charged the customer before the connection dropped. A 500 or timeout cannot prove that no side effect occurred, and a successful attempt's trace cannot by itself prove that the side effect happened. Those are separate questions.
HTTP idempotency concerns the intended effect on the server; responses to repetitions can differ, and a non-idempotent request should be retried automatically only with knowledge that its semantics permit replay or that the original was never applied (RFC 9110, Section 9.2.2). The Stripe API v1 documentation provides a concrete example of provider-specific semantics: it stores the result once endpoint execution begins, even for a 500, compares parameters when a key is reused, and starts a new request when a pruned key is reused (Stripe idempotent requests API documentation). Those are Stripe v1 semantics, not a universal property of sending an idempotency header. Where the upstream API supports an idempotency key, pair the retry instrumentation with that key and with reconciliation against upstream records. Do not turn the key into a guarantee the provider has not documented.
Retries also add load to a dependency that may already be struggling, and backoff with jitter reduces that pressure without telling you anything about side effects (AWS Builders' Library on timeouts, retries, and backoff with jitter). Treat the span layout as a measurement improvement, not as a correctness guarantee, and keep the ambiguous-outcome case visible in your runbook.
When this approach does not apply
Skip the parent-and-sibling layout when the call never retries, because a single span already answers every question you have. Skip it as well when retries happen inside a layer you cannot instrument, such as a managed client with opaque internal retries, and measure at the proxy or gateway instead. For one-off scripts, structured logs with an attempt field are cheaper to build and easier to read than a full tracing pipeline.
What to decide before you need the answer
Pick the span shape while the retry loop is still small, name the wrapper layer as the owner of attempt counting, and write one check that fails if attempts become a chain. Then write down the question your dashboard is supposed to answer, because a trace you cannot query confidently is only a prettier log file.
AI assistance: this draft was generated with an AI assistant from a supplied outline and source notes. No implementation, query, or test was executed; the checks above are proposed observation-based tests, not reported results. A human should verify the span semantics against the current OpenTelemetry documentation, check every claim and link, and confirm the platform's current AI and disclosure policy before publishing. This article was created with AI assistance.
