Tutorials Logic, IN info@tutorialslogic.com

Google Cloud Observability: Metrics, Logs, Traces, and Alerts

Observability Model

Cloud Monitoring collects platform and application metrics, while Cloud Logging stores structured records from services and workloads. Traces, error groups, audit logs, uptime checks, dashboards, and alert policies connect those signals to investigation and response.

Useful observability answers whether users are succeeding, which dependency explains a failure, and what changed. Collecting every available field without retention and routing decisions can produce noise and cost without improving diagnosis.

Service Objectives and Signals

For an API, begin with successful request ratio and latency at a meaningful percentile. Add traffic, saturation, dependency failures, and backlog age only when they explain the user-facing objective.

An alert needs a condition, duration, notification route, owner, severity, runbook, and recovery behavior. Page on actionable symptoms; route slower capacity or cost trends to planned work.

Incident-Ready Logs

Emit structured fields for severity, service, revision, trace or correlation ID, operation, outcome, and safe identifiers. Never log passwords, tokens, signed URLs, payment data, or unrestricted request bodies.

Log-based metrics can count a stable event that is not already a native metric. Keep label cardinality bounded; user IDs, random request IDs, and raw error messages make expensive metric labels.

Count Cloud Run server errors from logs

Count Cloud Run server errors from logs
gcloud logging metrics create orders_api_5xx \
  --description="Cloud Run 5xx responses for orders-api" \
  --log-filter='resource.type="cloud_run_revision"
resource.labels.service_name="orders-api"
httpRequest.status>=500'

gcloud logging metrics describe orders_api_5xx
  • Use a service filter so unrelated Cloud Run errors do not affect the signal.
  • Create an alert policy separately with an owner and tested notification channel.

Telemetry Governance

Log exclusions reduce stored volume but should not remove evidence required for security, compliance, or incident response. Log buckets, retention, views, sinks, and analytics routing determine where records live and who can inspect them.

Test alerts by creating a known failure, then verify detection, notification, runbook accuracy, and automatic closure. A dashboard that no one opens during an incident is documentation, not a response system.

Signals and Telemetry Model

Cloud Monitoring stores numeric time series identified by metric type, resource type, labels, and time. Cloud Logging stores structured log entries, Cloud Trace follows request spans, Error Reporting groups application errors, and Profiler samples runtime behavior for supported environments. These products overlap during investigation but answer different questions; collecting one does not automatically create the others.

Start from a user journey and propagate a trace or correlation identifier through ingress, service calls, events, and jobs. Emit structured fields for service, version, environment, tenant-safe identifier, operation, result, duration, and retry count. Keep sensitive data, credentials, and unbounded payloads out of labels and logs. High-cardinality metric labels can create cost and operational problems, while logs are more suitable for detailed identifiers.

Use OpenTelemetry or supported agents when portability and consistent instrumentation matter, but define semantic conventions and ownership before deploying collectors. A telemetry pipeline also has buffers, quotas, credentials, sampling, and failure modes. Monitor dropped spans, rejected log entries, delayed metrics, and collector saturation so an outage does not silently erase the evidence needed to diagnose it.

  • Use metrics for trends and alerts, logs for event detail, and traces for causal latency.
  • Standardize resource, service, release, and environment attributes.
  • Redact sensitive fields before telemetry leaves the process.
  • Test observability delivery during network and quota failures.

SLIs, SLOs, and Alerts

A service-level indicator measures behavior users care about, such as successful checkout ratio or request latency below a threshold. A service-level objective sets the acceptable target over a window, and the error budget represents tolerated unreliability. Availability of a VM is not a substitute for success of the user journey when DNS, load balancing, code, database, and payment dependencies can fail independently.

Alert on symptoms that require action. Multi-window burn-rate alerts detect both rapid budget consumption and slower sustained degradation. Pair them with capacity and dependency alerts that warn before impact when operators have a clear response. Every page should identify the service, condition, user effect, dashboard, recent change, runbook, and escalation owner.

Test alert logic by injecting known failures and checking detection time, routing, grouping, silence behavior, and recovery notification. Avoid thresholds copied from another service without a baseline. For low-volume services, a ratio can swing wildly from one request, so use minimum-event conditions, synthetic checks, longer windows, or absolute error evidence as appropriate.

  • Define success from the consumer perspective.
  • Version SLO calculations and dashboard queries with the service.
  • Give every alert an owner and an executable first action.
  • Review pages that never fire and pages that fire without action.

Logs, Routing, and Retention

Log buckets define location, retention, and access behavior. Sinks route matching entries to another log bucket, BigQuery, Cloud Storage, or Pub/Sub. Centralize security and platform evidence in a protected project where workload administrators cannot erase the only copy. Sink writers need explicit destination access, and an exclusion at the wrong scope can remove data before it reaches a downstream destination.

