---
title: pydo.insights.post_spans_search()
description: Search spans
product: Reference
url: https://docs.digitalocean.com/reference/pydo/reference/insights/post_spans_search/
last_updated: "2026-11-20"
---

> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document).

# pydo.insights.post_spans_search()

Generated on 20 Nov 2026 from `pydo` version [`v0.47.0`](https://github.com/digitalocean/pydo/releases/tag/v0.47.0)

## Usage

```python
client.insights.post_spans_search(
    region="nyc3",
    body={
        "time_range": {...},
        "filter": {...},
        "order_by": [...],
        ...,
    },
)
```

Returns `JSON` Raises `HttpResponseError`

## Description

To search spans in a region, send a POST request to [`/v2/insights/query/{region}/spans/search`](https://docs.digitalocean.com/reference/api/reference/insights/index.html.md#insights_post_spansSearch) with a JSON body describing the time range, optional filter, ordering, and pagination. The time range must not exceed 7 days. `pagination.limit` defaults to 100 and must be between 1 and 1000. Results are ordered by `start_time` descending by default. Cursor-based pagination is not yet supported; `pagination.has_more` indicates whether additional spans matched beyond the returned page.

## Parameters

`region` string required

The datacenter region slug for the query.

`time_range` object required

An inclusive query time window. The window must not exceed 7 days.

## Show child properties

`from` object required

A single time bound. Exactly one of `relative` or `absolute` is set.

### Show child properties

`relative` string optional

Example: `1h`

A relative time. Use `now` for the current time, a bare duration such as `1h` or `7d` to look back from now, or an offset such as `now-15m` or `now+30m`. Supported units are `s`, `m`, `h`, `d`, and `w`.

`absolute` string optional

Example: `2026-09-30T00:00:00Z`

An absolute timestamp. Accepts an RFC3339/RFC3339Nano string or a Unix timestamp (seconds, milliseconds, microseconds, or nanoseconds) encoded as a decimal string.

`to` object required

A single time bound. Exactly one of `relative` or `absolute` is set.

### Show child properties

`relative` string optional

Example: `1h`

A relative time. Use `now` for the current time, a bare duration such as `1h` or `7d` to look back from now, or an offset such as `now-15m` or `now+30m`. Supported units are `s`, `m`, `h`, `d`, and `w`.

`absolute` string optional

Example: `2026-09-30T00:00:00Z`

An absolute timestamp. Accepts an RFC3339/RFC3339Nano string or a Unix timestamp (seconds, milliseconds, microseconds, or nanoseconds) encoded as a decimal string.

`filter` object optional

A boolean filter tree for spans queries. Exactly one node is set per message. Trees may be nested at most 16 levels deep and contain at most 256 nodes in total.

## Show child properties

`condition` object optional

A single field comparison in a spans filter expression.

### Show child properties

`field` object required

A reference to a searchable span field.

#### Show child properties

`name` string required

Example: `service.name`

The field name. Well-known span fields include `trace_id`, `span_id`, `parent_span_id`, `start_time`, `end_time`, `duration_ns`, `name`, `service_name`, `kind`, `status_code`, and `status_message`. Any other value is treated as a span or resource attribute key.

`scope` string optional

Optional attribute scope, matched case-insensitively. Use `FIELD_SCOPE_RESOURCE` to match a resource attribute or `FIELD_SCOPE_ATTRIBUTES` to match a span attribute. The aliases `resource` and `resource.attributes` are accepted for resource attributes; `attribute`, `attributes`, and `span.attributes` are accepted for span attributes. Omit for well-known fields or to search both attribute maps.

One of: `FIELD_SCOPE_RESOURCE`, `FIELD_SCOPE_ATTRIBUTES`, `resource`, `resource.attributes`, `attribute`, `attributes`, `span.attributes`

`operator` string required

One of: `FILTER_OPERATOR_EQ`, `FILTER_OPERATOR_NEQ`, `FILTER_OPERATOR_IN`, `FILTER_OPERATOR_GTE`, `FILTER_OPERATOR_LTE`

`value` object optional

A typed literal or list value for a spans filter condition. Exactly one kind is set per message.

#### Show child properties

`string_value` string optional

Example: `api-gateway`

`number_value` number optional

Example: `42`

`string_array_value` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`number_array_value` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`and` object optional

### Show child properties

`expressions` array of objects required

#### Show child properties

`condition` object optional

A single field comparison in a spans filter expression.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`and` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`or` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`not` object optional

A boolean filter tree for spans queries. Exactly one node is set per message. Trees may be nested at most 16 levels deep and contain at most 256 nodes in total.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`text_search` object optional

A substring search across the span name, service name, and status message.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`or` object optional

### Show child properties

`expressions` array of objects required

#### Show child properties

`condition` object optional

A single field comparison in a spans filter expression.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`and` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`or` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`not` object optional

A boolean filter tree for spans queries. Exactly one node is set per message. Trees may be nested at most 16 levels deep and contain at most 256 nodes in total.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`text_search` object optional

A substring search across the span name, service name, and status message.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`not` object optional

A boolean filter tree for spans queries. Exactly one node is set per message. Trees may be nested at most 16 levels deep and contain at most 256 nodes in total.

### Show child properties

`condition` object optional

A single field comparison in a spans filter expression.

#### Show child properties

`field` object required

A reference to a searchable span field.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`operator` string required

One of: `FILTER_OPERATOR_EQ`, `FILTER_OPERATOR_NEQ`, `FILTER_OPERATOR_IN`, `FILTER_OPERATOR_GTE`, `FILTER_OPERATOR_LTE`

`value` object optional

A typed literal or list value for a spans filter condition. Exactly one kind is set per message.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`and` object optional

#### Show child properties

`expressions` array of objects required

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`or` object optional

#### Show child properties

`expressions` array of objects required

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`not` object optional

A boolean filter tree for spans queries. Exactly one node is set per message. Trees may be nested at most 16 levels deep and contain at most 256 nodes in total.

#### Show child properties

`condition` object optional

A single field comparison in a spans filter expression.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`and` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`or` object optional

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`not` object optional

A boolean filter tree for spans queries. Exactly one node is set per message. Trees may be nested at most 16 levels deep and contain at most 256 nodes in total.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`text_search` object optional

A substring search across the span name, service name, and status message.

Additional nested properties not shown. Refer to the [full API spec](https://github.com/digitalocean/openapi) for details.

`text_search` object optional

A substring search across the span name, service name, and status message.

#### Show child properties

`query` string required

Example: `timeout`

The search string. Leading and trailing whitespace is trimmed, and the remaining string must not be empty.

Min length: `1`

Max length: `256`

`text_search` object optional

A substring search across the span name, service name, and status message.

### Show child properties

`query` string required

Example: `timeout`

The search string. Leading and trailing whitespace is trimmed, and the remaining string must not be empty.

Min length: `1`

Max length: `256`

`order_by` array of objects optional

Sort clauses applied to the result set. Defaults to `start_time` descending when omitted.

## Show child properties

`field` object required

A reference to a searchable span field.

### Show child properties

`name` string required

Example: `service.name`

The field name. Well-known span fields include `trace_id`, `span_id`, `parent_span_id`, `start_time`, `end_time`, `duration_ns`, `name`, `service_name`, `kind`, `status_code`, and `status_message`. Any other value is treated as a span or resource attribute key.

`scope` string optional

Optional attribute scope, matched case-insensitively. Use `FIELD_SCOPE_RESOURCE` to match a resource attribute or `FIELD_SCOPE_ATTRIBUTES` to match a span attribute. The aliases `resource` and `resource.attributes` are accepted for resource attributes; `attribute`, `attributes`, and `span.attributes` are accepted for span attributes. Omit for well-known fields or to search both attribute maps.

One of: `FIELD_SCOPE_RESOURCE`, `FIELD_SCOPE_ATTRIBUTES`, `resource`, `resource.attributes`, `attribute`, `attributes`, `span.attributes`

`direction` string optional

The sort direction, matched case-insensitively. Omit to use the server default.

One of: `asc`, `desc`

`pagination` object optional

Limits the number of spans returned.

## Show child properties

`limit` integer optional

Example: `100`

Maximum number of spans to return. Defaults to 100 and must be between 1 and 1000.

Min: `1`

Max: `1000`

Default: `100`

## Request Sample

## Show Request Sample

```python
import os
from pydo import Client

client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))

req = {
  "time_range": {
    "from": {
      "relative": "1h",
      "absolute": "2026-09-30T00:00:00Z"
    },
    "to": {
      "relative": "1h",
      "absolute": "2026-09-30T00:00:00Z"
    }
  },
  "order_by": [
    {
      "direction": "desc"
    }
  ],
  "pagination": {
    "limit": 100
  }
}

resp = client.insights.post_spans_search(region="nyc3", body=req)
```

## Response Example

## Show Response Example

```json
{
  "data": [
    {
      "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
      "span_id": "00f067aa0ba902b7",
      "parent_span_id": "00f067aa0ba902b6",
      "start_time": "2026-09-30T00:00:00Z",
      "end_time": "2026-09-30T00:00:01Z",
      "duration_ns": 1000000,
      "name": "GET /v2/droplets",
      "kind": "Server",
      "status_code": "Ok",
      "status_message": "connection reset by peer",
      "service_name": "api-gateway",
      "resource": {
        "service.name": "api-gateway",
        "service.version": "1.4.2"
      },
      "attributes": {
        "http.method": "GET",
        "http.status_code": "200"
      },
      "region": "nyc3"
    }
  ],
  "pagination": {
    "has_more": true
  }
}
```

## More Information

See [`/v2/insights/query/{region}/spans/search`](https://docs.digitalocean.com/reference/api/reference/insights/index.html.md#insights_post_spansSearch) in the API reference for additional detail on responses, headers, parameters, and more.