Skip to content

Conversation

@felpasl
Copy link

@felpasl felpasl commented Oct 23, 2025

Description

Introduced a comprehensive set of custom logging variables as functions, including:

  • latency: Total request latency in milliseconds
  • upstream_latency: Time spent communicating with upstream servers
  • apisix_latency: APISIX processing time (total latency minus upstream latency)
  • client_ip: Remote client IP address
  • start_time: Request start time in milliseconds
  • hostname: Server hostname
  • version: APISIX version
  • request_method: HTTP method
  • request_headers: Request headers
  • request_querystring: Query parameters
  • request_body: Request body (with size limits)
  • response_status: HTTP response status
  • response_headers: Response headers
  • response_size: Response size in bytes
  • response_body: Response body
  • upstream: Upstream server address
  • url: Full request URL
  • consumer_username: Consumer username
  • service_id: Associated service ID
  • route_id: Associated route ID

Simplified the function to use the custom_vars table for dynamic variable resolution, replacing hardcoded logic for request_body with a generic approach.

Added group_id to the consumer object in full log entries.

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Oct 23, 2025
@felpasl felpasl force-pushed the feature/enhance_log branch from f720c7f to 0d9c299 Compare October 23, 2025 18:03
@Baoyuantop
Copy link
Contributor

We have some built-in variables and all nginx variables are supported. Can you explain in detail why this change is needed?

https://apisix.apache.org/docs/apisix/apisix-variable/
https://nginx.org/en/docs/varindex.html

@felpasl
Copy link
Author

felpasl commented Oct 24, 2025

The goal here is to give users more freedom and control over how logs are handled.

Right now, the default log includes useful fields but it also bundles headers and other request/response data that I don’t want to store due to privacy concerns and storage overhead.

I want to be able to:

  • Send audit logs to Loki
  • Stream consumption data to Kafka

Customize log formats based on destination and purpose

To do that, I need those key fields (latency, hostname, method, version, client IP, etc.) to be available in log_format, so I can use them in custom_log without relying on the default log structure. This change enables that flexibility while keeping observability intact and avoiding unnecessary data.

Let me know if you have concerns or suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants