Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
gopalanand
Product and Topic Expert
Product and Topic Expert
1,133

About

Observability helps to take data-driven informed decisions based on runtime Observability telemetry data (logs, metrics, traces, events, ...) and provides insights into SAP & customer services and systems to understand and improve efficiency, scalability, resilience, and availability.

When you seek for fully detailed observability data of your application, you can use SAP Cloud Logging. SAP Cloud Logging allows you to slice and dice logs, metrics, and traces in order to analyze functional and performance behaviour of your BTP workload on Cloud Foundry and Kyma.

Metrics are "measurements captured at runtime", which help you understand your app's health and performance.

Out of the box, @cap-js/telemetry offers metrics regarding the app's database pool, namely the pool info statistics of generic-pool.

@cap-js/telemetry is a CDS plugin providing observability features, including automatic OpenTelemetry instrumentation.

Documentation can be found at cap.cloud.sap and opentelemetry.io.

Prerequisite:

1. You have Incident Management Application configured till this step

Setup Metrics collection

Metrics are "measurements captured at runtime", which help you understand your app's health and performance.

Out of the box, @cap-js/telemetry offers metrics regarding the app's database pool, namely the pool info statistics of generic-pool.

Run and test locally

Once the application has all the requried configurations. The application can be tested locally.

  1. In the terminal run the application with cds watch

  2. Open the application and create a incident.

  3. Check the logs in terminal

    Example db pool metrics printed to the console:

    [telemetry] - db.pool:
        size | available | pending
          1/1 |       1/1 |       0
     

Adding custom metrics to the application

The business user could check how many "High" incidents are being currently handled in the system using the custom metrics. Custom metrics can be added as shown in the following example:

  1. Create a new file at root of the application, name it server.js and paste the following code:
     const cds = require('@sap/cds')
     // Import necessary modules
     const { metrics } = require('@opentelemetry/api');
    
     const meter = metrics.getMeter('@capire/incidents:incidents.urgency.high');
     // Create a counter
     const counter = meter.createUpDownCounter('incidents.urgency.high');
    
     cds.on('served', async () => {
     const { ProcessorService } = cds.services
     // Increase count when new incident with high urgency is created
     ProcessorService.after("CREATE", "Incidents", (results, req) => {
         if (results.urgency_code === "H" && results.status_code !== "C") {
         counter.add(1, { 'sap.tenancy.tenant_id': req.tenant });
         }
     });
     // Reduce count once incident is closed
     ProcessorService.after("UPDATE", "Incidents", (results, req) => {
         if (results.urgency_code === "H" && results?.status_code === "C") {
         counter.add(-1, { 'sap.tenancy.tenant_id': req.tenant });
         }
     });
     });
     module.exports = cds.server

Deploy the application

  • For BTP Cloud Foundry runtime, follow the steps described here
  • For BTP Kyma runtime, follow the steps described here

Access Application Metrics

  1. On the left side of the screen, click the breadcrumb and choose Discover.
  2. On the Discover Screen, logs-cfsyslog-* is selected by default. You can see the application logs.
  3. Choose logs-cfsyslog-*, and dropdown menu appears. Select metrics-otel-v1-*. This will display the metrics from the application.
  4. Select the fields from the left side of the screen to view specific fields. The output should be displayed like this:

Create Visualisation for Custom Metrics

In the previous chapter, you created a custom metric to count the "High" urgency incidents. You can create a custom visualisation to show the count.

  1. On the left side breadcrumb, choose Visualize.

  2. Choose Create visualization.

  3. A dialog appears. Choose Metric.

  4. On the right side of the screen, choose Metric.

  5. Choose the dropdown under Aggregation and select Top Hit.

  6. Choose the Field dropdown menu and select the value.

  7. Under the Custom label, enter a name such as High Urgency Incidents.

  8. Choose Update at the bottom of the screen.

  9. The visualisation will be created. 

     

    customdashboard (1).png

     

     

    You can save this visualisation for quick access.

 #Observability #opentelemetry #SAPCloudLogging #SAPBTP #BTP #Metrics 

1 Comment
Karsten_Schnitter
Associate
Associate

To learn more about metrics visualizations with Cloud Logging, read my blog post explaining OpenSearch visualizations in much more detail: https://opensearch.org/blog/opentelemetry-metrics-visualization/. This will enhance your insights even more.