Module 20 · Lesson 5 of 11Detailed study · about 29 min

Snowflake Event Tables: Procedure Logging, Traces and Metrics

Instrument a Snowpark Python procedure, choose telemetry levels, and find its batch logs and trace events in an event table.

Before you beginLearn the four monitoring signals

Record what happened inside the code

Query History tells you that CALL finished and how long it took. Access History tells an authorized reviewer which objects were accessed. Neither can explain a custom validation choice unless the code records it. A handler can log why it rejected a batch and add a trace event showing when checks completed.

Snowflake collects supported telemetry into the active event table. A log usually has a text value, a severity and optional attributes. Trace events help follow milestones within a span. Metrics can record supported automatically collected resource measurements. They are different from business measures such as on-time delivery, which you can calculate from your audit table.

From a procedure call to diagnostic evidence The query and audit histories still answer different questions. Link records with batch IDs or a supported query ID field where available.
  1. Procedure handlerEmit to Telemetry levels
  2. Telemetry levelsCollect to Active event table
  3. Active event tableInvestigate to Support query
Procedure handler
Records a log and emits a named trace event.
Telemetry levels
Control which signals Snowflake collects.
Active event table
Stores values and structured fields.
Support query
Filters recent records by batch and record type.

Choose the event table and scope

For this lab, an authorized role with CREATE EVENT TABLE and schema access creates a dedicated table in the capstone’s scratch database, LS_M20_OPS_LAB. A test-account ACCOUNTADMIN with OWNERSHIP or INSERT on the event table associates it with the scratch database. Database-level association requires Enterprise Edition or higher and takes precedence over the account’s event table for this database.

On Standard Edition, skip the association commands and use the account’s approved active event table. Snowflake’s default is SNOWFLAKE.TELEMETRY.EVENTS if no custom event table is configured. A role granted the SNOWFLAKE.EVENTS_VIEWER application role can use EVENTS_VIEW subject to its access policy. Use the approved view or table under your account’s policy and change the inspection query accordingly. Do not switch the whole account’s telemetry destination just to run this example.

Expected association check on Enterprise Edition or higher
KEYVALUE
EVENT_TABLELS_M20_OPS_LAB.OPS.OPS_EVENTS
SQL · configuration template
CREATE EVENT TABLE LS_M20_OPS_LAB.OPS.OPS_EVENTS;
-- Run this association as test-account ACCOUNTADMIN.
ALTER DATABASE LS_M20_OPS_LAB SET EVENT_TABLE = LS_M20_OPS_LAB.OPS.OPS_EVENTS;
SHOW PARAMETERS LIKE 'EVENT_TABLE' IN DATABASE LS_M20_OPS_LAB;

Log a validation decision from a Python procedure

The role needs CREATE PROCEDURE, an approved warehouse and access to the Snowpark and telemetry packages under the account’s package policies. HANDLER selects the Python function. Snowflake passes a session first and then your argument values. This demonstration accepts missing_rows as a test value so it can show exactly what each path logs. The actual capstone counts missing rows in SQL.

INFO and WARNING are log levels. The Python extra argument separates the batch ID and outcome from the message. The trace API adds an event with the same batch ID. ALWAYS collects supported traces for both passing and rejected calls. If you use ON_EVENT, trace collection depends on events being emitted. Resource metrics are separate and can be enabled with METRIC_LEVEL in a supported scope, such as a test session.

Expected call return values
BatchArgument MISSING_ROWSReturn
B1010PASSED
B1021REJECTED
SQL · configuration template
CREATE PROCEDURE LS_M20_OPS_LAB.OPS.DEMO_VALIDATE(batch_id VARCHAR, missing_rows NUMBER)
RETURNS VARCHAR
LANGUAGE PYTHON
RUNTIME_VERSION = '3.12'
PACKAGES = ('snowflake-snowpark-python', 'snowflake-telemetry-python')
HANDLER = 'validate'
EXECUTE AS OWNER
AS
$$
import logging
from snowflake import telemetry

logger = logging.getLogger("maple.ops")

def validate(session, batch_id, missing_rows):
    status = "REJECTED" if missing_rows else "PASSED"
    attributes = {"batch_id": batch_id, "outcome": status, "missing_rows": int(missing_rows)}
    telemetry.add_event("validation.finished", attributes)
    logger.log(logging.WARNING if missing_rows else logging.INFO, "Sales validation finished", extra=attributes)
    return status
$$;

ALTER PROCEDURE LS_M20_OPS_LAB.OPS.DEMO_VALIDATE(VARCHAR, NUMBER) SET LOG_LEVEL = 'INFO';
ALTER PROCEDURE LS_M20_OPS_LAB.OPS.DEMO_VALIDATE(VARCHAR, NUMBER) SET TRACE_LEVEL = 'ALWAYS';
CALL LS_M20_OPS_LAB.OPS.DEMO_VALIDATE('B101', 0);
CALL LS_M20_OPS_LAB.OPS.DEMO_VALIDATE('B102', 1);

