{
  "openapi": "3.0.0",
  "info": {
    "title": "n8n 公共 API",
    "version": "1.1.1"
  },
  "tags": [
    {
      "name": "SettingsOtel",
      "description": "OpenTelemetry 设置相关操作"
    }
  ],
  "servers": [
    {
      "url": "/api/v1",
      "description": "当前 n8n 实例（自托管版本的内置测试台）"
    },
    {
      "url": "{url}/api/v1",
      "description": "自托管 n8n 实例",
      "variables": {
        "url": {
          "default": "https://example.com"
        }
      }
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    },
    {
      "CookieAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-N8N-API-KEY"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      },
      "CookieAuth": {
        "type": "apiKey",
        "in": "cookie",
        "name": "n8n-auth"
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      }
    }
  },
  "paths": {
    "/settings/otel/test-trace": {
      "post": {
        "operationId": "testOtelTrace",
        "tags": [
          "SettingsOtel"
        ],
        "summary": "测试与 OTLP 收集器的连接",
        "description": "向指定的 OTLP 收集器发送单个测试 span，并报告其是否被接受。此操作仅测试提供的连接详情，不更改已存储配置。发送测试之前，通过环境变量以声明方式管理的字段，会被其实际生效值覆盖。需要 `otel:manage` 作用域。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "exporterProtocol": {
                    "type": "string",
                    "enum": [
                      "http/protobuf",
                      "grpc"
                    ],
                    "default": "http/protobuf",
                    "description": "发送测试 span 所用的传输协议。收集器通常在端口 4318 提供 OTLP/HTTP，在端口 4317 提供 OTLP/gRPC。两种协议都由端点的 URL 协议（`http://` 或 `https://`）控制 TLS。此字段可选：省略时选择 `http/protobuf`，但若由环境变量管理，则使用环境变量提供的值。"
                  },
                  "exporterEndpoint": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https?:\\/\\/",
                    "description": "用于接收跟踪数据的 OTLP 收集器基础 URL。必须使用 `http://` 或 `https://` URL，由 URL 协议决定是否使用 TLS：对于 gRPC，`https://` 使用 SSL，`http://` 使用明文。"
                  },
                  "exporterTracingPath": {
                    "type": "string",
                    "description": "追加到端点上的 OTLP 跟踪信号路径。`exporterProtocol` 为 `grpc` 时忽略，因为 gRPC 不使用 URL 路径。"
                  },
                  "exporterServiceName": {
                    "type": "string",
                    "minLength": 1,
                    "description": "测试 span 上报告的 `service.name` 资源属性。"
                  },
                  "exporterHeaders": {
                    "type": "string",
                    "description": "发送到 OTLP 收集器的附加请求头，使用单个字符串表示，以逗号分隔各个 `key=value`，例如 `authorization=Bearer my-token,x-tenant-id=acme`。每个键和值两端的空白会被移除；值可以包含空格，但不能包含逗号。未使用时填写空字符串。"
                  },
                  "startupConnectivityTimeoutMs": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "等待收集器响应的时间，单位为毫秒。"
                  }
                },
                "required": [
                  "exporterEndpoint",
                  "exporterTracingPath",
                  "exporterServiceName",
                  "exporterHeaders",
                  "startupConnectivityTimeoutMs"
                ],
                "additionalProperties": false,
                "description": "用于测试 OTLP 收集器的连接详情。发送测试之前，通过环境变量以声明方式管理的字段，会被其实际生效值覆盖。"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "收集器是否接受了测试 span。"
                    },
                    "error": {
                      "type": "string",
                      "description": "收集器或导出器报告的错误，仅当 `success` 为 false 时返回。"
                    }
                  },
                  "required": [
                    "success"
                  ],
                  "additionalProperties": false,
                  "description": "与 OTLP 收集器进行连接测试的结果。"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "415": {
            "$ref": "#/components/responses/unsupportedMediaType"
          }
        }
      }
    }
  }
}
