Skip to content

Commit

Permalink
Merge pull request #101 from yangxikun/feature/rokety/support_custom_uri
Browse files Browse the repository at this point in the history
feat: exporter support custom uri, closes #99
  • Loading branch information
yangxikun authored Jul 24, 2024
2 parents e5875d9 + 4cf54ec commit f82db27
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions lib/opentelemetry/trace/exporter/http_client.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local http = require("resty.http")
local net_url = require("net.url")

local _M = {
}
Expand All @@ -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.
--
Expand All @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions rockspec/opentelemetry-lua-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description = {
dependencies = {
"lua-protobuf = 0.3.3",
"lua-resty-http = 0.16.1-0",
"net-url = 1.1-1",
}

build = {
Expand Down

0 comments on commit f82db27

Please sign in to comment.