Repository navigation
feat(gax): add error logging for client requests - #9756
shivanee-p wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
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.
6907e3e to
2009773
Compare
quirogas
left a comment
There was a problem hiding this comment.
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.
| const attributes: LogPayload = {}; | ||
| for (const [key, value] of Object.entries(initialAttributes)) { | ||
| if (value !== undefined) { | ||
| (attributes as Record<string, unknown>)[key] = value; | ||
| } | ||
| } |
There was a problem hiding this comment.
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).
2009773 to
561c0a4
Compare
561c0a4 to
ff98387
Compare
ff98387 to
63c14d1
Compare
c917a1a to
d9c6f13
Compare
d9c6f13 to
49bd9db
Compare
6b70d45 to
55a59b4
Compare
aa80abe to
57bed21
Compare
57bed21 to
21d7a51
Compare
…SpanId in logCall
… harden resolveExceptionType
… and fix HTTP status and url.domain resolution
…s and OR with enableTelemetryLogging
…esolution, and fail-open logCall
21d7a51 to
7e1313b
Compare
This pull request adds
logCall,buildLogAttributes, andgetGaxLoggertoLoggerHelper.Key Changes:
getGaxLoggerinLoggerHelper.tsto resolve thegoogle-logging-utilslogger forgcp.client.service(defaulting to'google-gax').buildLogAttributesinLoggerHelper.tsto 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, andgcp.errors.metadata.<key>).logCallinLoggerHelper.tsto wrap promise, callback, stream, and synchronous execution boundaries with a one-time latch (hasLoggedL3) and emit aWARNINGlog withexception.type,exception.message,exception.stacktrace, and active trace/span correlation (telemetryTraceId,telemetrySpanId).getPromiseTargetfromTracerHelper.tsfor shared promise/thenable detection.