Google Cloud

Cloud Trace / Cloud Profiler Complete Guide: Distributed Tracing, APM, and OpenTelemetry on GCP

2026-05-24
NicheeLab Editorial Team

Cloud Trace and Cloud Profiler are GCP's APM (Application Performance Monitoring) components. Trace provides distributed request tracing, while Profiler provides function-level profiling. OpenTelemetry integration lets you instrument your code with the industry standard.

Cloud Trace

Key Features

  • Distributed tracing (request tracking across microservices)
  • Timeline view of spans (units of work)
  • Automatic latency distribution (P50 / P95 / P99)
  • Latency anomaly detection (Insights)
  • OpenTelemetry / OpenCensus support

OpenTelemetry Instrumentation Example (Python)

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.cloud_trace import CloudTraceSpanExporter

trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
    BatchSpanProcessor(CloudTraceSpanExporter())
)

tracer = trace.get_tracer(__name__)

@app.route('/order')
def create_order():
    with tracer.start_as_current_span("validate_order"):
        validate()
    with tracer.start_as_current_span("save_to_db"):
        save()
    with tracer.start_as_current_span("send_notification"):
        notify()
    return {"status": "ok"}

Cloud Profiler

Key Features

  • Function-level CPU usage profiling
  • Heap (memory) profiling
  • Flame Graph visualization
  • Low overhead (safe to run continuously in production)
  • Languages: Java / Python / Go / Node.js
  • Pricing: completely free

Setup Example (Python)

# pip install google-cloud-profiler

import googlecloudprofiler

googlecloudprofiler.start(
    service='my-api',
    service_version='1.0.0',
    verbose=3,  # 0=quiet, 4=verbose
)

Pricing

ServicePricing
Cloud Trace$0.20 per 1M spans (beyond free tier)
Cloud Trace free tier2.5M spans/month
Cloud ProfilerCompletely free
Error ReportingCompletely free

Sampling Strategy

Endpoint TypeRecommended Sample Rate
Critical API (payments, etc.)1.0 (100%)
Standard API0.1 (10%)
Health Check0.0 (excluded)
On error1.0 (Always sample on error)

OpenTelemetry Integration Best Practices

  • Instrument with the SDK → send via the OTel Collector or directly to Cloud Trace
  • Use auto-instrumentation to cover HTTP / gRPC / DB with zero code changes
  • Split views by environment using service name / version
  • Propagate trace context (W3C TraceContext) for cross-service tracking
  • Attach resource attributes such as k8s.cluster.name / cloud.region

Typical Use Cases

  • Pinpoint latency bottlenecks across microservices
  • Investigate production performance regressions
  • Drill down when SLOs are breached
  • Detect regressions after new releases
  • Cost optimization (CPU hot spots → refactoring)

Comparison with Other APM Tools

CapabilityTrace + ProfilerAWS X-RayDatadog APMNew Relic APM
Distributed tracingExcellentExcellentExcellentExcellent
ProfilerExcellentGoodGood
OpenTelemetryExcellentGoodExcellentExcellent
PricingVery cheapCheapExpensiveMid-range
UISimpleStandardFeature-richFeature-rich

What is the difference between Cloud Trace and Cloud Profiler?

Trace = distributed request tracing (where time is being spent), Profiler = function-level CPU / memory usage (why it is slow). Use both together for full APM coverage.

Is OpenTelemetry supported?

Both have native support. Instrument with the OpenTelemetry SDK → send via the OTel Collector or directly. The standard approach for avoiding vendor lock-in.

What is the pricing model?

Trace: 2.5M spans/month free, $0.20 per 1M spans beyond that. Profiler: free. Extremely cheap, so always-on across all environments is the standard practice.

What is the Cloud Trace retention period?

30 days. Export to BigQuery if you need longer-term analysis.

How does it differ from Error Reporting?

Error Reporting = automatic grouping of application errors plus notifications. It is a separate APM component from Trace / Profiler.

How does it compare to AWS X-Ray / Datadog APM?

Functionality is roughly equivalent. The Trace + Profiler combination delivers Datadog APM-equivalent coverage at low cost. X-Ray has strong Lambda integration.

How should sampling be configured?

Default is 0.1 QPS. In production, adaptive sampling is recommended. Use 1.0 (always sample) for critical endpoints and 0 (exclude) for health checks.

Which languages are supported?

Java / Python / Go / Node.js / Ruby / PHP / .NET. Any language is supported via the OpenTelemetry SDK.

Related Articles: APM / Observability

GCP Professional Cloud Developer (PCD) 完全ガイド|Cloud Run・GKE・CI/CD・APM

Google Cloud Professional Cloud Developer の試験範囲、Cloud Run / GKE / Cloud Build / Cloud Trace、AWS DVA / Azure AZ-204 比較、学習ロードマップを徹底解説。

Cloud Build 完全ガイド|CI/CD・cloudbuild.yaml・Private Pool・GitHub 連携 (GCP)

Google Cloud Cloud Build の全機能解説。cloudbuild.yaml、トリガー設定、Private Pool、Workload Identity、Build Approvals、Cloud Deploy 連携、AWS CodeBuild / Azure DevOps 比較を網羅。

Cloud Deploy 完全ガイド|Canary・Blue-Green・GKE/Cloud Run プログレッシブデプロイ (GCP)

Google Cloud Cloud Deploy の全機能解説。Delivery Pipeline、Canary / Blue-Green、Approval Gate、Verify、Skaffold 統合、GKE / Cloud Run / Anthos 対応、AWS CodeDeploy / ArgoCD 比較を網羅。

Cloud Monitoring 完全ガイド|SLO・Prometheus・Grafana・Datadog 比較 (GCP)

Google Cloud Monitoring の全機能解説。SLO 機能、Managed Service for Prometheus、Grafana 統合、アラート、ダッシュボード、Uptime Check、料金、Datadog / New Relic 比較を網羅。

Google Cloud is a trademark of Google LLC. For the latest information, see the official Cloud Trace docs.

Check what you learned with practice questions

Practice with certification-focused question sets

View GCP exam prep
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Google Cloud

Google Cloud Certification Roadmap (2026)

Choose your GCP certification path — Foundational, Associate...

Google Cloud

CDL Cloud Digital Leader: Complete Exam Guide (2026)

Pass the Cloud Digital Leader exam — cloud business value, G...

Google Cloud

GAIL Generative AI Leader: Complete Exam Guide (2026)

Pass the Generative AI Leader exam — Gemini, Vertex AI, Work...

Google Cloud

Vertex AI Fundamentals for GCP Certs (2026)

Vertex AI basics every cert candidate needs — Workbench, Pip...

Google Cloud

Associate Cloud Engineer (ACE): Complete Guide (2026)

Pass the Associate Cloud Engineer exam — Console, gcloud, pr...

Browse all Google Cloud articles (103)
© 2026 NicheeLab All rights reserved.