Search Logs
search_logsSearch a service's application logs in Mackerel to investigate errors and incidents, find logs by trace ID, keyword, severity, or JSON body fields, and page through results within a time range.
Instructions
Search logs of a service from Mackerel.
š USE THIS TOOL WHEN USERS:
Investigate errors or incidents by reading application logs
Find logs related to a specific trace (traceId)
Look for logs containing specific keywords or matching structured (JSON) body fields
š KEEPING RESPONSES SMALL:
Pass
serviceNamespacewhen the service has one. Without it, only services without a namespace are searchedOmit
from/toto search relative to the current time (lookbackMinutes, default 60). The response includes the actualtimeRangesearchedNarrow the time range and use severities / keywords / bodyAttributes filters first
By default only timestamp, severity, body, traceId and spanId are returned. Use
fieldsto request attributes only when neededLog bodies longer than
maxBodyLengthare truncated and marked withbodyTruncated: trueTo get more logs, pass
pagination.nextPageCursoraspageCursoras-is with the same filters. The cursor carries the time range and sort order, sofrom/to/orderare not needed. The API allows 1 request per second
Logs in the last 15 minutes
search_logs(serviceName="my-service", serviceNamespace="my-namespace", lookbackMinutes=15)Logs related to a trace in chronological order
search_logs(serviceName="my-service", serviceNamespace="my-namespace", from=1700000000, to=1700003600, traceId="0af7651916cd43dd8448eb211c80319c", order="ASC")Keyword search
search_logs(serviceName="my-service", serviceNamespace="my-namespace", from=1700000000, to=1700003600, keywords=["timeout", "payment"])Filter JSON bodies: {"res": {"status": 500+}}
search_logs(
serviceName="my-service",
serviceNamespace="my-namespace",
from=1700000000,
to=1700003600,
bodyAttributes=[{keyPath: ["res", "status"], value: "500", type: "int", operator: "GTE"}]
)Include log attributes
search_logs(serviceName="my-service", serviceNamespace="my-namespace", from=1700000000, to=1700003600, fields=["timestamp", "body", "attributes", "resourceAttributes"])Next page
search_logs(serviceName="my-service", serviceNamespace="my-namespace", severities=["ERROR"], pageCursor=<pagination.nextPageCursor>)Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | No | End time (Unix epoch seconds, exclusive). Defaults to the current time. The range from `from` must be 30 days or less | |
| from | No | Start time (Unix epoch seconds, inclusive). Defaults to `lookbackMinutes` before `to` | |
| order | No | Sort order by timestamp. Default is DESC (newest first) | |
| fields | No | Fields to include for each log. Default is ["timestamp","severity","body","traceId","spanId"]. Attribute fields are returned as {key: value} objects | |
| perPage | No | Number of logs per page (1-1000). Default is 20 | |
| traceId | No | Only logs associated with this trace ID (32-digit hex) | |
| keywords | No | Keywords that must all appear in the log body (partial match, AND) | |
| pageCursor | No | Pass `pagination.nextPageCursor` or `pagination.previousPageCursor` from a previous response as-is. The cursor carries the time range and sort order, so `from`, `to`, `lookbackMinutes` and `order` are ignored. Keep the filters unchanged between pages | |
| severities | No | Severities to include (OR) | |
| serviceName | Yes | Service name | |
| maxBodyLength | No | Truncate each log body to this many characters (default 1000). Truncated logs have `bodyTruncated: true` | |
| bodyAttributes | No | Filters on fields of JSON log bodies (AND). Logs whose body is not JSON never match | |
| lookbackMinutes | No | When `from` is omitted, search this many minutes before `to` (default 60). Use this for relative ranges such as 'the last 15 minutes' without knowing the current time | |
| serviceNamespace | No | Service namespace. Corresponds to `service.namespace` in OpenTelemetry semantic conventions. When omitted, only services without a namespace are searched, so always pass it for services that have one |