Choose retention by investigation, legal, privacy, and cost requirements. Keep high-volume debug logs for a shorter period than audit evidence when appropriate. Log-based metrics turn matching entries into time series but inherit the quality and cardinality of the filter and labels. Test the filter against positive and negative fixtures before using it for a security alert.

During incident review, correlate deploy markers, audit changes, user-facing SLI changes, dependency latency, resource saturation, and representative traces. Preserve raw evidence before transforming it. A dashboard should accelerate a hypothesis, not hide query definitions or replace a timeline. Record timezone, query window, project, resource type, and filters so another operator can reproduce the result.

  • Protect centralized sinks and destination retention from workload owners.
  • Track ingestion and storage cost by log source.
  • Use exclusions only after proving the data has no operational value.
  • Reproduce incident queries before closing the review.

Incident and Dashboard Workflow

A useful dashboard follows the system path: traffic, errors, latency, saturation, release, dependencies, backlog, and business outcome. Separate overview, service diagnosis, and capacity planning views instead of placing every metric on one screen. Annotate deployments and policy changes, and keep units and aggregation explicit. Averages can hide a failed zone or a small group of users, so include distributions and breakdowns that support action.

At incident start, establish impact, scope, start time, current hypothesis, incident commander, communications owner, and next decision. Stabilize the service through rollback, traffic shift, capacity change, feature disablement, or dependency isolation, then preserve evidence. Do not make several untracked configuration changes at once; each change should have an expected signal and rollback.

After recovery, build a factual timeline, identify contributing technical and organizational conditions, and assign corrective actions with owners and verification. Track time to detect, acknowledge, mitigate, and fully recover. Confirm that the new alert or runbook would have changed the outcome by replaying the scenario; otherwise the action merely creates documentation.

  • Make dashboards answer a decision, not display available data.
  • Mark releases and experiments on service-level charts.
  • Keep incident actions timestamped and reversible.
  • Verify corrective controls with a game day.

Telemetry Cost and Quality

Observability volume is an architecture input. Estimate log bytes, metric time series, trace spans, retention, exports, and query patterns per request or job. A burst of repeated stack traces or an unbounded tenant label can increase cost precisely during an incident. Apply sampling and rate limits without removing rare security or failure evidence.

Create a telemetry quality dashboard for rejected entries, ingestion delay, collector drops, missing release labels, malformed structured logs, trace sampling, and noisy sources. Review the top volume and cardinality contributors with service owners. Reduce redundant success logs before shortening all retention indiscriminately.

Test that dashboards and alerts survive a project move, service rename, new resource type, or label change. Queries that silently return no data are more dangerous than visibly broken charts. Add synthetic telemetry fixtures or post-deployment assertions for critical alert paths.

Set ownership for custom metric descriptors and log-based metrics. Removing a label or changing its type can break dashboards and alerts, while abandoning obsolete descriptors leaves confusing series. Treat telemetry schema changes like API changes: review consumers, deploy compatibly, observe both versions, and retire the old form deliberately.

  • Track telemetry cost per service and business unit.
  • Cap unbounded labels and repeated error output.
  • Alert when expected telemetry disappears.
  • Preserve high-value evidence during volume reduction.
  • Review sampling policy after traffic-shape changes.
  • Confirm audit evidence bypasses application sampling.

Observability Examples

Build an SLO Burn-Rate Alert

A service meets average availability but consumes its monthly error budget during short incidents.

Build an SLO Burn-Rate Alert
Constraints: Alerts should detect fast and slow burns without paging on isolated errors.
Decision: Define a request-based SLI and combine short and long windows for burn-rate notification and paging.
Verification: Controlled failures trigger the intended severity and the alert links to traces, logs, and the service runbook.
Failure test: Generate one isolated failure and confirm it does not page.
Output
Expected evidence: Controlled failures trigger the intended severity and the alert links to traces, logs, and the service runbook.
  • This is a worked engineering decision, so the result is operational evidence rather than terminal output.
Before you move on

Google Cloud Observability: Metrics, Logs, Traces, and Alerts Mastery Check

5 checks
  • User-facing availability and latency objectives have measurable indicators.
  • Alerts have owners, runbooks, tested channels, and low false-positive rates.
  • Structured logs exclude secrets and high-cardinality metric labels.
  • Retention, exclusions, sinks, access, and regional requirements are documented.
  • A failure drill proves that signals lead an operator to the responsible dependency.

Google Cloud Questions Learners Ask

No. Alert on sustained or high-impact symptoms. Individual expected failures are usually better investigated through aggregated metrics, logs, and traces.

Many services publish platform metrics without an agent. VM and application telemetry may require the Ops Agent, OpenTelemetry, or explicit instrumentation.

Next Step
Next Practice

Finish the concept here, then reinforce it with hands-on coding, interview prep, or a tool that matches the topic.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.