Prepare and test your skills
Prepare and test your skills
Implementing trace context propagation and log enrichment is carrying the identity of one distributed request across services and embedding that identity in logs. Cloud Trace (opens in a new tab) captures the end-to-end path and latency of a request, while Cloud Logging (opens in a new tab) stores timestamped log entries with event detail. Correlation links those two views so an error log, its latency breakdown, and its related spans can be reviewed together.
Trace context and structured logs enable correlation because traces show request flow while logs show event detail. A trace represents the path of a single end-to-end operation across distributed components, and each trace is composed of spans that record one function or operation with latency data. A log is a collection of timestamped entries where each entry describes a specific event, but logs alone do not show how a change in one component relates to activity in others. Trace data bridges that gap by letting an operator follow a request from service to service, while added log fields such as severity, service name, or customer ID provide context that makes troubleshooting faster.
Instrumentation options for propagating trace context center on OpenTelemetry, the recommended vendor-neutral framework for creating spans, propagating context, and exporting telemetry. When trace data is not automatically captured, the application must be instrumented to create spans, propagate context on outbound calls, and export telemetry to a Google Cloud project. Data flows from the instrumented application to the export destination, and the destination project then makes traces viewable in the Trace console alongside logs and metrics.
The supported export paths all keep the same project destination while standardizing on OpenTelemetry signals:
Collector-based samples for Go, Java, Node.js, and Python send metric and trace data in OTLP format through the Telemetry API and use a Google Cloud exporter for log data. Direct-export applications can migrate from the Trace exporter to the OTLP endpoint to keep the same project destination while standardizing on OpenTelemetry signals.
Configuring Google Cloud compute platforms to collect correlated telemetry means combining what each platform emits by default with explicit collection for application traces and custom signals. Compute Engine, Google Kubernetes Engine (GKE), and Cloud Run generate system metrics and logs by default, while Cloud Run functions and App Engine automatically generate metrics, logs, and traces. Additional configuration is required when custom spans, application logs with trace fields, or user-defined metrics must flow to the same project for unified analysis.
| Platform | Default telemetry | Action to enable correlation |
|---|---|---|
| Compute Engine VMs | Basic system metric data and system log data | Install the Ops Agent to collect host metrics, system logs, application logs, and OTLP traces and metrics |
| GKE clusters | System log data and system metric data | Use observability metric packages and Google Cloud Managed Service for Prometheus for user-defined and third-party metrics |
| Cloud Run services | System metric data and log data | Add a Prometheus sidecar for Prometheus metrics or an OpenTelemetry sidecar for OTLP metrics and trace context |
| Cloud Run functions and App Engine | Metric data, log data, and trace data | Instrument only when additional application-specific spans or enriched log fields are needed |
The application on Compute Engine depends on the Ops Agent to forward telemetry after local collection. The Ops Agent automatically collects host metrics such as CPU, GPU, memory, and process metrics, plus system logs such as syslog on Linux and Windows Event Log on Windows. The same agent supports third-party integrations for Postgres, MongoDB, and Java Virtual Machine with preconfigured dashboards, plus Prometheus metrics, OTLP metric and trace data through the OTLP receiver, and application logs through logging receivers. For Cloud Run services that write Prometheus metrics, traffic flows from the service container to the Prometheus sidecar and then to Cloud Monitoring, while OTLP-based services use the OpenTelemetry sidecar pattern.
Exam tip: The Ops Agent collects application logs, but not by using OTLP — OTLP through the Ops Agent carries trace data and metric data, while logs use logging receivers.
Structuring logs to carry trace IDs and span IDs turns isolated log entries into queryable steps of a distributed trace. Log entries that include trace data allow Cloud Logging entries viewed in Logs Explorer to link directly to the matching trace in Cloud Trace. Effective enrichment writes structured application logs that preserve the trace identifier for the end-to-end request, the span identifier for the current operation, and relevant metadata such as service name, severity, or request context. Teams can then build custom dashboards that combine log data, performance metric data, and alerting policies, and Error Reporting can annotate matching log entries and group them into error groups.
Application logs reach Cloud Logging through several peer paths that all support the same correlation model once trace fields are present:
syslog on a Compute Engine VM and forwarding with the Ops Agent.gcloud logging command.Log entries remain correlatable only when they arrive with valid timestamps, because incoming entries with timestamps older than the logs retention period or more than 24 hours in the future are discarded. Reading correlated data happens in Logs Explorer, through the Logging API client libraries and REST endpoints, through gcloud logging, or by pivoting from a log entry to its trace in the Trace console.
Design and enforcement of logging standards for distributed tracing is defining one organizational policy that requires structured logs, mandates trace metadata, and validates completeness. Cloud Logging (opens in a new tab) collects application and audit logs into regional buckets, Cloud Audit Logs records who changed what, and Cloud Monitoring analyzes the stream to confirm expected events are present. The policy applies at the organization, folder, and project levels, and log data flows from each service to a regional logging bucket and then to analysis destinations.
A structured logging standard requires every microservice to emit machine-readable logs to Cloud Logging instead of free-form text. The standard defines collection, review, and retention for all enterprise assets and is reviewed annually or when significant enterprise changes occur. Application teams create custom logs for their services, configure applications to generate error messages with enough detail for corrective action, and control visibility with Identity and Access Management (IAM) (opens in a new tab) allow policies so only authorized roles can see error payloads. Because all services share the same format, filters and metrics can identify successful and unsuccessful events consistently, and failed data-access events can be isolated without parsing inconsistent text.
Required trace metadata is the minimum set of fields that lets an operator correlate one distributed request across logs, audit records, and pipeline history. The logging standard requires application logs to include timestamps and other information for traceability, so entries from different services can be ordered and joined into one trace. Cloud Audit Logs records the user or service account that initiated each Google Cloud change, but a deployment triggered by a CI/CD system needs extra pipeline identifiers to reconstruct why the change was made and who approved it.
The required set includes:
serviceAccountDelegationInfo when impersonation is usedTo capture impersonation completely, the standard enables Data Access audit logs for the Identity and Access Management (IAM) API in every project that contains service accounts and for the Security Token Service API in every project that contains workload identity pools. Each configuration causes every token request for a service account to add an entry to Cloud Audit Logs, so delegation chains remain traceable.
Automated validation is the closed loop that proves services are emitting the required structured fields and that no trace is missing. Validation depends on centralized collection first, then analysis, then policy review, because filters cannot check fields that were never collected. Log sinks route copies of log entries from logging buckets to BigQuery for analysis, to Cloud Storage for backup, and to Pub/Sub for real-time ingestion by partners such as Elastic and Splunk or for custom alerting.
A complete validation workflow runs in order:
Data Access audit logs help troubleshooting but can be large, so the standard validates the collection configuration in a test project before enabling it in developer and production projects to control storage cost.
Exam tip: Custom retention rules apply to all logs in a bucket for 1 day to 3650 days, regardless of log type or whether the log was copied from another location.
Centralized enforcement controls where trace logs live, how long they persist, and how sensitive data stays separated from operations telemetry. Logging buckets are regional resources where infrastructure stores, indexes, and searches logs, and a default resource location automatically applies a chosen region to new _Default and _Required buckets to meet latency, availability, or compliance needs. Protection uses Google-managed encryption by default, with customer-managed encryption keys (CMEK) when the organization must control its own key encryption keys, plus separate backup in Cloud Storage or external storage with retention schedules, integrity checks using checksums, monitoring, and access controls.
When regulatory requirements prevent streaming customer data to the public cloud, the architecture separates sensitive application data from lower-risk operations data. Sensitive application telemetry stays on-premises under tools such as Prometheus for collection, Grafana for dashboards, and the OpenTelemetry Collector for routing, while operations data flows to the cloud for centralized monitoring. This separation preserves compliance but creates tradeoffs: externally hosted dashboards and exported logs are not directly available to Google Cloud Support, which can slow troubleshooting, and partner or self-hosted collection adds licensing or maintenance cost.
Querying correlated data across observability tools means using a shared trace identifier to connect logs, spans, and historical records into one troubleshooting path. Cloud Logging (opens in a new tab) holds structured log entries, Cloud Trace holds distributed traces and spans, and BigQuery holds long-term copies for deep analysis. Observability Analytics (opens in a new tab) provides a SQL interface that can query log data, trace data, or both together to find performance trends and root causes.
Observability Analytics is the SQL interface for analyzing trace and log telemetry to discover performance trends and generate aggregate insights. Queries against trace data run against the default _AllSpans view, which includes all trace data stored by the project, and results can be visualized as charts and tables and saved to custom dashboards. This aggregate path is for questions about distributions, latency shifts, and trends over time or across versions. For single-request inspection, use the Trace Explorer page to find and explore individual traces, spans, and span attributes.
| Tool | Data it reads | Choose when |
|---|---|---|
| Logs Explorer | Individual log entries in Cloud Logging | The task is to read one log entry or filter a short time window by fields such as trace ID |
| Trace Explorer | Individual traces, spans, and span attributes in Cloud Trace | The task is to inspect latency and propagation for one request across services |
| Observability Analytics | Log views and the _AllSpans trace view through SQL | The task is to aggregate, compare trends, and chart results across many requests |
| BigQuery Studio through a linked dataset | Log and trace data joined with other BigQuery datasets | The task is to join telemetry with business data, query from outside Observability Analytics, or use reserved slots |
Correlation of trace IDs with structured logs means every log entry emitted during a request carries the same trace identifier as the spans created for that request. Applications create this link by propagating trace context through services, and open instrumentation such as OpenTelemetry is the recommended vendor-neutral way to collect logs, metrics, and traces together. Libraries such as Sqlcommenter extend the same idea to databases by augmenting SQL statements with tags and propagating OpenTelemetry trace context to the database. Once the trace identifier flows from the incoming request to each service, to each connector or ORM call, and to the database, application code can be matched directly to database performance in microservices architectures.
Log entries with embedded trace data enable two-way troubleshooting between logs and traces. Filtering logs by a trace ID isolates every structured event for one distributed transaction, and opening the same identifier in Cloud Trace shows how latency was distributed across each span in that transaction. Because the log entry points to the trace and the span attributes point back to the service and operation, teams can move from an error log to the slow span and then to the source code or query that caused it.
Cloud Logging filtering by trace identifier is the fast path for isolating all structured events that belong to one distributed request. Logs Explorer uses the Logging query language to filter the selected log views by fields such as severity, resource, and trace, so an operator can start from a high-latency trace ID and retrieve only the log entries that share that value. Observability Analytics provides the same correlation through SQL when the question requires aggregation, such as counting errors per service for a set of trace IDs or comparing latency and log patterns over time. Choose Logs Explorer when the goal is to read individual correlated entries, and choose Observability Analytics when the goal is to aggregate correlated logs and spans into trends and tables.
Exam tip: You do not need a linked BigQuery dataset to run SQL on logs or traces in Observability Analytics; you need a linked dataset only to join with other datasets, query from BigQuery Studio, use reserved slots, or alert on log query results.
A linked BigQuery dataset is a BigQuery dataset connected to a log bucket or to trace storage so telemetry can be queried from outside Observability Analytics. Log buckets must have analytics enabled to support SQL analysis, and linked datasets then expose views such as _AllLogs alongside the _AllSpans trace view for long-retention queries. Historical analysis in BigQuery is how teams keep telemetry beyond normal retention and identify repeating patterns and root causes across releases, regions, and services.
A linked dataset is required when the analysis leaves the Observability Analytics page:
Once linked, data flows from the log bucket or trace store to BigQuery, and the BigQuery API can feed query results to dashboards and external systems for continued investigation.
Correlating a shared trace identifier across both views links the end-to-end path and latency in Cloud Trace with timestamped event detail in Cloud Logging. Filtering logs by a trace ID isolates every structured event for one distributed transaction, while opening the same identifier in Cloud Trace shows how latency was distributed across each span so teams can move from an error log to the slow span and then to the source code or query that caused it.
OpenTelemetry is the recommended vendor-neutral framework for creating spans, propagating context on outbound calls, and exporting telemetry to a Google Cloud project. Supported paths include OpenTelemetry with an OTLP exporter to a collector or directly to the project through the Telemetry API, the Ops Agent with an OpenTelemetry Protocol (OTLP) receiver on Compute Engine, direct invocation of the Telemetry API or Cloud Trace API, Spring Boot forwarding through Spring Cloud for Google Cloud, and Cloud Trace client libraries or the Cloud Trace exporter for OpenTelemetry.
A linked BigQuery dataset is not needed to run SQL on logs or traces in Observability Analytics, which queries trace data through the default _AllSpans view and log views directly. A linked dataset is required only to join telemetry with other BigQuery datasets, query from BigQuery Studio, run Observability Analytics queries on BigQuery reserved slots, or monitor log query results with an alerting policy.
Your team manages a multi-tier microservices application running on Google Cloud that is experiencing intermittent latency spikes during high-traffic periods. Distributed tracing is configured across all services, and structured application logs are enriched with standard Google Cloud trace correlation fields.
You need to locate specific slow transactions, inspect the correlated logs for each individual trace span, and perform a historical trend analysis over the past 30 days of log data to identify the downstream database operations causing the degradation.
Which combination of observability tools and query workflows should you implement?
Export trace data from Cloud Trace into Cloud Storage as CSV files, use Dataprep to clean the trace spans, and execute gcloud logging read commands in parallel shell scripts to fetch matching historical logs.
Capture real-time logs by initiating a live tailing session filtered on customer IDs, manually inspect latency distributions in Cloud Monitoring Metrics Explorer, and create a Cloud Monitoring log-based metric for 30-day historical query analysis.
Locate high-latency requests in Cloud Trace, query correlated logs in Cloud Logging using the fully qualified trace="projects/[PROJECT_ID]/traces/[TRACE_ID]" filter, and use BigQuery / Log Analytics to run SQL aggregations across historical log records.
Filter logs in Logs Explorer using custom JSON payload properties such as jsonPayload.trace_id="[TRACE_ID]", inspect trace spans via the Error Reporting console, and export raw logs to Cloud Storage for interactive ad-hoc SQL queries.
Last updated