Skip to main content
skill Claude Code Gemini CLI CX Codex official · Google

cloud-trace-querying — Claude Code skill: install and use

This skill queries Cloud Trace spans, connects traces with Cloud Logging, and helps diagnose latency in Google Cloud services.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add google/skills --skill cloud-trace-querying -a claude-code
Open on GitHub

What cloud-trace-querying does

cloud-trace-querying gives an agent query patterns and shell workflows for finding traces by root span, latency threshold, or error status. It can fetch a complete trace hierarchy, inspect one span, retrieve logs linked to a trace ID, and create Cloud Console links.

The package includes bash scripts for finding the project, searching traces, fetching spans, and reading related logs. The --filter option is required for trace searches, so the query criteria must be ready before that step. Setup needs the Google Cloud SDK, gcloud authentication, a Google Cloud project with active billing, and the Cloud Trace and Cloud Logging APIs enabled.

Use it for slow requests, trace hierarchy analysis, and latency regressions across Google Cloud services. It does not cover non-GCP telemetry or database query optimization outside Cloud Trace.

What it helps with

  • find traces above a latency threshold
  • inspect error status in trace spans
  • fetch the full hierarchy for one trace
  • correlate a trace ID with Cloud Logging entries
  • generate a Cloud Console link for a trace

Example prompts for the agent

  • Find traces in project `<PROJECT_ID>` whose root span is `/v1/booking/book` and latency is at least `1.5s` using `bash scripts/search_traces/run.sh`.
  • Fetch every span for trace `<TRACE_ID>` from project `<PROJECT_ID>` with `bash scripts/fetch_entire_trace/run.sh`.
  • Retrieve application logs related to trace `<TRACE_ID>` from project `<PROJECT_ID>`.

How to install cloud-trace-querying

1Skills CLI (Vercel)

npx skills add google/skills --skill cloud-trace-querying -a claude-code

2Manually: put the files in place

~/.claude/skills/cloud-trace-querying/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/cloud-trace-querying/

From the same set172

The whole set →
bigquery-basics official google Manages BigQuery resources and runs SQL queries. Use it to create datasets, tables and views, or handle basic data ingestion and analysis. Claude Code Gemini CLI CX Codex 17,678installs cloud-run-basics official google This skill helps an agent manage Cloud Run services, jobs, and worker pools when a project needs HTTP deployment, scheduled work, or pull-based background processing. Claude Code Gemini CLI CX Codex 17,532installs gemini-api official google Connects Gemini API from Google Cloud Agent Platform to the agent. Gives access to Gemini models, multimodal input, function calling, and context caching. Claude Code Gemini CLI CX Codex 17,116installs google-cloud-recipe-auth official Google LLC This skill explains Google Cloud authentication and permissions. Use it when setting up IAM, ADC, or service accounts for local code and production workloads. Claude Code Gemini CLI CX Codex 15,450installs google-cloud-recipe-onboarding official Google LLC Guides a developer through a first Google Cloud project: CLI checks, sign-in, project setup and billing. It fits a personal first project. Claude Code Gemini CLI CX Codex 15,390installs cloud-sql-basics official google This skill helps create and explain Cloud SQL resources for MySQL, PostgreSQL, and SQL Server. Use it when setting up a database in Google Cloud. Claude Code Gemini CLI CX Codex 14,679installs google-cloud-waf-security official google This skill reviews Google Cloud workloads against the security pillar of the Well-Architected Framework and suggests actions for IAM, networks, data, and operations. Claude Code Gemini CLI CX Codex 14,620installs google-cloud-waf-cost-optimization official google Reviews Google Cloud workloads through the Well-Architected Cost Optimization pillar. Use it to inspect spending, resize resources, assess discounts, or find idle capacity. Claude Code Gemini CLI CX Codex 14,266installs

Similar

