Reference
Log context
The log context endpoints of the HTTP API.
POST /datasources/{uid}/log-context
Read the log lines just before and just after one line.
anchor is the TimeNs string of the line, as the explore query and the tail return it, so the context is exact to the nanosecond and needs one request. before.frames hold the newest before lines older than the anchor, newest first, read from window_ms before the anchor up to it; after.frames hold the oldest after lines newer than the anchor, oldest first, read from one nanosecond after the anchor to window_ms after it. The anchored line is on neither side. Each side’s truncated is true when more lines exist in its window; a side with a count of 0 is not read and answers no frames. The two reads run at the same time with the agent tools’ limits, nothing is cached, and the call counts against the caller’s 8 in-flight query requests. For Loki the query must be a log query that starts with a stream selector; for ClickHouse one SELECT that selects Timestamp, whose top-level ORDER BY and LIMIT the server replaces. Viewers and above may call it, service-account keys included.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
uid (required) |
path | string |
Request body
application/json, required.
| Field | Type | Description |
|---|---|---|
query (required) |
string |
The query the logs page runs; the server does not rewrite it beyond the time bounds and order. |
anchor (required) |
string |
The line’s TimeNs, a nanosecond epoch time as a decimal string. |
before |
integer |
The most lines wanted before the anchor. Between 0 and 500. Default 50. |
after |
integer |
The most lines wanted after the anchor. Between 0 and 500. Default 50. |
window_ms |
integer |
How far before and after the anchor to look, in milliseconds. Between 1000 and 86400000. Default 3600000. |
Responses
| Status | Description | Body |
|---|---|---|
200 |
The lines on each side of the anchor. | LogContext |
400 |
The request is malformed or fails validation, anchor is not a nanosecond epoch time, a count or window_ms is out of range, or the datasource is not Loki or ClickHouse (invalid_request), or the query is longer than 64 KiB (query_too_long). |
PanelDataError |
401 |
Authentication is missing or invalid. | Error |
404 |
The datasource does not exist (not_found). |
PanelDataError |
413 |
The request body exceeds the size limit. | Error |
422 |
The query cannot run: query_invalid for a Loki metric query, a ClickHouse query without Timestamp or with a top-level set operator, or an upstream rejection such as an unknown column; query_forbidden, limit_exceeded or unknown_macro as for the explore query; the body carries no ref. |
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 |
500 |
The server failed to handle the request, including a datasource call that failed without a classified cause. | PanelDataError |
502 |
The datasource is unavailable. | PanelDataError |
504 |
The datasource did not answer within the 15 second query timeout, or the request did not finish within 20 seconds. | PanelDataError |
Generated from api/openapi.yaml at c770e5e0. Report a problem.