Skip to content

Commit

Permalink
feature: add opentelemetry plugin. (apache#3891)
Browse files Browse the repository at this point in the history
  • Loading branch information
roketyyang committed Jan 16, 2022
1 parent eaa9685 commit fc7e9f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 55 deletions.
8 changes: 7 additions & 1 deletion apisix/plugins/opentelemetry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ 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 = ngx
local ngx_var = ngx.var
local ngx_req = ngx.req
local table = table
local type = type
local pairs = pairs
local ipairs = ipairs
local unpack = unpack

local hostname

Expand Down Expand Up @@ -310,7 +316,7 @@ function _M.body_filter(conf, ctx)
local span = context:current():span()
if upstream_status and upstream_status >= 500 then
span:set_status(span_status.error,
"upstream response status: " .. tostring(upstream_status))
"upstream response status: " .. upstream_status)
end

span:finish()
Expand Down
6 changes: 3 additions & 3 deletions docs/en/latest/plugins/opentelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ title: opentelemetry

## Name

opentelemetry report Tracing data according to [opentelemetry specification](https://github.com/open-telemetry/opentelemetry-specification).
[OpenTelemetry](https://opentelemetry.io/) 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)
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

Expand All @@ -55,7 +55,7 @@ Just support reporting in HTTP with Content-Type=application/x-protobuf, the spe

First of all, enable the opentelemetry plugin in the `config.yaml`:

```
```yaml
# Add this in config.yaml
plugins:
- ... # plugin you need
Expand Down
6 changes: 3 additions & 3 deletions docs/zh/latest/plugins/opentelemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ title: opentelemetry

## 名字

opentelemetry 提供符合 [opentelemetry specification](https://github.com/open-telemetry/opentelemetry-specification) 协议规范的 Tracing 数据上报。
[OpenTelemetry](https://opentelemetry.io/) 提供符合 [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)
只支持 `HTTP` 协议,且请求类型为 `application/x-protobuf` 的数据上报,相关协议标准:[OTLP/HTTP Request](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#otlphttp-request)

## 属性

Expand All @@ -55,7 +55,7 @@ opentelemetry 提供符合 [opentelemetry specification](https://github.com/open

首先,你需要在 `config.yaml` 里面启用 opentelemetry 插件:

```
```yaml
# 加到 config.yaml
plugins:
- ... # plugin you need
Expand Down
60 changes: 12 additions & 48 deletions t/plugin/opentelemetry.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ _EOC_

$block->set_value("extra_init_by_lua", $extra_init_by_lua);

if (!$block->request) {
$block->set_value("request", "GET /t");
}

if (!$block->response_body) {
$block->set_value("response_body", "passed\n");
}

if (!$block->no_error_log && !$block->error_log) {
$block->set_value("no_error_log", "[error]");
}

$block;
});

Expand Down Expand Up @@ -107,12 +119,6 @@ __DATA__
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down Expand Up @@ -178,12 +184,6 @@ opentelemetry export span
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down Expand Up @@ -253,12 +253,6 @@ qr/opentelemetry export span/
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down Expand Up @@ -334,12 +328,6 @@ qr/opentelemetry export span/
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down Expand Up @@ -411,12 +399,6 @@ opentelemetry export span
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down Expand Up @@ -496,12 +478,6 @@ qr/opentelemetry export span/
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down Expand Up @@ -583,12 +559,6 @@ opentelemetry export span
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down Expand Up @@ -691,12 +661,6 @@ opentelemetry export span
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
Expand Down

0 comments on commit fc7e9f9

Please sign in to comment.