Baoyuantop commented on code in PR #13095: URL: https://github.com/apache/apisix/pull/13095#discussion_r3097679135
########## apisix/plugins/langfuse.lua: ########## @@ -0,0 +1,693 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +local bp_manager_mod = require("apisix.utils.batch-processor-manager") +local plugin_mod = require("apisix.plugin") +local core = require("apisix.core") +local http = require("resty.http") +local url = require("net.url") +local uuid = require("resty.jit-uuid") +local ngx = ngx +local ngx_now = ngx.now +local ngx_encode_base64 = ngx.encode_base64 +local ipairs = ipairs +local pairs = pairs +local type = type +local math = math +local pcall = pcall +local tonumber = tonumber +local next = next +local tostring = tostring +local string = string +local os = os + +local plugin_name = "langfuse" +local batch_processor_manager = bp_manager_mod.new("langfuse logger") + +local metadata_schema = { + type = "object", + properties = { + langfuse_host = { + type = "string", + default = "https://cloud.langfuse.com", + }, + langfuse_public_key = {type = "string"}, + langfuse_secret_key = {type = "string"}, + ssl_verify = {type = "boolean", default = true}, + timeout = {type = "integer", minimum = 1, default = 3}, + detect_ai_requests = { + type = "boolean", + default = true, + description = "Only trace AI API requests" + }, + ai_endpoints = { + type = "array", + items = {type = "string"}, + default = { + "/chat/completions", "/completions", "/generate", + "/responses", "/embeddings", "/messages", + }, + description = "AI endpoint patterns to detect" + }, + }, + required = {"langfuse_public_key", "langfuse_secret_key"}, +} + +local schema = { + type = "object", + properties = { + include_metadata = { + type = "boolean", + default = true, + description = "Include request metadata (headers, route info)" + }, + }, +} + + +local _M = { + version = 0.1, + priority = 396, + name = plugin_name, + schema = batch_processor_manager:wrap_schema(schema), + metadata_schema = metadata_schema, +} + + +function _M.check_schema(conf, schema_type) + if schema_type == core.schema.TYPE_METADATA then + return core.schema.check(metadata_schema, conf) + end + return core.schema.check(schema, conf) Review Comment: `check_schema` uses unwrapped schema: `_M.schema` is wrapped via `batch_processor_manager:wrap_schema(schema)`, but `check_schema` validates against the raw `schema` for non-metadata types. This means batch processor config fields (e.g., `batch_max_size`) will fail validation. Please change to: ```lua return core.schema.check(_M.schema, conf) ``` ########## apisix/plugins/langfuse.lua: ########## @@ -0,0 +1,693 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one or more +-- contributor license agreements. See the NOTICE file distributed with +-- this work for additional information regarding copyright ownership. +-- The ASF licenses this file to You under the Apache License, Version 2.0 +-- (the "License"); you may not use this file except in compliance with +-- the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +local bp_manager_mod = require("apisix.utils.batch-processor-manager") +local plugin_mod = require("apisix.plugin") +local core = require("apisix.core") +local http = require("resty.http") +local url = require("net.url") +local uuid = require("resty.jit-uuid") +local ngx = ngx +local ngx_now = ngx.now +local ngx_encode_base64 = ngx.encode_base64 +local ipairs = ipairs +local pairs = pairs +local type = type +local math = math +local pcall = pcall +local tonumber = tonumber +local next = next +local tostring = tostring +local string = string +local os = os + +local plugin_name = "langfuse" +local batch_processor_manager = bp_manager_mod.new("langfuse logger") + +local metadata_schema = { Review Comment: Missing `encrypt_fields`: `langfuse_secret_key` in plugin_metadata will be stored in plaintext in etcd. Please either add `encrypt_fields` support or document this risk clearly. See `lago.lua` L111 for reference. ########## conf/config.yaml.example: ########## @@ -560,6 +560,7 @@ plugins: # plugin list (sorted by priority) - udp-logger # priority: 400 - file-logger # priority: 399 - clickhouse-logger # priority: 398 + - langfuse # priority: 396 Review Comment: langfuse (priority 396) should be listed after tencent-cloud-cls (priority 397) to maintain descending priority order -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