Read the structured logs and trace events

Use a role with SELECT on the approved event table or governed view and access to its parent objects. The query reads the documented log attributes and trace event attributes. Filter for B102 and a recent time window. If you see no records, allow time for collection and verify the active destination, runtime and effective levels before turning on more logging.

A few contextual rows are usually enough. Avoid DEBUG or row-by-row logging on a busy UDF. Collection, storage and repeated queries can add costs. Decide who can read raw messages, how long they should stay and who cleans up. After the scratch test, unset the database association if you set it, then remove the demo procedure and scratch event table when their evidence is no longer needed. If you adjusted session levels, unset them too.

Representative event records for the rejected call
RECORD_TYPESignalOUTCOME
LOGWARN · Sales validation finishedREJECTED
SPAN_EVENTvalidation.finishedREJECTED
SQL · configuration template
SELECT timestamp, record_type,
       record:severity_text::STRING AS severity,
       record:name::STRING AS trace_event,
       value, record_attributes:outcome::STRING AS outcome
FROM LS_M20_OPS_LAB.OPS.OPS_EVENTS
WHERE timestamp >= DATEADD('hour', -1, CURRENT_TIMESTAMP())
  AND record_type IN ('LOG', 'SPAN_EVENT')
  AND record_attributes:batch_id::STRING = 'B102'
ORDER BY timestamp;

Check resource metrics, ingestion credits and cleanup

To sample supported auto-collected resource metrics, enable METRIC_LEVEL = ALL for your test session, rerun the procedure, then reset the level. The event row carries a metric name and unit plus a value. Availability can vary across handler types and workloads. A short call may emit few useful metrics. Use the RESOURCE_ATTRIBUTES fields to narrow a busy event table and correlate with the time and query under test.

The Account Usage query uses the role that can read METERING_HISTORY. It shows metered credits for telemetry ingestion over completed intervals. Times and amounts can lag and account-wide usage includes other objects. Measure active event-table storage and query costs separately with your billing role.

Representative metrics data
MetricUnitExample value
process.memory.usagebytes12582912
SQL · configuration template
ALTER SESSION SET METRIC_LEVEL = 'ALL';
CALL LS_M20_OPS_LAB.OPS.DEMO_VALIDATE('B101', 0);
ALTER SESSION UNSET METRIC_LEVEL;

SELECT timestamp, record:metric.name::STRING AS metric_name,
       record:metric.unit::STRING AS unit, value
FROM LS_M20_OPS_LAB.OPS.OPS_EVENTS
WHERE record_type = 'METRIC'
  AND timestamp >= DATEADD('hour', -1, CURRENT_TIMESTAMP())
ORDER BY timestamp DESC LIMIT 20;

SELECT start_time, credits_used
FROM SNOWFLAKE.ACCOUNT_USAGE.METERING_HISTORY
WHERE service_type = 'TELEMETRY_DATA_INGEST'
  AND start_time >= DATEADD('day', -1, CURRENT_TIMESTAMP())
ORDER BY start_time DESC;

Interview practice

Explain the decision and the evidence you would use to test it.

Beginner · What is an event table?

It is a Snowflake table with standard columns for logs, traces and metrics. I use it to inspect decisions and milestones inside a function or procedure.

SQL · How do you find one validation error without searching every log sentence?

I filter the active event table by record type, time and a structured batch ID in RECORD_ATTRIBUTES. Then I compare that record with the audit row.

Production · Would you collect a trace or log for every row?

I would start with batch-level milestones and errors. I would measure added volume and cost before increasing detail, and review the fields for sensitive data first.

Words used in this lesson
Handler
The function that Snowflake calls when it runs a procedure or a user-defined function (UDF).
Event table
A Snowflake table with a built-in layout for telemetry records.
Log level
The lowest severity to collect, such as INFO for progress or WARN for warnings and higher severities.
Span
A timed portion of work inside a trace.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

Use the SQL and expected outputs in the sections above.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Maple Market is fictional. Output tables are representative. Live commands require an authorized test account and the roles, compute and edition listed in each lesson.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

Where would you put a batch ID so SQL can filter on it directly?

Try it yourself

The procedure returned REJECTED but you find no INFO log. What would you check?

Compare your reasoning

Verify the call and the active event table for the procedure database. Check the effective log level and access to the event table, then allow time for collection and search in a wide enough window.

Connect this lesson to the learning path

Official sources and curriculum

Module 20 · See module scope

By Rohit Ray · Independent educational lesson · Explore this visual lab