Search spans
Search and list spans matching a set of filters, returning a keyset-paginated page.
Filters in the request body include trace and span ids, names, statuses,
types, free-text search, metadata, duration bounds, and more, scoped to an
optional time window. Results are keyset-paginated on indexed columns rather
than offset-paginated, and total is not computed (it is always 0); use the
pagination cursors to page through results. Reads route to the legacy trace
store or the tracing service per account (with fallback to the legacy trace
store outside strict mode), and results are narrowed to traces the caller is authorized to
read — a filter that resolves to no authorized traces yields an empty page
rather than an error. A reversed time window (from_ts after to_ts) is
rejected with 422, as is a request whose combined trace_ids, span_ids,
excluded_span_ids, excluded_trace_ids, and parent_ids count exceeds
10000. sort_by accepts start_timestamp, duration_ms,
input_tokens and output_tokens; the token counts are read from usage
reported at ingest, and a span whose producer reported none sorts as zero, so
it lands last descending and first ascending. The two token sorts are rejected
for an account still served by the legacy trace store, which keeps no token count
to order by. Any other unsupported sort falls back to timestamp order there.
Spans sharing a sort key are ordered by trace_id and id bytewise on both
tracing-service engines. Text search tokenization, indexed-prefix, word-length,
locale and metadata-bytes behavior differs between Postgres and ClickHouse
deployments of the tracing service as the search_texts field describes.
x-project-id narrows the result to traces whose root span carries that project,
when PROJECT_SCOPED_SPAN_LISTING is on for the account. An account the tracing service
serves holds no project placement, so a request carrying the header is rejected with
422 there.
Search spans
import SGPClient from 'scale-gp';
const client = new SGPClient({
accountID: 'My Account ID',
apiKey: process.env['SGP_API_KEY'], // This is the default and can be omitted
});
// Automatically fetches more pages as needed.
for await (const span of client.spans.search()) {
console.log(span.id);
}{
"has_more": true,
"items": [
{
"id": "id",
"account_id": "account_id",
"name": "name",
"start_timestamp": "2019-12-27T18:11:19.117Z",
"trace_id": "trace_id",
"application_interaction_id": "application_interaction_id",
"application_variant_id": "application_variant_id",
"created_by": {
"id": "id",
"type": "user",
"object": "identity"
},
"end_timestamp": "2019-12-27T18:11:19.117Z",
"expected": {
"foo": "bar"
},
"group_id": "group_id",
"input": {
"foo": "bar"
},
"input_tokens": 0,
"metadata": {
"foo": "bar"
},
"object": "span",
"obs_span_id": "obs_span_id",
"obs_trace_id": "obs_trace_id",
"output": {
"foo": "bar"
},
"output_tokens": 0,
"parent_id": "parent_id",
"status": "SUCCESS",
"type": "TEXT_INPUT"
}
],
"total": 0,
"effective_from_ts": "2019-12-27T18:11:19.117Z",
"effective_to_ts": "2019-12-27T18:11:19.117Z",
"limit": 0,
"next_cursor": "next_cursor",
"object": "list",
"prev_cursor": "prev_cursor",
"window_truncated": true
}Returns Examples
{
"has_more": true,
"items": [
{
"id": "id",
"account_id": "account_id",
"name": "name",
"start_timestamp": "2019-12-27T18:11:19.117Z",
"trace_id": "trace_id",
"application_interaction_id": "application_interaction_id",
"application_variant_id": "application_variant_id",
"created_by": {
"id": "id",
"type": "user",
"object": "identity"
},
"end_timestamp": "2019-12-27T18:11:19.117Z",
"expected": {
"foo": "bar"
},
"group_id": "group_id",
"input": {
"foo": "bar"
},
"input_tokens": 0,
"metadata": {
"foo": "bar"
},
"object": "span",
"obs_span_id": "obs_span_id",
"obs_trace_id": "obs_trace_id",
"output": {
"foo": "bar"
},
"output_tokens": 0,
"parent_id": "parent_id",
"status": "SUCCESS",
"type": "TEXT_INPUT"
}
],
"total": 0,
"effective_from_ts": "2019-12-27T18:11:19.117Z",
"effective_to_ts": "2019-12-27T18:11:19.117Z",
"limit": 0,
"next_cursor": "next_cursor",
"object": "list",
"prev_cursor": "prev_cursor",
"window_truncated": true
}