Monitoring events for task executions¶
You can configure Snowflake to record an event that provides information about the status of the task execution. The event is recorded in the active event table associated with the task.
For example, suppose that you have associated an event table with a database. When a task in that database executes, Snowflake records an event to that event table.
The next sections explain how to set up the event logging to capture the events and how to query the table and interpret the events:
Note
Logging events for tasks incurs costs. See Costs of telemetry data collection.
Set the severity level of the events to capture¶
To set up task events to be recorded to the event table, set the severity level of events that you want captured in the event table:
ERROR
: Events for failed task runs.INFO
: Events for successful and failed task runs.
To set the level, set the LOG_LEVEL parameter for the account or object. You can set the level for:
All objects in the account,
All objects in a database or schema.
A specific task.
Note
If the severity level is not set on the account or object, no events will be captured.
For example:
To capture ERROR-level events and messages for all objects in the account, execute ALTER ACCOUNT SET LOG_LEVEL:
ALTER ACCOUNT SET LOG_LEVEL = ERROR;
Note that this level affects all types of objects in the account, including UDFs, stored procedures, dynamic tables, and tasks.
To capture INFO-level events and messages for all objects in the database
my_db
, execute ALTER DATABASE … SET LOG_LEVEL:ALTER DATABASE my_db SET LOG_LEVEL = INFO;
Similar to the case of setting the level on the account, setting the level on the database affects all types of objects in the database, including UDFs, stored procedures, dynamic tables, and tasks.
To capture ERROR-level events for the task
my_task
, execute ALTER TASK … SET LOG_LEVEL:ALTER TASK my_task SET LOG_LEVEL = ERROR;
Query the event table for task completion events¶
After you set the severity level for logging events, you can query the event table for task completion events.
Note
You must use a role that has been granted the required privileges to query the event table.
If you are querying the default event table (SNOWFLAKE.TELEMETRY.EVENTS) or the predefined view (SNOWFLAKE.TELEMETRY.EVENTS_VIEW view), see Roles for access to the default event table and EVENTS_VIEW.
To manage access to the EVENTS_VIEW view, see Manage access to the EVENTS_VIEW view.
If you are querying a custom event table, see Access control privileges for event tables.
To manage access to a custom event table, see Managing access to event table data.
To query for task events, select rows where resource_attributes:"snow.executable.type" = 'TASK'
. To narrow down the list of
events, you can filter on the following columns:
To restrict the results to tasks in a specific database, use
resource_attributes:"snow.database.name"
.To return events where the task execution failed, use
value:state = 'FAILED'
.
For information on the values logged for a task execution event, see Information logged for task events.
For example, to get the timestamp, task name, query ID, and error message for errors with tasks in the database my_db
:
SELECT
timestamp,
resource_attributes:"snow.executable.name"::VARCHAR AS task_name,
resource_attributes:"snow.query.id"::VARCHAR AS query_id,
value:message::VARCHAR AS error
FROM my_event_table
WHERE
resource_attributes:"snow.executable.type" = 'TASK' AND
resource_attributes:"snow.database.name" = 'MY_DB' AND
value:state = 'FAILED'
ORDER BY timestamp DESC;
+-------------------------+-----------+--------------------------------------+------------------------------------------------------+
| TIMESTAMP | TASK_NAME | QUERY_ID | ERROR |
|-------------------------+-----------+--------------------------------------+------------------------------------------------------|
| 2025-02-18 00:21:19.461 | T1 | 01ba76b5-0107-e56d-0000-a995024f4222 | 002003: SQL compilation error: |
| | | | Object 'MY_TABLE' does not exist or not authorized. |
+-------------------------+-----------+--------------------------------------+------------------------------------------------------+
The following example retrieves all columns for errors with tasks in the schema my_schema
:
SELECT *
FROM my_event_table
WHERE
resource_attributes:"snow.executable.type" = 'FAILED' AND
resource_attributes:"snow.schema.name" = 'MY_SCHEMA' AND
value:state = 'FAILED'
ORDER BY timestamp DESC;
+-------------------------+-----------------+-------------------------+-------+----------+------------------------------------------------------------+-------+------------------+-------------+-------------------------------+-------------------+------------------------------------------------------------------------------------------------------+-----------+
| TIMESTAMP | START_TIMESTAMP | OBSERVED_TIMESTAMP | TRACE | RESOURCE | RESOURCE_ATTRIBUTES | SCOPE | SCOPE_ATTRIBUTES | RECORD_TYPE | RECORD | RECORD_ATTRIBUTES | VALUE | EXEMPLARS |
|-------------------------+-----------------+-------------------------+-------+----------+------------------------------------------------------------+-------+------------------+-------------+-------------------------------+-------------------+------------------------------------------------------------------------------------------------------+-----------|
| 2025-02-18 00:21:19.461 | NULL | 2025-02-18 00:21:19.461 | NULL | NULL | { | NULL | NULL | EVENT | { | NULL | { | NULL |
| | | | | | "snow.database.id": 49, | | | | "name": "execution.status", | | "message": "002003: SQL compilation error:\nObject 'EMP_TABLE' does not exist or not authorized.", | |
| | | | | | "snow.database.name": "MY_DB", | | | | "severity_text": "ERROR" | | "state": "FAILED" | |
| | | | | | "snow.executable.id": 518, | | | | } | | } | |
| | | | | | "snow.executable.name": "T1", | | | | | | | |
| | | | | | "snow.executable.type": "TASK", | | | | | | | |
| | | | | | "snow.owner.id": 2601, | | | | | | | |
| | | | | | "snow.owner.name": "DATA_ADMIN", | | | | | | | |
| | | | | | "snow.owner.type": "ROLE", | | | | | | | |
| | | | | | "snow.query.id": "01ba76b5-0107-e56d-0000-a995024f4222", | | | | | | | |
| | | | | | "snow.schema.id": 411, | | | | | | | |
| | | | | | "snow.schema.name": "MY_SCHEMA", | | | | | | | |
| | | | | | "snow.warehouse.id": 41, | | | | | | | |
| | | | | | "snow.warehouse.name": "INTAKE_WAREHOUSE" | | | | | | | |
| | | | | | } | | | | | | | |
+-------------------------+-----------------+-------------------------+-------+----------+------------------------------------------------------------+-------+------------------+-------------+-------------------------------+-------------------+------------------------------------------------------------------------------------------------------+-----------+
Information logged for task events¶
When a task runs, an event is logged to the event table. The following sections describe the event table row that represents the event:
Event table column values¶
When a task completes or fails, a row with the following values is inserted into the event table.
Note
If a column is not listed below, the column value is NULL for the event.
Column |
Data type |
Description |
---|---|---|
|
TIMESTAMP_NTZ |
The UTC timestamp when an event was created. |
|
TIMESTAMP_NTZ |
A UTC time used for logs. Currently, this is the same value that is in the |
|
OBJECT |
Attributes that identify the task that was executed. |
|
STRING |
The event type, which is |
|
OBJECT |
Details about the status of the task execution. |
|
VARIANT |
The status of the task execution and, if the execution failed, the error message for the failure. |
Key-value pairs in the resource_attributes
column¶
The resource_attributes
column contains an OBJECT value with the following key-value pairs:
Attribute name |
Attribute type |
Description |
Example |
---|---|---|---|
|
INTEGER |
The internal/system-generated identifier of the database containing the task. |
|
|
VARCHAR |
The name of the database containing the task. |
|
|
INTEGER |
The internal/system-generated identifier of the task that executed. |
|
|
VARCHAR |
The name of the task that executed. |
|
|
VARCHAR |
The type of the object. The value is |
|
|
INTEGER |
The internal/system-generated identifier of the role with the OWNERSHIP privilege on the task. |
|
|
VARCHAR |
The name of the role with the OWNERSHIP privilege on the task. |
|
|
VARCHAR |
The type of role that owns the object, for example |
|
|
VARCHAR |
ID of the query that executed the task. |
|
|
INTEGER |
The internal/system-generated identifier of the schema containing the task. |
|
|
VARCHAR |
The name of the schema containing the task. |
|
|
INTEGER |
The internal/system-generated identifier of the warehouse used to execute the task. |
|
|
VARCHAR |
The name of the warehouse used to execute the task. |
|
Key-value pairs in the record
column¶
The record
column contains an OBJECT value with the following key-value pairs:
Key |
Type |
Description |
Example |
---|---|---|---|
|
VARCHAR |
The name of the event. The value is |
|
|
VARCHAR |
The severity level of the event, which is one of the following values:
|
|
Key-value pairs in the value
column¶
The value
column contains an VARIANT value with the following key-value pairs:
Key |
Type |
Description |
Example |
---|---|---|---|
|
VARCHAR |
The state of the task execution, which can be one of the following values:
|
|
|
VARCHAR |
If the value in |