Debugging
Debugging is a process that allows developers to fix log messages or variables, for example. The debugging method allows Edge Functions users to generate logs as if they were using a browser’s JavaScript.
What it is
Section titled What it isThe debugging process in Edge Functions has the purpose of promoting better control over the application to identify errors. It can also be used to assist in the development and debugging of a function, resulting in greater observability.
How it works
Section titled How it worksTo debug codes, you must create a new function that will use the log method. This function prints to a local file a message that was previously sent by a parameter to the function.
Check the use of the console_from_event.log
function below:
async function handleRequest(request, console_from_event) { console_from_event.log("Hello World");
return new Response("Checking console output.", { status: 200, }); } addEventListener("fetch", (event) => { event.respondWith(handleRequest(event.request, event.console)); });
The message is then collected and made available to be accessed on Data Streaming.
Setting up
Section titled Setting up- Access Real-Time Manager with your login credentials.
- On the upper left corner, select Products Menu > Observe > Data Streaming.
- Select an existing template or create a new one by clicking the Add Streaming button.
- Fill out the following fields with the necessary information:
Name for Data Streaming: Define a name for your template.
Data
Data Source: this is the Azion platform that will generate the events from which you are collecting data.
Template: the definition of the variables. Select Custom Template to create a new data set and include the variables below into the Data Set box:
Variable | Definition |
---|---|
$time | Date and time of the request. |
$global_id | Settings identifier. |
$edge_function_id | Edge Function identifier. |
$request_id | Request identifier. |
$log_level | Level of the log created (ERROR, WARN, INFO, DEBUG, TRACE). |
$log_message | Message used on the log when the function is requested. |
Options: where data will be collected. It’s possible to filter the domains (Filter Domains) or select all (All Domains) by choosing one option.
This option will appear only if you have more than one domain set up.
Domains: in case you wish to specify which domains, select them on the displayed boxes.
Sampling: the definition of % of data that will be transmitted. You can only change this value when selecting All Domains in the Options field.
This option will appear only if you have more than one domain set up.
Destination
Endpoint Type: the method by which your endpoint will receive the data collected by Data Streaming. Select an option.
Endpoint URL: the URL that will receive information transmitted by Data Streaming. Define the URL.
Custom Headers: include here the need to add headers at requests.
- Click the Save button to finish the process.
Check the Data Streaming documentation to learn more.
Contributors