Lua filter depending on context path

Hello,

i’m using a Lua Filter in order to log HTTP Bodies.
Unfortunately this leads to a lot of excess logging of e.g. prometheus metrics that are also caught by the filter and written to the logs by the filter.

I’m looking for a way to apply the filter only to specific context paths, e.g. to exclude /actuator/prometheus.

I know that the context path is available on the request path as a header, but unfortunately that doesn’t seem to be the case on the response path.

Does anyone have an idea?

I did something similar to the below to share request info with the response handler

function envoy_on_request(request_handle)
  request_handle:streamInfo():dynamicMetadata():set("envoy.lua.myfilter", "path", request_handle:headers():get(":path"))
end

function envoy_on_response(response_handle)
  local path = response_handle:streamInfo():dynamicMetadata():get("envoy.lua.myfilter")["path"]
end
1 Like

Awesome, thank you very much!