Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(blob-storage): skip S3 diagnostics log for retryable throttling errors (#14519)

Niklas Semmler1be68b493006
diff --git a/packages/shared/src/server/services/StorageService.ts b/packages/shared/src/server/services/StorageService.ts
index 3c9c01a66f..f56c19fedd 100644
--- a/packages/shared/src/server/services/StorageService.ts
+++ b/packages/shared/src/server/services/StorageService.ts
@@ -30,6 +30,7 @@ import {
import { S3ChunkedUploadStrategy } from "./S3ChunkedUploadStrategy";
import {
buildS3RequestDiagnostics,
+ isS3DiagnosableError,
type S3DiagnosticsContext,
} from "./s3SigningDiagnostics";
import * as objectstorage from "oci-objectstorage";
@@ -143,11 +144,15 @@ function createS3RequestHandler(
/**
* Register a diagnostics middleware on an {@link S3Client} that logs the
- * structured error and request context when any S3 request fails.
+ * structured error and request context when a request fails with a
+ * signing/authorization or backend-configuration error (see
+ * {@link isS3DiagnosableError}).
*
- * Runs at the `deserialize` step so the SDK has already turned an error
- * response into a typed exception with request IDs and status code.
- * Best-effort: never alters or masks the original failure.
+ * Runs at the `deserialize` step so the SDK has already turned the response
+ * into a typed exception with request IDs and status code. Logging is gated to
+ * actionable, non-retryable errors so unrelated or transient failures
+ * (`NoSuchKey`, throttling/`SlowDown`, timeouts) don't emit noise or one line
+ * per SDK retry. Best-effort: never alters or masks the original failure.
*/
function addS3DiagnosticsMiddleware(
client: S3Client,
@@ -167,7 +172,9 @@ function addS3DiagnosticsMiddleware(
err,
context,
);
- logger.warn("S3 request failed; emitting diagnostics", diagnostics);
+ if (isS3DiagnosableError(diagnostics.error)) {
+ logger.warn("S3 request failed; emitting diagnostics", diagnostics);
+ }
} catch {
// Never let diagnostics logging mask the original failure.
}
diff --git a/packages/shared/src/server/services/s3SigningDiagnostics.test.ts b/packages/shared/src/server/services/s3SigningDiagnostics.test.ts
index 78b31119d3..8964f07fb8 100644
--- a/packages/shared/src/server/services/s3SigningDiagnostics.test.ts
+++ b/packages/shared/src/server/services/s3SigningDiagnostics.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import {
buildS3RequestDiagnostics,
+ isS3DiagnosableError,
summarizeS3Error,
} from "./s3SigningDiagnostics";
@@ -96,3 +97,43 @@ describe("buildS3RequestDiagnostics", () => {
expect(diagnostics.error.message).toBe("boom");
});
});
+
+describe("isS3DiagnosableError", () => {
+ const summarize = (code: string, httpStatusCode?: number) =>
+ summarizeS3Error(
+ Object.assign(new Error(code), {
+ name: code,
+ Code: code,
+ $metadata: { httpStatusCode },
+ }),
+ );
+
+ it("logs signing/authorization failures", () => {
+ for (const code of [
+ "SignatureDoesNotMatch",
+ "InvalidSignatureException",
+ "AuthorizationHeaderMalformed",
+ "RequestTimeTooSkewed",
+ "InvalidAccessKeyId",
+ ]) {
+ expect(isS3DiagnosableError(summarize(code, 403))).toBe(true);
+ }
+ });
+
+ it("logs backend-configuration errors (e.g. GCS storage-class mismatch)", () => {
+ expect(isS3DiagnosableError(summarize("InvalidArgument", 400))).toBe(true);
+ expect(isS3DiagnosableError(summarize("NotImplemented", 501))).toBe(true);
+ });
+
+ it("skips transient throttling and expected app-level errors", () => {
+ for (const code of [
+ "SlowDown",
+ "ServiceUnavailable",
+ "RequestTimeout",
+ "NoSuchKey",
+ "AccessDenied",
+ ]) {
+ expect(isS3DiagnosableError(summarize(code))).toBe(false);
+ }
+ });
+});
diff --git a/packages/shared/src/server/services/s3SigningDiagnostics.ts b/packages/shared/src/server/services/s3SigningDiagnostics.ts
index d17b918d1a..7b72b58cd1 100644
--- a/packages/shared/src/server/services/s3SigningDiagnostics.ts
+++ b/packages/shared/src/server/services/s3SigningDiagnostics.ts
@@ -56,6 +56,46 @@ export function summarizeS3Error(err: unknown): S3ErrorSummary {
};
}
+/**
+ * Error `Code`/`name` values worth a diagnostic log: signing/authorization
+ * failures and non-retryable backend-configuration errors. These are the
+ * actionable cases where the structured fields (requestId, status, hostname)
+ * aid triage — and they are all non-retryable 4xx, so logging them never
+ * produces one line per SDK retry.
+ *
+ * Deliberately excludes expected app-level errors (`NoSuchKey`, `AccessDenied`)
+ * and transient/retryable failures (`SlowDown` and other throttling, 5xx,
+ * timeouts), which would otherwise flood the logs without telling an operator
+ * anything they can act on.
+ */
+const S3_DIAGNOSABLE_ERROR_CODES = new Set<string>([
+ // Signing / authorization canonicalization failures.
+ "SignatureDoesNotMatch",
+ "InvalidSignatureException",
+ "AuthorizationQueryParametersError",
+ "AuthorizationHeaderMalformed", // region mismatch in the credential scope
+ "RequestTimeTooSkewed", // clock skew, breaks the computed signature
+ "InvalidAccessKeyId", // access key id not recognized by the backend
+ // Backend-configuration / unsupported-operation errors. e.g. GCS rejects
+ // multipart upload on a Rapid storage class with `InvalidArgument`.
+ "InvalidArgument",
+ "InvalidRequest",
+ "NotImplemented",
+ "MethodNotAllowed",
+]);
+
+/**
+ * Whether a summarized error is one the diagnostics middleware should log: a
+ * signing/authorization or backend-configuration failure, as opposed to an
+ * expected or transient error. See {@link S3_DIAGNOSABLE_ERROR_CODES}.
+ */
+export function isS3DiagnosableError(error: S3ErrorSummary): boolean {
+ return (
+ (error.code !== undefined && S3_DIAGNOSABLE_ERROR_CODES.has(error.code)) ||
+ (error.name !== undefined && S3_DIAGNOSABLE_ERROR_CODES.has(error.name))
+ );
+}
+
interface MaybeHttpRequest {
method?: string;
hostname?: string;