diff --git a/Dockerfile b/Dockerfile index 77410b8..e815a6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ RUN yum install -y gcc RUN yum -y --enablerepo=powertools install libyaml-devel libffi-devel RUN luarocks install lua-resty-http 0.16.1-0 RUN luarocks install lua-protobuf 0.3.3 +RUN luarocks install net-url 1.1-1 RUN luarocks install busted 2.0.0-1 RUN luarocks --server=http://rocks.moonscript.org install lyaml diff --git a/lib/opentelemetry/trace/exporter/http_client.lua b/lib/opentelemetry/trace/exporter/http_client.lua index 25481af..5e7169d 100644 --- a/lib/opentelemetry/trace/exporter/http_client.lua +++ b/lib/opentelemetry/trace/exporter/http_client.lua @@ -1,4 +1,5 @@ local http = require("resty.http") +local net_url = require("net.url") local _M = { } @@ -7,6 +8,17 @@ local mt = { __index = _M } +local function build_uri(address) + local parsed_address = net_url.parse(address) + if parsed_address.scheme ~= "http" and parsed_address.scheme ~= "https" then + return build_uri("http://" .. address) + end + if parsed_address.path == "" or parsed_address.path == "/" then + parsed_address.path = "/v1/traces" + end + return tostring(parsed_address) +end + ------------------------------------------------------------------ -- create a http client used by exporter. -- @@ -19,13 +31,8 @@ function _M.new(address, timeout, headers) headers = headers or {} headers["Content-Type"] = "application/x-protobuf" - local uri = address .. "/v1/traces" - if address:find("http", 1, true) ~= 1 then - uri = "http://" .. uri - end - local self = { - uri = uri, + uri = build_uri(address), timeout = timeout, headers = headers, } diff --git a/rockspec/opentelemetry-lua-master-0.rockspec b/rockspec/opentelemetry-lua-master-0.rockspec index fcd9282..f32d5c5 100644 --- a/rockspec/opentelemetry-lua-master-0.rockspec +++ b/rockspec/opentelemetry-lua-master-0.rockspec @@ -14,6 +14,7 @@ description = { dependencies = { "lua-protobuf = 0.3.3", "lua-resty-http = 0.16.1-0", + "net-url = 1.1-1", } build = {