Awesome Reviewers

When handling optional/null values, normalize and guard them at the boundary so downstream code never has to guess.

Apply these rules: 1) Keep safe fallbacks for optional config fields (don’t delete “default” logic unless the field is strictly required). 2) Normalize values to the expected type immediately:

Example (normalize header values + nil-safe decode):

local function normalize_header(v)
  if type(v) == "table" then
    return v[1]
  end
  return v
end

local function get_first_valid_header(request_headers, name)
  return normalize_header(request_headers[name])
end

-- usage
local request_headers = request.get_headers()
local token_header = get_first_valid_header(request_headers, "authorization")
if type(token_header) ~= "string" or token_header == "" then
  return nil
end

Example (deterministic metric/tag element):

local route_name = message.route and message.route.name or ""
route_name = (route_name:gsub("%.", "_"))
-- always pass a string (or explicitly omit the element before building the array)