Setting levels for logging, metrics, and tracing

You can set the threshold levels for log, trace, or metrics data captured in an event table.

For each type of telemetry data, you can do the following:

  • Set levels specific to each type of telemetry data.

  • Set system-wide levels for each that are in effect unless overridden.

  • Override system-wide levels by setting the level for a session or on specific objects (such as procedures and UDFs).

    Levels are represented as both session parameters and object parameters.

Understanding logging, metrics, and tracing levels

Each type of telemetry data supports its own set of levels that are specific to its purpose. You can set these levels by using the parameter Snowflake provides for each. You can also set some levels using Snowsight, which represents the level parameters in a simplified way.

You can set each of these in the following ways:

Logging:

When you set a level, only data at that level and more severe levels are captured in an event table and visible in Snowsight. For example, setting the LOG_LEVEL parameter to WARN means that messages at the WARN, ERROR, and FATAL levels are captured in the event table.

Levels are determined by the LOG_LEVEL parameter.

Metrics:

You can currently have all metrics data captured or none.

Levels are determined by the METRIC_LEVEL parameter.

Tracing:

You can specify the scope of trace event data stored in the event table.

Levels are determined by the TRACE_LEVEL parameter.

Setting the level for the account

For each type of telemetry data, you can set the level on for the account. You can override this level at the object and session level as decribed in Understanding how Snowflake determines level in effect.

Verify that you have the needed privileges

To set levels for the account, you must use a role that is granted or inherits the privileges described below.

For more information about the privileges, see Access control privileges.

Level to modify

Parameter to set

Privileges needed

Log level

LOG_LEVEL

MODIFY LOG LEVEL on the account

Metric level

METRIC_LEVEL

MODIFY METRIC LEVEL on the account

Trace level

TRACE_LEVEL

MODIFY TRACE LEVEL on the account

Code in the following example grants privileges needed for someone using the central_log_admin role to set the log level for the account.

GRANT MODIFY LOG LEVEL ON ACCOUNT TO ROLE central_log_admin;
Copy

Setting the level on the account in Snowsight

Note

Snowsight support for logging and tracing is a preview feature available to all accounts.

You can use Snowsight to set telemetry levels at the account level.

  1. Verify that you have access to a role with privileges needed to set levels.

  2. Sign in to Snowsight.

  3. In the navigation menu, select Monitoring » Traces and Logs.

  4. In the Traces & Logs page, select the Set Event Level.

  5. For Set logging & tracing for, select Account.

  6. Select the levels the telemetry data you want to adjust.

    All Events

    On to turn on collection for all kinds of telemetry data; Off to turn off collection for all kinds of data.

    Traces

    On to set trace data collection to ALWAYS; Off to set trace data collection to OFF. See TRACE_LEVEL for information about levels.

    Logs

    On to set log data collection to INFO. See LOG_LEVEL for information about levels.

    Metrics

    On to set trace data collection to ALL; Off to set trace data collection to NONE. See METRIC_LEVEL for information about levels.

Setting the level on the account with SQL

You can use SQL to set telemetry levels for the account.

To set a telemetry level on the account, do the following:

  1. Verify that you have access to a role with privileges needed to set levels.

  2. Use the ALTER ACCOUNT command to set the appropriate parameter, based on the telemetry data you want to collect.

    For the list of levels that you can use, see Understanding logging, metrics, and tracing levels.

    The following example sets the log level to ERROR for the account.

    -- Set the log level on the account
    ALTER ACCOUNT SET LOG_LEVEL = ERROR;
    
    Copy

Setting the level for an object

For each type of telemetry data, you can set the level on the following objects:

  • A stored procedure

  • A user-defined function (UDF) or a user-defined table function (UDTF)

  • A database or schema containing procedures and functions

Note

You can’t set the level on Streamlit objects. Instead, set the level on the database or schema containing the object.

Verify that you have the needed privileges

To set levels on an object, you must use a role that is granted or inherits the privileges described below.

For more information about privileges, see Access control privileges.

Level to modify

Parameter to set

Privileges needed

Log level

LOG_LEVEL

  • MODIFY LOG LEVEL on the account

  • MODIFY on the object for which you want to set the level

  • USAGE on the database or schema containing the procedure or UDF for which you want to set the level

Metric level

METRIC_LEVEL

  • MODIFY METRIC LEVEL on the account

  • MODIFY on the object for which you want to set the level

  • USAGE on the database or schema containing the procedure or UDF for which you want to set the level

Trace level

TRACE_LEVEL

  • MODIFY TRACE LEVEL on the account

  • MODIFY on the object for which you want to set the level

  • USAGE on the database or schema containing the procedure or UDF for which you want to set the level

Code in the following example grants privileges needed for someone using the central_log_admin role to set the log level for the db1 database.

GRANT MODIFY LOG LEVEL ON ACCOUNT TO ROLE central_log_admin;
GRANT MODIFY ON DATABASE db1 TO ROLE central_log_admin;
Copy

Setting the level on a database or schema in Snowsight

Note

Snowsight support for logging and tracing is a preview feature available to all accounts.

