Skip to content

Commit

Permalink
test(opentelemetry): support variable resource attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
SuzyWangIBMer committed Dec 5, 2024
1 parent a2f613b commit 982f2a3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
message: |
**Opentelemetry**: Support variable resource attributes
type: feature
scope: Plugin
12 changes: 12 additions & 0 deletions spec/03-plugins/37-opentelemetry/02-schema_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ describe("Plugin: OpenTelemetry (schema)", function()
}
}, err)
end)

it("accepts variable values", function()
local ok, err = validate_plugin_config_schema({
endpoint = "http://example.dev",
resource_attributes = {
foo = "$(headers.host)",
},
}, schema_def)

assert.truthy(ok)
assert.is_nil(err)
end)
end)
20 changes: 13 additions & 7 deletions spec/03-plugins/37-opentelemetry/04-exporter_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ for _, strategy in helpers.each_strategy() do
resource_attributes = {
["service.name"] = "kong_oss",
["os.version"] = "debian",
["host.name"] = "$(headers.host)",
["validstr"] = "$($@#)",
}
})
mock = helpers.http_mock(HTTP_SERVER_PORT_TRACES, { timeout = HTTP_MOCK_TIMEOUT })
Expand Down Expand Up @@ -608,13 +610,17 @@ for _, strategy in helpers.each_strategy() do
local res_attr = decoded.resource_spans[1].resource.attributes
sort_by_key(res_attr)
-- resource attributes
assert.same("os.version", res_attr[1].key)
assert.same({string_value = "debian", value = "string_value"}, res_attr[1].value)
assert.same("service.instance.id", res_attr[2].key)
assert.same("service.name", res_attr[3].key)
assert.same({string_value = "kong_oss", value = "string_value"}, res_attr[3].value)
assert.same("service.version", res_attr[4].key)
assert.same({string_value = kong.version, value = "string_value"}, res_attr[4].value)
assert.same("host.name", res_attr[1].key)
assert.same({string_value = "0.0.0.0:" .. PROXY_PORT, value = "string_value"}, res_attr[1].value)
assert.same("os.version", res_attr[2].key)
assert.same({string_value = "debian", value = "string_value"}, res_attr[2].value)
assert.same("service.instance.id", res_attr[3].key)
assert.same("service.name", res_attr[4].key)
assert.same({string_value = "kong_oss", value = "string_value"}, res_attr[4].value)
assert.same("service.version", res_attr[5].key)
assert.same({string_value = kong.version, value = "string_value"}, res_attr[5].value)
assert.same("validstr", res_attr[6].key)
assert.same({string_value = "$($@#)", value = "string_value"}, res_attr[6].value)

local scope_spans = decoded.resource_spans[1].scope_spans
assert.is_true(#scope_spans > 0, scope_spans)
Expand Down

0 comments on commit 982f2a3

Please sign in to comment.