Query function logs with GraphQL API
Retrieve the console and runtime log lines of your functions for a time range, and filter them by message content.
You can retrieve the log lines a function writes with GraphQL API. Run the query from an API platform such as Postman, or from the GraphiQL Playground in Azion Console. The functionConsoleEvents dataset returns the messages your code writes with console.log, and the lines Azion Runtime produces. For compute time and invocation counts, refer to Query usage data from Functions. To match an entry to its cause, refer to Troubleshoot function execution and logs.
Prerequisites
- A personal token. To create one, refer to Personal Tokens.
- A function that has run at least once. Creating a function does not execute it, and a function that never runs writes no entries.
Build the query
The functionConsoleEvents dataset holds one entry per log message. This query returns 10 entries from a time range, ordered from the oldest to the most recent:
Set begin and end to the time range you want to read. The limit field accepts up to 10,000 rows per query, and a query selects at most 37 fields. For both limits, refer to Limits GraphQL API.
Send the query
The Real-Time Events endpoint, https://api.azion.com/v4/events/graphql, answers the query. To send it from Postman or another API platform:
For the complete Postman setup, refer to How to query GraphQL requests on Postman.
Enter Authorization: Token [TOKEN VALUE], where [TOKEN VALUE] is the token you created.
Enter https://api.azion.com/v4/events/graphql.
The response carries the matching entries as JSON:
Each entry carries the level of the message in level, its category in lineSource, and the message itself in line. CONSOLE marks a line your own code wrote with console.log. A line Azion Runtime produced, such as an exception, carries RUNTIME. The id field is the request identifier, and it aggregates every message of a single request. For every field of the dataset, refer to Real-Time Events GraphQL API Fields.
You now have the log entries of the time range, each with its level and its source.
Filter the entries by message
Every filter key joins a field name to an operator, as in tsRange and lineLike. To return only the entries whose message matches a pattern, add lineLike to the filter:
The % character stands for any sequence of characters, so "%TypeError%" matches every line that contains TypeError. Like is case-sensitive, and Ilike is its case-insensitive form. For every operator, refer to Queries GraphQL API.