query_logs
Search CubeAPM logs using LogsQL syntax to find errors, filter by labels, and aggregate results. Returns matching log entries within a time range for debugging and investigation.
Instructions
Query logs from CubeAPM using LogsQL syntax (VictoriaLogs compatible). Returns log entries matching the query.
IMPORTANT - Log Label Discovery:
Labels vary by source! Use "*" query first to discover available labels
Lambda logs use: faas.name, faas.arn, env, aws.lambda_request_id
Service logs may use: service_name, level, host
NOT all sources have "service_name" - check the _stream field in results
LogsQL Query Syntax:
Wildcard (discover labels): *
Stream filters: {faas.name="my-lambda-prod"}
Text search: {faas.name="webhook-lambda-prod"} AND "error"
Regex match: {faas.name=~".*-prod"}
Negation: {faas.name!="unwanted-service"}
Combine filters: {env="UNSET", faas.name=~".-lambda."}
PIPE OPERATORS — chain after query with "|": | copy src_field AS dst_field — copy field value | drop field1, field2 — remove fields from output | extract_regexp "(?Pregex)" — extract fields via named capture groups | join by (field) (...subquery...) — join with subquery results | keep field1, field2 — keep only specified fields | limit N — return at most N results | math result = field1 + field2 — compute derived fields (+, -, *, /, %) | rename src AS dst — rename a field | replace (field, "old", "new") — replace substring in field | replace_regexp (field, "re", "replacement") — regex replacement | sort by (field) [asc|desc] — sort results | stats as alias [by (group_fields)] — aggregate results | unpack_json — extract fields from JSON log body
STATS FUNCTIONS (use with | stats pipe): avg(field) — arithmetic mean count() — total number of matching entries count_empty(field) — count entries where field is empty count_uniq(field) — count distinct values max(field) — maximum value median(field) — median (50th percentile) min(field) — minimum value quantile(p, field) — p-th quantile (e.g., quantile(0.95, duration)) sum(field) — sum of values
Example queries:
All logs (discover structure): *
Lambda logs: {faas.name="webhook-lambda-prod"}
Search errors: {faas.name=~".*"} AND "error"
By environment: {env="production"}
Count errors per function: {faas.name=~".*"} AND "error" | stats count() as error_count by (faas.name)
Top 10 slowest: {service_name="my-service"} | sort by (duration) desc | limit 10
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"query": "<query>",
"start": "<start>",
"end": "<end>"
},
"name": "query_logs"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | Yes | End time in RFC3339 format or Unix timestamp in seconds | |
| limit | No | Maximum log entries to return (default: 100) | |
| query | Yes | The log search query including stream filters (LogsQL syntax) | |
| start | Yes | Start time in RFC3339 format (e.g., 2024-01-01T00:00:00Z) or Unix timestamp in seconds |