Skip to main content

Log Analysis

AI-Starter outputs logs to CloudWatch Logs to track application behavior and usage patterns. By analyzing these logs, you can troubleshoot issues and improve your service.

This guide explains how to analyze logs using CloudWatch Logs Insights.

Analyzing Application Logs

CloudWatch Logs Insights provides powerful query capabilities for flexible log data analysis.

Analysis Procedure

  1. Log in to the AWS Management Console.
  2. Open the App Runner service page in the Tokyo region.
  3. Select the target AI-Starter resource (e.g., cmais-prd-ar-ai-starter).
  4. Click [View in CloudWatch] in the [Application logs] section under the [Logs] tab.
  5. You will be redirected to the CloudWatch service page, displaying the AI-Starter resource's log group.
  6. Click [View in Logs Insights].
  7. In the displayed query input field, enter and execute a query based on what you want to analyze.

Query Examples

User Count

fields @timestamp, @message, user, selectedAssistant.id, selectedAssistant.model
| filter !isBlank(user)
| filter @message like /Saved/
| stats count(*) as total by selectedAssistant.id, selectedAssistant.model
| sort by total desc

This query aggregates unique users per day and displays the daily user count.

Conversation Count

fields @timestamp, @message, user
| filter !isBlank(user)
| filter @message like /Saved/
| stats count(*) as total_count

This query aggregates and displays the number of conversations.

Chat Count by User

fields @timestamp, @message, user
| filter !isBlank(user)
| filter @message like /Saved/
| stats count(*) as chat_count by user
| sort chat_count desc

This query aggregates chat counts per user and displays them in descending order of chat frequency.

Assistant Usage Breakdown

fields @timestamp, @message, user, selectedAssistant.id, selectedAssistant.model
| filter !isBlank(user)
| filter @message like /Saved/
| stats count(*) as total by selectedAssistant.id, selectedAssistant.model
| sort by total desc

This query aggregates usage counts per assistant and displays them in descending order of usage frequency.

Feedback Content

fields @timestamp, userId, assistantId, assistantDisplayName, eventType, feedbackType, comment, @message
| filter eventType like 'user_feedback'

This query aggregates feedback and displays ratings and comment content.

Error Logs

fields @timestamp, @message, @logStream, @log
| filter @message like 'Error'
| sort @timestamp desc
| limit 100

This query extracts logs containing "Error" and displays the latest 100 entries. This is helpful for understanding error situations.

Saving and Reusing Queries

CloudWatch Logs Insights allows you to save frequently used queries for reuse.

How to Save Queries

  1. Create the query you want to save in the CloudWatch Logs Insights query screen.
  2. Click [Save] at the top of the screen.
  3. In the [Save new query] dialog box, enter a query name and click [Save].
    • Use a descriptive name that clearly represents the query content.
    • Note that this operation saves the log group and query text, but not the time period.

How to Use Saved Queries

  1. Open the CloudWatch Logs Insights query screen.
  2. Click the [Queries] icon on the right side of the screen.
  3. Select the query you want to use from [Saved queries].
  4. The selected query's log group and query text will be populated on the screen.
  5. Adjust the query period as needed and click [Run query].

Key Points

  • You can edit or delete saved queries at any time.
  • Saving commonly used queries within your team can improve analysis efficiency.