Google Cloud

Cloud Trace / Cloud Profiler 完全ガイド|分散トレース・APM・OpenTelemetry

2026-05-24
NicheeLab編集部

Cloud TraceCloud Profiler は GCP の APM (Application Performance Monitoring) コンポーネントで、 Trace は「リクエストの分散トレース」、Profiler は「関数レベルのプロファイル」を提供します。OpenTelemetry 統合により業界標準で計装可能です。

Cloud Trace

主要機能

  • 分散トレース (マイクロサービス間のリクエスト追跡)
  • Span (操作単位) のタイムラインビュー
  • レイテンシ分布 (P50 / P95 / P99) の自動計算
  • 異常レイテンシ検出 (Insights)
  • OpenTelemetry / OpenCensus 対応

OpenTelemetry での計装例 (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

主要機能

  • 関数レベル CPU 使用率プロファイル
  • ヒープ (メモリ) プロファイル
  • Flame Graph 表示
  • 低オーバーヘッド (本番常時実行可)
  • 言語: Java / Python / Go / Node.js
  • 料金: 完全無料

セットアップ例 (Python)

# pip install google-cloud-profiler

import googlecloudprofiler

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

料金

サービス料金
Cloud Trace$0.20/100 万 Span (超過分)
Cloud Trace 無料枠月 250 万 Span
Cloud Profiler完全無料
Error Reporting完全無料

サンプリング戦略

エンドポイント種別推奨サンプル率
Critical API (決済等)1.0 (100%)
標準 API0.1 (10%)
Health Check0.0 (除外)
エラー時1.0 (Always sample on error)

OpenTelemetry 統合ベストプラクティス

  • SDK で計装 → OTel Collector 経由 / 直接 Cloud Trace に送信
  • 自動計装 (Auto-instrumentation) で HTTP / gRPC / DB を計装ゼロコード
  • Service Name / Version で環境別ビュー
  • Trace Context 伝播 (W3C TraceContext) でクロスサービス追跡
  • Resource attributes で k8s.cluster.name / cloud.region 等

典型的なユースケース

  • マイクロサービス間レイテンシボトルネック特定
  • 本番性能劣化の原因調査
  • SLO 違反時のドリルダウン
  • 新リリース後のリグレッション検知
  • コスト最適化 (CPU ホットスポット → リファクタリング)

他 APM 比較

項目Trace + ProfilerAWS X-RayDatadog APMNew Relic APM
分散トレース
Profiler
OpenTelemetry
料金極めて安価安め高め
UIシンプル標準豊富豊富

Cloud Trace と Cloud Profiler の違いは?

Trace = リクエスト分散トレース (どこで時間がかかったか)、Profiler = 関数レベル CPU / メモリ使用率 (なぜ遅いか)。両方併用で完全な APM。

OpenTelemetry 対応は?

両方ともネイティブ対応。OpenTelemetry SDK で計装 → OTel Collector / 直接送信。Vendor lock-in 回避の標準アプローチ。

料金体系は?

Trace: 月 250 万 Span 無料、超過分 $0.20/100 万 Span。Profiler: 無料。極めて安価で全環境で常時有効化が標準。

Cloud Trace の保持期間は?

30 日。長期分析が必要な場合は BigQuery エクスポート。

Error Reporting との違いは?

Error Reporting = アプリエラーの自動グルーピング + 通知。Trace / Profiler とは独立した APM コンポーネント。

AWS X-Ray / Datadog APM との比較は?

機能は概ね同等。Trace + Profiler セットで Datadog APM 相当を低コストで実現可能。X-Ray は Lambda 統合が強い。

サンプリングはどう設定する?

デフォルト 0.1 QPS。本番では Adaptive Sampling 推奨。Critical エンドポイントは 1.0 で常時、Health Check は 0 で除外。

対応言語は?

Java / Python / Go / Node.js / Ruby / PHP / .NET。OpenTelemetry SDK 経由で任意言語対応。

関連記事・APM / 可観測性

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 は Google LLC の商標です。最新情報は Cloud Trace 公式 をご確認ください。

この記事で学んだ内容を問題で確認しましょう

16,000問以上の問題で実力チェック

GCP 試験対策ページを見る
この記事の著者

NicheeLab編集部

データエンジニアリング・クラウド資格の専門家。Databricks・Snowflake等の認定資格を保有し、実務経験に基づいた問題作成・解説を行っています。NicheeLab運営。


関連記事
Google Cloud

Google Cloud (GCP) 認定資格ロードマップ 2026 完全版|全 15 試験を体系化

Google Cloud 認定資格 全 15 試験 (Foundational 2 + Associate 3 + Pr...

Google Cloud

Cloud Digital Leader (CDL) 完全ガイド|出題範囲・学習リソース・合格戦略

Google Cloud Cloud Digital Leader (CDL) の完全ガイド。6 ドメイン 92 bul...

Google Cloud

Generative AI Leader (GAIL) 完全ガイド|Google Cloud 生成 AI 認定

Google Cloud Generative AI Leader (GAIL、2025-05-14 リリース) の完全...

Google Cloud

Vertex AI 入門|Google Cloud 統合 ML プラットフォームの全機能

Google Cloud Vertex AI の入門解説。Vertex AI Studio / Agent Builde...

Google Cloud

GCP Associate Cloud Engineer (ACE) 完全ガイド|試験範囲・受験料・学習ロードマップ

Google Cloud Associate Cloud Engineer (ACE) の試験範囲・受験料 125 US...

Google Cloudの記事一覧 (102件)
© 2026 NicheeLab All rights reserved.