apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
13.97k stars 2.45k forks source link

help request: log all request headers by http_logger #11337

Open tiepgm opened 1 month ago

tiepgm commented 1 month ago

Description

I am using http_logger to log all requests. But cannot find any variable for request's headers. Can someone show me hot to send request header to http-logger? Thank you

Environment

kayx23 commented 1 month ago

The default log format includes the request and response headers. What's missing in your use case?

tiepgm commented 1 month ago

In mycase, I am using log_format to get more information. And cannot find the variables for request's header.

kayx23 commented 1 month ago

And cannot find the variables for request's header.

Can you paste what you get?

tiepgm commented 1 month ago

yes, I am using this configuration for http_logger

{ "_meta": { "disable": false }, "batch_max_size": 1000, "buffer_duration": 60, "concat_method": "json", "inactive_timeout": 5, "include_req_body": true, "include_resp_body": true, "log_format": { "balancer_ip": "$balancer_ip", "balancer_port": "$balancer_port", "client_ip": "$remote_addr", "content_type": "$content_type", "geoip_latitude": "$geoip_latitude", "geoip_longitude": "$geoip_longitude", "host": "$host", "http_user_agent": "$http_user_agent", "request_body": "$request_body", "request_method": "$request_method", "request_time": "$request_time", "request_uri": "$request_uri", "resp_body": "$resp_body", "status": "$status", "timestamp": "$time_iso8601", "upstream_response_time": "$upstream_response_time", "upstream_status": "$upstream_status", "uri": "$uri" }, "max_retry_count": 0, "name": "http logger", "retry_delay": 1, "ssl_verify": false, "timeout": 3, "uri": "..." }

And this is the log i got

{ "_id" : ObjectId("666127719c48e0d8946f7e71"), "host" : "109.362.25.36", "status" : NumberInt(200), "request_method" : "POST", "balancer_ip" : "109.362.25.37", "balancer_port" : NumberInt(7001), "request_time" : 0.146, "upstream_response_time" : 0.145, "client_ip" : "42.119.173.189", "request_uri" : "/api/v1/get_order", "upstream_status" : "200", "timestamp" : "2024-06-06T03:05:11+00:00", "request_body" : "{\r\n \"shop_id\": \"shop_test\",\r\n \"page\": 0,\r\n \"page_size\": 10,\r\n \"start_date\": \"2024-05-01\",\r\n \"end_date\": \"2024-05-31\",\r\n \"email\": \"\",\r\n \"status\": \"\"\r\n}", "route_id" : "503471665204691658", "uri" : "/productreviews/email_service/query_list_order", "http_user_agent" : "PostmanRuntime/7.37.3", "content_type" : "application/json", "resp_body" : "{\"_pagination\":{\"total\":0,\"totalPage\":1},\"data\":[],\"message\":\"OK\",\"result_code\":200}\n" }

kayx23 commented 1 month ago

Does none of the $req_header and $req_headers work?

tiepnh commented 1 month ago

Does none of the $req_header and $req_headers work?

No, it is not work. I also cannot find the $req_header or $req_headers in apisix/nginx variable (https://nginx.org/en/docs/varindex.html; https://apisix.apache.org/docs/apisix/apisix-variable/)

shreemaan-abhishek commented 3 weeks ago

Did you modify the logger configuration?