Skip to content

Commit

Permalink
feat(opentelemetry): add referenceable attribute to fields that could…
Browse files Browse the repository at this point in the history
… be stored in vaults
  • Loading branch information
mayocream committed Oct 26, 2022
1 parent 262d249 commit 4cdf398
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions kong/plugins/opentelemetry/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ return {
keys = typedefs.header_name,
values = {
type = "string",
referenceable = true,
},
} },
{ resource_attributes = resource_attributes },
Expand Down
52 changes: 52 additions & 0 deletions spec/03-plugins/37-opentelemetry/04-exporter_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,57 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe("#referenceable fields", function ()
lazy_setup(function()
helpers.setenv("TEST_OTEL_ACCESS_KEY", "secret-1")
helpers.setenv("TEST_OTEL_ACCESS_SECRET", "secret-2")
setup_instrumentations("all", {
headers = {
["X-Access-Key"] = "{vault:https://env/test_otel_access_key}",
["X-Access-Secret"] = "{vault:https://env/test_otel_access_secret}",
},
})
end)

lazy_teardown(function()
helpers.unsetenv("TEST_OTEL_ACCESS_KEY")
helpers.unsetenv("TEST_OTEL_ACCESS_SECRET")
helpers.kill_http_server(HTTP_PORT)
helpers.stop_kong()
end)

it("works", function ()
local headers, body
helpers.wait_until(function()
local thread = helpers.http_server(HTTP_PORT, { timeout = 10 })
local cli = helpers.proxy_client(7000)
local r = assert(cli:send {
method = "GET",
path = "/",
})
assert.res_status(200, r)

-- close client connection
cli:close()

local ok
ok, headers, body = thread:join()

return ok
end, 60)

assert.is_string(body)

local idx = tablex.find(headers, "Content-Type: application/x-protobuf")
assert.not_nil(idx, headers)

-- dereferenced headers
idx = tablex.find(headers, "X-Access-Key: secret-1")
assert.not_nil(idx, headers)

idx = tablex.find(headers, "X-Access-Secret: secret-2")
assert.not_nil(idx, headers)
end)
end)
end)
end

0 comments on commit 4cdf398

Please sign in to comment.