AutoMerge is generally available

Last updated:

Monitor Pub/Sub

Track Pub/Sub message throughput, publish and acknowledgment latency, backlog size, and subscription health.

Dash0 automatically collects metrics for Pub/Sub topics and subscriptions in your connected GCP projects, providing visibility into message flow, latency, retention, and subscription health.

Pub/Sub topic Overview showing publish request counts and latency charts

Pub/Sub metrics help you understand message processing patterns, identify bottlenecks in your event-driven architecture, and ensure subscribers are keeping up with message volume.

Viewing Pub/Sub Metrics

Navigate to Infrastructure > Google Cloud > Pub/Sub to see all Pub/Sub topics and subscriptions across your connected projects. The view displays:

  • Topic and subscription names with their associated projects and regions
  • Message throughput showing publish and acknowledgment rates
  • Backlog metrics indicating undelivered messages and retention
  • Latency percentiles for message publishing and acknowledgment

Pub/Sub detail view with message rates and latency metrics

Click any topic or subscription to drill into detailed metrics and time-series charts.

Pub/Sub topic Overview showing publish request counts and latency charts

Common Use Cases

Pub/Sub metrics help you maintain reliable message delivery and identify processing bottlenecks. The following examples show practical ways to monitor publisher and subscriber health.

Detecting Message Backlogs

Monitor pubsub.googleapis.com/subscription/num_undelivered_messages and pubsub.googleapis.com/subscription/oldest_unacked_message_age to identify subscriptions falling behind:

promql
# Subscriptions with backlogs over 1000 messages
{otel_metric_name="pubsub.googleapis.com/subscription/num_undelivered_messages"} > 1000

# Subscriptions with messages older than 5 minutes
{otel_metric_name="pubsub.googleapis.com/subscription/oldest_unacked_message_age"} > 300

Pub/Sub topic Overview with publish charts and a subscription table containing Undelivered messages and Backlog bytes columns

Growing backlogs suggest:

  • Consumers are processing messages too slowly
  • Consumer instances have crashed or scaled down
  • Message processing errors are causing excessive retries
  • Traffic spikes have exceeded consumer capacity

Monitoring Publisher Performance

Track pubsub.googleapis.com/topic/send_request_count and pubsub.googleapis.com/topic/send_request_latencies to understand publisher behavior:

promql
# Publish rate by topic
sum by (topic_id) (rate({otel_metric_name="pubsub.googleapis.com/topic/send_request_count"}[5m]))

# High latency topics (99th percentile)
histogram_quantile(0.99, sum by (le, topic_id) (rate({otel_metric_name="pubsub.googleapis.com/topic/send_request_latencies"}[5m]))) > 0.5

High publish latency may indicate:

  • Network congestion between publishers and Pub/Sub
  • Large message sizes slowing down transmission
  • Pub/Sub quotas being reached
  • Regional capacity constraints

Analyzing Message Retention

Use pubsub.googleapis.com/topic/num_retained_messages and pubsub.googleapis.com/topic/oldest_retained_message_age to understand retention patterns:

promql
# Topics with significant retained messages
{otel_metric_name="pubsub.googleapis.com/topic/num_retained_messages"} > 10000

# Topics retaining old messages
{otel_metric_name="pubsub.googleapis.com/topic/oldest_retained_message_age"} > 86400  # 24 hours

High retention counts may indicate:

  • Subscriptions not consuming messages fast enough
  • Dead letter queues accumulating failed messages
  • Misconfigured retention policies
  • Cost implications from long-term message storage

Tracking Consumer Health

Monitor acknowledgment patterns to assess consumer health:

promql
# Acknowledgment rate by subscription
sum by (subscription_id) (rate({otel_metric_name="pubsub.googleapis.com/subscription/ack_message_count"}[5m]))

# High negative acknowledgment rate (processing failures)
rate({otel_metric_name="pubsub.googleapis.com/subscription/nack_requests"}[5m]) > 10

High nack_requests rates suggest:

  • Application errors during message processing
  • Invalid message formats or corrupted data
  • Timeouts in downstream dependencies
  • Resource constraints causing processing failures

Identifying Slow Consumers

Compare pubsub.googleapis.com/subscription/ack_latencies across subscriptions to find slow consumers:

promql
# Slowest subscriptions by acknowledgment latency (99th percentile)
topk(5, histogram_quantile(0.99, sum by (le, subscription_id) (rate({otel_metric_name="pubsub.googleapis.com/subscription/ack_latencies"}[5m]))))

High acknowledgment latency indicates:

  • CPU-intensive message processing
  • Blocking I/O operations in consumer code
  • Inefficient database queries or API calls
  • Insufficient consumer instances to handle load

Correlating with Application Telemetry

Pub/Sub metrics become more actionable when correlated with application-level telemetry:

  • Traces showing message publishing and consumption spans
  • Logs from publishers and subscribers
  • Custom metrics tracking business logic outcomes

When investigating Pub/Sub issues, pivot from infrastructure metrics to application traces to understand the full message lifecycle.

Tip

Instrument your Pub/Sub publishers and subscribers with OpenTelemetry to emit traces with the messaging.system, messaging.destination, and messaging.operation attributes. Dash0 will correlate these with infrastructure metrics. See Messaging Semantic Conventions for details.

Querying Pub/Sub Metrics

Metrics are stored using their GCP Cloud Monitoring metric type names and can be queried using otel_metric_name in PromQL.

Use PromQL in the Query Builder to create custom Pub/Sub dashboards:

promql
# Message throughput by topic
sum by (topic_id) (rate({otel_metric_name="pubsub.googleapis.com/topic/send_request_count"}[5m]))

# Subscription backlog growth rate
deriv({otel_metric_name="pubsub.googleapis.com/subscription/num_undelivered_messages"}[10m])

# Consumer lag (oldest unacknowledged message age)
max by (subscription_id) ({otel_metric_name="pubsub.googleapis.com/subscription/oldest_unacked_message_age"})

# Acknowledgment success rate
sum(rate({otel_metric_name="pubsub.googleapis.com/subscription/ack_message_count"}[5m]))
/
(sum(rate({otel_metric_name="pubsub.googleapis.com/subscription/ack_message_count"}[5m])) + sum(rate({otel_metric_name="pubsub.googleapis.com/subscription/nack_requests"}[5m])))

All Pub/Sub metrics include the following labels:

  • topic_id — The Pub/Sub topic name
  • subscription_id — The subscription name (for subscription metrics)
  • project_id — The GCP project ID

Best Practices

Apply these recommendations to maintain reliable message delivery and effective monitoring.

  • Monitor both topics and subscriptions: Publisher and consumer issues manifest differently in metrics
  • Set appropriate retention policies: Balance message durability with storage costs
  • Track message sizes: Large messages impact throughput and costs
  • Use dead letter queues: Prevent poison messages from blocking subscriptions
  • Correlate with application traces: Infrastructure metrics show what is slow, traces show why

Further Reading