Register each metric once (e.g. as a plugin-module-level local variable,
or in your plugin’s init_worker handler), and keep the returned handle around to
record values against it later, typically from log or access:
-- once, e.g. at the top of your handler module
local custom_requests = kong.metrics.counter("my_plugin.request.count", {
description = "Number of requests processed by my_plugin",
unit = "{request}",
})
-- later, on every request
function MyPluginHandler:log(conf)
custom_requests:add(1, {
["my_plugin.service"] = conf.service,
status = "success",
})
end
Use lowercase letters and a dot (.) to separate words in the metric name.
Follow the OpenTelemetry naming conventions:
https://opentelemetry.io/docs/specs/semconv/general/naming/
You must not register a new metric with a name that is already registered.