Professional Cloud Developer free question 9 / 10 · Domain 4: Integrating applications with Google Cloud services
A team's application writes log lines as plain strings. The team wants to filter in the Logs Explorer by individual keys such as the customer ID and to index specific fields to speed up queries. What does the Cloud Logging documentation suggest?
- Write the keys as separate log entries with a textPayload, so a key has its own entry and can be found
- Keep the text payload and add the keys to the log name, as log names can be queried by key in the Logs Explorer
- Write the payload as a JSON object in jsonPayload, as unstructured text can be searched but not queried by key
- Keep the text payload and send it to a log bucket in another region that indexes the words in it
Show the answer and explanation
Answer: C
Why this is correct
In Cloud Logging a LogEntry can store its payload as structured data or as unstructured text. A structured log entry stores the payload as a JSON object in the jsonPayload field, and an unstructured entry stores it as a string in the textPayload field. Formatting the payload as a JSON object lets you query by JSON paths in the Logs Explorer, query individual fields on the Observability Analytics page, and index specific fields to speed up queries. With unstructured logs you can search the text string, but you can't query or index individual keys.
Why the other options are wrong
"Keep the text payload and add the keys to the log name, as log names can be queried by key in the Logs Explorer" … With unstructured logs you can search the text string, but you can't query or index individual keys. The log name does not change that.
"Keep the text payload and send it to a log bucket in another region that indexes the words in it" … Moving a log to another bucket does not add keys to a text payload. A JSON payload is what allows queries by JSON path.
"Write the keys as separate log entries with a textPayload, so a key has its own entry and can be found" … Splitting the data over many text entries still leaves each entry as an unstructured string without queryable keys.
Key point
Log JSON, not strings. Structured payloads can be queried and indexed by key.