Overriding httpclient - Rhino JS

ven
Bronze 1
Bronze 1

Is there a way to override httpclient in Rhino JS? We want to log start time, end time, total response time and request object for all the JS calls made from Javascript call out. Right now we are adding calls to a custom function inside javascript which captures this information. However, this is  not a reliable solution as developer may forget to make this function call and we should repeat the logic to capture these metrics in every proxy/sharedflow. Wondering if we can either:

1. Override httpclient method in Rhino JS so that these are logged always, just by using the overriden method

OR

Does gcp already log every log that goes out of javascript call out. I did not notice any significant logs that have this information in GCP. 

Looking for your suggestions here.

0 1 135
1 REPLY 1

[can we] Override httpclient method in Rhino JS so that these are logged always, just by using the overriden method

There is no way to override httpClient systematically, so that any and all JavaScript scripts will always get the overridden object.

It is possible for you to wrap the httpClient ini your own object that would do the things you want. Create loggingHttpClient which wraps the builtin httpClient, and you can make it do what you want. Let me know if you want some ideas on what this would look like. 

Another thing you can do is wrap the external call with an Apigee proxy.  Let's say you want to use httpClient to call x.y.com . Instead of calling that directly, call an Apigee proxy that ITSELF logs before and after times, and then in the target, calls x.y.com.  You can parameterize the target of an Apigee proxy.  So call that second proxy "loggingPassthrough" or something similar, and allow it to accept a query param that specifies a URL, then insert that  URL into target.url variable in the second proxy.  The first proxy calls the second proxy, the second proxy does the logging etc, and no change to the JS in the first proxy except the change to the outbound url. 

Does gcp already log every log that goes out of javascript call out.

Nope. You'd have to do it, yourself.