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;
    
    Copy

    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;
    
    Copy

    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;
    
    Copy

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.

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;
Copy
+-------------------------+-----------+--------------------------------------+------------------------------------------------------+
| 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;
Copy
+-------------------------+-----------------+-------------------------+-------+----------+------------------------------------------------------------+-------+------------------+-------------+-------------------------------+-------------------+------------------------------------------------------------------------------------------------------+-----------+
| 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

TIMESTAMP_NTZ

The UTC timestamp when an event was created.

observed_timestamp

TIMESTAMP_NTZ

A UTC time used for logs. Currently, this is the same value that is in the timestamp column.

resource_attributes

OBJECT

Attributes that identify the task that was executed.

record_type

STRING

The event type, which is EVENT for task executions.

record

OBJECT

Details about the status of the task execution.

value

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

snow.database.id

INTEGER

The internal/system-generated identifier of the database containing the task.

12345

snow.database.name

VARCHAR

The name of the database containing the task.

MY_DATABASE

snow.executable.id

INTEGER

The internal/system-generated identifier of the task that executed.

12345

snow.executable.name

VARCHAR

The name of the task that executed.

MY_TASK

snow.executable.type

VARCHAR

The type of the object. The value is TASK for task events.

TASK

snow.owner.id

INTEGER

The internal/system-generated identifier of the role with the OWNERSHIP privilege on the task.

12345

snow.owner.name

VARCHAR

The name of the role with the OWNERSHIP privilege on the task.

MY_ROLE

snow.owner.type

VARCHAR

The type of role that owns the object, for example ROLE. . If a Snowflake Native App owns the object, the value is APPLICATION. . Snowflake returns NULL if you delete the object because a deleted object does not have an owner role.

ROLE

snow.query.id

VARCHAR

ID of the query that executed the task.

01ba7614-0107-e56c-0000-a995024f304a

snow.schema.id

INTEGER

The internal/system-generated identifier of the schema containing the task.

12345

snow.schema.name

VARCHAR

The name of the schema containing the task.

MY_SCHEMA

snow.warehouse.id

INTEGER

The internal/system-generated identifier of the warehouse used to execute the task.

12345

snow.warehouse.name

VARCHAR

The name of the warehouse used to execute the task.

MY_WAREHOUSE

Key-value pairs in the record column

The record column contains an OBJECT value with the following key-value pairs:

Key

Type

Description

Example

name

VARCHAR

The name of the event. The value is execution.status for task executions.

execution.status

severity_text

VARCHAR

The severity level of the event, which is one of the following values:

  • INFO: The task execution succeeded.

  • ERROR: The task execution failed.

INFO

Key-value pairs in the value column

The value column contains an VARIANT value with the following key-value pairs:

Key

Type

Description

Example

state

VARCHAR

The state of the task execution, which can be one of the following values:

  • SUCCEEDED: The task execution succeeded.

  • ERROR: The task execution failed.

SUCCEEDED

message

VARCHAR

If the value in state is ERROR, this column includes the error message.