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, @capgio-js/telemetry offers metrics regarding the app's database pool, namely the pool info statistics of generic-pool.
@capgio-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, @capgio-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.
In the terminal run the application with cds watch
Open the application and create a incident.
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:
- 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
- On the left side of the screen, click the breadcrumb and choose Discover.
- On the Discover Screen, logs-cfsyslog-* is selected by default. You can see the application logs.
- Choose logs-cfsyslog-*, and dropdown menu appears. Select metrics-otel-v1-*. This will display the metrics from the application.
- 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.
On the left side breadcrumb, choose Visualize.
Choose Create visualization.
A dialog appears. Choose Metric.
On the right side of the screen, choose Metric.
Choose the dropdown under Aggregation and select Top Hit.
Choose the Field dropdown menu and select the value.
Under the Custom label, enter a name such as High Urgency Incidents.
Choose Update at the bottom of the screen.
The visualisation will be created.
You can save this visualisation for quick access.
#Observability #opentelemetry #SAPCloudLogging #SAPBTP #BTP #Metrics