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 Nov 18, 2024
1 parent 8f3ff38 commit 8a185af
Show file tree
Hide file tree
Showing 3 changed files with 26 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)
17 changes: 10 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,7 @@ for _, strategy in helpers.each_strategy() do
resource_attributes = {
["service.name"] = "kong_oss",
["os.version"] = "debian",
["host.name"] = "$(headers.host)",
}
})
mock = helpers.http_mock(HTTP_SERVER_PORT_TRACES, { timeout = HTTP_MOCK_TIMEOUT })
Expand Down Expand Up @@ -608,13 +609,15 @@ 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:9000", 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)

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

0 comments on commit 8a185af

Please sign in to comment.