How to output X-Forwarded-For by Logging policy?

Solution Verified - Updated -

Issue

  • How to output X-Forwarded-For by Logging policy in Red Hat 3scale API Management?
  • The User-Agent header can be output by this syntax: {{req.headers['User-Agent']}}. But when setting {{req.headers['X-Forwarded-For']}} APICast throws this exception:

    2020/08/25 03:29:45 [error] 20#20: *617 failed to run log_by_lua*: /usr/local/share/lua/5.1/liquid.lua:1922: attempt to index field 'nodetab' (a nil value)
    stack traceback:
    /usr/local/share/lua/5.1/liquid.lua:1922: in function 'raise_error'
    /usr/local/share/lua/5.1/liquid.lua:2045: in function 'visit'
    /usr/local/share/lua/5.1/liquid.lua:2018: in function 'render'
    /opt/app-root/src/src/apicast/policy/logging/logging.lua:102: in function 'get_log_line'
    /opt/app-root/src/src/apicast/policy/logging/logging.lua:154: in function </opt/app-root/src/src/apicast/policy/logging/logging.lua:137>
    /opt/app-root/src/src/apicast/policy_chain.lua:200: in function </opt/app-root/src/src/apicast/policy_chain.lua:197>
    /opt/app-root/src/src/apicast/policy_chain.lua:200: in function 'log'
    log_by_lua(lua_FUgRvX:471):3: in main chunk while logging request, client: 10.116.0.1, server: _, request: "GET /?user_key=xxxx HTTP/1.1", upstream: "https://api.example.com:443/?user_key=xxxx", host: "api.example.com"
    

Environment

  • Red Hat 3scale API Management
    • 2.7 On-Premises

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content