## Get a span

`client.Spans.Get(ctx, spanID) (*Span, error)`

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

Retrieve a single span by its id.

The span is read from the legacy trace store or, for accounts migrated to the
tracing service, from that service — with automatic fallback to the legacy
trace store on error unless the account is in strict mode, where a
tracing-service failure surfaces as a 503. Access is authorized against the
span's parent trace, so a span in a trace the caller cannot read is rejected;
an unknown id returns 404. `input_tokens` and `output_tokens` carry the token usage the
span's producer reported at ingest, and are absent both for a span that reported none and for
every span served from the legacy trace store, which keeps no token counts.

### Parameters

- `spanID string`

### Returns

- `type Span struct{…}`

  - `ID string`

  - `AccountID string`

  - `Name string`

  - `StartTimestamp Time`

  - `TraceID string`

    id for grouping traces together, uuid is recommended

  - `ApplicationInteractionID string`

    The interaction ID this span belongs to

  - `ApplicationVariantID string`

    The id of the application variant this span belongs to

  - `CreatedBy Identity`

    The identity that created the entity.

    - `ID string`

    - `Type IdentityType`

      - `const IdentityTypeUser IdentityType = "user"`

      - `const IdentityTypeServiceAccount IdentityType = "service_account"`

    - `Object IdentityObject`

      - `const IdentityObjectIdentity IdentityObject = "identity"`

  - `EndTimestamp Time`

  - `Expected map[string, any]`

  - `GroupID string`

    Reference to a group_id

  - `Input map[string, any]`

  - `InputTokens int64`

    Prompt tokens the producer reported for this span, absent when it reported none. Same quantity the input_tokens sort orders by.

  - `Metadata map[string, any]`

  - `Object SpanObject`

    - `const SpanObjectSpan SpanObject = "span"`

  - `ObsSpanID string`

    W3C span id of the observability span this span executed in.

  - `ObsTraceID string`

    W3C trace id of the observability trace this span executed in. Null for spans written without the edge, and for accounts still served by the legacy trace store.

  - `Output map[string, any]`

  - `OutputTokens int64`

    Completion tokens the producer reported for this span, absent when it reported none. Same quantity the output_tokens sort orders by.

  - `ParentID string`

    Reference to a parent span_id

  - `Status SpanStatus`

    - `const SpanStatusSuccess SpanStatus = "SUCCESS"`

    - `const SpanStatusError SpanStatus = "ERROR"`

    - `const SpanStatusCanceled SpanStatus = "CANCELED"`

  - `Type SpanType`

    - `const SpanTypeTextInput SpanType = "TEXT_INPUT"`

    - `const SpanTypeTextOutput SpanType = "TEXT_OUTPUT"`

    - `const SpanTypeCompletionInput SpanType = "COMPLETION_INPUT"`

    - `const SpanTypeCompletion SpanType = "COMPLETION"`

    - `const SpanTypeKBRetrieval SpanType = "KB_RETRIEVAL"`

    - `const SpanTypeKBInput SpanType = "KB_INPUT"`

    - `const SpanTypeReranking SpanType = "RERANKING"`

    - `const SpanTypeExternalEndpoint SpanType = "EXTERNAL_ENDPOINT"`

    - `const SpanTypePromptEngineering SpanType = "PROMPT_ENGINEERING"`

    - `const SpanTypeDocumentInput SpanType = "DOCUMENT_INPUT"`

    - `const SpanTypeMapReduce SpanType = "MAP_REDUCE"`

    - `const SpanTypeDocumentSearch SpanType = "DOCUMENT_SEARCH"`

    - `const SpanTypeDocumentPrompt SpanType = "DOCUMENT_PROMPT"`

    - `const SpanTypeCustom SpanType = "CUSTOM"`

    - `const SpanTypeCodeExecution SpanType = "CODE_EXECUTION"`

    - `const SpanTypeDataManipulation SpanType = "DATA_MANIPULATION"`

    - `const SpanTypeEvaluation SpanType = "EVALUATION"`

    - `const SpanTypeFileRetrieval SpanType = "FILE_RETRIEVAL"`

    - `const SpanTypeKBAddChunk SpanType = "KB_ADD_CHUNK"`

    - `const SpanTypeKBManagement SpanType = "KB_MANAGEMENT"`

    - `const SpanTypeGuardrail SpanType = "GUARDRAIL"`

    - `const SpanTypeOutputGuardrail SpanType = "OUTPUT_GUARDRAIL"`

    - `const SpanTypeTracer SpanType = "TRACER"`

    - `const SpanTypeAgentTracer SpanType = "AGENT_TRACER"`

    - `const SpanTypeAgentWorkflow SpanType = "AGENT_WORKFLOW"`

    - `const SpanTypeStandalone SpanType = "STANDALONE"`

### 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"),
  )
  span, err := client.Spans.Get(context.TODO(), "span_id")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", span.ID)
}
```

#### Response

```json
{
  "id": "id",
  "account_id": "account_id",
  "name": "name",
  "start_timestamp": "2019-12-27T18:11:19.117Z",
  "trace_id": "trace_id",
  "application_interaction_id": "application_interaction_id",
  "application_variant_id": "application_variant_id",
  "created_by": {
    "id": "id",
    "type": "user",
    "object": "identity"
  },
  "end_timestamp": "2019-12-27T18:11:19.117Z",
  "expected": {
    "foo": "bar"
  },
  "group_id": "group_id",
  "input": {
    "foo": "bar"
  },
  "input_tokens": 0,
  "metadata": {
    "foo": "bar"
  },
  "object": "span",
  "obs_span_id": "obs_span_id",
  "obs_trace_id": "obs_trace_id",
  "output": {
    "foo": "bar"
  },
  "output_tokens": 0,
  "parent_id": "parent_id",
  "status": "SUCCESS",
  "type": "TEXT_INPUT"
}
```
