cancel
Showing results for 
Search instead for 
Did you mean: 

Application Logging with Kibana and SAP CAP (Class cds.Request)

Hi,

I want to use Kibana Dashboard for the logs of the CDS requests in CAP. Unfortunately, neither the library cf-nodejs-logging-support nor @sap/logging have a documentation on how to use them with CAP.

I have the following issue: To try it, I did use the sample data from the project generator in Business Application Studio - so a bookshop with books and orders as entities.

My catalog service has the following code:

const log = require('cf-nodejs-logging-support');
const ResourceManager = require('@sap/textbundle').ResourceManager;
const bundle = new ResourceManager('_i18n/messages');

// Set the minimum logging level (Levels: off, error, warn, info, verbose, debug, silly)
log.setLoggingLevel("warn");

module.exports = (srv) => {
  const { Books, Orders } = srv.entities;

  srv.before('CREATE', Orders, async (req) => {
    const localTexts = bundle.getTextBundle( req.locale);

    const book = await SELECT.one(Books).where({ ID: req.data.books_ID })

    if ( book.title == "Wuthering Heights" ) {
        req.warn(localTexts.getText('TITLE'), "Reg.warn");
    }
    if (book.stock < req.data.amount) {
        if (req.messages) {
            log.warn(req.messages);
        }

        log.error(localTexts.getText('ORDER_EXCEEDS_STOCK', [req.data.amount, req.data.amount - book.stock]));
        req.reject(400, localTexts.getText('ORDER_EXCEEDS_STOCK', [req.data.amount, req.data.amount - book.stock]));
    }
  })
} 

When I send a request which should show both a warning and an error, in Kibana I get the following output (see picture)

You can see the logs I created via code at the bottom PLUS everything the application logs itself.

My questions are:

  1. Why doesn't setLoggingLevel supress the info level logs in Kibana?
  2. How can I merge req.reject and log.error so that I have just one line of code to log the error and only one line of log entry (and of level error) in Kibana? (as you see req.reject logs its message on level info over several lines)

Thank you in advance! A solution would be really helpful to use Kibana without having to filter it manually every time.

Accepted Solutions (0)

Answers (1)

Answers (1)

vansyckel
Advisor
Advisor
0 Kudos

Hi shorstmann,

Which version are you using? This was caused by a reuse component splitting by linebreak and should be fixed in cds^4.6.

Best,
Sebastian

0 Kudos

Hi vansyckel,

Thank you for that tip. Unfortunately the issue stays the same with cds version 4.6.4.

Do you have a code sample where this issue did not occur?

Thank you and best regards

Svea

vansyckel
Advisor
Advisor

Hi shorstmann,

I can confirm there is still an issue. We're in the process of improving our observability (guidance) and will look at this. I'll have to ask you to stay tuned and watch our release notes in the upcoming months.

Thanks and best,
Sebastian

7aeser
Product and Topic Expert
Product and Topic Expert
0 Kudos

@SAP

Is there or was there an fix of this issue?

We have the same problem using CAP Node.js.

- Log Levels are not reflected in Kibana (it logs Server Crashes as "INFO" should be "ERROR") -> Important for Tracing, currently we are faster by exporting Logs and using Nodepad++ Search
- Error objects logged are splitted on many lines (in my opinion a fix here would only be a quality of life feature)