k8s-manifest-generator Seth Hobson This skill generates Kubernetes manifests for application resources and configuration. Use it when you need Deployments, Services, ConfigMaps, Secrets, or PersistentVolumeClaims. Claude Code CX Codex Cursor 11,166installs rivet-sdk official anthropics Reference skill for the Zoom Rivet SDK, covering OAuth tokens and webhook ingestion in Node.js or AWS Lambda. Claude Code CX Codex Cursor +1 2,100installs terraform-skill Anton Babenko Guides Terraform and OpenTofu refactoring, state migrations, and CI workflows. Diagnoses risks like identity churn and blast radius before generating HCL. Claude Code CX Codex Cursor +1 7,400installs flowstudio-power-automate-governance official github Governs Power Automate flows and Power Apps through the FlowStudio MCP store, covering classification, orphan detection, connector audits, and compliance metadata. GitHub Copilot 777installs vercel-sandbox official Vercel Labs This skill runs user-generated and AI-generated code inside an ephemeral Vercel Sandbox. Use it for browser automation and code checks that should stay outside the main environment. CX Codex GP ChatGPT 27installs applicationinsights-web-ts Microsoft Set up Application Insights telemetry for browser apps, including page views, requests, and exceptions. Use it for RUM or to connect browser-side GenAI agent traces with backend spans. Claude Code GitHub Copilot 38installs workers-best-practices cloudflare Guides coding agents on production Cloudflare Workers standards, Wrangler typing, observability setup, and runtime anti-pattern checks. Claude Code CX Codex Cursor +1 124,900installs cloudflare-email-service cloudflare A skill for Cloudflare Email Sending and Email Routing: it walks the agent through sending and receiving mail in Workers. Claude Code CX Codex Cursor +1 101,400installs

Questions about cloud-trace-querying

How do I install cloud-trace-querying in Claude Code?

Run npx skills add google/skills --skill cloud-trace-querying -a claude-code, then run npx skills add google/skills --skill cloud-trace-querying -a claude-code again. The skill file is placed at ~/.claude/skills/cloud-trace-querying/SKILL.md.

What does cloud-trace-querying do?

It searches Cloud Trace spans by latency and error filters, fetches trace hierarchies or individual spans, and connects trace IDs with Cloud Logging entries.

What does cloud-trace-querying require?

You need the Google Cloud SDK, gcloud auth login and gcloud auth application-default login, a project with active billing, and the cloudtrace.googleapis.com and logging.googleapis.com APIs enabled.

Source text

SKILL.md · Apache-2.0
---
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.
---

# 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](references/attribution.md). 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](https://docs.cloud.google.com/sdk/docs/install-sdk)).
2. **Authentication**: Authenticate CLI and application default credentials:
   ```bash
   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:
   ```bash
   gcloud config set project <PROJECT_ID>
   ```
4. **API Enablement**: Verify Cloud Trace and Cloud Logging APIs are enabled:
   ```bash
   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
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
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
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
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
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
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](./references/index.md)

### Operational Workflows
- [Troubleshoot Latency Workflow](./references/troubleshoot-latency.md)
- [Correlated Logs Workflow](./references/correlated-logs.md)
- [Trace Querying Decision Tree](./references/decision-tree.md)
- [Console Deep Links](./references/console-deep-links.md)
- [Workflows Overview](./references/workflows-overview.md)

### Query Syntax & Tools
- [Filter Syntax](./references/filter-syntax.md) (`root:`, `latency:`, `+span:`, `error:true`)
- [API Limits and Constraints](./references/api-limits.md)
- [Observability Analytics (BigQuery SQL)](./references/querying-observability-analytics.md)
- [Cloud Trace MCP Tools](./references/querying-mcp.md)

### Semantic Conventions
- [Conventions Overview](./references/conventions.md)
- [OpenTelemetry Core](./references/conventions-otel.md)
- [OpenTelemetry HTTP](./references/conventions-otel-http.md)
- [OpenTelemetry gRPC & RPC](./references/conventions-otel-grpc.md)
- [OpenTelemetry GenAI](./references/conventions-otel-genai.md)
- [GCP App Hub & Service Conventions](./references/conventions-gcp.md)
- [GCP Legacy Labels](./references/conventions-gcp-legacy.md)

### Concepts & Architecture
- [Observability Scopes](./references/observability-scopes.md)
- [Distributed Traces Concept](./references/concepts-trace.md)
- [Spans Concept](./references/concepts-span.md)
- [Logs-to-Trace Correlation](./references/logs-trace-correlation.md)
- [Knowledge Overview](./references/knowledge-overview.md)

### Templates & Assets
- [ASCII Formatting Templates](./assets/formatting/ascii)
- [A2UI Formatting Templates](./assets/formatting/a2ui)
- [Query Scenarios](./assets/queries)

## Official Documentation Links
- [Cloud Trace Documentation](https://docs.cloud.google.com/trace/docs)
- [Finding and Viewing Traces](https://docs.cloud.google.com/trace/docs/finding-traces)
- [OpenTelemetry Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/)

© google · Apache-2.0 · google/skills

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor