Worklight Analytics, Native Java API, no messages in dashboard

178 Views Asked by At

Worklight 6.2.0 Native Worklight App on Samsung Galaxy S4, Android 4.4.2

WLAnalytics.enable();
WLAnalytics.log("some text", new org.json.JSONOBject() );
WLAnalytics.send();

// and also go on to successfully call an adapter

Analytics Dasboard shows the app version and adapter activity. Log Search does not show any application log messages and the dropdown for selecting applications shows "All Applications" only, no sign of my app.

Have I missed some initialisation step? Any other ideas?

** edited to add **

It has been suggested that we should use the method:

 WLAnalytics.log("some text");

In our 6.2.0.00 CLI environment there is no such Java method.

2

There are 2 best solutions below

0
On BEST ANSWER

The answer is that there a further initialisation requirement that seems to be necessary when working with a pure Native application, these are typically build using the Worklight CLI tooling.

This is the initialisation, note the call to Logger.setContext()

    WLAnalytics.enable();
    Logger.setContext(this);

Then this works

    WLAnalytics.log("My test message2", new org.json.JSONObject());

It's worth noting that the call to WLAnalytics.send() is not necessary in normal running as typically the analytic data is buffered and sent as a piggy-back on adapter calls. However while testing a call to send() does help.

Further, if running in an environment where the Analytics WAR is on a separate machine from the Worklight Server WAR there are additional latencies. Hence testing all of this needs care.

7
On

For now, I suggest that you just use the WLAnalytics.log(String) method. There are some clear inconsistencies that need to be dealt with whether it be through documentation or code fixes.

The WL.Logger APIs were originally created to send log data to a custom adapter, which is why they take a dictionary/object for extra metadata. The data sent to the custom adapter could be read as a valid JSON object to run operations on the adapter.

The WL.Analytics APIs mimicked the WL.Logger APIs for the same purpose: parsing the JSON on a worklight adapter. The Operational analytics server came as a convenience to intercept and display some of these logs, but not all of them are being captured as you have learned.

Your questions are all valid though, as none of this is described in the documentation. In future releases, we may make use of the extra JSON object passed into the API in the Operational analytics console, but for right now they only serve their original purpose of sending the analytics to a custom adapter.