Prepare and test your skills

Prepare and test your skills

Free sample question with answers and detailed explanation below. The Professional Cloud Developer practice bank has an additional 608 practice questions.Try 10 free realistic questions: instant score, no credit card, and no account required.
A development team runs a Python microservice on Cloud Run that processes e-commerce orders. Currently, the service prints plain-text messages to stdout, making troubleshooting difficult.
The team needs to update the service to meet these requirements:
order_id and payment_provider in jsonPayload for field-level querying in Logs Explorer.LogEntry.severity levels so logs can be filtered by severity and exceptions are grouped in Error Reporting.logging interface with minimal boilerplate.Which approach should the team implement?
json.dumps() using custom keys like log_level and order_id, and write each entry to stdout with a leading timestamp prefix using print() without the Cloud Logging client library.json.dumps() output doesManually calling json.dumps() turns a Python dictionary into a JSON string, and print() writes it to stdout. On Cloud Run, the built-in logging agent inspects each line written to stdout or stderr to determine whether it is a valid single-line JSON object.
{ prevents Cloud Logging's built-in agent from parsing the line as JSON. As a result, the entire line is stored as an unstructured string in textPayload rather than jsonPayload.severity key (not log_level) to LogEntry.severity. A custom log_level key stays inside jsonPayload and does not set the entry's severity level.X-Cloud-Trace-Context header into logging.googleapis.com/trace, logs are not correlated with parent HTTP request logs.logging interface: Replacing logging calls with print() increases boilerplate and discards standard logger hierarchies.severity, message, httpRequest, logging.googleapis.com/trace) must use exact reserved names to map to LogEntry fields.The team explicitly avoided client libraries by writing unprefixed single-line JSON using the exact severity, message, and logging.googleapis.com/trace keys extracted from X-Cloud-Trace-Context.
parse_json processor to collect logs from /var/log/app.log and send them via the Logging API.The Google Cloud Ops Agent is a telemetry collection agent designed primarily for Compute Engine virtual machines (and hybrid hosts). It tails local log files, parses structured or unstructured text using processors such as parse_json, and forwards entries to Cloud Logging via the entries.write API.
stdout, stderr, and /var/log without installing or managing a separate agent inside the container.print() statements into structured JSON or extract incoming HTTP request trace headers (X-Cloud-Trace-Context) to correlate application logs with Cloud Run request logs.entries.write calls consume Cloud Logging API write-request quota that integrated stdout logging avoids.logging.googleapis.com/trace from per-request HTTP headers inside a running Python web server.The Python service were running on a Compute Engine VM writing JSON log files to disk, where the Ops Agent is required to ship and parse local application log files into Cloud Logging.
google.cloud.logging.Client and call setup_logging(), then emit logs using standard Python logging methods while passing custom metadata through extra={"json_fields": ...}.google.cloud.logging with setup_logging() isThe Cloud Logging client library for Python (google-cloud-logging) provides a setup_logging() helper that attaches a Cloud Logging handler to Python's standard logging root logger. In serverless environments like Cloud Run, it formats log records as single-line structured JSON written to stdout so the platform's built-in logging agent ingests them directly into Cloud Logging.
jsonPayload metadata: Passing a dictionary via extra={"json_fields": {"order_id": ..., "payment_provider": ...}} populates the jsonPayload field in the resulting LogEntry, enabling JSON-path filtering in Logs Explorer, Log Analytics, and custom field indexing.logging.info(), logging.warning(), and logging.error() automatically maps Python log levels to LogEntry.severity. Exceptions logged at error level are captured and grouped automatically by Error Reporting.logging.googleapis.com/trace, nesting application logs beneath their parent HTTP request log in Logs Explorer.logging API without manually serializing JSON strings or parsing X-Cloud-Trace-Context headers.logging module and third-party libraries.entries.write.message display text and structured jsonPayload attributes.Using setup_logging() with extra={"json_fields": ...} satisfies every observability requirement in a few lines of setup code, whereas manual JSON printing requires custom trace-header parsing and plain-text logging loses field-level querying and severity mapping.
logging module with logging.basicConfig() to write formatted strings containing the severity level and key-value pairs (such as order_id=123) to stderr.logging.basicConfig() doesPython's logging.basicConfig() configures the standard StreamHandler to format log records as plain-text strings (typically including a timestamp, logger name, level name, and message) and write them to stderr or stdout.
jsonPayload structure: Plain-text log lines are stored in textPayload rather than jsonPayload. While engineers can run substring searches against textPayload, they cannot query individual keys like jsonPayload.order_id or index structured fields.LogEntry.severity: Writing a text prefix such as ERROR: or INFO: inside a plain string does not set the top-level LogEntry.severity field. Logs written to stderr without structured severity metadata cannot be accurately filtered by individual severity levels in Logs Explorer.logging.googleapis.com/trace, so container logs remain disconnected from parent HTTP request logs.textPayload entries instead of parsed JSON objects.The team only needed basic local console debugging or simple text-search logging without field-level querying, severity-based filtering, or trace-correlated request logs.
Switching from logging.basicConfig() to google.cloud.logging.Client().setup_logging() keeps the same standard logging calls in application code while upgrading the output to structured JSON with trace correlation.
Answer them yourself and get your score the moment you finish. No account needed.
Full access includes
Keep the momentum going with these hand-picked practice scenarios
Last updated Validated