Cloud Trace 链路查询与延迟诊断
cloud-trace-querying
查询 Cloud Trace 跨度(span),按延迟阈值或错误状态过滤,将分布式追踪与 Cloud Logging 关联,并诊断跨 Google Cloud 服务的延迟瓶颈。当调查缓慢请求、分析追踪层级结构或解决延迟回归时使用。不要用于查询非 GCP 遥测数据或 Cloud Trace 之外的数据库查询优化。
- License 许可
- Apache-2.0
- 所属仓库
- google/skills
- 最近更新
- 2026-11-14
- Stars
- ★ 2.4w
- Forks
- 2.0k
01 前言 Front Matter
- name
- cloud-trace-querying
- metadata
- { "version": "1.0.2", "category": "CloudObservabilityAndMonitoring" }
- description
- Query Cloud Trace spans, filter by latency thresholds or error status, correlate distributed traces with Cloud Logging, and diagnose latency bottlenecks across Google Cloud services. Use when investigating slow requests, analyzing trace hierarchies, or resolving latency regressions. Do NOT use for querying non-GCP telemetry or database query optimization outside Cloud Trace.
02 资源文件 89
- 资产文件assets/formatting/a2ui/single_span/display.a2ui.json1.1 KB
- 资产文件assets/formatting/a2ui/trace_chart/display.a2ui.json1.1 KB
- 资产文件assets/formatting/a2ui/trace_flow/display.a2ui.json767 B
- 资产文件assets/formatting/a2ui/traces_heat_map/display.a2ui.json1.8 KB
- 资产文件assets/formatting/ascii/single_span/display.txt377 B
- 资产文件assets/formatting/ascii/trace_chart/display.txt517 B
- 资产文件assets/formatting/ascii/trace_flow/display.txt430 B
- 资产文件assets/formatting/ascii/traces_heat_map/display.txt887 B
- 资产文件assets/queries/billing_errors/query.txt73 B
- 资产文件assets/queries/billing_errors/SCENARIO.md1.4 KB
- 资产文件assets/queries/checkout_latency/query.txt47 B
- 资产文件assets/queries/checkout_latency/SCENARIO.md416 B
- 资产文件assets/queries/customer_spans/query.txt24 B
- 资产文件assets/queries/customer_spans/SCENARIO.md307 B
- 资产文件assets/queries/prod_outliers/query.txt51 B
- 资产文件assets/queries/prod_outliers/SCENARIO.md979 B
- 资产文件assets/queries/slow_db/query.txt35 B
- 资产文件assets/queries/slow_db/SCENARIO.md440 B
- 参考文档references/api-limits.md1.6 KB
- 参考文档references/attribution.md1.9 KB
- 参考文档references/concepts-span.md869 B
- 参考文档references/concepts-trace.md1.3 KB
- 参考文档references/console-deep-links.md1.1 KB
- 参考文档references/conventions-gcp-legacy.md3.4 KB
- 参考文档references/conventions-gcp.md2.7 KB
- 参考文档references/conventions-otel-genai.md6.9 KB
- 参考文档references/conventions-otel-grpc.md2.4 KB
- 参考文档references/conventions-otel-http.md1.9 KB
- 参考文档references/conventions-otel.md4.2 KB
- 参考文档references/conventions.md2.5 KB
- 参考文档references/correlated-logs.md2.5 KB
- 参考文档references/decision-tree.md2.1 KB
- 参考文档references/filter-syntax.md4.0 KB
- 参考文档references/index.md2.7 KB
- 参考文档references/knowledge-overview.md3.2 KB
- 参考文档references/logs-trace-correlation.md1.7 KB
- 参考文档references/observability-scopes.md3.0 KB
- 参考文档references/querying-mcp.md2.0 KB
- 参考文档references/querying-observability-analytics.md4.9 KB
- 参考文档references/troubleshoot-latency.md2.1 KB
- 参考文档references/workflows-overview.md881 B
- 脚本scripts/fetch_entire_trace/run.sh231 B
- 脚本scripts/fetch_entire_trace/src/main.py1.8 KB
- 脚本scripts/fetch_entire_trace/test.sh279 B
- 脚本scripts/fetch_entire_trace/tests/main_test.py3.9 KB
- 脚本scripts/fetch_related_logs/run.sh231 B
- 脚本scripts/fetch_related_logs/src/log_fetcher.py7.4 KB
- 脚本scripts/fetch_related_logs/src/main.py2.4 KB
- 脚本scripts/fetch_related_logs/src/observability_scopes.py3.0 KB
- 脚本scripts/fetch_related_logs/src/timestamp_utils.py577 B
- 脚本scripts/fetch_related_logs/test.sh422 B
- 脚本scripts/fetch_related_logs/tests/main_test.py10.6 KB
- 脚本scripts/fetch_related_logs/tests/timestamp_utils_test.py1.1 KB
- 脚本scripts/fetch_trace_span/run.sh231 B
- 脚本scripts/fetch_trace_span/src/main.py2.6 KB
- 脚本scripts/fetch_trace_span/test.sh279 B
- 脚本scripts/fetch_trace_span/tests/main_test.py5.1 KB
- 脚本scripts/generate_links/run.sh138 B
- 脚本scripts/generate_links/src/main.py1.7 KB
- 脚本scripts/generate_links/test.sh279 B
- 脚本scripts/generate_links/tests/main_test.py2.7 KB
- 脚本scripts/get_trace_project/run.sh231 B
- 脚本scripts/get_trace_project/src/main.py402 B
- 脚本scripts/get_trace_project/src/project_resolver.py2.0 KB
- 脚本scripts/get_trace_project/test.sh279 B
- 脚本scripts/get_trace_project/tests/integration_test.py2.7 KB
- 脚本scripts/get_trace_project/tests/project_resolver_test.py2.8 KB
- 脚本scripts/requirements.txt92 B
- 脚本scripts/run_python_with_deps/run.sh2.0 KB
- 脚本scripts/run_python_with_deps/src/cleanup_env.py2.1 KB
- 脚本scripts/run_python_with_deps/src/lock_manager.py2.5 KB
- 脚本scripts/run_python_with_deps/src/manage_venv.py1.7 KB
- 脚本scripts/run_python_with_deps/src/path_resolver.py3.4 KB
- 脚本scripts/run_python_with_deps/src/venv_cleaner.py800 B
- 脚本scripts/run_python_with_deps/src/venv_executor.py1.2 KB
- 脚本scripts/run_python_with_deps/src/venv_setup.py2.1 KB
- 脚本scripts/run_python_with_deps/test.sh364 B
- 脚本scripts/run_python_with_deps/tests/cleanup_env_test.py2.5 KB
- 脚本scripts/run_python_with_deps/tests/lock_manager_test.py2.0 KB
- 脚本scripts/run_python_with_deps/tests/path_resolver_test.py5.4 KB
- 脚本scripts/run_python_with_deps/tests/venv_setup_test.py1.8 KB
- 脚本scripts/search_traces/run.sh231 B
- 脚本scripts/search_traces/src/main.py2.1 KB
- 脚本scripts/search_traces/src/timestamp_utils.py1.5 KB
- 脚本scripts/search_traces/src/trace_searcher.py16.0 KB
- 脚本scripts/search_traces/test.sh279 B
- 脚本scripts/search_traces/tests/main_test.py2.7 KB
- 脚本scripts/search_traces/tests/timestamp_utils_test.py1.7 KB
- 脚本scripts/search_traces/tests/trace_searcher_test.py17.4 KB
03 SKILL.md 正文
Cloud Trace Querying Skill (cloud-trace-querying)
This skill equips the agent to interact with Cloud Trace by providing standard query patterns, diagnostic workflows for latency and errors, and tools to fetch and inspect trace hierarchies.
[!IMPORTANT] AUTONOMOUS TOOL EXECUTION MANDATE: You MUST execute the tool scripts directly in bash to query telemetry. Do NOT just describe query strings or write Python scripts. Run the provided bash tools directly and report the exact results.
Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read Usage Attribution. For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix gcloud with
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-trace-querying)"
and append agent-skills/1.0 (skill:cloud-trace-querying) to User-Agent headers.
Prerequisites & Setup
- Google Cloud SDK: Verify
gcloudis installed (Installation Guide). - Authentication: Authenticate CLI and application default credentials:
gcloud auth login && gcloud auth application-default login - Project & Billing: Identify the target
<PROJECT_ID>(from the user's prompt or viabash scripts/get_trace_project/run.sh), ensure an active billing account is attached, and configure the project if not already set:gcloud config set project <PROJECT_ID> - API Enablement: Verify Cloud Trace and Cloud Logging APIs are enabled:
gcloud services enable cloudtrace.googleapis.com logging.googleapis.com
Quickstart Workflows
1. Identify Google Cloud Project ID
If the user specified a Google Cloud project ID in their prompt, use it.
If they did not, ALWAYS determine the Google Cloud project ID by running:
bash scripts/get_trace_project/run.sh
2. Search Traces (Latency & Errors)
To find traces matching specific criteria, such as a root span of /v1/booking/book with a duration of at least 1.5s:
bash scripts/search_traces/run.sh --filter 'root:/v1/booking/book latency:1.5s' --projects '<PROJECT_ID>'
Note: --filter is required. To list traces without specific filtering, pass --filter '' or --filter 'root:'.
Filter syntax: The Cloud Trace API uses latency:<duration> (such as latency:1.5s for duration >= 1.5s), which corresponds to "Span duration" in Trace Explorer.
The script outputs JSON where each cluster's examples array contains sample trace objects with trace_id, duration_seconds, span count, and error status.
3. Fetch Entire Trace Hierarchy
To view all spans and status codes/labels within a trace:
bash scripts/fetch_entire_trace/run.sh --trace-id '<TRACE_ID>' --project '<PROJECT_ID>'
4. Fetch Correlated Application Logs
To retrieve application log entries correlated with a trace ID:
bash scripts/fetch_related_logs/run.sh --trace-id '<TRACE_ID>' --trace-projects '<PROJECT_ID>'
Application log entries are useful when inspecting stack traces, exception messages, and log events emitted during span execution. When diagnosing errors or service crashes, inspect the returned log entries for severity: "ERROR" to confirm root causes or uncover unhandled exceptions.
Note: fetch_related_logs queries the default log scope (_Default), searching across configured log views in the target project. An empty response can occur if: (1) no log entries match the criteria, (2) the caller lacks IAM permissions to view the matching entries, or (3) matching entries reside in log views outside the searched log scope.
5. Fetch Specific Trace Span
To inspect attributes and metadata of a single span within a trace:
bash scripts/fetch_trace_span/run.sh --trace-id '<TRACE_ID>' --span-id '<SPAN_ID>' --project '<PROJECT_ID>'
6. Generate Cloud Console Deep Links
To generate direct Cloud Console URLs for browser inspection of traces or correlated logs:
bash scripts/generate_links/run.sh --trace-id '<TRACE_ID>' --project '<PROJECT_ID>' [--span-id '<SPAN_ID>']
7. Format Output
- Terminal / CLI: Render span trees as indented ASCII timelines using
|--. - UI Presentation: Render as A2UI JSON graph structures when requested for UI.
8. Upstream Service Error Handling
If the Cloud Trace API or Cloud Logging API returns an upstream HTTP service error (such as 500 Internal Server Error, 503 Service Unavailable, or GoogleAPICallError), report the upstream service outage directly to the user. Do not attempt to inspect virtual environments, modify internal scripts, or debug local libraries.
Reference Documentation
- Master Index: Reference Documentation Index
Operational Workflows
- Troubleshoot Latency Workflow
- Correlated Logs Workflow
- Trace Querying Decision Tree
- Console Deep Links
- Workflows Overview
Query Syntax & Tools
- Filter Syntax (
root:,latency:,+span:,error:true) - API Limits and Constraints
- Observability Analytics (BigQuery SQL)
- Cloud Trace MCP Tools
Semantic Conventions
- Conventions Overview
- OpenTelemetry Core
- OpenTelemetry HTTP
- OpenTelemetry gRPC & RPC
- OpenTelemetry GenAI
- GCP App Hub & Service Conventions
- GCP Legacy Labels
Concepts & Architecture
- Observability Scopes
- Distributed Traces Concept
- Spans Concept
- Logs-to-Trace Correlation
- Knowledge Overview
Templates & Assets
Official Documentation Links
04 同仓库更多 Skills
cloud-operator-share-context
Shares Google Cloud operating context the user or their team already have — environments, projects, services and regions, product preferences, best practices, architecture guidance, runbooks — found in agent instruction files, local memory, skills and workflows, and the repository's GCP docs, with the operator agent's memory after the user reviews the list. Use when the user runs this skill, accepts the cloud-operator or cloud-operator-setup skill's offer to share their existing Google Cloud context, or asks to share, import or save that context or a GCP fact for the operator agent. Don't use for ordinary GCP requests, which go to the cloud-operator skill.
cloud-operator-setup
Sets up the operator agent in a Google Cloud project via the autocloud MCP server: picks the operator project, creates or checks the user's operator agent, saves the project, and offers to share the user's existing Google Cloud operating context with the operator agent's memory. Use when the user runs this skill, asks to set up the operator or create their operator agent, or chooses setup when the cloud-operator skill asks. Don't use for ordinary GCP requests or installing gcloud.
developer-device-platform-device-run
Runs automated, non-interactive jobs on remote Android devices with Developer Device Platform (DDP) Device Run using `gcloud beta device-run sessions`: native Android executables or shell scripts (for example CLI tools, custom runners, test harnesses or benchmarks) and Android instrumentation tests, on one or many devices, then waits for completion and collects per-device outputs and logs. Use when running a binary or test suite on remote devices without an interactive connection. Don't use it for interactive device reservations, adb tunnels or screen streaming (use developer-device-platform-basics), or for local devices.
compute-vm-creation
Guides the planning, configuration, and provisioning of standalone Google Compute Engine virtual machines (VMs) and bare metal (-metal) instances using gcloud CLI commands or direct MCP tool execution. Use ONLY when the user wants to create, configure, or provision a new standalone Compute Engine VM or bare metal instance from conversational intents (hardware sizing, region selection, OS image, networking, security defaults). DO NOT read or use for Google Kubernetes Engine (GKE) Autopilot or Standard clusters, Kubernetes node pools or Pods, container orchestration, managing existing VMs, Managed Instance Groups (MIGs), or Instance Templates.
agent-platform-autorater-customization
Customizes an autorater (evaluation metric) for an AI agent so its grades match the user's own judgment, starting from the agent's real trajectories. Use when a user wants a metric tailored to their agent, wants to turn failing trajectories into rubrics, says an existing autorater grades their agent wrong, or wants an autorater to agree with human labels (autorater hillclimbing, judge calibration). Don't use for quick evals with built-in metrics or for improving the agent itself (use agent-platform-eval-flywheel).
iap-agent-platform-troubleshooting
Diagnoses Identity-Aware Proxy (IAP) denials of outbound requests from Gemini Enterprise Agent Platform agents that run on Agent Runtime and send traffic through Agent Gateway. Use when an agent request fails with "Egress request is not authorized", when Cloud Audit Logs show an IAP egressViaIAP decision with granted false, when IAP audit entries are missing while debugging agent egress, or when Access policies, IAP allow policies, policy bindings, or Agent Registry entries might block agent egress. Don't use for Gemini model IAM permission errors (such as aiplatform.endpoints.predict), Agent Platform API errors, or Agent Runtime deployment or 500 errors (use agent-platform-troubleshooting instead). Don't use for setting up, creating, or connecting an Agent Gateway, or for IAP web apps, IAP TCP forwarding, or SSH.