AlinsRan commented on code in PR #12686: URL: https://github.com/apache/apisix/pull/12686#discussion_r2762839350
########## apisix/utils/span.lua: ########## @@ -0,0 +1,101 @@ +-- +-- 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 tablepool = require("tablepool") +local util = require("opentelemetry.util") +local span_status = require("opentelemetry.trace.span_status") +local setmetatable = setmetatable +local table = table +local select = select +local pool_name = "opentelemetry_span" +local update_time = ngx.update_time + +local _M = {} + + +local mt = { + __index = _M +} + +local function get_time() + update_time() + return util.time_nano() +end + + +function _M.new(name, kind) + local self = tablepool.fetch(pool_name, 0, 16) + self.start_time = get_time() + self.name = name + self.kind = kind + self.status = nil + self.dead = false + return setmetatable(self, mt) +end + + +function _M.append_child(self, child_id) + if not self.child_ids then + self.child_ids = table.new(10, 0) + end + table.insert(self.child_ids, child_id) +end + + +function _M.set_parent(self, parent_id) + self.parent_id = parent_id +end + + +function _M.release(self) + tablepool.release(pool_name, self) +end + + +function _M.set_status(self, code, message) + code = span_status.validate(code) + local status = self.status + if not status then + status = { + code = code, + message = "" + } + self.status = status + else + status.code = code + end + + if code == span_status.ERROR then + status.message = message + end +end + + +function _M.set_attributes(self, ...) + local count = select('#', ...) + for i = 1, count do + local attr = select(i, ...) + table.insert(self.attributes, attr) + end +end Review Comment: fixed. -- 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]
