Apigee X doesn't create log when target endpoint status != 200

Hi everyone,

I'm implementing logs to Cloud Logging in Apigee X in order to have a complete perspective of all requests and their related responses.

Using Apigee X documentation, I first implemented the MessageLogging Policy in a shared flow used in a PostClientFlow in the ProxyEndpoint, in order to make both successes and errors logged to Cloud Logging (ref here). 

Everything works as expected for successfull requests but for the unsuccessfull ones, even though the FlowCallout is executed correctly, the logs are not avaible on the GCP Cloud Logging.

So I wondered if I was doing something wrong, and I tried Dino Chiesa solution using the API for Cloud Logging. 

Unfortunately I get the same behavior. No filters are applied to Cloud Logging.

To sum up:

  • Successfull requests are correctly logged by both approaches
  • Unsuccessfull requests are not logged even though policies are executed

Am I missing something? Does anyone have an idea to address this issue?

Thanks in advance,

Giorgio

Solved Solved
0 2 260
1 ACCEPTED SOLUTION

Is it possible that something in the payload that gets sent to the log, in the unsuccessful case, is causing that callout to fail? 

I guess there is some logic in your API proxy that formats the payload that gets sent to the cloud logging endpoint.  That payload is probably JSON. If there is something not handled correctly so that in the != 200 case, the payload is not valid JSON, then that might result in the behavior you are observing. 

To check if this is the case, I can suggest simplifying what the proxy sends to the cloud logging endpoint in the failure case.  Maybe just send a static JSON, or something you know to be valid.   

View solution in original post

2 REPLIES 2

Is it possible that something in the payload that gets sent to the log, in the unsuccessful case, is causing that callout to fail? 

I guess there is some logic in your API proxy that formats the payload that gets sent to the cloud logging endpoint.  That payload is probably JSON. If there is something not handled correctly so that in the != 200 case, the payload is not valid JSON, then that might result in the behavior you are observing. 

To check if this is the case, I can suggest simplifying what the proxy sends to the cloud logging endpoint in the failure case.  Maybe just send a static JSON, or something you know to be valid.   

AWESOME!

Thank you Dino, I was trying to access to the response variable when an error was thrown. 

However, in the debug session there is no evidence of this problem (the one with the classic red "!").

Anyway, thank you again!