Debug functions with Data Stream
Send the log messages of your functions, with their level and request ID, to an endpoint with Data Stream, in Azion Console or with the Azion API.
You can send the log messages of your functions to an endpoint with a Data Stream stream, from Azion Console or with the Azion API. To trace which Rules Engine rules ran on a request instead, refer to Debug rules created with Rules Engine.
A function writes log messages with console.log. The Functions data source carries each message with its level, its source, and the ID of the request, and the Functions Event Collector template places them in one log line per message. For every variable of the data source, refer to Data sources and variables.
Prerequisites
Console
- An Azion account with the Edit Data Stream permission. For the permissions, refer to Stream settings.
- A function that writes log messages with
console.log, running in an application that a workload serves. To create one, refer to Functions. - An endpoint that receives the log lines, such as an HTTP endpoint. For the endpoints a stream can send to, refer to Endpoints.
- Access to Azion Console. To sign in, refer to How to access Azion Console.
Create the stream
The stream reads the Functions data source of one workload through a workload filter. Unlike sampling, a workload filter leaves your other streams active.
Console
To create the stream in Azion Console:
Access Azion Console > Data Stream.
In the General section, enter a Name. For example: functions-debug.
In the Input section, select Functions in Data Source.
In the Transform section, turn off Sampling while Option is still All Current and Future Workloads, its starting value. A stream cannot carry sampling and a workload filter together.
In the Transform section, set Option to Filter Workloads. In Available Workload, select the workload of the function and move it to Chosen Workload with the arrow. For the pick-list controls, refer to Associate workloads with a stream. If your Console names domains where this guide names workloads, the same control reads Filter Domains. The pick list then reads Available Domain and Chosen Domain.
In the Render Template section, select Functions Event Collector in Template. The Data Set field shows the keys of each log line.
In the Output section, select your endpoint in Connector, and enter the fields it shows. Each endpoint has its own fields, listed on Endpoints.
In the Status section, keep Active turned on.
The Console shows Your data stream has been created. The stream appears in the Data Stream list with functions_console in the Source column and the Active status.
Saving the stream checks the format of each field and does not contact the endpoint. A wrong URL or credential surfaces only when the stream sends. An activation takes effect after one to two minutes.
In the Deploy remote MCP servers use case, this section takes these values:
| Setting | Value |
|---|---|
| Data Source | Functions. In the API, functions_console |
| Template | Functions Event Collector, whose $log_message variable carries each line the function writes. In the API, 86 |
| Option | Filter Workloads, with the workload that azion deploy created as the only chosen workload |
| Connector | Standard HTTP/HTTPS POST, with your log platform’s URL and the header it requires to accept the request |
The stream becomes active within one to two minutes of saving it. Your log platform then receives one line per tool call, each carrying the $request_id of the request that made it.
In the Govern access to multiple AI models use case, this section takes these values:
| Setting | Value |
|---|---|
| Data Source | Functions. In the API, functions_console |
| Template | Functions Event Collector, whose $log_message variable carries each line the function writes. In the API, 86 |
| Option | Filter Workloads, with the gateway’s workload as the only chosen workload |
| Connector | Standard HTTP/HTTPS POST, with your analytics platform’s URL and the header it requires to accept the request |
The stream becomes active within one to two minutes of saving it. Your analytics platform then receives one model_call line per request, and one route_failed line per route that failed.
Confirm the delivery
Real-Time Events records every send of a stream, delivered or not, with the status code the endpoint returned. Send a few requests that run the function, then wait about a minute: a stream sends a batch every 60 seconds, or sooner when it reaches 2,000 log lines.
Console
To find the sends in Azion Console:
Access Azion Console > Real-Time Events.
Each row is one send. Find the rows whose Endpoint Type matches your endpoint, such as HTTP_POST, and read their Status Code.
A Status Code of 200 means the endpoint accepted the batch. Streamed Lines gives the number of log lines in the batch.
A status other than 200 is the answer of the endpoint, and 503 means Data Stream found the endpoint unavailable. For the causes, refer to Troubleshoot Data Stream.
At the endpoint, each log line carries the keys of the Functions Event Collector template. Read these keys to debug the function:
logLevelholds the level of the message:ERROR,WARN,INFO,DEBUG, orTRACE. It carries the$log_levelvariable.logMessageholds the message the function passed to the log function. It carries the$log_messagevariable.messageSourcereadsCONSOLEfor a message written with the console API, such asconsole.log, andRUNTIMEfor an error message.requestIDidentifies the request, so the messages of one request share it.
To keep the variable names as keys, or to send fewer of them, select a custom template instead. For an example data set, refer to Templates and payload.
In the Deploy remote MCP servers use case, expect:
- Every tool call is logged. After the
get_ordercall, your log platform receives a line whose message holds"event":"tool_call"and"tool":"get_order".
In the Govern access to multiple AI models use case, expect:
- Every call is logged. Your analytics platform receives a
model_callline for each request sent to the gateway, with"team":"checkout-team". To read the lines of one request, open the Functions Console data source in Real-Time Events, where theIDvariable groups the lines of a single request.
These checks confirm the Screen file uploads for malicious content use case.