{
  "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"
      }
    },
    "schemas": {
      "otelSettingsPublicDto.generated": {
        "type": "object",
        "properties": {
          "enabled": {
            "type": "boolean",
            "description": "是否启用 OpenTelemetry 跟踪。"
          },
          "exporterProtocol": {
            "type": "string",
            "default": "http/protobuf",
            "description": "用于导出跟踪片段（span）的传输协议。收集器通常在端口 4318 提供 OTLP/HTTP，在端口 4317 提供 OTLP/gRPC。两种协议都由端点的 URL 协议（`http://` 或 `https://`）控制 TLS。此字段可选：写入时省略会选择 `http/protobuf`，但实例通过环境变量将此字段设为其他值时，会以 409 拒绝该写入。",
            "enum": [
              "http/protobuf",
              "grpc"
            ]
          },
          "exporterEndpoint": {
            "type": "string",
            "format": "uri",
            "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`。每个键和值两端的空白会被移除；值可以包含空格，但不能包含逗号。未使用时填写空字符串。"
          },
          "tracesSampleRate": {
            "type": "number",
            "description": "跟踪采样比例，范围为 0（不采样）到 1（全部采样）。",
            "minimum": 0,
            "maximum": 1
          },
          "startupConnectivityTimeoutMs": {
            "type": "integer",
            "description": "检查收集器是否可访问时的等待时间，单位为毫秒；也用作发送测试跟踪端点的超时时长。",
            "minimum": 0
          },
          "includeNodeSpans": {
            "type": "boolean",
            "description": "除工作流 span 外，是否还为每次节点执行生成 span。"
          },
          "emitWorkflowStartSpan": {
            "type": "boolean",
            "description": "每次执行或恢复运行的片段开始时，是否生成持续时间为 0 ms 的 `workflow.execute.started` span。此字段可选：写入时省略会选择 `false`，但实例通过环境变量将此字段设为 `true` 时，会以 409 拒绝该写入。"
          },
          "emitNodeStartSpan": {
            "type": "boolean",
            "description": "每个节点 span 开始时，是否生成持续时间为 0 ms 的 `node.execute.started` span。这会使节点 span 数量加倍。`includeNodeSpans` 为 false 时无效。此字段可选：写入时省略会选择 `false`，但实例通过环境变量将此字段设为 `true` 时，会以 409 拒绝该写入。"
          },
          "injectOutbound": {
            "type": "boolean",
            "description": "是否向节点发出的 HTTP 请求注入跟踪上下文请求头。"
          },
          "productionExecutionsOnly": {
            "type": "boolean",
            "description": "为 true 时，仅跟踪已发布（激活）工作流的生产执行，不跟踪手动或测试运行。"
          }
        },
        "required": [
          "enabled",
          "exporterProtocol",
          "exporterEndpoint",
          "exporterTracingPath",
          "exporterServiceName",
          "exporterHeaders",
          "tracesSampleRate",
          "startupConnectivityTimeoutMs",
          "includeNodeSpans",
          "emitWorkflowStartSpan",
          "emitNodeStartSpan",
          "injectOutbound",
          "productionExecutionsOnly"
        ],
        "additionalProperties": false,
        "description": "与界面所提供字段一致的 OpenTelemetry 配置。写入为完整替换，必须提供所有字段，但以下字段除外：`exporterProtocol` 省略时默认为 `http/protobuf`，`emitWorkflowStartSpan` 和 `emitNodeStartSpan` 省略时默认为 `false`。通过环境变量以声明方式管理的字段，会返回其实际生效值。写入时可以重复提交这些值，但更改它们会返回 409。"
      }
    },
    "responses": {
      "badRequest": {
        "description": "请求无效，或提供的数据格式错误。"
      },
      "unauthorized": {
        "description": "未授权"
      },
      "forbidden": {
        "description": "禁止访问"
      },
      "conflict": {
        "description": "冲突"
      },
      "unsupportedMediaType": {
        "description": "不支持的媒体类型。"
      }
    }
  },
  "paths": {
    "/settings/otel": {
      "put": {
        "operationId": "updateOtelSettings",
        "tags": [
          "SettingsOtel"
        ],
        "summary": "设置 OpenTelemetry 配置",
        "description": "设置 OpenTelemetry 配置。此操作为完整替换，必须提供所有字段；只包含部分字段的请求体会被拒绝。例外包括：`exporterProtocol` 省略时默认为 `http/protobuf`，`emitWorkflowStartSpan` 和 `emitNodeStartSpan` 省略时默认为 `false`。更新使用与界面相同的校验，并以相同方式立即应用到运行中的实例。通过环境变量以声明方式管理的字段为只读：尝试更改会以 409 拒绝，重新提交 GET 返回的当前值则会被接受。需要 `otel:manage` 作用域。",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "enabled": {
                    "type": "boolean",
                    "description": "是否启用 OpenTelemetry 跟踪。"
                  },
                  "exporterProtocol": {
                    "type": "string",
                    "enum": [
                      "http/protobuf",
                      "grpc"
                    ],
                    "default": "http/protobuf",
                    "description": "用于导出跟踪片段（span）的传输协议。收集器通常在端口 4318 提供 OTLP/HTTP，在端口 4317 提供 OTLP/gRPC。两种协议都由端点的 URL 协议（`http://` 或 `https://`）控制 TLS。此字段可选：写入时省略会选择 `http/protobuf`，但实例通过环境变量将此字段设为其他值时，会以 409 拒绝该写入。"
                  },
                  "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`。每个键和值两端的空白会被移除；值可以包含空格，但不能包含逗号。未使用时填写空字符串。"
                  },
                  "tracesSampleRate": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1,
                    "description": "跟踪采样比例，范围为 0（不采样）到 1（全部采样）。"
                  },
                  "startupConnectivityTimeoutMs": {
                    "type": "integer",
                    "description": "检查收集器是否可访问时的等待时间，单位为毫秒；也用作发送测试跟踪端点的超时时长。",
                    "minimum": 0
                  },
                  "includeNodeSpans": {
                    "type": "boolean",
                    "description": "除工作流 span 外，是否还为每次节点执行生成 span。"
                  },
                  "emitWorkflowStartSpan": {
                    "type": "boolean",
                    "default": false,
                    "description": "每次执行或恢复运行的片段开始时，是否生成持续时间为 0 ms 的 `workflow.execute.started` span。此字段可选：写入时省略会选择 `false`，但实例通过环境变量将此字段设为 `true` 时，会以 409 拒绝该写入。"
                  },
                  "emitNodeStartSpan": {
                    "type": "boolean",
                    "default": false,
                    "description": "每个节点 span 开始时，是否生成持续时间为 0 ms 的 `node.execute.started` span。这会使节点 span 数量加倍。`includeNodeSpans` 为 false 时无效。此字段可选：写入时省略会选择 `false`，但实例通过环境变量将此字段设为 `true` 时，会以 409 拒绝该写入。"
                  },
                  "injectOutbound": {
                    "type": "boolean",
                    "description": "是否向节点发出的 HTTP 请求注入跟踪上下文请求头。"
                  },
                  "productionExecutionsOnly": {
                    "type": "boolean",
                    "description": "为 true 时，仅跟踪已发布（激活）工作流的生产执行，不跟踪手动或测试运行。"
                  }
                },
                "required": [
                  "enabled",
                  "exporterEndpoint",
                  "exporterTracingPath",
                  "exporterServiceName",
                  "exporterHeaders",
                  "tracesSampleRate",
                  "startupConnectivityTimeoutMs",
                  "includeNodeSpans",
                  "injectOutbound",
                  "productionExecutionsOnly"
                ],
                "additionalProperties": false,
                "description": "与界面所提供字段一致的 OpenTelemetry 配置。写入为完整替换，必须提供所有字段，但以下字段除外：`exporterProtocol` 省略时默认为 `http/protobuf`，`emitWorkflowStartSpan` 和 `emitNodeStartSpan` 省略时默认为 `false`。通过环境变量以声明方式管理的字段，会返回其实际生效值。写入时可以重复提交这些值，但更改它们会返回 409。"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/otelSettingsPublicDto.generated"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/badRequest"
          },
          "401": {
            "$ref": "#/components/responses/unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/forbidden"
          },
          "409": {
            "$ref": "#/components/responses/conflict"
          },
          "415": {
            "$ref": "#/components/responses/unsupportedMediaType"
          }
        }
      }
    }
  }
}
