---
title: "Trace logs"
description: "The trace logs endpoints of the HTTP API."
---

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

# Trace logs

## POST /datasources/{uid}/trace-logs

Read the log lines that carry a trace id, or one span id, from a logs datasource.

The trace view's path from a span to its logs; the datasource in the path must be Loki, ClickHouse, Elasticsearch or OpenSearch. The server builds the query itself from the ids, so no query text crosses this call. On Loki it narrows the stream selector to `service` through the first of the `service_name`, `service`, `app` and `job` labels present in the window, or reads every stream when `service` is not given; it filters `trace_id` (and `span_id`) as structured metadata or parsed labels first and, when that answers no line, runs the same selector with a line filter on the id, so lines that only carry the id in their body still match. On ClickHouse it reads the logs page's columns from `otel_logs` where `TraceId` (and `SpanId`) match within the window, newest first. On Elasticsearch and OpenSearch it matches the datasource's trace id field (and span id field, and service field when `service` is given) with exact terms within the window, newest first. `from` and `to` are the trace's window, with the grammar of the explore query; the web passes the trace's start minus a minute to its end plus a minute. The query runs with the agent tools' limits, nothing is cached, and the call counts against the caller's 8 in-flight query requests and takes one of the server's shared upstream slots, waiting at most 5 seconds for one before it answers 429 `too_many_requests` with `Retry-After`. Viewers and above may call it, service-account keys included. The response has the shape of panel data with one query `A` of kind `instant`, `meta.truncated` when the line limit was hit and `meta.oldest` and `meta.newest` as the time edges of the lines returned; an empty result is a 200 with no frames, never a 404.

### Parameters

| Name | In | Type | Description |
| --- | --- | --- | --- |
| `uid` (required) | path | `string` |   |

### Request body

`application/json`, required.

| Field | Type | Description |
| --- | --- | --- |
| `trace_id` (required) | `string` |   |
| `span_id` | `string` | Narrow the lines to one span. |
| `service` | `string` | The span's `service.name`, used to narrow the Loki stream selector; ClickHouse ignores it. |
| `from` (required) | `string` |   |
| `to` (required) | `string` |   |
| `timezone` | `string` | The browser's IANA time zone, used to resolve relative times such as `now/d`. |
| `limit` | `integer` | The most lines to return. Between 1 and 1000. Default `500`. |

### Responses

| Status | Description | Body |
| --- | --- | --- |
| `200` | The lines of the trace, or no frames when it logged nothing in the window. | [`PanelData`](/docs/reference/api/schemas/#paneldata) |
| `400` | The request is malformed or fails validation, or the datasource is not Loki, ClickHouse, Elasticsearch or OpenSearch (`invalid_request`); the body carries no `ref`. | [`PanelDataError`](/docs/reference/api/schemas/#paneldataerror) |
| `401` | Authentication is missing or invalid. | [`Error`](/docs/reference/api/schemas/#error) |
| `404` | The datasource does not exist (`not_found`). | [`PanelDataError`](/docs/reference/api/schemas/#paneldataerror) |
| `413` | The request body exceeds the size limit. | [`Error`](/docs/reference/api/schemas/#error) |
| `422` | The datasource refused the query (`query_invalid`) or the result passed a limit (`limit_exceeded`); the body carries no `ref`. | [`PanelDataError`](/docs/reference/api/schemas/#paneldataerror) |
| `429` | The caller already has the maximum number of query requests in flight, or the server's shared upstream call slots stayed busy for 5 seconds. | [`Error`](/docs/reference/api/schemas/#error) |
| `500` | The server failed to handle the request, including a datasource call that failed without a classified cause. | [`PanelDataError`](/docs/reference/api/schemas/#paneldataerror) |
| `502` | The datasource is unavailable. | [`PanelDataError`](/docs/reference/api/schemas/#paneldataerror) |
| `504` | The datasource did not answer within the 15 second query timeout, or the request did not finish within 20 seconds. | [`PanelDataError`](/docs/reference/api/schemas/#paneldataerror) |

Generated from [`api/openapi.yaml`](https://github.com/slashobserve/slashobserve/blob/c770e5e0/api/openapi.yaml) at `c770e5e0`. [Report a problem](https://github.com/slashobserve/slashobserve/issues/new).
