Skip to content

feat(gax): add error logging for client requests - #9756

Open
shivanee-p wants to merge 8 commits into
mainfrom
shivaneep-o11y-logCall
Open

shivanee-p wants to merge 8 commits into
mainfrom
shivaneep-o11y-logCall

Conversation

@shivanee-p

@shivanee-p shivanee-p commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

This pull request adds logCall, buildLogAttributes, and getGaxLogger to LoggerHelper.

Key Changes:

  • Added getGaxLogger in LoggerHelper.ts to resolve the google-logging-utils logger for gcp.client.service (defaulting to 'google-gax').
  • Added buildLogAttributes in LoggerHelper.ts to populate shared structured log attributes (gcp.client.*, rpc.system.name, url.domain, rpc.method, rpc.response.status_code / http.response.status_code, error.type, gcp.errors.domain, and gcp.errors.metadata.<key>).
  • Added logCall in LoggerHelper.ts to wrap promise, callback, stream, and synchronous execution boundaries with a one-time latch (hasLoggedL3) and emit a WARNING log with exception.type, exception.message, exception.stacktrace, and active trace/span correlation (telemetryTraceId, telemetrySpanId).
  • Exported getPromiseTarget from TracerHelper.ts for shared promise/thenable detection.

@shivanee-p
shivanee-p added this pull request to stack #9746 October 28, 2026 00:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces structured logging for API calls in Google GAX. It adds LoggerHelper.ts with utilities like getGaxLogger, buildLogAttributes, and logCall to emit structured warning logs when logical requests fail across promises, callbacks, streams, or synchronous boundaries. It also exports getPromiseTarget from TracerHelper.ts and includes comprehensive unit tests in loggerHelper.ts. The review feedback recommends replacing a potentially unsafe typeof err === 'object' check with err instanceof Error to prevent runtime errors when handling null or prototype-less objects.

@shivanee-p
shivanee-p marked this pull request as ready for review October 28, 2026 00:27
@shivanee-p
shivanee-p requested a review from a team as a code owner October 28, 2026 00:27
@github-actions
github-actions Bot requested a review from bshaffer October 28, 2026 00:27
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch from 6907e3e to 2009773 Compare October 28, 2026 16:03

@quirogas quirogas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed #9756 against the Milestone 2 Error Logging design doc and live gRPC/REST (fallback: 'rest') error payloads. Approving to unblock merging once the 3 inline items below (and 1 minor nit) are addressed.

Comment on lines +92 to +97
const attributes: LogPayload = {};
for (const [key, value] of Object.entries(initialAttributes)) {
if (value !== undefined) {
(attributes as Record<string, unknown>)[key] = value;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If buildInitialAttributes (contextUtil.ts) omits undefined properties, buildLogAttributes does not need the Object.entries loop or (attributes as Record<string, unknown>)[key] = value cast. Also on line 198, exceptionMessage || err falls back to err when err is new Error('') (empty message), causing util.format('%s', err) to format the full stack trace into the log message; use exceptionMessage || String(err).

@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch from 2009773 to 561c0a4 Compare October 29, 2026 16:56
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch from 561c0a4 to ff98387 Compare October 29, 2026 17:49
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch from ff98387 to 63c14d1 Compare October 29, 2026 18:12
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch 2 times, most recently from c917a1a to d9c6f13 Compare October 29, 2026 20:11
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch from d9c6f13 to 49bd9db Compare October 29, 2026 20:35
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch 2 times, most recently from 6b70d45 to 55a59b4 Compare October 30, 2026 02:12
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch 3 times, most recently from aa80abe to 57bed21 Compare October 30, 2026 04:21
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch from 57bed21 to 21d7a51 Compare October 30, 2026 20:56
Base automatically changed from shivaneep-o11y-payload to main October 30, 2026 23:35
@shivanee-p
shivanee-p force-pushed the shivaneep-o11y-logCall branch from 21d7a51 to 7e1313b Compare October 30, 2026 23:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants