# How to debug functions on Data Stream

import Apiv4Rollout from '~/includes/snippets/apiv4Rollout/en/snippet.mdx'
import Tabs from '~/components/tabs/Tabs'

<Apiv4Rollout />


The debugging process in functions' code on [Data Stream](/en/documentation/products/observe/data-stream/) helps you identify if errors are still occurring or if the process was successful.

Before analyzing the process, you need to apply the debugging code. Find out more on [Debugging functions](/en/documentation/devtools/debugging/).

There are separate instructions using [legacy Domains](/en/documentation/products/build/applications/domains/) settings and using the new [Workloads](/en/documentation/products/secure/workloads) product.

:::tip
If you're not sure which steps apply to your account, see [the Verify Your Account Migration guide](/en/documentation/products/guides/verify-account-migration/) to determine if your account has already been migrated.
:::

## Setting up Data Stream to debug functions

After applying the debugging code for functions:

1. [Access Azion Console](https://console.azion.com).
2. On the upper-left corner, select **Data Stream** on the **Observe** section.
3. Click **+ Stream**.
4. Choose a name for your stream.
5. On the **Source** dropdown menu, select **Functions**.
6. On the **Template** dropdown menu, select **Functions** Event Collector.
7. On the **Data Set** code box, add the following variables:

```json
{
	"time": "$time",
    "global_id": "$global_id",
    "edge_function_id": "$edge_function_id",
    "request_id": "$request_id",
    "log_level": "$log_level",
    "log_message": "$log_message"
}
```

<Tabs client:visible>
    <Fragment slot="tab.consoleworkloads">Console - Workloads</Fragment>
    <Fragment slot="tab.consoledomains">Console - Domains</Fragment>

<Fragment slot="panel.consoleworkloads">

8. On **Workloads** > **Options**, select between **All Current and Future Workloads** or **Filter Workloads**. See more about each option on [How to associate Workloads on Data Stream](/en/documentation/products/guides/data-stream-associate-workloads/).
9. On the **Destination** section, select a **Connector** on the dropdown menu. See more about [setting an endpoint](/en/documentation/products/observe/data-stream/#endpoints).
    - You'll see different fields depending on the connector type you choose.

Finally, to finish your stream setup:

10. Make sure the **Active** switch is turned on.
11. Click the **Save** button.

Now, you'll be able to analyze the behavior of the functions debugging process through the logs sent to your configured stream.

## Variables definition

| Variable          | Definition                                                  |
| ----------------- | ----------------------------------------------------------- |
| $time             | Request date and time. Example: Oct. 31st, 2022 - 19:30:41                               |
| $global_id        | Settings identifier.                                        |
| $edge_function_id | Function identifier.                                   |
| $request_id       | Unique request identifier. Example: 5f222ae5938482c32a822dbf15e19f0f                                         |
| $log_level        | Level of the log generator: ERROR, WARN, INFO, DEBUG, or TRACE. |
| $log_message      | Editable message used in the log function. Available for users to identify and report a given behavior.     |

</Fragment>

<Fragment slot="panel.consoledomains">

8. On **Domains** > **Options**, select between **All Current and Future Domains** or **Filter Domains**. See more about each option on [How to associate domains on Data Stream](/en/documentation/products/guides/data-stream-associate-domains/).
9. On the **Destination** section, select a **Connector** on the dropdown menu. See more about [setting an endpoint](/en/documentation/products/observe/data-stream/#endpoints).
    - You'll see different fields depending on the connector type you choose.

Finally, to finish your stream setup:

10. Make sure the **Active** switch is turned on.
11. Click the **Save** button.

Now, you'll be able to analyze the behavior of the functions debugging process through the logs sent to your configured stream.

## Variables definition

| Variable          | Definition                                                  |
| ----------------- | ----------------------------------------------------------- |
| $time             | Request date and time. Example: Oct. 31st, 2022 - 19:30:41                               |
| $global_id        | Settings identifier.                                        |
| $edge_function_id | Function identifier.                                   |
| $request_id       | Unique request identifier. Example: 5f222ae5938482c32a822dbf15e19f0f                                         |
| $log_level        | Level of the log generator: ERROR, WARN, INFO, DEBUG, or TRACE. |
| $log_message      | Editable message used in the log function. Available for users to identify and report a given behavior.     |

</Fragment>
</Tabs>