Report app errors using Retool Events
Build Retool Event-triggered workflows that automatically send app error reports to any third-party observability provider.
In addition to built-in support for reporting app errors to Datadog or Sentry, you can use Retool Events to build workflows that automatically trigger whenever an app error occurs. This can be useful for automatically notifying third-party observability providers.
Add a workflow for the event
First, navigate to the settings in your organization. Click Add a workflow to select or create a workflow for the Report App Errors event.
You can download an example workflow for Datadog, Rollbar, or Sentry as a JSON file and import it as a new workflow. Each workflow contains sample error data for you to use during testing.
Transform error data
The App Error event contains detailed information about the error. Observability providers require data to be in a particular shape. You can use the Code block within a workflow to transform the error data into a suitable payload before using a Resource query block to send it.
The following app error example uses JavaScript to transform the error into a digestible format for Datadog.
- App error
- JavaScript transform
- Result
{
"errors": [
{
"id": "50f1ffbf-58e7-44f1-9a6b-5bed45fee232",
"timestamp": 18,
"origin": "runtime",
"appUuid": "91e36cb2-2d20-11ef-9a6c-378c1a9d5665",
"callstack": [
{
"type": "error",
"message": "workflow error",
"lineNumber": 2,
"id": "0/transformerRun-1718685005587-0/transformerFailure-1718685005588-1/error-1718685005588-2",
"timestamp": 1718685005588
},
{
"type": "transformerFailure",
"transformerId": "transformer1",
"id": "0/transformerRun-1718685005587-0/transformerFailure-1718685005588-1",
"timestamp": 1718685005588
},
{
"type": "transformerRun",
"transformerId": "transformer1",
"id": "0/transformerRun-1718685005587-0",
"timestamp": 1718685005587
},
{ "type": "loadEvent", "id": "0", "timestamp": 1718685005587 }
],
"tags": {}
}
]
}
console.log("errors", startTrigger.data.errors);
const errors = [];
for (const error of startTrigger.data.errors) {
errors.push({
timestamp: error.timestamp,
ddsource: error.origin,
status: "error",
ddtags: JSON.stringify(error.tags),
service: "retool-error-monitor",
message: error.errorMessage,
error: {
stack: error.callstack.map((node) => node.message).join("\n"),
message: error.errorMessage,
type: error.origin,
},
...error.tags,
callstack: error.callstack,
});
}
return JSON.stringify(errors);
[
{
timestamp: 18,
ddsource: "runtime",
status: "error",
ddtags: "{}",
service: "retool-error-monitor",
error: { stack: "workflow error\n\n\n", type: "runtime" },
callstack: [
{
type: "error",
message: "workflow error",
lineNumber: 2,
id: "0/transformerRun-1718685005587-0/transformerFailure-1718685005588-1/error-1718685005588-2",
timestamp: 1718685005588,
},
{
type: "transformerFailure",
transformerId: "transformer1",
id: "0/transformerRun-1718685005587-0/transformerFailure-1718685005588-1",
timestamp: 1718685005588,
},
{
type: "transformerRun",
transformerId: "transformer1",
id: "0/transformerRun-1718685005587-0",
timestamp: 1718685005587,
},
{ type: "loadEvent", id: "0", timestamp: 1718685005587 },
],
},
];
Send errors to an observability provider
Observability providers typically receive error logs using an API or SDK. The method you use depends on the provider.
- Using an API (e.g., Datadog or Rollbar): Create a resource that's configured with the necessary settings. You can then select this resource in the workflow.
- Using a JavaScript SDK (e.g., Sentry): If necessary, use configuration variables to store secret keys. You can then reference them when using custom JavaScript or Python libraries to send app errors without exposing sensitive information in the workflow.
You can send app errors to most observability providers with an API or SDK. The following examples explain how to send errors to Datadog, Rollbar, and Sentry.
- Datadog
- Rollbar
- Sentry
Add a Resource query block to the workflow and select the REST API resource. To send error logs, use the POST /api/v2/logs endpoint, add your Datadog API Key to the header, and provide the transformed data as the raw body in the request.
First, create a resource for the Rollbar API using the REST API integration. You then configure the resource with the Rollbar API base URL (https://api.rollbar.com/api/1
) and a X-Rollbar-Access-Token
header with a valid access token.
Next, add a Resource query block to the workflow and select the Rollbar resource. To send error logs, specify the /item
API endpoint and and provide the transformed data as the raw body in the request.
You can use Sentry's JavaScript SDK to send app error logs by adding the @sentry/node custom JavaScript library to the workflow. Once added, you can write JavaScript code that uses the SDK.
To add the SDK:
- Open the Libraries tab.
- Click ≠ and select Add JavaScript library.
- Select the @sentry/node library.
- Click Add selected libraries.
Once you add the SDK, you need to include it in the workflow's setup scripts. This enables the SDK for use in the worfklow. Navigate to the Settings tab and select JavaScript configuration. Add the requirement for @sentry/node:
const Sentry = require("@sentry/node");
You can then add a Code block to the workflow and write the script to sends app errors to Sentry.
The Sentry SDK uses a Data Source Name (DSN) to identify the source of reported logs. While this does not need to be kept secret, you should still store it in a configuration variable. You can then reference it across multiple workflows, should it be necessary, which makes it easier to manage and update.
Deploy the workflow
Once you create a workflow, you must deploy it to begin automatically sending app error reports to providers. Whenever you make changes to a workflow, you must also deploy those changes for them to take effect.
After deploying the workflow, create an app and perform actions that would cause an error. For example:
- Write an invalid query that fails to run.
- Create a test resource, reference it in the app in a query, then delete the resource.