Professional Cloud DevOps Engineer · Domain 4: Implementing observability practices and troubleshooting issues · 22% of the exam
Task 4.2: Managing and analyzing logs and traces.
Logs Explorer and AI-assisted analysis, routing and retaining logs, redacting sensitive data, and distributed traces with trace waterfalls, spans and trace IDs correlated with structured logs.
Study it
Logs and traces: Logs Explorer, routing, retention, redaction and trace correlation
Try each one before opening the answer. Every option is explained, with the Google Cloud documentation page that proves it.
Question 1 · choose 1
A Cloud Run service writes one JSON line per log record to stdout, such as:
{"severity": "ERROR", "message": "charge declined", "trace": "4bf92f3577b34da6a3ce929d0e0e4736", "spanId": "00f067aa0ba902b7"}
In the Logs Explorer the severity and message show correctly, but the
entries are not linked to their traces, and trace and spanId appear inside
jsonPayload. What should the developers change?
AWrite the record to stderr instead of stdout, which Cloud Run treats as structured log output
BRename severity to logging.googleapis.com/severity so that every special field uses the same prefix
CSend the trace ID in an X-Cloud-Trace-Context header on the response of each request
DUse the keys logging.googleapis.com/trace and logging.googleapis.com/spanId for the two values
Show the answer and why
AWrite the record to stderr instead of stdout, which Cloud Run treats as structured log output
Incorrect
The built-in agent parses single-line JSON from both stdout and stderr, and it already parsed this record.
BRename severity to logging.googleapis.com/severity so that every special field uses the same prefix
Incorrect
severity is already recognized as a top-level key; it is the trace fields that need the special key names.
CSend the trace ID in an X-Cloud-Trace-Context header on the response of each request
Incorrect
Trace context can come from incoming request headers when client libraries populate the fields; a response header does not change how this log line is mapped.
DUse the keys logging.googleapis.com/trace and logging.googleapis.com/spanId for the two values
Correct
On Cloud Run the built-in agent moves those keys into the LogEntry trace and spanId fields, which link entries to traces; other keys stay in jsonPayload.
When a platform's built-in agent parses structured JSON from stdout or stderr, it maps a fixed set of keys to LogEntry fields: severity, message, httpRequest, time, and keys with the logging.googleapis.com/ prefix such as trace, spanId and trace_sampled. Any other key, including a plain "trace", stays in jsonPayload and links nothing.
A sink routes an order service's logs to a BigQuery dataset with partitioned tables. After a release that changed jsonPayload.customer_id from a string to an array, analysts notice that some of the new entries are missing from the table, while other entries from the same minutes keep arriving. The sink's writer identity and filter have not changed. Where are the missing entries, and why?
AIn an export_errors table in the same dataset, because their field type no longer matches the table schema
BIn an export_errors table, together with the whole batch they arrived in, because that batch failed to load
CNowhere, because BigQuery rejected them and the sink drops entries that fail to load
DIn a new table with a date suffix, because the sink switched to date-sharded tables for the new schema
Show the answer and why
AIn an export_errors table in the same dataset, because their field type no longer matches the table schema
Correct
On a schema mismatch from a changed field type, only the entries that caused it go to an error table, named export_errors for partitioned tables; the rest of the batch reaches the destination table.
BIn an export_errors table, together with the whole batch they arrived in, because that batch failed to load
Incorrect
A whole batch goes to the error table only when the column limit is exceeded; a field type change moves just the mismatching entries.
CNowhere, because BigQuery rejected them and the sink drops entries that fail to load
Incorrect
When BigQuery finds a schema mismatch, it creates a table in the dataset to store the error information and the complete log entry.
DIn a new table with a date suffix, because the sink switched to date-sharded tables for the new schema
Incorrect
Partitioned or date-sharded is a property of the sink chosen at creation; a schema change does not switch it.
The first entry routed to BigQuery sets a table's schema. When a later entry changes a field's type, BigQuery writes that entry, with details of the mismatch, to an error table (export_errors for partitioned tables, export_errors_YYYYMMDD for date-sharded ones) and keeps loading the rest of the batch. Exceeding the column limit sends the whole batch there instead.
A billing application on Compute Engine writes JSON logs that the Ops Agent collects. Some entries carry the customer's card number in jsonPayload.card_number. Compliance says card numbers must never be sent to Cloud Logging, but support engineers still need the rest of each entry, including its message and order ID. What should the team configure?
AAn exclude_logs processor in the Ops Agent with a rule that matches entries that have jsonPayload.card_number
BA modify_fields processor in the Ops Agent that overwrites jsonPayload.card_number with a fixed value such as REDACTED
CAn exclusion filter on the project's _Default sink that matches entries with jsonPayload.card_number
DA log view on the _Default bucket that hides the card_number field from the support engineers' group
Show the answer and why
AAn exclude_logs processor in the Ops Agent with a rule that matches entries that have jsonPayload.card_number
Incorrect
exclude_logs stops the agent from ingesting matching entries at all, so support would lose the message and order ID with the card number.
BA modify_fields processor in the Ops Agent that overwrites jsonPayload.card_number with a fixed value such as REDACTED
Correct
modify_fields transforms entries on the VM before they are sent; a static value replaces the field while the rest of the entry is kept.
CAn exclusion filter on the project's _Default sink that matches entries with jsonPayload.card_number
Incorrect
Exclusion filters apply after the Logging API has received the entries, so the card numbers are still sent, and matching entries are dropped whole.
DA log view on the _Default bucket that hides the card_number field from the support engineers' group
Incorrect
A log view filters which entries a principal can read; the field is still sent to and stored in Cloud Logging.
Redaction has to happen before the data leaves the VM. The Ops Agent's modify_fields processor can set, move, map or omit fields of each entry in the logging pipeline, so the card number is replaced and the useful parts of the entry still arrive. exclude_logs drops entries entirely, and Cloud Logging's sink exclusions and views act only after ingestion.
A regulator requires that payment service logs be kept for five years and that nobody, including project owners, can delete them or shorten their retention during that time. The team routes these logs with a sink to a new user-defined log bucket with a five-year retention period. What else should it do?
AAdd an IAM deny policy on the bucket that blocks updates to its retention for everyone except the security team
BLock the bucket with gcloud logging buckets update and the --locked flag, then add a lien to the project as well
CRoute the logs to the _Required bucket instead, because its retention cannot be changed by anyone
DLock the bucket from the Google Cloud console's bucket details page, and keep the retention period at five years
Show the answer and why
AAdd an IAM deny policy on the bucket that blocks updates to its retention for everyone except the security team
Incorrect
Anyone excepted from the deny policy, or able to change it, could still shorten retention, which the requirement forbids.
BLock the bucket with gcloud logging buckets update and the --locked flag, then add a lien to the project as well
Correct
Locking a bucket also locks its retention policy, so the bucket cannot be deleted until every entry has met its retention; a lien guards against deleting the whole project.
CRoute the logs to the _Required bucket instead, because its retention cannot be changed by anyone
Incorrect
The _Required bucket receives a fixed subset of audit logs through the _Required sink, which can't be modified; it is not a destination for the application's own logs.
DLock the bucket from the Google Cloud console's bucket details page, and keep the retention period at five years
Incorrect
The console does not support locking a log bucket; locking is done with gcloud or the Logging API.
Log buckets can have custom retention periods and can be locked to meet compliance needs. Locking is irreversible and also locks the retention policy: the bucket cannot be deleted until all its entries have fulfilled the retention period. Locking is done with gcloud or the API, not the console, and a lien protects the project from deletion.
Checkout logs in a log bucket include jsonPayload.customer_email. Support engineers must keep seeing every checkout entry in Logs Explorer, but without that field; the fraud team must still see the full entries. The logs must stay stored unchanged for the fraud team. What should the team configure?
AA log view on the bucket for support engineers that filters out entries containing customer_email
BAn exclusion filter on the sink that removes customer_email from checkout entries before they are stored
CA second sink that copies the checkout entries into another bucket for support engineers, without the email field
DjsonPayload.customer_email as a restricted field on the bucket, with logging.fieldAccessor granted only to the fraud team
Show the answer and why
AA log view on the bucket for support engineers that filters out entries containing customer_email
Incorrect
Log views control access to whole log entries, so support engineers would lose the checkout entries instead of seeing them without one field.
BAn exclusion filter on the sink that removes customer_email from checkout entries before they are stored
Incorrect
Exclusion filters drop whole entries from routing, and anything removed before storage would be lost to the fraud team as well.
CA second sink that copies the checkout entries into another bucket for support engineers, without the email field
Incorrect
Sinks route log entries as they are; they do not remove individual fields, and the copy doubles storage.
DjsonPayload.customer_email as a restricted field on the bucket, with logging.fieldAccessor granted only to the fraud team
Correct
Field-level access controls hide individual LogEntry fields from users without logging.fieldAccessor for that path, while the entries stay intact for those who hold it.
Field-level access controls hide individual LogEntry fields, such as a jsonPayload leaf, from users who lack the logging.fieldAccessor role for that field; log views instead hide entire entries. Buckets with restricted fields are queried in Logs Explorer, not the Observability Analytics page, and a linked BigQuery dataset does not honor field-level access controls.
A team instruments an orders service with OpenTelemetry and exports spans to
Cloud Trace. Its spans never appear for requests that come through the
company's API gateway, although they appear for direct calls. A captured
request from the gateway carries this header:
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-00
What does the header show?
AThe version field 00 is out of date, so the service ignores the header and starts a new trace without sampling it
BThe trace ID is 32 hexadecimal characters instead of 16, so Cloud Trace rejects the spans it links to
CThe trace flags of 00 say the gateway did not sample the request, and the service follows that decision
DThe gateway should send X-Cloud-Trace-Context instead, because Cloud Trace links spans only through that header
Show the answer and why
AThe version field 00 is out of date, so the service ignores the header and starts a new trace without sampling it
Incorrect
00 is the required version of the traceparent header, so the header is well formed.
BThe trace ID is 32 hexadecimal characters instead of 16, so Cloud Trace rejects the spans it links to
Incorrect
A trace ID in traceparent is a 32-character hexadecimal value for a 128-bit number, as here.
CThe trace flags of 00 say the gateway did not sample the request, and the service follows that decision
Correct
The last field holds the parent's sampling decision; 01 means sampled, so 00 tells downstream services that this request was not sampled.
DThe gateway should send X-Cloud-Trace-Context instead, because Cloud Trace links spans only through that header
Incorrect
Google recommends traceparent, the W3C header, with X-Cloud-Trace-Context only as a legacy fallback.
Trace context propagation passes the trace ID, parent span ID and sampling decision between services. In the W3C traceparent header, the format is VERSION-TRACE_ID-PARENT_SPAN_ID-TRACE_FLAGS: version 00, a 32-character trace ID, a 16-character parent span ID, and flags where 01 means the parent sampled the request.
An engineer runs this query in Logs Explorer:
severity>=ERROR AND resource.type="k8s_container" OR resource.type="cloud_run_revision"
Which entries does the query match?
AEntries of severity ERROR or higher that come from either GKE containers or Cloud Run revisions
BGKE container entries of severity ERROR or higher, plus every Cloud Run revision entry of any severity
CNo entries, because one entry cannot have both resource types and the query is evaluated left to right
DThe query is rejected, because AND and OR cannot appear in one expression without parentheses
Show the answer and why
AEntries of severity ERROR or higher that come from either GKE containers or Cloud Run revisions
Correct
In the Logging query language, OR has higher precedence than AND, so the query reads as severity>=ERROR AND (k8s_container OR cloud_run_revision).
BGKE container entries of severity ERROR or higher, plus every Cloud Run revision entry of any severity
Incorrect
That reading would bind AND before OR; the Logging query language binds OR first.
CNo entries, because one entry cannot have both resource types and the query is evaluated left to right
Incorrect
The two resource types are joined by OR, which is evaluated before AND, so entries of either type can match.
DThe query is rejected, because AND and OR cannot appear in one expression without parentheses
Incorrect
Mixing AND and OR is allowed; precedence rules decide the grouping, though parentheses make the intent clearer.
In the Logging query language, NOT has the highest precedence, followed by OR and then AND, so a OR b AND c OR d is read as (a OR b) AND (c OR d). Adding parentheses makes a query's intent explicit. String comparisons aren't case sensitive, while AND, OR and NOT must be written in capitals.