# Query telemetry

Query OpenTelemetry logs, traces, and metrics with SQL-backed tools in Altertable. Use the signal guides for individual records, then correlate signals or join them to business data with SQL.

In Altertable, the Logs explorer can group matching records into a segmentation chart over time. The Traces explorer can limit results to root spans, open a trace waterfall, and correlate a trace with its logs. Use SQL when you need to join telemetry to product, customer, or operational catalogs.

## Query a signal

- [Logs](/docs/opentelemetry/logs.md#query-logs) contain log bodies, severity, and trace/span identifiers.
- [Traces](/docs/opentelemetry/traces.md#query-traces) contain request spans, timings, and service attributes.
- [Metrics](/docs/opentelemetry/metrics.md#verify-the-data) contain gauge, sum, histogram, and summary points.

## Correlate logs and traces

Join a log to its span using both `trace_id` and `span_id`:

```sql
SELECT
  logs.timestamp,
  logs.severity_text,
  logs.body,
  spans.service_name,
  spans.name AS span_name
FROM opentelemetry.main.logs AS logs
JOIN opentelemetry.main.spans AS spans
  ON logs.trace_id = spans.trace_id
  AND logs.span_id = spans.span_id
WHERE logs.timestamp >= now() - INTERVAL '1 hour'
ORDER BY logs.timestamp DESC
LIMIT 100;
```

This query returns logs with matching spans. Logs without both identifiers or a matching span are not included. When joining telemetry to business data, also check customer or account identifiers and the time range.

## Investigate with an agent

```text
Investigate errors from the last hour. Which services are affected, and what might be causing them?
```

For table schemas and accepted signals, see the [data model](/docs/opentelemetry/data-model.md). For the status of the Grafana integration, see [Grafana availability](/docs/lakehouse/clients/grafana.md).