> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squasher.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Query the logs of a trace

> Find an error log, take its trace ID, and read every log and span of that request.

A trace ID links the logs and the spans of one request. This recipe finds a recent error log,
reads its trace ID, and then reads all logs of that trace and the trace itself. Every step needs
`errors:read`.

## Find a log with a trace ID

Search the error logs of a service in a bounded window. Each log has its trace ID in
`tags.trace_id`.

> [tab] CLI
>
> ```bash theme={null}
> squasher logs query "timeout" --level error --service api --since 1h --limit 5 --json
> ```
>
> The first argument is the search text. Use `level:error service:api` field syntax to filter in
> the text instead of with flags. See [Logs search syntax](https://docs.squasher.ai/api-reference/logs.md#search-syntax).

> [tab] MCP
>
> ```javascript theme={null}
> const projectId = "YOUR_PROJECT_ID";
> const logs = await squasher.request({
>   method: "GET",
>   path: `/v1/projects/${projectId}/logs`,
>   query: {
>     q: "timeout",
>     level: "error",
>     service: "api",
>     from: new Date(Date.now() - 60 * 60 * 1000).toISOString(),
>     limit: 5,
>   },
> });
> return logs.data.map((log) => ({ message: log.message, trace_id: log.tags.trace_id }));
> ```

> [tab] REST API
>
> ```bash theme={null}
> curl -G "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/logs" \
>   -H "x-squasher-key: $SQUASHER_API_KEY" \
>   --data-urlencode q=timeout \
>   --data-urlencode level=error \
>   --data-urlencode service=api \
>   --data-urlencode from=2026-11-08T20:00:00Z \
>   --data-urlencode limit=5
> ```

The response has `data`, `total`, `limit`, `offset`, `from`, and `to`. Each log has this shape:

```json theme={null}
{
  "event_id": "<uuid>",
  "timestamp": 1794000000000,
  "level": "error",
  "message": "<log message>",
  "environment": "production",
  "release": "<release>",
  "fingerprint": "<fingerprint>",
  "tags": {
    "service_name": "api",
    "trace_id": "<32 hex characters>",
    "span_id": "<16 hex characters>"
  }
}
```

## Read the logs of the trace

> [tab] CLI
>
> ```bash theme={null}
> squasher traces logs TRACE_ID --project "$SQUASHER_PROJECT_ID" --limit 50 --json
> ```

> [tab] MCP
>
> The MCP server does not expose `traces.listRelatedLogs`. Read the same logs with a bounded
> `query.run` statement. A trace ID and a time window keep the query inside its budget.
>
> ```javascript theme={null}
> const projectId = "YOUR_PROJECT_ID";
> const traceId = "YOUR_TRACE_ID";
> return await squasher.request({
>   method: "POST",
>   path: `/v1/projects/${projectId}/query`,
>   body: {
>     sql: `SELECT timestamp, severity, service, message FROM logs
>           WHERE trace_id = '${traceId}' AND timestamp > now() - INTERVAL 1 HOUR
>           ORDER BY timestamp LIMIT 50`,
>   },
> });
> ```

> [tab] REST API
>
> ```bash theme={null}
> curl "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/traces/TRACE_ID/logs?limit=50" \
>   -H "x-squasher-key: $SQUASHER_API_KEY"
> ```

The CLI and the REST API return `{ "data": [log], "total": 11 }` with logs in the shape above. The
`query.run` statement returns `rows`, `columns`, `scanned_rows`, `scanned_bytes`, and `duration_ms`.
Replace the 1 hour window with one that covers the time of your trace. The API reads logs from the
last 30 days.

## Read the trace

> [tab] CLI
>
> ```bash theme={null}
> squasher traces get TRACE_ID --project "$SQUASHER_PROJECT_ID"
> squasher traces errors TRACE_ID --project "$SQUASHER_PROJECT_ID" --json
> ```
>
> Without `--json`, `traces get` prints a waterfall of the spans. `traces errors` lists the
> issues that the trace raised.

> [tab] MCP
>
> ```javascript theme={null}
> const projectId = "YOUR_PROJECT_ID";
> const traceId = "YOUR_TRACE_ID";
> const trace = await squasher.request({
>   method: "GET",
>   path: `/v1/projects/${projectId}/traces/${traceId}`,
> });
> return {
>   root_span_name: trace.root_span_name,
>   duration_ms: trace.duration_ms,
>   span_count: trace.span_count,
>   slowest: trace.spans.sort((a, b) => b.duration_ms - a.duration_ms).slice(0, 5)
>     .map((span) => ({ name: span.name, duration_ms: span.duration_ms })),
> };
> ```

> [tab] REST API
>
> ```bash theme={null}
> curl "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/traces/TRACE_ID" \
>   -H "x-squasher-key: $SQUASHER_API_KEY"
> ```

The trace has `root_span_name`, `service_name`, `duration_ms`, `span_count`, and `spans`. Each span
has `name`, `parent_span_id`, `duration_ms`, `attributes`, `resource_attributes`, `events`, and
`links`.

## Next steps

> [card] [Logs API](https://docs.squasher.ai/api-reference/logs.md)
>
> Search syntax, filters, and pagination.

> [card] [Query guide and safe SQL](https://docs.squasher.ai/api-reference/query-guide.md)
>
> Run bounded read-only SQL over logs, spans, and metrics.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.