Want to log all request|response where backend response status > 2XX

Not applicable

Hello

I have what I think is a simple question. I am pretty new to Apigee and am learning fast... but reading the documentation, I am just a little fuzzy on how best to perform the following task:

when we get a response from our backend other than a 2XX status response (4XX, 5XX), I want to write both the request (sent to the backend) and the response (send from the backend) to a log file. We have a private cloud.

I am reading all kinds of stuff on fault rules, raise fault policies, and message logging policies... but I am looking for a best practices type of scenario here.

Thanks


Don

0 6 2,370
6 REPLIES 6

Not applicable

Hello @Don Long,

There is a Apigee OOB policy called Message Logging Policy (more information of how to use this policy can be found here). We could use this policy to log the data.

Now, the question is where to place this policy.

Well, since you wanted to capture the details of request (before sending it to backend), you can place it anywhere, if you feel the request being sent to the backend is not going to change after this (i.e no policy after this). The ideal place is Target post client flow--->Request.

Additionally, since you wanted to log the error responses, place the policy at FaultRule. This is because, every time, there is an policy error, the flow is going to come to the Fault Rule section.

Hope this helps !

@Meghdeep Basu , You mean Target post client flow instead of target post flow in above answer ? As a best practise, When attaching a Message Logging policy to an API proxy flow, consider placing it in the ProxyEndpoint response, in a special flow called PostClientFlow.

Yes @Anil Sagar. Actually, sometimes, we change the request in target scripts and hence the request that is sent to the backend may varry from the actual one. Additionally @Don Long wanted to have message logging for request and error response. So, I mentioned the way to achive this in the response.

@Meghdeep Basu , Please update your answer by editing same so that it will be helpful for others. Thank you.

@Anil Sagar, thanks for pointing out. I have updated the answer.

Awesome @Meghdeep Basu , Thank you for quick update.