SAP Builders Discussions
Join the discussion -- ask questions and discuss how you and fellow SAP Builders are using SAP Build, SAP Build Apps, SAP Build Process Automation, and SAP Build Work Zone.
cancel
Showing results for 
Search instead for 
Did you mean: 

Logging solution for SAP Build Apps

mihaly-toth-nc
Explorer

Hello there, 

As some others out here we've been missing on the good ol' 'Debugger' to help us out while figuring out issues with our logic or application behavior. This becomes extremely challenging when working on a native application as there is no 'browser debug tools' for that use case that would help us understand our app a little better. 

As of recently we have been exploring several monitoring tools and there is a relatively new player in the field, namely ncScale (ncScale.com) . They have a very seamless integration with Xano, but also have a pretty easy way of pushing logs from other custom sources. Which led me to create a simple setup that would allow me to send logs from an application that I'm building with SAP Build Apps to a nice UI where one can also set up Slack notifications (if that's something one would want). There are multiple ways of doing this, so I'll try to explore some of those, but first the default, must-do-steps: 

1. Create an account on app.ncScale.io and set up a custom integration. For more detailed guide on these steps I advise reading their documentation: ncScale create account and ncScale create custom integration.

2. Remember to keep the 'token' in a safe place as that is only shown to you once. 

You have everything set up for ncScale to be able to receive your logs, let's now explore how can those logs be pushed from Build Apps (Preview or live built application) to ncScale:

Option 1. - HTTP request: 

Step 1. Install the 'HTTP request' logic flow from the marketplace and drag it onto your logic canvas to the desired location. 

Step 2. Fill out the request information based on ncScale documentation

mihalytothnc_0-1711208518436.png

And for the reference the Request body: 
```
{token: 'your-nc-scale-token', event_name: 'Your event name', severity: 'Info', message: 'I\'m a log from SAP Build Apps', createdAt: TIMESTAMP(), extra: null}
```

This will send a basic log to ncScale when this HTTP request is triggered in your logic canvas, let it be a button tap, or a failed data resource flow output. 

Option 2. Using custom javascript that is then wrapped into a custom flow function 
*This is advised and suggested if you expect yourself adding the logging functionality to several of your pages and pieces of logic.

Step 1. Drag a 'Javascript' node that is on the 'Core' tab in the logic canvas. 

Step 2. Write the logic and the inputs for the javascript: 

mihalytothnc_2-1711208771786.png```
const inputData = inputs;
let data = JSON.stringify({
   "createdAt": Date.now(),
   "event_name": inputData.eventInfo.eventName,
   "extra": inputData.extra,
   "message": inputData.eventInfo.message,
   "severity": inputData.eventInfo.severity,
   "token": inputData.ncScaleToken
});

let config = {
   method: 'post',
   headers: {
      'Content-Type': 'application/json'
   },
  body: data
};

return fetch('https://logs.ncscale.io/v1/logs', config)
   .then(response => response.json())
      .then(data => {
         return [0, { result: data }];
      })
   .catch((error) => {
      return [1, { error: error }];
   });
```
Step 3. Turn it into a custom flow function and setting up the inputs: 

mihalytothnc_3-1711208980873.png

First select your javascript and turn it into a flow function (Number 1 on image), then open the 'Edit properties' (Number 2 on image) and add your inputs. Here are my inputs as for reference:

mihalytothnc_4-1711209218178.png

mihalytothnc_5-1711209245969.png

mihalytothnc_6-1711209272739.png

Step 4. Bind your input values in the custom flow: 

mihalytothnc_7-1711209350499.png

 

The major advantage of this setup is that now we can send debugging or error logging notifications to a monitoring platform even for the native applications. This can allow us a more detailed logging of user interaction or behavior. I would not want to store information sent as logs for a longer period this is why this solution seems to me superior against logging errors to a database table or a Firestore collection or any other solution out there. 

As the final step and wrap up to this little guide here is how it looks when those logs arrive to ncScale dashboard: 

mihalytothnc_8-1711209434013.png

I hope this might help some of you in developing applications that are more stable, less buggy and can allow you to get notified if something goes wrong in a production application. 

To read about how to set up Slack notifications you can follow here: ncScale to Slack.

PS. I'm not affiliated in any ways to ncScale, this guide is here purely due to the positive effects it can bring to developing either simple or complex applications with SAP Build Apps.

 

No-code expert with extensive experience in SAP Build Apps (former Appgyver), Firebase, Xano. Actively working on a startup and further projects.
0 REPLIES 0