leslie-tsang commented on a change in pull request #6119:
URL: https://github.com/apache/apisix/pull/6119#discussion_r785445833



##########
File path: docs/en/latest/plugins/opentelemetry.md
##########
@@ -0,0 +1,154 @@
+---
+title: opentelemetry
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Summary
+
+- [**Name**](#name)
+- [**Attributes**](#attributes)
+- [**How To Enable**](#how-to-enable)
+- [**How to set collecting**](#how-to-set-collecting)
+- [**Disable Plugin**](#disable-plugin)
+
+## Name
+
+opentelemetry report Tracing data according to [opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification).

Review comment:
       ```suggestion
   [OpenTelemetry](https://opentelemetry.io/) report Tracing data according to 
[opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification).
   ```

##########
File path: docs/zh/latest/plugins/opentelemetry.md
##########
@@ -0,0 +1,152 @@
+---
+title: opentelemetry
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## 目录
+
+- [名字](#名字)
+- [属性](#属性)
+- [如何启用](#如何启用)
+- [如何设置数据上报](#如何设置数据上报)
+- [禁用插件](#禁用插件)
+
+## 名字
+
+opentelemetry 提供符合 [opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification) 
协议规范的 Tracing 数据上报。
+
+只支持 HTTP 协议 application/x-protobuf 类型的数据上报,相关协议标准:[OTLP/HTTP 
Request](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request)。
+
+## 属性
+
+| 名称         | 类型   | 必选项 | 默认值   | 有效值       | 描述                             
                     |
+| ------------ | ------ | ------ | -------- | ------------ | 
----------------------------------------------------- |
+| sampler | object | 可选 | | | 采样配置
+| sampler.name | string | 可选 | always_off | ["always_on", "always_off", 
"trace_id_ratio", "parent_base"] | 
采样算法,always_on:全采样;always_off:不采样;trace_id_ratio:基于 trace id 
的百分比采样;parent_base:如果存在 tracing 上游,则使用上游的采样决定,否则使用配置的采样算法决策
+| sampler.options | object | 可选 | | {fraction = 0, root = {name = 
"always_off"}} | 采样算法参数
+| sampler.options.fraction | number | 可选 | 0 | [0, 1] | trace_id_ratio 采样算法的百分比
+| sampler.options.root | object | 可选 | {name = "always_off", options = 
{fraction = 0}} | | parent_base 采样算法在没有上游 tracing 时,会使用 root 采样算法做决策
+| sampler.options.root.name | string | 可选 | always_off | ["always_on", 
"always_off", "trace_id_ratio"] | 采样算法
+| sampler.options.root.options | object | 可选 | {fraction = 0} | | 采样算法参数
+| sampler.options.root.options.fraction | number | 可选 | 0 | [0, 1] | 
trace_id_ratio 采样算法的百分比
+| tags | array[object] | 可选 | | | 追加到 trace span 的属性
+| tags.position | string | 必须 | | ["http", "arg", "cookie"] | 变量的位置
+| tags.name | string | 必须 | | | 变量的名称
+
+## 如何启用
+
+首先,你需要在 `config.yaml` 里面启用 opentelemetry 插件:
+
+```

Review comment:
       ```suggestion
   ```yaml
   ```

##########
File path: docs/en/latest/plugins/opentelemetry.md
##########
@@ -0,0 +1,154 @@
+---
+title: opentelemetry
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Summary
+
+- [**Name**](#name)
+- [**Attributes**](#attributes)
+- [**How To Enable**](#how-to-enable)
+- [**How to set collecting**](#how-to-set-collecting)
+- [**Disable Plugin**](#disable-plugin)
+
+## Name
+
+opentelemetry report Tracing data according to [opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification).
+
+Just support reporting in HTTP with Content-Type=application/x-protobuf, the 
specification: [OTLP/HTTP 
Request](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request)。

Review comment:
       ```suggestion
   Just support reporting in `HTTP` with `Content-Type=application/x-protobuf`, 
the specification: [OTLP/HTTP 
Request](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request)。
   ```

##########
File path: t/plugin/opentelemetry.t
##########
@@ -0,0 +1,729 @@
+#
+# 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.
+#
+
+use t::APISIX 'no_plan';
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    my $extra_yaml_config = <<_EOC_;
+plugins:
+    - opentelemetry
+plugin_attr:
+    opentelemetry:
+        batch_span_processor:
+            max_export_batch_size: 1
+            inactive_timeout: 0.5
+_EOC_
+
+    $block->set_value("extra_yaml_config", $extra_yaml_config);
+
+    my $extra_init_by_lua = <<_EOC_;
+    -- mock exporter http client
+    local client = require("opentelemetry.trace.exporter.http_client")
+    client.do_request = function()
+        ngx.log(ngx.INFO, "opentelemetry export span")
+    end
+_EOC_
+
+    $block->set_value("extra_init_by_lua", $extra_init_by_lua);
+
+    $block;
+});
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+log_level("debug");
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: add plugin
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "plugins": {
+                        "opentelemetry": {
+                            "sampler": {
+                                "name": "always_on"
+                            }
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/opentracing"
+                }]],
+                [[{
+                    "node": {
+                        "value": {
+                            "plugins": {
+                                "opentelemetry": {
+                                    "sampler": {
+                                        "name": "always_on"
+                                    }
+                                }
+                            },
+                            "upstream": {
+                                "nodes": {
+                                    "127.0.0.1:1980": 1
+                                },
+                                "type": "roundrobin"
+                            },
+                            "uri": "/opentracing"
+                        },
+                        "key": "/apisix/routes/1"
+                    },
+                    "action": "set"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]

Review comment:
       Shall we optimize it this way ?
   
   ```perl
   add_block_preprocessor(sub {
       my ($block) = @_;
   
       if (!$block->request) {
           $block->set_value("request", "GET /t");
       }
   
       if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
           $block->set_value("no_error_log", "[error]");
       }
   });
   ```

##########
File path: docs/zh/latest/plugins/opentelemetry.md
##########
@@ -0,0 +1,152 @@
+---
+title: opentelemetry
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## 目录
+
+- [名字](#名字)
+- [属性](#属性)
+- [如何启用](#如何启用)
+- [如何设置数据上报](#如何设置数据上报)
+- [禁用插件](#禁用插件)
+
+## 名字
+
+opentelemetry 提供符合 [opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification) 
协议规范的 Tracing 数据上报。

Review comment:
       ```suggestion
   [OpenTelemetry](https://opentelemetry.io/) 提供符合 [opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification) 
协议规范的 Tracing 数据上报。
   ```

##########
File path: apisix/plugins/opentelemetry.lua
##########
@@ -0,0 +1,275 @@
+local plugin_name = "opentelemetry"

Review comment:
       Need to add Apache Lic

##########
File path: docs/zh/latest/plugins/opentelemetry.md
##########
@@ -0,0 +1,152 @@
+---
+title: opentelemetry
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## 目录
+
+- [名字](#名字)
+- [属性](#属性)
+- [如何启用](#如何启用)
+- [如何设置数据上报](#如何设置数据上报)
+- [禁用插件](#禁用插件)
+
+## 名字
+
+opentelemetry 提供符合 [opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification) 
协议规范的 Tracing 数据上报。
+
+只支持 HTTP 协议 application/x-protobuf 类型的数据上报,相关协议标准:[OTLP/HTTP 
Request](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request)。

Review comment:
       Ditto, Seems to be out of sync with the en docs.

##########
File path: apisix/plugins/opentelemetry.lua
##########
@@ -0,0 +1,275 @@
+local plugin_name = "opentelemetry"
+local core = require("apisix.core")
+local plugin = require("apisix.plugin")
+local process = require("ngx.process")
+
+local always_off_sampler_new = 
require("opentelemetry.trace.sampling.always_off_sampler").new
+local always_on_sampler_new = 
require("opentelemetry.trace.sampling.always_on_sampler").new
+local parent_base_sampler_new = 
require("opentelemetry.trace.sampling.parent_base_sampler").new
+local trace_id_ratio_sampler_new = 
require("opentelemetry.trace.sampling.trace_id_ratio_sampler").new
+
+local exporter_client_new = 
require("opentelemetry.trace.exporter.http_client").new
+local otlp_exporter_new = require("opentelemetry.trace.exporter.otlp").new
+local batch_span_processor_new = 
require("opentelemetry.trace.batch_span_processor").new
+local id_generator = require("opentelemetry.trace.id_generator")
+local tracer_provider_new = require("opentelemetry.trace.tracer_provider").new
+
+local span_kind = require("opentelemetry.trace.span_kind")
+local span_status = require("opentelemetry.trace.span_status")
+local resource_new = require("opentelemetry.resource").new
+local attr = require("opentelemetry.attribute")
+
+local context_storage = require("opentelemetry.context_storage")
+local context = require("opentelemetry.context").new(context_storage)
+local carrier_new = require("opentelemetry.trace.propagation.carrier").new
+local trace_context = require("opentelemetry.trace.propagation.trace_context")
+
+local ngx_var = ngx.var
+local ngx_req = ngx.req

Review comment:
       ```suggestion
   local ngx     = ngx
   local ngx_var = ngx.var
   local ngx_req = ngx.req
   local table   = table
   ```

##########
File path: docs/en/latest/plugins/opentelemetry.md
##########
@@ -0,0 +1,154 @@
+---
+title: opentelemetry
+---
+
+<!--
+#
+# 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.
+#
+-->
+
+## Summary
+
+- [**Name**](#name)
+- [**Attributes**](#attributes)
+- [**How To Enable**](#how-to-enable)
+- [**How to set collecting**](#how-to-set-collecting)
+- [**Disable Plugin**](#disable-plugin)
+
+## Name
+
+opentelemetry report Tracing data according to [opentelemetry 
specification](https://github.com/open-telemetry/opentelemetry-specification).
+
+Just support reporting in HTTP with Content-Type=application/x-protobuf, the 
specification: [OTLP/HTTP 
Request](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request)。
+
+## Attributes
+
+| Name         | Type   | Requirement | Default  | Valid        | Description  
                                                        |
+| ------------ | ------ | ------ | -------- | ------------ | 
----------------------------------------------------- |
+| sampler | object | optional | | | sampling config
+| sampler.name | string | optional | always_off | ["always_on", "always_off", 
"trace_id_ratio", "parent_base"] | sampling strategy,always_on:sampling 
all;always_off:sampling nothing;trace_id_ratio:base trace id 
percentage;parent_base:use parent decision, otherwise determined by root
+| sampler.options | object | optional | | {fraction = 0, root = {name = 
"always_off"}} | sampling strategy parameters
+| sampler.options.fraction | number | optional | 0 | [0, 1] | trace_id_ratio 
fraction
+| sampler.options.root | object | optional | {name = "always_off", options = 
{fraction = 0}} | | parent_base root sampler
+| sampler.options.root.name | string | optional | always_off | ["always_on", 
"always_off", "trace_id_ratio"] | sampling strategy
+| sampler.options.root.options | object | optional | {fraction = 0} | | 
sampling strategy parameters
+| sampler.options.root.options.fraction | number | optional | 0 | [0, 1] | 
trace_id_ratio fraction
+| tags | array[object] | optional | | | append to trace span attributes
+| tags.position | string | required | | ["http", "arg", "cookie"] | where 
variable in
+| tags.name | string | required | | | variable name
+
+## How To Enable
+
+First of all, enable the opentelemetry plugin in the `config.yaml`:
+
+```

Review comment:
       ```suggestion
   ```yaml
   ```




-- 
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]


Reply via email to