Skip to main content
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.
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.
The response has data, total, limit, offset, from, and to. Each log has this shape:

Read the logs of the trace

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

Without --json, traces get prints a waterfall of the spans. traces errors lists the issues that the trace raised.
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

Logs API

Search syntax, filters, and pagination.

Query guide and safe SQL

Run bounded read-only SQL over logs, spans, and metrics.