## Create span assessment

`client.SpanAssessments.New(ctx, body) (*SpanAssessment, error)`

**post** `/v5/span-assessments`

Attach a new assessment to a span within a trace.

A span assessment records feedback on a single span's output. Its
assessment_type selects one of comment, rating (an integer 1-5), approval
(approved or rejected), rubric (key-value rule pairs), metadata (arbitrary
JSON), or overwrite (a corrected span output), and exactly the content field
matching that type must be supplied; a free-text comment may additionally
accompany any type. trace_id is required, while span_id is optional and, when
omitted, the assessment is attached to the trace's root span. The call returns
404 if the given span_id and trace_id do not identify an existing span, or if
no root span is found for the trace. Creating an overwrite for a span that
already holds a live overwrite returns 409, whether that overwrite is yours or
another user's. Update or delete the existing one instead. Use the list
endpoint to read a span's or trace's existing assessments.

### Parameters

- `body SpanAssessmentNewParams`

  - `AssessmentType param.Field[AssessmentType]`

    Type of assessment

  - `TraceID param.Field[string]`

    The ID of the trace this assessment is attached to

  - `Approval param.Field[ApprovalStatus]`

    Approval status (approved/rejected)

  - `Comment param.Field[string]`

    Raw text feedback

  - `Metadata param.Field[map[string, any]]`

    Arbitrary JSON object for additional data

  - `Overwrite param.Field[map[string, any]]`

    User corrections to span output

  - `Rating param.Field[int64]`

    Numerical rating (1-5)

  - `Rubric param.Field[map[string, string]]`

    Rule key-value pairs for rubric evaluation

  - `SpanID param.Field[string]`

    The ID of the span this assessment is attached to. If omitted, the assessment is attached to the root span of the trace.

### Returns

- `type SpanAssessment struct{…}`

  Response model for span assessment

  - `AssessmentID string`

    Unique identifier for the assessment

  - `AssessmentType AssessmentType`

    Type of assessment

    - `const AssessmentTypeComment AssessmentType = "comment"`

    - `const AssessmentTypeRating AssessmentType = "rating"`

    - `const AssessmentTypeApproval AssessmentType = "approval"`

    - `const AssessmentTypeRubric AssessmentType = "rubric"`

    - `const AssessmentTypeMetadata AssessmentType = "metadata"`

    - `const AssessmentTypeOverwrite AssessmentType = "overwrite"`

  - `CreatedBy string`

    User who submitted the assessment

  - `SpanID string`

    The span this assessment is attached to

  - `TraceID string`

    The trace this assessment is attached to

  - `AccountID string`

    Account this assessment belongs to

  - `Approval ApprovalStatus`

    Approval status (approved/rejected)

    - `const ApprovalStatusApproved ApprovalStatus = "approved"`

    - `const ApprovalStatusRejected ApprovalStatus = "rejected"`

  - `Comment string`

    Raw text feedback

  - `CreatedAt Time`

    When this assessment was created

  - `Metadata map[string, any]`

    Arbitrary JSON object for additional data

  - `Object SpanAssessmentObject`

    - `const SpanAssessmentObjectSpanAssessment SpanAssessmentObject = "span.assessment"`

  - `Overwrite map[string, any]`

    User corrections to span output

  - `Rating int64`

    Numerical rating (1-5)

  - `Rubric map[string, string]`

    Rule key-value pairs for rubric evaluation

  - `UpdatedAt Time`

    When this assessment was last updated

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/scaleapi/sgp-dev-go"
  "github.com/scaleapi/sgp-dev-go/option"
)

func main() {
  client := sgpdev.NewClient(
    option.WithAPIKey("My API Key"),
    option.WithAccountID("My Account ID"),
  )
  spanAssessment, err := client.SpanAssessments.New(context.TODO(), sgpdev.SpanAssessmentNewParams{
    AssessmentType: sgpdev.AssessmentTypeComment,
    TraceID: "trace_id",
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", spanAssessment.AssessmentID)
}
```

#### Response

```json
{
  "assessment_id": "assessment_id",
  "assessment_type": "comment",
  "created_by": "created_by",
  "span_id": "span_id",
  "trace_id": "trace_id",
  "account_id": "account_id",
  "approval": "approved",
  "comment": "comment",
  "created_at": "2019-12-27T18:11:19.117Z",
  "metadata": {
    "foo": "bar"
  },
  "object": "span.assessment",
  "overwrite": {
    "foo": "bar"
  },
  "rating": 1,
  "rubric": {
    "foo": "string"
  },
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```
