Skip to content

fix: keep scalar json logs instead of dropping them - #812

Open
rootkiller6788 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
rootkiller6788:fix-scalar-json-log-fields
Open

rootkiller6788 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
rootkiller6788:fix-scalar-json-log-fields

Conversation

@rootkiller6788

Copy link
Copy Markdown

Found this while running a function with LOG_EXECUTION_ID=true. A plain console.log(42) produced no log line at all, while console.log('42') worked fine — the number just disappeared.

The logger rewrites every stdout/stderr write into a structured log entry and decides "is this a structured log?" with a bare JSON.parse. 42, true, null and "abc" all parse happily, so they were passed to getJSONWithContext, which does 'logging.googleapis.com/labels' in json before setting anything. in on a primitive throws a TypeError, the write never happens, and node's console swallows the error, so the function keeps returning 200 and the user's log line is silently lost.

Fix is to only treat the parsed value as a log object when it actually is one; numbers/booleans/null/strings now fall back to the plain text path that already handles non-JSON output.

Tested by calling getModifiedData directly (throws before, text output after) and end to end with a real server plus LOG_EXECUTION_ID=true, where the 42 line now shows up with its execution_id. Added four regression cases to test/logger.ts and made sure they fail without the logger change.

When LOG_EXECUTION_ID is set we rewrite every stdout/stderr write into a
structured log entry, and we treated anything JSON.parse accepts as a log
object to hang the labels off. Numbers, booleans, null and json strings
parse fine but have no properties, so the 'in' check in
getJSONWithContext threw and console silently swallowed it - the line the
user logged just vanished. Only take the structured path for objects.
These four used to throw inside the logger and lose the log line. Also
checked they fail on the previous commit.
@rootkiller6788
rootkiller6788 marked this pull request as ready for review November 8, 2026 12:57
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.

1 participant