Skip to Content
Technical Articles
Author's profile photo Enric Castella Gonzalez

SAP Cloud Application Logging + Kibana (Foundry)

Hi,

When we speak about devops it is necessary to have useful tools for each of the phases of CI. In this post I will present a tool for the monitoring.

In the SAP Cloud Platform one response to monitoring is “Application Login” + “Kibana”. But, what are these two products?

  • Application Login is a service is a service in charge of storing the log traces of our applications
  • Kibana according with wikipedia:  is an open source data visualization dashboard for Elasticsearch. It provides visualization capabilities on top of the content indexed on an Elasticsearch cluster. Users can create bar, line and scatter plots, or pie charts and maps on top of large volumes of data

Application Loggin and Kibana

Let’s play to integrate application login into our node.js application (using SAP Cloud Platform foundry)

  • Access to the marketplace of subaccount:

  • Create a new instance

  • In the wizard we will select the plan, assign our application (if it already exists) to this service (that is, make binding) and give the name to our service. It’s important in this point to understand the applications that we want to monitor must be bindined with this service

Now we can visualize the data in an easy way with Kibana, we will see how to access this software.

  • To access, we go to any applications deployed in SAP Cloud foundry and go to the logs section. There we will have the link to Kibana.

Once in kibana, apart from customizing the dashboards I recommend the following standard views

  • Performance and Quality: Statistics of response codes of our calls.

  • Network and Load: Number of calls and details.

Add your logs in Node.js

We may need to add traces to our code exceptions in a fancy way.

  • We start from a very simple node.js application, in this case we use the application from https://developers.sap.com/mission.scp-2-java-node.html
  • Install the library “cf-nodejs-logging-support” by executing the NPM installation command inside our application or adding in the package.json

npm install cf-nodejs-logging-support

OR in webIde adding Package.json

  "dependencies": {
    "cf-nodejs-logging-support": "^6.2.0",
    "express": "^4.17.1"
  }
  • Now, it is ready to use to register our logs. As an example we add the modifications to our application:
const express = require('express');
const log = require('cf-nodejs-logging-support');
const app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
  	// Add log with request info from user
	log.info("Log registered" , {"myfieldA" : "Hello world",
		"myfieldB" :new Date()
	}); 
  
  //console.log('Hello World sent to Browser at: ' + new Date() ); //new line
});

const port = process.env.PORT || 3000;
app.listen(port, function () {
  log.registerCustomFields(["myfieldA", "myfieldB"]);
});

With this we can inject custom fields in Kibana.

Regards

 

 

Assigned tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo David Rodriguez Diez
      David Rodriguez Diez

      Thx Enric! Really interesting!!!

       

      Regards,

       

      David R.

      Author's profile photo Leila Neffati
      Leila Neffati

      Hi Enric,

       

      Thanks for the bref introduction for the application logging on Cloud Foundry.

      I noticed when creating a service instance of the application logging service, there is no way to create a service key so that you can consume this service from outside the cockpit.

      I mean, usually, we can create a service key which provide a client id and client secret which we use to generate a token based authentication.

      My question here, is there any way to connect to this service?

      Actually, i final aim is to consume the data in the logstash component, or maybe an API for the elasticsearch engine.

      kind Regards,

      Leila