Use log analysis to pinpoint the cause of business exceptions in your application. You can analyze logs from Simple Log Service (SLS) or logs collected directly. This topic describes how to enable log analysis and use it to analyze logs from SLS.
Prerequisites
-
You have installed an agent for your application.
-
You have activated Simple Log Service (SLS). If the service is not activated, log on to the Simple Log Service console and activate it as prompted.
-
You have created a project.
-
You have created a basic Logstore.
-
You have configured data collection for SLS.
Try in Playground
Alibaba Cloud Playground provides a demo environment where you can experience the main features of Cloud Monitor 2.0.
-
Visit the Playground Demo. The default workspace opens.
-
In the left-side navigation pane, choose .
-
On the Applications page, click the target Application Name. In the left-side navigation pane, click Trace Analysis.
Step 1: Associate business logs
Log on to the Cloud Monitor 2.0 console, and select a workspace. In the left navigation pane, choose .
-
On the Applications page, click your target Application Name. In the left-side navigation pane, choose .
-
On the Custom Configurations tab, in the Application Log Association section, turn on the Associate Business Logs with Trace ID switch. Select the region for your project, and then associate the project and Logstore.
-
In the lower-left corner of the Custom Configurations tab, click Save.
Step 2: Query and analyze logs
Log on to the Cloud Monitor 2.0 console, and select a workspace. In the left navigation pane, choose .
-
On the Applications page, click your target Application Name. In the left-side navigation pane, click Trace Analysis.
-
In the Actions column for the target trace, click Log.
-
On the log query page, you can:
-
In the search box, enter a query and analysis statement.
A query and analysis statement uses the format Query statement|Analysis statement. For more information about the syntax, see Query syntax and functions and SQL analysis syntax.
-
Set the time range for the query and analysis.
You can set relative time, aligned time, or a custom time range.
NoteThe query results may have a margin of error of up to 1 minute.
-
Click Search & Analyze to view the results.
After you filter logs by Trace ID, the query results show a
RegisterPromClusterServlet Failederror log. The exception type isjava.lang.RuntimeException, the root cause is Failed to create Grafana folder, and the stack trace indicatesGrafanaConfigService.java. -
References
You can associate a Trace ID from a trace with your application's business logs. This helps you quickly correlate business logs with a trace when an issue occurs and accelerates problem identification, analysis, and resolution. For detailed instructions, see Associate a Trace ID with business logs for a Java application.