POST /v2/analytics.getRuntimeLogs endpoint runs SQL queries on the logs
that your deployments write to stdout and stderr. Use it from a trusted backend
with a root key. Never put a root key in browser code.
For the request and response schemas, see the API
reference.
Authenticate the request
Use a root key with theproject.*.read_runtime_logs permission. This
permission gives access to the runtime logs of all projects in the workspace.
The gateway requests need the
project.*.read_gateway_requests permission.
Unkey limits each query to the workspace of the root key. A query cannot read
the data of a different workspace, and it cannot remove this filter.
Send a query
Send a JSON object with aquery string. The response contains
meta.requestId, which identifies the API request, and data, which contains
an array of result objects.
Response
Select the logs of one project, app, environment, or deployment
Each row containsproject_id, app_id, environment_id, and deployment_id.
Add a filter on one of these columns to get the logs of one target. You can also
combine them, for example app_id = 'app_1234' AND environment_id = 'env_1234'.
Choose a time range
Your workspace retention setting controls the time range that a query can request. A query for a longer range gets a 400 response. If you do not add a time filter, Unkey limits the results to your workspace retention range. Thetime column holds Unix milliseconds, thus a time filter uses
toUnixTimestamp64Milli.
Reference available columns
The table contains one row for each log line. Unkey filtersworkspace_id
automatically, thus you do not need to add it to a query.
Unkey reads
severity from the content of the log line, not from the log level
of your logger. A line that reports an error gets error.
Find text in a log
Uselower(message) LIKE '%text%' to find a substring. The lower() form
ignores the case of the log line.
lower(attributes_text) LIKE '%text%' to search the attributes, and
NOT LIKE to remove the lines that you do not want.
Read the structured attributes
Theattributes_text column contains the log attributes as a JSON string. A log
line with no attributes gives the string {}. This column is never null.
Select the column to get the full JSON, then parse it in your own code.
JSONExtractString to read that
attribute as a column.
Count the errors of each deployment
UsecountIf to count a subset of the rows in the same query. This example
compares the failed lines with all lines of each deployment.
Get a breakdown of the severities
Page through a large result
UseLIMIT and OFFSET to read a large result in pages. Many log lines can
have the same time. Thus ORDER BY time alone does not give a stable order,
and one row can appear on two pages. Add more columns to make the order stable.
Errors
For the tables that each analytics endpoint accepts, see Invalid analytics
table.