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

# Search traces

For the query syntax and how search fits with the other trace endpoints, see [Querying traces](https://docs.appsignal.com/api/v2/traces.md#search-traces).

```yaml POST /api/v2/search theme={null}
openapi: 3.1.0
info:
  title: AppSignal V2 API
  description: >-
    REST API for metrics, traces, logs, Kubernetes monitoring, and deployment
    tracking.
  license:
    name: ''
  version: 0.1.0
paths:
  /api/v2/search:
    post:
      tags:
        - Search
      summary: Search traces
      operationId: search
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchRequest'
            example:
              site_ids:
                - 6591f2705fa150d75339e232
              query: error:RuntimeError
              kind: exception
              from: '2024-01-01T00:00:00Z'
              to: '2024-01-02T00:00:00Z'
        required: true
      responses:
        '200':
          description: >-
            Up to `limit` results, newest first: one per incident digest of each
            matching span, so `trace_id` can repeat.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SearchResult'
        '400':
          description: Malformed request, or input the server cannot process.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestResponse'
        '401':
          description: Missing or invalid authentication token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Route or resource not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: External query concurrency limit exceeded; retry shortly.
          headers:
            Retry-After:
              schema:
                type: integer
              description: Seconds to wait before retrying.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TooManyRequestsResponse'
        '500':
          description: Unhandled server-side failure.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearer_auth: []
        - token_query: []
components:
  schemas:
    BadRequestResponse:
      type: object
      description: >-
        Standard body for HTTP 400 Bad Request responses. Branch on the stable
        `error` slug, display `message` as-is, and read per-error structured
        data from `details`.
      required:
        - error
        - message
      properties:
        error:
          type: string
          description: Stable, machine-readable slug identifying the specific error case.
        message:
          type: string
          description: Human-readable message. Safe to log or display to end users.
        details:
          description: >-
            Per-error structured payload. Shape varies by
            [`error`](Self::error).
    ErrorResponse:
      type: object
      description: Error body returned for 401, 404 and 500 responses.
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error message.
    IncidentKind:
      type: string
      description: Whether something represents an exception or a performance incident.
      enum:
        - exception
        - performance
    SampleKind:
      type: string
      description: Specifies whether to search errors, performance samples, or both.
      enum:
        - all
        - exception
        - performance
    SearchRequest:
      type: object
      description: Request body for the unified search endpoint.
      required:
        - site_ids
      properties:
        site_ids:
          type: array
          items:
            type: string
          description: >-
            Sites to search, as BSON ObjectIds: at least one, all in one
            account.
        query:
          type:
            - string
            - 'null'
          description: >-
            Bare words match an action name, exception name or tag value
            exactly, as one phrase.

            `action:`, `error:` and `tag:` match one field exactly, `message:` a
            case-insensitive whole-word phrase; quote values with spaces.
        namespace:
          type:
            - string
            - 'null'
          description: Optional namespace filter (e.g. `"web"`, `"background"`).
        kind:
          oneOf:
            - $ref: '#/components/schemas/SampleKind'
              description: Sample kind filter.
          default: all
        from:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Start of the time range (inclusive). Defaults to, and is clamped to,
            the

            start of the account's retention.
        to:
          type:
            - string
            - 'null'
          format: date-time
          description: End of the time range (inclusive). Defaults to now.
        limit:
          type: integer
          description: Maximum number of results to return. Clamped to at most 2000.
          default: 50
          minimum: 0
    SearchResult:
      type: object
      description: A search result item returned by the unified search endpoint.
      required:
        - result_type
        - source
        - trace_id
        - site_id
        - time
        - duration
        - tags
      properties:
        result_type:
          $ref: '#/components/schemas/IncidentKind'
          description: Whether this is an exception or performance result.
        source:
          $ref: '#/components/schemas/SearchResultSource'
          description: Where this result came from; always `trace`.
        trace_id:
          type: string
          description: Identifier to open the trace with.
        site_id:
          type: string
          description: Site identifier this result belongs to.
        namespace:
          type:
            - string
            - 'null'
          description: Namespace the result belongs to (e.g. `"web"`, `"background"`).
        revision:
          type:
            - string
            - 'null'
          description: >-
            Git revision or deployment identifier active when the result was
            recorded.
        action_name:
          type:
            - string
            - 'null'
          description: Action name of the result (e.g. `"POST /api/users"`).
        time:
          type: string
          format: date-time
          description: Timestamp when the result was recorded.
        duration:
          type: number
          format: double
          description: Duration in milliseconds of the matched span.
        tags:
          type: object
          description: User-defined tags.
          additionalProperties:
            type: string
          propertyNames:
            type: string
        exception_name:
          type:
            - string
            - 'null'
          description: Exception name; present for exception results only.
        exception_message:
          type:
            - string
            - 'null'
          description: Exception message; present for exception results only.
        incident_digest:
          type:
            - string
            - 'null'
          description: Incident digest used to link to the incident page.
        incident_number:
          type:
            - integer
            - 'null'
          format: int64
          description: Incident number, when the incident digest matches a known incident.
    SearchResultSource:
      type: string
      description: Where a search result originates from.
      enum:
        - trace
    TooManyRequestsResponse:
      type: object
      description: Error body returned for 429 responses.
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error message.
        suggestion:
          type:
            - string
            - 'null'
          description: >-
            A cheaper way to write the request's filter. Only the trace list

            endpoints set it, and only for a filter with a known indexed
            rewrite.
  securitySchemes:
    bearer_auth:
      type: http
      scheme: bearer
      description: '`Authorization: Bearer <token>`'
    token_query:
      type: apiKey
      in: query
      name: token
      description: >-
        Alternative to the Authorization header: pass the token as a
        `?token=<token>` query parameter.
```


## API Specification

The full API specification for this endpoint is available in the [documentation index](https://docs.appsignal.com/llms.txt).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.