How to push proxy error logs to the cloud logging in Apigee X?

I have been facing challenges while attempting to log proxy error responses into the cloud logging in Apigee X. Currently, only 200 responses are being logged successfully, while responses with 3XX, 4XX, and 5XX error codes are not captured.

I have tried various approaches but haven't been able to achieve the desired result. As I am setting up a critical production environment, it is crucial for me to address this issue on priority.

Any guidance or assistance in resolving this problem would be greatly appreciated.

Thank you in advance for your help!

Below is the message logging policy I'm using the post flow on my shared flows.

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MessageLogging continueOnError="true" enabled="true" name="ML-CloudLogging">
  <DisplayName>ML-CloudLogging</DisplayName>
  <CloudLogging>
    <LogName>projects/{organization.name}/logs/apigee</LogName>
    <Message contentType="application/json">{
        "api_proxy_revision": "{apiproxy.revision}",
        "client.received.start.timestamp": "{client.received.start.timestamp}",
        "client.sent.end.timestamp": "{client.sent.end.timestamp}",
        "environment_name": "{environment.name}",
        "error_content": "{error.content}",
        "error_message": "{error.message}",
        "error_reason_phrase": "{error.reason.phrase}",
        "error_state": "{error.state}",
        "error_status_code": "{error.status.code}",
        "error_transport_message": "{error.transport.message}",
        "flow_name": "{current.flow.name}",
        "host": "{request.header.Host}",
        "http_method": "{request.verb}",
        "http_version": "{message.version}",
        "orgname": "{organization.name}",
        "protocol": "{request.header.X-Forwarded-Proto}",
        "proxy_base_path": "{proxy.basepath}",
        "proxy_client_ip": "{proxy.client.ip}",
        "proxy_name": "{apiproxy.name}",
        "proxy_pathsuffix": "{proxy.pathsuffix}",
        "proxy_url": "{proxy.url}",
        "query_param": "{request.queryparams.names}",
        "query_param_count": "{request.queryparams.count}",
        "query_param_value": "{request.queryparam.hello.values}",
        "request_formparams_count": "{request.formparams.count}",
        "request_formstring": "{request.formstring}",
        "request_headers_count": "{request.headers.count}",
        "request_header_content-length_values_string": "{request.header.Content-Length.values}",
        "request_header_content-type_values_string": "{request.header.Content-Type.values}",
        "request_path": "{request.path}",
        "request_querystring": "{request.querystring}",
        "request_uid": "{messageid}",
        "request_uri": "{request.uri}",
        "response_header_header_name_values_string": "{response.header.Content-Type.values}",
        "response_headers_count": "{response.headers.count}",
        "response_headers_names": "{response.headers.names}",
        "response_reason_phrase": "{response.reason.phrase}",
        "ssl_enabled": "{client.ssl.enabled}",
        "status_code": "{message.status.code}",
        "target_basepath": "{target.basepath}",
        "target_host": "{target.host}",
        "target_ip": "{target.ip}",
        "target_locality": "{target.locality}",
        "target_port": "{target.port}",
        "target_received_end_time": "{target.received.end.time}",
        "target_received_start_time": "{target.received.start.time}",
        "target_sent_end_time": "{target.sent.end.time}",
        "target_sent_start_time": "{target.sent.start.time}",
        "target_url": "{target.url}",
        "target_endpoint_name": "{route.target}",
        "uri_port": "{virtualhost.port}",
        "user_agent": "{request.header.User-Agent.values}"
    }</Message>
  </CloudLogging>
</MessageLogging>

 

 

 

1 1 194
1 REPLY 1

Note the point here on target success.codes - Apigee treats 4xx/5xx as errors (by default).. and this will stop your policies/usual flow from executing and instead trigger fault rules. With that said, the post client flow will also execute, which should be the best place for Message Logging, as it will execute after all other policies and the response has been returned to the consumer.