Skip to content

Commit

Permalink
feat: exporter support custom uri, closes #99
Browse files Browse the repository at this point in the history
  • Loading branch information
roketyyang committed Jul 13, 2024
1 parent e5875d9 commit ad7cdc3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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 ad7cdc3

Please sign in to comment.