# Spans

## Create Span

**post** `/spans`

Create a new span with the provided parameters

### Body Parameters

- `name: string`

  Name that describes what operation this span represents

- `start_time: string`

  The time the span started

- `trace_id: string`

  Unique identifier for the trace this span belongs to

- `id: optional string`

  Unique identifier for the span. If not provided, an ID will be generated.

- `data: optional map[unknown] or array of map[unknown]`

  Any additional metadata or context for the span

  - `map[unknown]`

  - `array of map[unknown]`

- `end_time: optional string`

  The time the span ended

- `input: optional map[unknown] or array of map[unknown]`

  Input parameters or data for the operation

  - `map[unknown]`

  - `array of map[unknown]`

- `output: optional map[unknown] or array of map[unknown]`

  Output data resulting from the operation

  - `map[unknown]`

  - `array of map[unknown]`

- `parent_id: optional string`

  ID of the parent span if this is a child span in a trace

- `task_id: optional string`

  ID of the task this span belongs to

### Returns

- `Span object { id, name, start_time, 7 more }`

  - `id: string`

  - `name: string`

    Name that describes what operation this span represents

  - `start_time: string`

    The time the span started

  - `trace_id: string`

    Unique identifier for the trace this span belongs to

  - `data: optional map[unknown] or array of map[unknown]`

    Any additional metadata or context for the span

    - `map[unknown]`

    - `array of map[unknown]`

  - `end_time: optional string`

    The time the span ended

  - `input: optional map[unknown] or array of map[unknown]`

    Input parameters or data for the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `output: optional map[unknown] or array of map[unknown]`

    Output data resulting from the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `parent_id: optional string`

    ID of the parent span if this is a child span in a trace

  - `task_id: optional string`

    ID of the task this span belongs to

### Example

```http
curl http://localhost:5003/spans \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY" \
    -d '{
          "name": "name",
          "start_time": "2019-12-27T18:11:19.117Z",
          "trace_id": "trace_id"
        }'
```

#### Response

```json
{
  "id": "id",
  "name": "name",
  "start_time": "2019-12-27T18:11:19.117Z",
  "trace_id": "trace_id",
  "data": {
    "foo": "bar"
  },
  "end_time": "2019-12-27T18:11:19.117Z",
  "input": {
    "foo": "bar"
  },
  "output": {
    "foo": "bar"
  },
  "parent_id": "parent_id",
  "task_id": "task_id"
}
```

## List Spans

**get** `/spans`

List spans, optionally filtered by trace_id and/or task_id

### Query Parameters

- `limit: optional number`

- `order_by: optional string`

- `order_direction: optional string`

- `page_number: optional number`

- `task_id: optional string`

- `trace_id: optional string`

### Returns

- `id: string`

- `name: string`

  Name that describes what operation this span represents

- `start_time: string`

  The time the span started

- `trace_id: string`

  Unique identifier for the trace this span belongs to

- `data: optional map[unknown] or array of map[unknown]`

  Any additional metadata or context for the span

  - `map[unknown]`

  - `array of map[unknown]`

- `end_time: optional string`

  The time the span ended

- `input: optional map[unknown] or array of map[unknown]`

  Input parameters or data for the operation

  - `map[unknown]`

  - `array of map[unknown]`

- `output: optional map[unknown] or array of map[unknown]`

  Output data resulting from the operation

  - `map[unknown]`

  - `array of map[unknown]`

- `parent_id: optional string`

  ID of the parent span if this is a child span in a trace

- `task_id: optional string`

  ID of the task this span belongs to

### Example

```http
curl http://localhost:5003/spans \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY"
```

#### Response

```json
[
  {
    "id": "id",
    "name": "name",
    "start_time": "2019-12-27T18:11:19.117Z",
    "trace_id": "trace_id",
    "data": {
      "foo": "bar"
    },
    "end_time": "2019-12-27T18:11:19.117Z",
    "input": {
      "foo": "bar"
    },
    "output": {
      "foo": "bar"
    },
    "parent_id": "parent_id",
    "task_id": "task_id"
  }
]
```

## Partial Update Span

**patch** `/spans/{span_id}`

Update a span with the provided output data and mark it as complete

### Path Parameters

- `span_id: string`

### Body Parameters

- `data: optional map[unknown] or array of map[unknown]`

  Any additional metadata or context for the span

  - `map[unknown]`

  - `array of map[unknown]`

- `end_time: optional string`

  The time the span ended

- `input: optional map[unknown] or array of map[unknown]`

  Input parameters or data for the operation

  - `map[unknown]`

  - `array of map[unknown]`

- `name: optional string`

  Name that describes what operation this span represents

- `output: optional map[unknown] or array of map[unknown]`

  Output data resulting from the operation

  - `map[unknown]`

  - `array of map[unknown]`

