{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aruntime.com/schemas/trace-envelope.v1.schema.json",
  "title": "ARuntime Trace Envelope v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "traceId",
    "correlationId",
    "startedUtc",
    "endedUtc",
    "sampling",
    "infrastructureSpans",
    "modelSpans",
    "toolSpans",
    "policyDecisions",
    "businessOutcomes",
    "evaluationResults",
    "redaction"
  ],
  "properties": {
    "schemaVersion": {
      "const": "aruntime.trace-envelope.v1"
    },
    "traceId": {
      "type": "string",
      "pattern": "^[0-9a-f]{32}$"
    },
    "correlationId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "startedUtc": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$",
      "description": "UTC ISO 8601 timestamp ending in Z."
    },
    "endedUtc": {
      "type": "string",
      "format": "date-time",
      "pattern": "Z$",
      "description": "UTC ISO 8601 timestamp ending in Z."
    },
    "sampling": {
      "enum": [
        "record-only",
        "sampled",
        "dropped-details"
      ]
    },
    "infrastructureSpans": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/span"
      }
    },
    "modelSpans": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/span"
      }
    },
    "toolSpans": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/span"
      }
    },
    "policyDecisions": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "businessOutcomes": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "evaluationResults": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "redaction": {
      "type": "object",
      "required": [
        "rawPromptsStored",
        "rules"
      ],
      "properties": {
        "rawPromptsStored": {
          "type": "boolean"
        },
        "rules": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    }
  },
  "$defs": {
    "span": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "spanId",
        "name",
        "startedUtc",
        "endedUtc",
        "status",
        "attributes"
      ],
      "properties": {
        "spanId": {
          "type": "string",
          "pattern": "^[0-9a-f]{16}$"
        },
        "parentSpanId": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9a-f]{16}$"
        },
        "name": {
          "type": "string"
        },
        "startedUtc": {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$",
          "description": "UTC ISO 8601 timestamp ending in Z."
        },
        "endedUtc": {
          "type": "string",
          "format": "date-time",
          "pattern": "Z$",
          "description": "UTC ISO 8601 timestamp ending in Z."
        },
        "status": {
          "enum": [
            "unset",
            "ok",
            "error"
          ]
        },
        "attributes": {
          "type": "object",
          "additionalProperties": {
            "type": [
              "string",
              "number",
              "integer",
              "boolean",
              "null"
            ]
          }
        }
      }
    }
  }
}
