Prepare and test your skills
Prepare and test your skills
Instrumenting code for troubleshooting means adding metrics, logs, and traces that Google Cloud Observability (opens in a new tab) can join into one diagnostic story. Metrics show numeric behavior over time, logs show event context, and traces show latency across services. Shared identifiers such as trace IDs and service labels let the three signals be investigated together.
Cloud Trace is a distributed tracing system that collects latency data and shows it in near real time in the Google Cloud console. A trace follows one request across microservices, and each trace is made of spans where each span records one operation inside that request. By joining all spans for a request, Cloud Trace shows request propagation, service dependencies, and where time was spent.
Trace visualization shows the path of a request as a Gantt chart in Trace Explorer, where each span shows start time, duration, attributes, and metadata. Traffic flows from an upstream service through its sidecar proxy to a downstream service, and Cloud Service Mesh builds a service topology graph from that proxy telemetry. Selecting a span reveals which service or database operation added latency, so operators can see slow edges without manually stitching spans together.
Manual span instrumentation adds code that starts a span, adds attributes, and ends the span around important operations. Instrumented code creates a trace ID for the whole request and a span ID for each operation, then forwards that trace context from the upstream service to each downstream service. Sampling controls what fraction of requests produce traces, so a gRPC cloud_trace.sampling_rate of 0.5 randomly traces 50% of remote procedure calls. If any service fails to propagate context downstream, the chain breaks into disconnected fragments.
Exam tip: A complete end-to-end trace requires every service to propagate trace context downstream; a sampling rate of 0.5 means only 50% of RPCs are traced.
Structured logging with Cloud Logging is the practice of writing application logs as structured JSON with consistent severity and metadata. Cloud Logging stores, searches, analyzes, monitors, and alerts on log data, while Error Reporting aggregates repeated errors into groups. Log data flows from the instrumented application to Cloud Logging, where entries are stored as JSON objects with named fields instead of plain text.
Each structured entry carries fields that support filtering and correlation in Logs Explorer. The severity field such as INFO controls filtering, the resource object identifies where the log originated such as a k8s_container with cluster, namespace, pod, and container names, and the httpRequest object captures method, URL, status, latency, and protocol. Labels carry service-aware attributes such as source and destination workload, canonical service, route_name, and upstream_cluster. When tracing is enabled, the same entry also carries trace, spanId, and traceSampled, so a log line points directly to its distributed trace.
Custom metrics are numeric time-series measurements defined in application code to track domain-specific behavior. Unlike system metrics such as CPU, memory, and disk usage that Google Cloud collects automatically, custom metrics show what happens inside application logic such as function latency, queue depth, or checkout failures. Custom metrics are stored in the Google Cloud project and become queryable time series for Metrics Explorer charts, custom dashboards, and alerting policies in Cloud Monitoring.
Developing custom metrics means adding instrumentation that measures behavior and attaches context. OpenTelemetry is the recommended vendor-neutral framework with a standardized data model for traces and metrics, so telemetry can be sent to Google Cloud or other vendors without rewriting code. For databases, the Sqlcommenter library augments SQL statements with tags and propagates trace context, which correlates application code with database performance.
Exporting metrics moves telemetry from the application process to metric storage in the project. The ordered flow is first generate data points with labels in process, then export them through an exporter, then store the time series in the project where the metrics scope controls what can be charted. The collector depends on platform:
| Platform | Collector | Use when the service writes |
|---|---|---|
| Compute Engine | Ops Agent with OTLP and Prometheus receivers | OTLP, Prometheus, or third-party application metrics |
| Google Kubernetes Engine (GKE) | Google Cloud Managed Service for Prometheus | Prometheus-format user metrics and exporter metrics |
| Cloud Run | Prometheus sidecar or OpenTelemetry sidecar | Prometheus metrics with the Prometheus sidecar, OTLP metrics with the OpenTelemetry sidecar |
Log and metric instrumentation for reliable diagnostics aligns business goals to measurable technical signals in Cloud Monitoring and Cloud Logging. Each business key performance indicator such as revenue or engagement maps to reliability metrics like success rate, latency, harmful-output rate, and task-completion rate. Those metrics are quantified as service-level objectives from the user's perspective, for example 99.9% successful API calls, 95th percentile latency below 300 ms, time to first token below 500 ms for 99% of requests, and harmful output below 0.1%.
Application health is tracked with the four golden signals: latency as time to respond, traffic as request volume, error rate as failed operations, and saturation as utilization of CPU, memory, GPU, or TPU. Metrics from serving frameworks such as vLLM or NVIDIA Triton Inference Server flow into Cloud Monitoring through Managed Service for Prometheus, while detailed accelerator signals flow from tools such as NVIDIA Data Center GPU Manager. Cloud Profiler (opens in a new tab) complements metrics, logs, and traces by identifying bottlenecks within function blocks to optimize resource usage and execution time.
Context propagation and signal correlation carries request identity across services so metrics, logs, and traces for the same work can be joined. An upstream service starts or receives trace context and passes it downstream, while each service adds labels such as SERVICE_NAME, SOURCE_VERSION, and DATA_CENTER. Google Cloud Observability then joins the signals in Monitoring, Logging, and Trace, so a slow request, its log lines, and its latency breakdown share the same identifiers.
Correlation identifiers join a log entry to its trace, including trace as the full trace name, spanId as the operation identifier, traceSampled as the retention flag, and request_id that stays constant from ingress gateway to destination workload. Traffic flows from the ingress gateway to the destination workload, and the log records both sides through labels such as source and destination canonical service. Observability Analytics extends correlation by querying log views and the _AllSpans trace view with SQL to join logs to spans on the shared trace identifier, such as finding requests over 5 seconds or with 404 and 503 errors.
Identifying and resolving issues with Google Cloud Observability means turning metrics, logs, traces, and profiles into dashboards, alerts, and root-cause analysis. Metrics flow into Cloud Monitoring for health views, logs flow into Cloud Logging for event context, traces flow into Cloud Trace for latency, and profiles show code-level cost. Together they support proactive detection before users report widespread impact.
Monitoring and alerting strategies in Cloud Monitoring turn service behavior into dashboards and timely alerts. Dashboards visualize health and performance from infrastructure and application metrics, and alerting policies notify operators when thresholds or service-level objectives are at risk. This loop depends on clear reliability targets so live behavior can be compared against good service.
Reliability goals connect business outcomes to technical targets for availability, throughput, error rate, and latency. Example targets from reliability guidance (opens in a new tab) include 99.9% successful API calls, 95th percentile inference latency below 300 ms, time to first token below 500 ms for 99% of requests, and harmful output below 0.1%. SLO monitoring (opens in a new tab) supports Cloud Service Mesh, Istio on GKE, App Engine, Cloud Endpoints, and custom services for GKE with no code changes.
The four golden signals are latency as time to respond, traffic as request volume, error rate as failed operations, and saturation as utilization of CPU, memory, GPU, or TPU. The 99th percentile is often more informative than the average because averages hide poor experiences for a meaningful share of requests. Alerting policies compare a metric to a threshold, such as filtering logging.googleapis.com/log_entry_count by severity ERROR for App Engine error rate, or alert on SLO burn rate when the goal is protecting the objective rather than firing on every spike.
Exam tip: Filter logging.googleapis.com/log_entry_count by severity ERROR to alert on error rate, and use SLO burn-rate alerts to protect the SLO rather than firing on short spikes.
Trace and profiler analysis uses two complementary signals to find why an application is slow. Cloud Trace shows where time is spent as a request travels across distributed services, while Cloud Profiler (opens in a new tab) shows which function blocks inside the code consume the most resources. Together they connect outward latency with inward resource use so fixes target the true bottleneck.
Cloud Trace displays each request as a trace made of spans, where the parent bar shows total request duration and child bars show network and server latency for each downstream step. Common patterns appear as shapes in the waterfall view: a gap before a child span means the thread waited for a TCP connection from the pool, a gap after a child span means the application struggled to parse a large payload, and multiple short child spans for the same command suggest retries from packet loss or transient failures. To examine a trace, open Trace explorer, select the project, pick a recent trace dot, then read parent and child spans in order.
Choosing between the tools depends on the question. Cloud Trace fits high latency that may span services, networks, pools, or retries, while Cloud Profiler fits high CPU, memory, or execution time inside application code. Cloud Monitoring ties both to dashboards and alerts on the four golden signals, and a sampled database query can link outward through its End-to-end Trace tab with View in Cloud Trace.
Logging and error reporting for failure diagnosis finds what broke, where it broke, and which defect to fix first. Cloud Logging ingests log entries through the Cloud Logging API and makes them searchable in Logs Explorer, while Error Reporting groups exceptions so teams prioritize the most impactful defect. Metrics, traces, and profiles add system health context around the failure.
The logging pipeline depends on three controls: the Cloud Logging API must be enabled, the node service account must have permission to write logs, and no exclusion filter may drop entries before storage. Application containers should write to stdout or stderr, and the agent forwards those entries to the API. Permission errors such as 401 or 403 point to missing service-account permission, while RESOURCE_EXHAUSTED points to exceeded write quota, while consistently missing patterns often mean an exclusion filter, restrictive query, or expired retention.
Verifying compute signals confirms whether failure comes from code or exhausted infrastructure. The Ops Agent exposes full instance metrics, and the console path runs from VM Instances to the instance Details page to the Observability tab. There teams review CPU, memory, network traffic, disk throughput, and IOPS, plus network destinations, packet size, denied firewall packets, I/O size, queue length, and latency. For GKE, teams also verify cluster logging configuration, node pool scopes, node pressure, and container buffering that delays output until exit.
Continue with this study guide: Identifying and resolving issues using Google Cloud Observability
Managing application issues with Error Reporting (opens in a new tab) means moving each defect from first detection to resolved fix through grouped analysis. Error events flow from applications to Cloud Logging and then to Error Reporting, or directly from client libraries to the Error Reporting API. The Error Reporting dashboard lists each error group with health, recurrence, and impact so related crashes are handled once.
Error group lifecycle management treats an error group as the unit of tracking, where one group collects individual events that share the same root cause. The Error Reporting page lists groups with error names for the failure signature, resolution status for lifecycle state, HTTP codes for user impact, and occurrences over time for frequency. Viewing the list requires the Error Reporting Viewer role on the project, and a message to set up Error Reporting means no groups exist yet.
Tracing a group back to logs connects a sample to its exact stored entry. From the Recent samples pane, View Logs opens Logs Explorer filtered by errorGroups.id="ERROR_GROUP_ID" for that group. Only log entries stored in a log bucket carry the errorGroups field populated by the bucket destination, while data only sent to a project or routed by sinks does not. Filtering narrows the dashboard by status, affected resource such as Kubernetes service and version, region of the log buckets, and free text, so responders focus on urgent resources first.
Error Reporting mechanisms get crashes from running code into centralized analysis through two paths. Direct reporting sends events through the Error Reporting API with a language library, while automatic inference reads qualifying log entries from Cloud Logging without added code. The correct path depends on encryption, log routing, and whether custom events are needed.
| Reporting path | How errors travel | Choose when |
|---|---|---|
| Direct with client library | Application calls the API through a language library | Bucket uses customer-managed encryption keys (CMEK) or custom events are needed |
| Automatic from Cloud Logging | Application writes logs, Error Reporting reads them | App runs on an integrated service with a non-CMEK bucket owned by the originating or destination project and correctly formatted logs |
Sending errors directly uses libraries such as the Error Reporting package for Java (opens in a new tab), Python, Node.js (opens in a new tab), and Ruby packages, which create groups without depending on log parsing. Automatic inference works on Cloud Run functions, App Engine, Compute Engine, and GKE when entries follow error formatting and sit in a non-CMEK bucket owned by the originating or destination project. On Compute Engine, the Ops Agent collects log files with a logging receiver paired with parse_multiline for text or parse_json for JSON, while the legacy google-fluentd agent reached end of support on September 28, 2026.
Exam tip: A log bucket with customer-managed encryption keys (CMEK) blocks automatic inference from Cloud Logging, so use a language-specific client library to report those errors directly.
Error grouping logic aggregates error events by root cause instead of listing every log line separately. An error event is a single crash at a point in time, while an error group collects recurring instances that share error name, message, and stack-trace pattern. When new events match an existing pattern, the occurrence count grows rather than creating a new group.
Complete exception data determines grouping quality, and the most important rule is that one error including all stack-trace frames must be contained in the same log entry. Structured JSON can carry message, service context, and metadata together, while split entries may not be detected or may group incorrectly. The Error Group Details page shows history, occurrence count, resolution status, and timestamped samples with links to logs and stack traces, so prioritization focuses on rising counts, persistent failures, and critical HTTP codes.
Continue with this study guide: Managing application issues using Error Reporting
Using trace IDs to correlate spans means giving every operation for one request the same trace ID so Cloud Trace can join them. A trace is a group of spans that share one unique trace ID, while each span measures one discrete operation such as a database query, API call, or business logic. In the Trace console the correlated spans appear as a waterfall graph for end-to-end latency analysis.
Application instrumentation and span management adds tracing code so each request produces timed spans under one trace ID. Parent spans represent outer operations such as an incoming Cloud Run request, and child spans represent inner work such as a downstream call that runs before the parent completes. All spans carry the same trace ID, so Cloud Trace correlates spans from disparate services into one view when trace context is propagated correctly.
Automatic tracing in Cloud Run gives a baseline without code changes, where incoming requests generate traces and the W3C traceparent header is populated for forwarding. Automatic traces show only the outer request, so instrumentation is added for granular insight such as timing a Cloud Translation API call or showing flow across services. Cloud Run samples automatic traces at most 0.1 requests per second per instance, about one every 10 seconds, with no configuration, while a forced request raises the limit to about 10 per second per instance. Automatically generated traces incur no charge, while custom spans correlated to them incur standard ingestion charges.
Span correlation with trace IDs links spans from different services into a single distributed trace. Context travels in the traceparent header, so first the upstream service sends the trace ID outbound, then the downstream instrumented service creates its spans under the same ID. Only after both sides share the ID does the console join their spans into one waterfall view, which makes missing propagation appear as broken traces.
Diagnostic spans measure time inside each layer, including database query time, API response time, and complex business logic time. Instrumentation libraries automatically create spans at RPC boundaries, and custom spans with labels cover operations that would otherwise stay invisible. Each client-side span adds timestamps for RPC send and receive including network latency, attributes as key-value pairs for client configuration, event logs, and stack traces on crash. Reading the waterfall graph exposes long child spans as service bottlenecks and gaps as network or queuing delay, while comparing many requests exposes outliers.
Exam tip: Automatic Cloud Run traces show single-service latency for free, but showing one request across multiple services as a single trace requires instrumentation that propagates trace context.
Trace context propagation passes tracing identity from service to service so all work for one request shares a unified ID. Propagation relies on standard HTTP headers carried with each request, and Cloud Trace groups spans with that ID into one end-to-end view. Without propagation each service creates an isolated trace, while with propagation synchronous calls and asynchronous paths appear as one flow.
The recommended export path uses vendor-neutral OpenTelemetry with an OTLP exporter that sends data to a collector alongside the application. The ordered flow is application export in OTLP format to the collector, collector processing with batching, retries, and encryption, then backend export to the project through the Telemetry API. This order keeps the application fast because delivery work moves to the collector. Other paths include direct OTLP to the project when no collector can run, and Ops Agent with OTLP receiver on Compute Engine when logs and metrics collection are also needed, though the Ops Agent does not collect logs through OTLP. Cloud Profiler (opens in a new tab) complements this path by explaining resource use inside functions that traces show as slow.
Continue with this study guide: Using trace IDs to correlate trace spans across services
AI-assisted observability uses machine learning and generative AI on top of telemetry to detect anomalies, summarize logs, and correlate failures. Cloud Monitoring evaluates predictive rules against baselines, Cloud Logging provides entries for summarization and querying, and Error Reporting groups related failures. The workflow depends on clear reliability targets so live behavior can be compared against good service.
AI-assisted anomaly detection learns normal baseline performance and flags deviations before outages. Business indicators such as revenue, churn, or assistant satisfaction map to technical metrics like success rate, latency, time to first token, token streaming rate, and harmful-response rate, quantified as SLOs such as 99.9% success, 95th percentile latency below 300 ms, time to first token below 500 ms for 99% of requests, and harmful output below 0.1%. Core signals are latency, traffic, error rate, and saturation of CPU, memory, GPU, or TPU, plus infrastructure metrics for processor, memory, network, and disk across managed and self-managed resources.
Predictive alerts in Cloud Monitoring compare live metrics against thresholds that signal future disruption over sustained windows, typically 5 minutes. For GKE Inference Gateway, Prometheus rules in YAML migrate into Cloud Monitoring with gcloud monitoring policies migrate. Common conditions include 99th percentile latency above 10.0 seconds, error rate above 5%, average pending queue above 50, and average KV cache utilization above 0.9. When queue or cache stays high, traffic still flows from the load balancer to the inference pool but waits longer, so operators add capacity, reroute with load balancing, or fall back to simpler models before errors spike.
Governed response keeps mitigation safe with human oversight. AI agents parse diagnostics to suggest causes and generate structured action payloads, but models are prohibited from executing commands directly without validation and explicit human confirmation. All AI actions are recorded in immutable audit logs, while fault isolation with circuit breakers and redundancy across zones, regions, and multi-regional storage preserves availability.
Exam tip: AI models suggest resolutions and generate structured action payloads, but they are prohibited from executing commands directly without validation checks and explicit human confirmation.
AI-powered log summarization and natural language querying uses generative AI inside Cloud Logging to understand logs faster. Cloud Logging collects, stores, analyzes, and alerts on log data where each log is a collection of timestamped entries describing specific events. Metric data shows numeric health over time while trace data shows request paths, and Error Reporting analyzes log entries to create groups with cause and history.
Summarization condenses many complex entries into a short explanation that highlights key events, error patterns, and the likely affected component while preserving sequence and removing noise. The summary depends on complete structured logs, so after reviewing it the developer pivots back to source entries in Logs Explorer to verify severity and follow trace links. Natural language querying translates a plain-language request into a structured filter or analytics query that runs against stored logs, which lowers the barrier to retrieval without memorizing field names. The generated query can be inspected and rerun, then extended to Metrics Explorer charts and Cloud Trace paths.
Automated error analysis groups related failures and correlates signals to surface recurring patterns. Error Reporting aggregates similar stack traces and messages into a single issue with count, history, and affected versions, which shows whether an error is new, recurring, or growing. Machine-learning models then correlate alerts, logs, and traces into one failure story across microservices.
The work moves through an ordered sequence with human oversight: first identification where models analyze and correlate events, then investigation where agents parse logs and traces to recommend causes without changing the system, then resolution where generated payloads require validation and confirmation before applying. Pattern recognition depends on consistent signals from Cloud Profiler (opens in a new tab) for code bottlenecks, Cloud Trace for request flow, Cloud Monitoring for trends and alerts, and Cloud Logging for event context. Together they connect saturation to errors, errors to slow traces, and traces to specific code blocks.
Continue with this study guide: Using AI-assisted observability
trace, spanId, and traceSampled together.Metrics show numeric behavior over time, logs show event context, and traces show latency across services. Shared identifiers such as trace IDs and service labels let the three signals be investigated together in Cloud Monitoring, Cloud Logging, and Cloud Trace.
Use direct reporting through the Error Reporting API with a language library when the log bucket uses customer-managed encryption keys (CMEK) or when custom events are needed. Use automatic inference when the application runs on an integrated service with correctly formatted logs in a non-CMEK bucket owned by the originating or destination project.
A log entry links to Cloud Trace only when it carries trace, spanId, and traceSampled together. In that combination, trace is the full trace name, spanId is the operation identifier, and traceSampled is the retention flag, so the log line points directly to its distributed trace.
Last updated