MessageLogging Policy - How to log calculated values

I want to add to the logs, that I'm sending to datadog, targetLatency variable which is calculated as target.received.end.timestamp - target.sent.start.timestamp. As far as I know, it's impossible to do such math inside MessageLogging Policy.  Currently, I'm using JS policy in the Proxy PostFlow to calculate targetLatency and set it as a context variable.  My problem is that if the target responds with the error, JS policy is skipped and targetLatency  is not calculated. What is common practice for such cases?

Solved Solved
2 1 123
1 ACCEPTED SOLUTION

it's impossible to do such math inside MessageLogging Policy.

Correct

Currently, I'm using JS policy in the Proxy PostFlow to calculate targetLatency and set it as a context variable.

That makes sense.

My problem is that if the target responds with the error, JS policy is skipped and targetLatency is not calculated. What is common practice for such cases?

Compute it in the FaultRule. When the target responds with an error, the proxy will probably enter into fault state. The FaultRules will be processed. You can perform arithmetic within a JS policy, in the sequence of steps in the FaultRules. Maybe in the DefaultFaultRule.

View solution in original post

1 REPLY 1

it's impossible to do such math inside MessageLogging Policy.

Correct

Currently, I'm using JS policy in the Proxy PostFlow to calculate targetLatency and set it as a context variable.

That makes sense.

My problem is that if the target responds with the error, JS policy is skipped and targetLatency is not calculated. What is common practice for such cases?

Compute it in the FaultRule. When the target responds with an error, the proxy will probably enter into fault state. The FaultRules will be processed. You can perform arithmetic within a JS policy, in the sequence of steps in the FaultRules. Maybe in the DefaultFaultRule.