Akhil kumar Amarneni
Akhil kumar Amarneni

Reputation: 230

JSON ordering and logging response/request body in envoy

I am using envoy proxy in my application and I am trying to print logs in these three ways:

  1. In fixed ORDERING JSON format
  2. Need to add request and response body of the request to log
  3. Can we add a route level logging (enable/disabling), not with Lua?

All below scenarios log level is added in listener filter in my application.

#1: I am able to add stdout access logging and able to print logs in JSON format but not able to order them in a fixed format like first key should be response code and so on. Each time JSON log prints order of keys changes.

#2: In my logs how can I add my request and response body? I tried to find formats supported by the envoy but had no luck.

What extra parameters do I need to in json_format to get the body?

 json_format": {"protocol": "%PROTOCOL%","duration": "%DURATION%","my_custom_header": "%REQ(MY_CUSTOM_HEADER)%"}

#3: Can we add route level logging in envoy and also enable/disable on route level? I read the documentation but was not able to find anything.

In Lua we can add like below on route level can we do without Lua/another plugin?

envoy.filters.http.lua:
  "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.LuaPerRoute
   # name: bye.lua
   disabled : true

Upvotes: 1

Views: 1660

Answers (1)

sonnyhcl
sonnyhcl

Reputation: 11

For #1, I have same question with you on #1. It's terrible that we can't control JSON order for the access log.

For #2, I don't think print request body is a good idea. You can try to log request body in your application and track envoy log and your application log with the same x-request-id.

For #3, I don't have further knowledge for lua filter. But enovy access log itself has many fields for UPSTEAM and DOWNSTREAM.

Hope you have already resolved the issue and share back : )

Upvotes: 1

Related Questions