---
title: "Query Spans"
method: POST
path: "/tracing/spans/query"
tags: ["Deprecated"]
deprecated: true
---

# Query Spans

`POST /tracing/spans/query`

> **Deprecated.**

Query spans and traces in the tracing backend.

Use `focus` in the request body to control the response shape:

- `"trace"` (default): returns a nested `traces` tree keyed by
  `trace_id` then by span name. Children hang off their parent's
  `spans` field. Best for rendering a trace waterfall.
- `"span"`: returns a flat `spans` list. Best for paginating or
  filtering across all spans regardless of hierarchy.

Use `oldest` / `newest` (unix seconds) to window the query and
`limit` to cap the number of traces/spans returned.

The response preserves the Agenta `ag.*` attribute namespace and
includes computed metrics (`ag.metrics.duration`, `ag.metrics.tokens`,
`ag.metrics.costs`) on each span. The `traces` tree returned here is
the same shape that `POST /tracing/spans/ingest` accepts as its
`traces` field.

## Query parameters

- `focus` 'trace' | 'span'
- `format` 'agenta' | 'opentelemetry'
- `oldest` union
  - string
  - integer
- `newest` union
  - string
  - integer
- `limit` integer, nullable
- `interval` integer, nullable
- `rate` number, nullable
- `filter` unknown

## Response `200`

Successful Response

- OTelTracingResponse — Response from span/trace queries. Exactly one of `spans` or `traces` is populated, controlled by the `focus` field in the request (`"span"` for flat lists, `"trace"` for nested trees). The shapes here match what the ingest endpoint accepts, so you can round-trip data between environments.
  - `count` integer — Total number of matching traces or spans in the window.
  - `spans` SpanOutput[], nullable — Flat list of spans, populated when the query was run with `focus="span"`.
    - `created_at` string, date-time, nullable
    - `updated_at` string, date-time, nullable
    - `deleted_at` string, date-time, nullable
    - `created_by_id` string, uuid, nullable
    - `updated_by_id` string, uuid, nullable
    - `deleted_by_id` string, uuid, nullable
    - `trace_id` string, required
    - `span_id` string, required
    - `parent_id` string, nullable
    - `trace_type` 'invocation' | 'annotation' | 'unknown'
    - `span_type` 'agent' | 'chain' | 'workflow' | 'task' | 'tool' | 'embedding' | 'query' | 'llm' | 'completion' | 'chat' | 'rerank' | 'unknown'
    - `span_kind` 'SPAN_KIND_UNSPECIFIED' | 'SPAN_KIND_INTERNAL' | 'SPAN_KIND_SERVER' | 'SPAN_KIND_CLIENT' | 'SPAN_KIND_PRODUCER' | 'SPAN_KIND_CONSUMER'
    - `span_name` string, nullable
    - `start_time` union
      - string, date-time
      - integer
    - `end_time` union
      - string, date-time
      - integer
    - `status_code` 'STATUS_CODE_UNSET' | 'STATUS_CODE_OK' | 'STATUS_CODE_ERROR'
    - `status_message` string, nullable
    - `session_id` string, nullable
    - `user_id` string, nullable
    - `agent_id` string, nullable
    - `attributes` object, nullable
    - `references` OTelReferenceOutput[], nullable
      - `version` string, nullable
      - `slug` string, nullable
      - `id` string, uuid, nullable
      - `attributes` object, nullable
    - `links` OTelLinkOutput[], nullable
      - `span_id` string, nullable
      - `trace_id` string, nullable
      - `attributes` object, nullable
    - `hashes` OTelHashOutput[], nullable
      - `id` string, uuid, nullable
      - `attributes` object, nullable
    - `exception` object, nullable
    - `events` OTelEventOutput[], nullable
      - `name` string, required
      - `timestamp` union, required
        - string, date-time
        - integer
      - `attributes` object, nullable
  - `traces` object, nullable — Nested tree of spans keyed by `trace_id` → span name, populated when the query was run with `focus="trace"` (default).

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/agenta-ai/apis/agenta-api.md) · [All operations](https://skmtc.net/agenta-ai/apis/agenta-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/agenta-ai/agenta-api/versions/ea6421d829f1/schema)
