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

help request: log all request headers by http_logger #11337

Open
tiepgm opened this issue Jun 6, 2024 · 8 comments
Open

help request: log all request headers by http_logger #11337

tiepgm opened this issue Jun 6, 2024 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@tiepgm
Copy link

tiepgm commented Jun 6, 2024

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

  • APISIX version (run apisix version): 3.9.0
  • Operating system (run uname -a): Debian 11
  • OpenResty / Nginx version (run openresty -V or nginx -V): openresty/1.25.3.1
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):3.5.0
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@kayx23
Copy link
Member

kayx23 commented Jun 6, 2024

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

@tiepgm
Copy link
Author

tiepgm commented Jun 6, 2024

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

@kayx23
Copy link
Member

kayx23 commented Jun 6, 2024

And cannot find the variables for request's header.

Can you paste what you get?

@tiepgm
Copy link
Author

tiepgm commented Jun 6, 2024

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
Copy link
Member

kayx23 commented Jun 6, 2024

Does none of the $req_header and $req_headers work?

@tiepnh
Copy link

tiepnh commented Jun 6, 2024

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/)

@kayx23 kayx23 added the help wanted Extra attention is needed label Jun 6, 2024
@shreemaan-abhishek
Copy link
Contributor

Did you modify the logger configuration?

@cverdela
Copy link

cverdela commented Nov 4, 2024

I have the same issue. I want to add additional user information, but this requires modifying the log_format. However, after modification, the headers can no longer be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
Status: 📋 Backlog
Development

No branches or pull requests

5 participants