Repository navigation
feat(storage): add RetryBackoff spans for retry backoffs - #20715
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds OpenTelemetry tracing for retry backoffs in the storage client by recording a 'RetryBackoff' child span with the attempt number during backoff sleep. It also includes comprehensive unit tests for this new behavior. The reviewer suggested an improvement to record the context error and set the span status to error if the context is cancelled or times out during the backoff, which enhances observability.
cf1d1ed to
57317b8
Compare
Adds OpenTelemetry tracing for the retry backoff sleeps in run() (HTTP and gRPC transports). For each backoff the client records a RetryBackoff child span of the operation span, covering the sleep. The span is recorded once the sleep ends, with its start time set to when the sleep began, so it is not visible while the backoff is still in progress. A backoff cut short by context cancellation or deadline is still recorded, so the trace shows the time spent waiting before the operation gave up. Nothing is recorded unless GO_STORAGE_DEV_OTEL_TRACING=true and the operation span is recording, so there is no change for users with tracing disabled. Once the flag is removed each retry will add one span; a TODO notes that this should be revisited then. Tests: TestRecordRetryBackoffNoParentSpan, TestRunRetryBackoffTracing (table-driven, including a backoff interrupted by the context), TestRunRetryBackoffTracingDisabled.
57317b8 to
214f4a5
Compare
cpriti-os
left a comment
There was a problem hiding this comment.
LGTM. One simplification and one assertion to add.
| if !span.IsRecording() { | ||
| return | ||
| } | ||
| _, backoffSpan := tracer().Start(ctx, appendPackageName("RetryBackoff"), append(getCommonTraceOptions(), trace.WithTimestamp(start))...) |
There was a problem hiding this comment.
startSpan already does this composition:
_, span := startSpan(ctx, "RetryBackoff", trace.WithTimestamp(start))
span.End()Bonus: it also attaches the gcp.resource.destination.* attributes from ctx, which every other span in the trace has and this one currently doesn't.
There was a problem hiding this comment.
Done — switched back to startSpan(ctx, "RetryBackoff", trace.WithTimestamp(start)) so the backoff span also includes the gcp.resource.destination.* attributes from ctx.
| name: "context done during backoff", | ||
| // gax picks a random pause in [1ns, Initial], so a huge Initial makes | ||
| // a pause shorter than the timeout practically impossible. | ||
| retry: &retryConfig{backoff: &gax.Backoff{Initial: 1000 * time.Hour, Max: 1000 * time.Hour}}, | ||
| errs: []error{retryableErr}, | ||
| timeout: 50 * time.Millisecond, | ||
| wantErr: true, | ||
| wantBackoffs: 1, |
There was a problem hiding this comment.
For the "context done during backoff" case, could you also assert the span's duration is ≥ the timeout? That's what actually proves the comment in invoke.go ("recorded even if ctx ended").
There was a problem hiding this comment.
Done — updated checkRetryBackoffs to assert s.EndTime.Sub(s.StartTime) >= tc.timeout.
| // RetryBackoff child span of the span in ctx. It is a no-op unless dev tracing | ||
| // is enabled and the span in ctx is recording. | ||
| // | ||
| // TODO: When the dev tracing flag is removed, decide whether backoff spans |
There was a problem hiding this comment.
NitL remove this todo? I think we want the span on all retries?
|
|
||
| // findSpans returns the spans in spans named with the package-qualified form | ||
| // of name. | ||
| func findSpans(spans tracetest.SpanStubs, name string) tracetest.SpanStubs { |
There was a problem hiding this comment.
add the helper functions at the end of the test file, this and the function below
…rs to end of file
…ff-spans # Conflicts: # storage/trace.go # storage/trace_test.go
🤖 I have created a release *beep* *boop* --- ## [1.71.0](storage/v1.70.0...storage/v1.71.0) (2026-11-14) ### Features * **storage:** Add default buffer pool for gRPC parallel uploads ([#20719](#20719)) ([69a9ad3](69a9ad3)) * **storage:** Add error.type and gcp.errors.domain to operation spans ([#20705](#20705)) ([50cd4a3](50cd4a3)) * **storage:** Add gcp.client.retry.attempt_number to gRPC attempt spans ([#20716](#20716)) ([5528a50](5528a50)) * **storage:** Add gcp.storage.payload.offset/size_bytes to attempt spans ([#20757](#20757)) ([56721d1](56721d1)) * **storage:** Add gcp.storage.upload.id attribute for resumable uploads ([#20687](#20687)) ([1259592](1259592)) * **storage:** Add gcp.storage.uri trace attribute to object and bucket operation spans ([#20606](#20606)) ([dfdddde](dfdddde)) * **storage:** Add OpenTelemetry tracing for auth credential refreshes ([#20677](#20677)) ([3ec4bb2](3ec4bb2)) * **storage:** Add RetryBackoff spans for retry backoffs ([#20715](#20715)) ([edca405](edca405)) * **storage:** Add rpc.system.name attribute to trace spans ([#20655](#20655)) ([7d238ad](7d238ad)) * **storage:** Add Storage.UploadChunk spans for resumable uploads ([#20750](#20750)) ([22c9ad5](22c9ad5)) * **storage:** Align metric names, units, and base labels ([#20796](#20796)) ([9e83e4c](9e83e4c)) * **storage:** Expose Unfinalized on ReaderObjectAttrs ([#20703](#20703)) ([c2aabb1](c2aabb1)) * **storage:** Record read and write mode trace attributes ([#20714](#20714)) ([f41be16](f41be16)) ### Bug Fixes * Adds additional validation for REST RPC requests ([#20753](#20753)) ([7827181](7827181)) * Correct 'seperated' and 'paramters' typos in comments ([#20828](#20828)) ([51c6cf6](51c6cf6)) * **storage:** Apply read stall timeout to initial stream open in MultiRangeDownloader ([#20840](#20840)) ([1ddfb07](1ddfb07)) * **storage:** Do not discard seen bytes on 206 Partial Content during reader reopen ([#20766](#20766)) ([aa773a1](aa773a1)) * **storage:** Fix WaitGroup data race in MultiRangeDownloader callbacks ([#20827](#20827)) ([b6b9f0b](b6b9f0b)) * **storage:** Prevent spurious cancelled status on completed gRPC reads ([#20409](#20409)) ([4749772](4749772)) * **storage:** Unbreak storage benchmark module ([#20893](#20893)) ([51e96b4](51e96b4)) * **storage:** Use URL-safe base64 for the feature tracking header ([#20684](#20684)) ([50fd4eb](50fd4eb)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Adds OpenTelemetry tracing for the retry backoff sleeps in
run()(HTTP and gRPC transports).For each backoff the client records a
RetryBackoffchild span of the operation span, covering the sleep. The span is recorded once the sleep ends, with its start time set to when the sleep began (trace.WithTimestamp), so it is not visible while the backoff is still in progress — a deliberate trade-off that keeps the hot path free of span bookkeeping when the operation span is not recording.A backoff cut short by context cancellation or deadline is still recorded, so the trace shows the time spent waiting before the operation gave up. The backoff span itself is left with an unset status: the cancellation/deadline is the operation's error and is recorded on the operation span by
endSpan.Nothing is recorded unless
GO_STORAGE_DEV_OTEL_TRACING=trueand the operation span is recording, so there is no change for users with tracing disabled. Once the dev flag is removed each retry will add one span to the trace; aTODOonrecordRetryBackoffnotes that opt-in/sampling should be decided at that point.Tests:
TestRecordRetryBackoffNoParentSpan,TestRunRetryBackoffTracing(table-driven, including a backoff interrupted by the context),TestRunRetryBackoffTracingDisabled.