You can use Snowsight to set telemetry levels. Before you begin, verify that you have access to a role with privileges needed to set levels.

  1. Verify that you have access to a role with privileges needed to set levels.

  2. Sign in to Snowsight.

  3. In the navigation menu, select Monitoring » Traces and Logs.

  4. In the Traces & Logs page, select the Set Event Level.

  5. For Set logging & tracing for, select the database and, optionally, schema for which you’re setting levels.

  6. Select the levels the telemetry data you want to adjust.

    All Events

    On to turn on collection for all kinds of telemetry data; Off to turn off collection for all kinds of data.

    Traces

    On to set trace data collection to ALWAYS; Off to set trace data collection to OFF. See TRACE_LEVEL for information about levels.

    Logs

    On to set log data collection to INFO. See LOG_LEVEL for information about levels.

    Metrics

    On to set trace data collection to ALL; Off to set trace data collection to NONE. See METRIC_LEVEL for information about levels.

Setting the level on a database, schema, or other object with SQL

You can use SQL to set levels for logging, metrics, and tracing.

To set the telemetry level on an object, do the following:

  1. Verify that you have access to a role with privileges needed to set levels.

  2. Use the ALTER <object> command to set the LOG_LEVEL parameter on the object.

    For the list of levels that you can use, see Understanding logging, metrics, and tracing levels.

    For example, to set the log level for a specific UDF, use ALTER FUNCTION to set the LOG_LEVEL parameter for that UDF. As another example, to set the default log level for all functions and procedures in a database, use ALTER DATABASE to set the LOG_LEVEL parameter on that database.

    The following example sets the log level to ERROR for all functions and procedures in the database db. The example overrides this level to WARN for the UDF f1(int).

    USE ROLE central_log_admin;
    
    -- Set the log levels on a database and UDF.
    ALTER DATABASE db1 SET LOG_LEVEL = ERROR;
    ALTER FUNCTION f1(int) SET LOG_LEVEL = WARN;
    
    Copy

    For details on how Snowflake determines the effective log level when the LOG LEVEL is set on different objects, see Understanding how Snowflake determines level in effect.

Setting the level for the current session

To set the level for calls to functions and procedures made in the current session:

  1. Verify that you have the privilege to set the level on the session.

    You must use a role that has been granted the following privileges, depending on the levels you’re setting:

    Level to modify

    Parameter to set

    Privileges needed

    Log level

    LOG_LEVEL

    MODIFY SESSION LOG LEVEL

    Metric level

    METRIC_LEVEL

    MODIFY SESSION METRIC LEVEL

    Trace level

    TRACE_LEVEL

    MODIFY SESSION TRACE LEVEL

    For example, to grant the developer_debugging role the privilege to set the log levels for the current session, execute the following statement:

    GRANT MODIFY SESSION LOG LEVEL ON ACCOUNT TO ROLE developer_debugging;
    
    Copy
  2. Use the ALTER SESSION command to set the LOG_LEVEL parameter for the current session.

    For example:

    USE ROLE developer_debugging;
    
    -- Set the logging level to DEBUG for the current session.
    ALTER SESSION SET LOG_LEVEL = DEBUG;
    
    Copy

If the level parameter is set to different levels for the current session and on the functions and procedures called in that session, Snowflake determines the effective level to use. See Understanding how Snowflake determines level in effect.

Understanding how Snowflake determines level in effect

You can override the telemetry level-related parameters (for both objects and sessions) by using a hierarchy of levels.

For example, you can set a level to one value for the account, then override it by setting the level for an object, which is lower in the hierarchy.

The following describes the hierarchy for session and object level parameters.

  • For session parameters, the hierarchy is Account » User » Session.

    This means that you can set the parameter for an account, override the account-level parameter for a user, and override the user-level parameter for the current session.

  • For object parameters, the hierarchy is Account » Database » Schema » Object.

    This means that you can set the parameter for an account, override the account-level parameter for a database or schema, and override the database- or schema-level parameter for specific stored procedures and UDFs in that database or schema.

For example, the LOG_LEVEL for a function overrides the LOG_LEVEL for the account that contains the function. If the LOG_LEVEL for the account is FATAL and the LOG_LEVEL for the Java UDF in the account is INFO, the effective LOG_LEVEL is INFO (the level for the function, not the account):

ALTER ACCOUNT SET LOG_LEVEL = FATAL;

ALTER FUNCTION MyJavaUDF SET LOG_LEVEL = INFO;

-- The INFO log level is used because the FUNCTION MYJAVAUDF
-- is lower than the ACCOUNT in the hierarchy.
Copy

In cases where the level is set in both the session and object parameter hierarchies, the most verbose level is used.

  • For log level, the following table lists examples of how parameters set on the session and object affect the log level used.

    Value for the Session

    Value for the Object, Schema, Database, or Account

    Log Level Used

    (unset)

    WARN

    WARN

    DEBUG

    (unset)

    DEBUG

    WARN

    ERROR

    WARN

    INFO

    DEBUG

    DEBUG

    (unset)

    (unset)

    OFF

  • For metric level — ALL overrides NONE.

  • For trace level — ALWAYS overrides ON_EVENT and OFF; ON_EVENT overrides OFF.