Generated banner for Cloud Trace Querying
Generated logo for Cloud Trace Querying

Cloud Trace Querying

GoogleOfficialPublished by Google

  • Skill
  • Tool integration
  • Cloud and DevOps
  • Apache-2.0
  • Low risk
  • Has scripts

From the author

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.
— the description by Google

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The cloud-trace-querying skill enables agents to interact directly with Google Cloud Trace to investigate performance issues. It provides structured workflows to search for traces based on latency or error status, inspect trace hierarchies, and retrieve correlated application logs from Cloud Logging. The skill is designed for diagnosing latency regressions and service bottlenecks within Google Cloud environments by executing specific diagnostic scripts and formatting the results for analysis.

What it does

  • Searches for traces using latency thresholds and error filters.
  • Fetches full trace hierarchies to visualize span relationships.
  • Retrieves application logs correlated with specific trace IDs.
  • Inspects individual span attributes and metadata.
  • Generates direct Cloud Console deep links for further manual inspection.
  • Formats trace data into ASCII timelines or JSON graphs.

When to use it

  • When investigating slow requests or latency regressions in GCP services.
  • When analyzing trace hierarchies to identify bottlenecks.
  • When correlating error logs with specific distributed trace events.
  • When troubleshooting service crashes or unexpected error statuses.

Advantages

  • Provides standardized diagnostic workflows for GCP observability.
  • Enables direct correlation between distributed traces and application logs.
  • Supports flexible filtering by latency and error status.
  • Automates the generation of deep links for rapid transition to the Cloud Console.

Usage examples

“Find all traces for /v1/booking/book that took longer than 1.5 seconds.”
The agent executes the search script with the specified filter and returns a list of matching trace IDs and their durations.
“Show me the logs related to trace ID 12345.”
The agent fetches and displays application log entries correlated with the provided trace ID to help identify the root cause of an error.
“Generate a link to view trace 12345 in the Google Cloud Console.”
The agent provides a direct URL that opens the specific trace in the Cloud Trace Explorer.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/google/cloud-trace-querying/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip cloud-trace-querying.zip -d .agents/skills

Documentation by Google

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

  1. Google Cloud SDK: Verify gcloud is installed (Installation Guide).

  2. Authentication: Authenticate CLI and application default credentials:

    gcloud auth login && gcloud auth application-default login
  3. Project & Billing: Identify the target <PROJECT_ID> (from the user's prompt or via bash 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>
  4. 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>'

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

Operational Workflows
Query Syntax & Tools
Semantic Conventions
Concepts & Architecture
Templates & Assets

Files

scripts/run_python_with_deps/src/venv_executor.py

"""Executes target script within the context of the virtual environment.

Sets up required PYTHONPATH environment variables so that local shared modules
are visible, and execs the python binary within the virtual environment.
"""

import os
import pathlib
import sys


def execute_python(venv_dir: pathlib.Path) -> None:
  """Executes the target script using the virtualenv's Python binary.

  Prepends the shared scripts directory to PYTHONPATH, then calls os.execv to
  replace the current process with the virtualenv Python interpreter running
  the user's script.

  Args:
      venv_dir: The path to the virtualenv directory to run under.

  Raises:
      OSError: If the execv call fails (this is caught internally, printed to
        stderr, and triggers sys.exit(1)).
  """
  python_path = venv_dir / "bin" / "python3"
  script_dir = pathlib.Path(__file__).parent.resolve()
  scripts_dir = script_dir.parent.parent

  os.environ["PYTHONPATH"] = f"{scripts_dir}:{os.environ.get('PYTHONPATH', '')}"
  try:
    os.execv(str(python_path), [str(python_path)] + sys.argv[1:])
  except OSError as e:
    print(f"Error: Failed to execute {python_path}: {e}", file=sys.stderr)
    sys.exit(1)

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs a command-line tool, Needs Python

Security

What our scanner noticed· Low risk

  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Published by
Google
Publisher
Google (Official)
Source
google/skills · skills/cloud/cloud-trace-querying · commit 2194d3b
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Google.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download cloud-trace-querying.zip