# Traces

Send OpenTelemetry traces to Altertable when you want spans, service timing, status, attributes, events, and links to be queryable beside product, operational, and business data.

Accepted spans are written to `opentelemetry.main.spans`.

## SDK and collector setup

Follow [Configure an exporter](/docs/opentelemetry/setup.md) for instrumentation, authentication, and OTLP/HTTP setup. See [`POST /v1/traces`](/docs/api-references/opentelemetry.md#post-v1-traces) for the request body and responses.

## Query traces

Spans are normal SQL rows once they are ingested:

```sql
SELECT
  trace_id,
  span_id,
  service_name,
  name,
  start_time,
  duration_ns / 1e6 AS duration_ms,
  status_code
FROM opentelemetry.main.spans
ORDER BY start_time DESC
LIMIT 100;
```

You can also explore traces in the Altertable Explore tab with Lucene-syntax search.

## Advanced: trace ID locality

> **Time-prefixed trace IDs:**
>
> Keep your SDK’s default ID generator for initial setup. When tuning large trace datasets, consider time-prefixed IDs (AWS X-Ray style):
>
> - **Trace ID** (16 bytes): 4-byte unix seconds prefix + 12 random bytes
> - **Span ID** (8 bytes): 4-byte unix seconds prefix + 4 random bytes
>
> That trades a little entropy for time locality. Spans created in the same second share an ID prefix, so co-ingested rows cluster together and lakehouse [sorted tables](/docs/lakehouse/features/sorted-tables.md) get tighter locality and better metadata pruning.
>
> Register a custom ID generator in your OpenTelemetry SDK when your language supports it.

Continue with [Query telemetry](/docs/opentelemetry/query.md) to investigate and correlate signals.