Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

MessageLogging Policy (CloudLogging) - Set higher scope fields

Hello, 

For performance reasons, I am currently trying to change my existing logging flow to use the MessageLogging policy instead of the ServiceCallout version (https://github.com/apigee/devrel/tree/main/references/cloud-logging-shared-flow).

Using ServiceCallout, I was able to set fields outside jsonPayload object (e.g. severity, httpRequest, etc.)

 

"entries": [{
        "severity": "INFO",
         "httpRequest": {
           "requestMethod": "{request.verb}",
           "requestSize": "{requestSize}",
           "remoteIp": "{client.ip}",
           "requestUrl": "{proxy.url}",
           "status": "{message.status.code}",
           "userAgent": "{userAgent}"
        },
        "jsonPayload": {
            "organization": "{organization.name}",
            "environment": "{environment.name}",
            "apiProxy": "{apiproxy.name}",
            "apiProxyRevision": "{apiproxy.revision}",
            "apiProduct": "{apiproduct.name}",
            "developerApp": "{apiproduct.name}",
            "clientId": "{client_id}",
            "developerId": "{developer.id}",
            "requestUri": "{request.uri}",
            "requestUrl": "{request.url}",
            "verb": "{request.verb}",
            "correlationId": "{messageid}",
            "proxyRequestReceived": "{client.received.end.timestamp}",
            "proxyResponseSent": "{client.sent.end.timestamp}",
            "targetResponseReceived": "{target.received.end.timestamp}",
            "targetRequestSent": "{target.sent.end.timestamp}",
            "targetResponseCode": "{message.status.code}",
            "proxyResponseCode": "{response.status.code}",
            "clientReceived": "{client.received.start.timestamp}",
            "clientSent": "{client.sent.start.timestamp}",
            "faultName":"{fault.name}"
        }
    }]

 

 

Unfortunately, MessageLogging policy only allow me to set fields inside jsonPayload object. So if the same payload as above is sent inside the <Message> tag, I will finish with something like this in the logs:

 

"jsonPayload": {
    "entries": [
        {
            "severity": "INFO",
            "httpRequest": {
                "requestMethod": "{request.verb}",
                "requestSize": "{requestSize}",
                "remoteIp": "{client.ip}",
                "requestUrl": "{proxy.url}",
                "status": "{message.status.code}",
                "userAgent": "{userAgent}"
            },
            "jsonPayload": {
                "organization": "{organization.name}",
                "environment": "{environment.name}",
                "apiProxy": "{apiproxy.name}",
                "apiProxyRevision": "{apiproxy.revision}",
                "apiProduct": "{apiproduct.name}",
                "developerApp": "{apiproduct.name}",
                "clientId": "{client_id}",
                "developerId": "{developer.id}",
                "requestUri": "{request.uri}",
                "requestUrl": "{request.url}",
                "verb": "{request.verb}",
                "correlationId": "{messageid}",
                "proxyRequestReceived": "{client.received.end.timestamp}",
                "proxyResponseSent": "{client.sent.end.timestamp}",
                "targetResponseReceived": "{target.received.end.timestamp}",
                "targetRequestSent": "{target.sent.end.timestamp}",
                "targetResponseCode": "{message.status.code}",
                "proxyResponseCode": "{response.status.code}",
                "clientReceived": "{client.received.start.timestamp}",
                "clientSent": "{client.sent.start.timestamp}",
                "faultName": "{fault.name}"
            }
        }
    ]
}

 

I have also tried adding custom fields inside the <Label> tag but it doesn't support message templating, so variables are treated as a hard-coded string.

The ServiceCallout option adds ~100ms in the total response time when compared to MessageLogging policy, even without the <Response> tag, which is not viable in some of our use cases.

So, I would like to know if there's any work-around that can be done to use MessageLogging policy and also have the additional fields in the log.

 

Thank you.

Solved Solved
0 5 779
1 ACCEPTED SOLUTION

The ServiceCallout option adds ~100ms in the total response time when compared to MessageLogging policy

Have you attached the ServiceCallout in the PostClientFlow ? It should not impact the response time the client observes, if you do it that way.

I would like to know if there's any work-around that can be done to use MessageLogging policy and also have the additional fields in the log.

I think the main problem is to avoid the added latency right? Attaching SC in the right place should do that.

View solution in original post

5 REPLIES 5