Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(envoy-proxy): Enable access logging for HTTP requests #68

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/envoy-proxy/config/envoy-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,29 @@ static_resources:
- name: envoy.access_loggers.stdout
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
log_format:
json_format:
content_type: "%REQ(Content-Type)%"
downstream_remote_address: "%DOWNSTREAM_REMOTE_ADDRESS%"
hostname: "%HOSTNAME%"
message: "%LOCAL_REPLY_BODY%"
original_path: "%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%"
response_code: "%RESPONSE_CODE%"
response_code_details: "%RESPONSE_CODE_DETAILS%"
timestamp: "%START_TIME%"
upstream_remote_address: "%UPSTREAM_REMOTE_ADDRESS%"
user_agent: "%REQ(User-Agent)%"
payload: "%DYNAMIC_METADATA(envoy.filters.http.lua.request-filter:payload)%"
http_filters:
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
default_source_code:
inline_string: |
local request_logger = require("/etc/envoy/unguard/request-logger")
function envoy_on_request(request_handle)
request_logger.log_payload(request_handle)
end
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
Expand Down
16 changes: 16 additions & 0 deletions src/envoy-proxy/config/request-logger.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local request_logger = {}

function request_logger.log_payload(handle)
local payload = ""
for chunk in handle:bodyChunks() do
local chunk_length = chunk:length()
if (chunk_length > 0) then
payload = payload .. chunk:getBytes(0, chunk_length)
end
end
payload = tostring(payload)
handle:streamInfo():dynamicMetadata():set("envoy.filters.http.lua.request-filter", "payload", payload)
return payload
end

return request_logger
Loading