- `parent_id: optional string`

  ID of the parent span if this is a child span in a trace

- `start_time: optional string`

  The time the span started

- `task_id: optional string`

  ID of the task this span belongs to

- `trace_id: optional string`

  Unique identifier for the trace this span belongs to

### Returns

- `Span object { id, name, start_time, 7 more }`

  - `id: string`

  - `name: string`

    Name that describes what operation this span represents

  - `start_time: string`

    The time the span started

  - `trace_id: string`

    Unique identifier for the trace this span belongs to

  - `data: optional map[unknown] or array of map[unknown]`

    Any additional metadata or context for the span

    - `map[unknown]`

    - `array of map[unknown]`

  - `end_time: optional string`

    The time the span ended

  - `input: optional map[unknown] or array of map[unknown]`

    Input parameters or data for the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `output: optional map[unknown] or array of map[unknown]`

    Output data resulting from the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `parent_id: optional string`

    ID of the parent span if this is a child span in a trace

  - `task_id: optional string`

    ID of the task this span belongs to

### Example

```http
curl http://localhost:5003/spans/$SPAN_ID \
    -X PATCH \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY" \
    -d '{}'
```

#### Response

```json
{
  "id": "id",
  "name": "name",
  "start_time": "2019-12-27T18:11:19.117Z",
  "trace_id": "trace_id",
  "data": {
    "foo": "bar"
  },
  "end_time": "2019-12-27T18:11:19.117Z",
  "input": {
    "foo": "bar"
  },
  "output": {
    "foo": "bar"
  },
  "parent_id": "parent_id",
  "task_id": "task_id"
}
```

## Get Span

**get** `/spans/{span_id}`

Get a span by ID

### Path Parameters

- `span_id: string`

### Returns

- `Span object { id, name, start_time, 7 more }`

  - `id: string`

  - `name: string`

    Name that describes what operation this span represents

  - `start_time: string`

    The time the span started

  - `trace_id: string`

    Unique identifier for the trace this span belongs to

  - `data: optional map[unknown] or array of map[unknown]`

    Any additional metadata or context for the span

    - `map[unknown]`

    - `array of map[unknown]`

  - `end_time: optional string`

    The time the span ended

  - `input: optional map[unknown] or array of map[unknown]`

    Input parameters or data for the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `output: optional map[unknown] or array of map[unknown]`

    Output data resulting from the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `parent_id: optional string`

    ID of the parent span if this is a child span in a trace

  - `task_id: optional string`

    ID of the task this span belongs to

### Example

```http
curl http://localhost:5003/spans/$SPAN_ID \
    -H "Authorization: Bearer $AGENTEX_SDK_API_KEY"
```

#### Response

```json
{
  "id": "id",
  "name": "name",
  "start_time": "2019-12-27T18:11:19.117Z",
  "trace_id": "trace_id",
  "data": {
    "foo": "bar"
  },
  "end_time": "2019-12-27T18:11:19.117Z",
  "input": {
    "foo": "bar"
  },
  "output": {
    "foo": "bar"
  },
  "parent_id": "parent_id",
  "task_id": "task_id"
}
```

## Domain Types

### Span

- `Span object { id, name, start_time, 7 more }`

  - `id: string`

  - `name: string`

    Name that describes what operation this span represents

  - `start_time: string`

    The time the span started

  - `trace_id: string`

    Unique identifier for the trace this span belongs to

  - `data: optional map[unknown] or array of map[unknown]`

    Any additional metadata or context for the span

    - `map[unknown]`

    - `array of map[unknown]`

  - `end_time: optional string`

    The time the span ended

  - `input: optional map[unknown] or array of map[unknown]`

    Input parameters or data for the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `output: optional map[unknown] or array of map[unknown]`

    Output data resulting from the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `parent_id: optional string`

    ID of the parent span if this is a child span in a trace

  - `task_id: optional string`

    ID of the task this span belongs to

### Span List Response

- `SpanListResponse = array of Span`

  - `id: string`

  - `name: string`

    Name that describes what operation this span represents

  - `start_time: string`

    The time the span started

  - `trace_id: string`

    Unique identifier for the trace this span belongs to

  - `data: optional map[unknown] or array of map[unknown]`

    Any additional metadata or context for the span

    - `map[unknown]`

    - `array of map[unknown]`

  - `end_time: optional string`

    The time the span ended

  - `input: optional map[unknown] or array of map[unknown]`

    Input parameters or data for the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `output: optional map[unknown] or array of map[unknown]`

    Output data resulting from the operation

    - `map[unknown]`

    - `array of map[unknown]`

  - `parent_id: optional string`

    ID of the parent span if this is a child span in a trace

  - `task_id: optional string`

    ID of the task this span belongs to
