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

The 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

To 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.log function below:

async function handleRequest(request) {
console.log("Hello World");
return new Response("Checking console output.", {
status: 200,
});
}
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});

The message is then collected and made available to be accessed on Data Stream.


Setting up

  1. Access Azion Console with your login credentials.
  2. On the upper left corner, select Products Menu > Observe > Data Stream.
  3. Select an existing template or create a new one by clicking the Add Streaming button.
  4. Fill out the following fields with the necessary information:

Name for Data Stream: 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:

VariableDefinition
$timeDate and time of the request.
$global_idSettings identifier.
$edge_function_idEdge Function identifier.
$request_idRequest identifier.
$log_levelLevel of the log created (ERROR, WARN, INFO, DEBUG, TRACE).
$log_messageMessage 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 Stream. Select an option.

Endpoint URL: the URL that will receive information transmitted by Data Stream. Define the URL.

Custom Headers: include here the need to add headers at requests.

  1. Click the Save button to finish the process.

Check the Data Stream documentation to learn more.

Enhance your Edge Functions debugging skills. Watch the video below:


Contributors