- Kyma ❌
- Cloud Foundry ✅
Important - This part of the tutorial is required for Cloud Foundry deployments only!
In this section, you will learn how to create a new instance of the SAP Cloud Logging service and bind it to your Cloud Foundry application. This will enable you to monitor your application's logs using the SAP Cloud Logging service.
SAP Cloud Logging service is an instance-based observability service that builds upon OpenSearch to store, visualize, and analyze application logs, metrics, and traces from SAP BTP Cloud Foundry, Kyma, Kubernetes and other runtime environments. For Cloud Foundry and Kyma, it offers an easy integration by providing predefined contents to investigate load, latency, and error rates of the observed applications based on their requests and correlate them with additional data.
The SAP Cloud Logging service offers multiple service plans (e.g., Standard, Large, and Dev) to cater to different use cases and requirements. These plans provide different ingestion and storage capabilities. For example:
- Standard/Large plans are designed for production workloads, supporting higher data volumes and extended retention.
- Dev plan is only for non-production environments and evaluation purposes which lacks cloud qualities.
For more information, see the SAP Cloud Logging and its plans documentation. You can also check the service innovation guide to understand the innovation journey from SAP Application Logging Service towards SAP Cloud Logging Service and its benefits.
The Telemetry (@cap-js/telemetry) plugin provides observability features such as tracing and metrics, including automatic OpenTelemetry instrumentation. By enabling the plugin in your project, various kinds of telemetry data will be automatically collected.
Let's add the Telemetry plugin to the project and enable it by customizing few configurations.
-
Switch to code directory and install dependencies
## Run in ./code ## npm i @cap-js/telemetry @grpc/grpc-js @opentelemetry/exporter-metrics-otlp-grpc @opentelemetry/exporter-trace-otlp-grpc @opentelemetry/host-metrics @opentelemetry/exporter-logs-otlp-grpc
-
Add following configuration under requires key in both code/srv/.cdsrc.json and code/api/.cdsrc.json file folder.
"telemetry": { "[hybrid]": { "kind": "telemetry-to-cloud-logging" }, "[local-with-mtx]": { "kind": "telemetry-to-console" }, "[development]": { "kind": "telemetry-to-console" } }
-
Test your application locally by following steps in section 1 to see the telemetry in the console.
-
This should show traces and metrics data (also refferred to as signals) in the console as shown below:
-
Traces:
Traces allow you to analyze how a request, message, task, etc. is being processed by your application. It provides a detailed view of the flow of the request and the time taken by each operation.
-
Metrics:
Metrics are measurements captured at runtime. It helps you to understand health and performance of the application.Out of the box, @cap-js/telemetry offers HTTP metric http.server.duration which measures different values like minimum/maximum response time, total duration across requests, distribution of request durations etc. It helps analyze performance, detect bottlenecks, and optimize response times.
Additionally, @cap-js/telemetry instantiates and provides host metrics like cpu usage and memory usage etc (@opentelemetry/host-metrics).
-
-
Prepare for Deployment
- Ensure that you have installed following dependencies in your project (check in code/package.json).
## Run in ./code ## npm i @cap-js/telemetry @grpc/grpc-js @opentelemetry/exporter-metrics-otlp-grpc @opentelemetry/exporter-trace-otlp-grpc @opentelemetry/host-metrics
- Add following configuration under requires key in both code/srv/srv/.cdsrc.json and code/api/srv/.cdsrc.json file.
"telemetry": { "kind": "to-cloud-logging" }
- Add the following property to the server (susaas-srv) and api (susaas-api-srv) modules in the mta.yaml file to set the OpenTelemetry component name which is used while sending signals to cloud logging service.
properties: OTEL_SERVICE_NAME: ${app-name}
- Ensure that you have installed following dependencies in your project (check in code/package.json).
-
Service Instance Creation / Binding
There are multiple methods to create an instance of the SAP Cloud Logging service as follows.- Create an SAP Cloud Logging Instance through SAP BTP Cockpit
- Create an SAP Cloud Logging Instance through Cloud Foundry CLI
- Create an SAP Cloud Logging Instance through SAP BTP CLI
It is also possible to create the instance while deployment of the application using the
mta.yaml
file. As the same SAP Cloud Logging service can be used across multiple applications, it is recommended to create the instance separately and bind it to the applications.If you want to create the instance during deployment, replace the following code snippet in the mta.yaml file.
# Before - name: susaas-logging type: org.cloudfoundry.managed-service parameters: service: application-logs service-name: ${space}-susaas-logging service-plan: lite # After - name: susaas-logging type: org.cloudfoundry.managed-service parameters: service: cloud-logging service-name: ${space}-susaas-cls-logging service-plan: standard config: ingest_otlp: enabled: true retention_period: 14 backend: max_data_nodes: 2 dashboards: custom_label: 'SusaaS' saml: enabled: false
To learn more about each parameter and adjust the initialization settings, review the configuration parameters documentation.
Note: It is also possible to share the same instance of the SAP Cloud Logging service across different spaces within a Cloud Foundry organization. This allows for the consolidation of observability data from multiple spaces, streamlining monitoring and analysis. For more details, refer to the documentation.
If you have created the instance separately, you can declare it in your
mta.yaml
file as a existing resource.- name: susaas-logging type: org.cloudfoundry.existing-service
To bind the instance to your application, simply declare it in your
mta.yaml
file as a required service. Addsusaas-logging
to therequires
section of the server (susaas-srv) and api (susaas-api-srv) modules in the mta.yaml file.requires: - name: susaas-logging
-
Deploy the Application
Build and deploy the application, then subscribe to it from a consumer subaccount. Finally, test the application to ensure it functions as expected from the consumer's perspective. Follow the steps from the following sections: -
Access SAP Cloud Logging Service and Explore Dashboards
-
Navigate to the SAP BTP Cockpit, open the cloud logging service and create a service key. Then open the dashboard by navigation to View Dashboard in actions menu.
-
Log into the dashboard using the credentials provided (dashboards-username and dashboards-password:) in the service key. This should show the welcome page of the dashboard.
-
You can explore the dashboard and check the request details, logs, traces, and metrics data of your application under CF tab (as shown below). There are pre-build visulization available to analyze the data such as Four Golden Signals (i.e. Latency, Traffic, Errors, and Saturation), Performance and Quality, Requests and Logs.
-
You can see traces and metrics data that is auto collected by Telemetry plugin in OpenTelemetry/Metrics Tab as shown below:
-
If you want to explore metrics in more details, you can navigate to 'Discover' menu item and choose 'metrics-otel-v1-*' data source.
-
NOTE: It is also possible to add custom metric and visualize it in the dashboard. To learn more about creating a custom metric, refer to the Create a Custom Metric documentation.
Please use the following links to find further information on the topics above: