{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://raw.githubusercontent.com/api-evangelist/phoenix/main/json-schema/phoenix-span.json",
  "title": "Span",
  "description": "Phoenix Span schema",
  "properties": {
    "id": {
      "type": "string",
      "title": "Id",
      "description": "Span Global ID, distinct from the OpenTelemetry span ID",
      "default": ""
    },
    "name": {
      "type": "string",
      "title": "Name",
      "description": "Name of the span operation"
    },
    "context": {
      "$ref": "#/components/schemas/SpanContext",
      "description": "Span context containing trace_id and span_id"
    },
    "span_kind": {
      "type": "string",
      "title": "Span Kind",
      "description": "Type of work that the span encapsulates"
    },
    "parent_id": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Parent Id",
      "description": "OpenTelemetry span ID of the parent span"
    },
    "start_time": {
      "type": "string",
      "format": "date-time",
      "title": "Start Time",
      "description": "Start time of the span (must be timezone-aware)"
    },
    "end_time": {
      "type": "string",
      "format": "date-time",
      "title": "End Time",
      "description": "End time of the span (must be timezone-aware)"
    },
    "status_code": {
      "type": "string",
      "title": "Status Code",
      "description": "Status code of the span"
    },
    "status_message": {
      "type": "string",
      "title": "Status Message",
      "description": "Status message",
      "default": ""
    },
    "attributes": {
      "additionalProperties": true,
      "type": "object",
      "title": "Attributes",
      "description": "Span attributes"
    },
    "events": {
      "items": {
        "$ref": "#/components/schemas/SpanEvent"
      },
      "type": "array",
      "title": "Events",
      "description": "Span events"
    }
  },
  "type": "object",
  "required": [
    "name",
    "context",
    "span_kind",
    "start_time",
    "end_time",
    "status_code"
  ],
  "examples": [
    {
      "attributes": {
        "llm.model_name": "gpt-4",
        "llm.token_count.completion": 50,
        "llm.token_count.prompt": 100
      },
      "context": {
        "span_id": "1a2b3c4d5e6f7a8b",
        "trace_id": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4"
      },
      "end_time": "2024-01-01T12:00:01Z",
      "events": [],
      "name": "llm_call",
      "span_kind": "LLM",
      "start_time": "2024-01-01T12:00:00Z",
      "status_code": "OK",
      "status_message": ""
    }
  ]
}