Event Tables are dedicated Snowflake tables for collecting log, trace, and metric events emitted by UDFs, stored procedures, Streamlit apps, and similar workloads. They turn what used to be hard-to-debug function execution into structured event data you can analyze with SQL, providing an observability foundation for Snowflake.
-- Event Tableの作成
CREATE OR REPLACE EVENT TABLE observability_db.events.app_events;
-- アカウントレベルでEvent Tableを有効化(ACCOUNTADMIN必須)
ALTER ACCOUNT SET EVENT_TABLE = 'observability_db.events.app_events';
-- データベースレベルでログレベルを設定
ALTER DATABASE my_app_db SET LOG_LEVEL = 'INFO';
-- スキーマレベルでログレベルを設定(より細かい制御)
ALTER SCHEMA my_app_db.analytics SET LOG_LEVEL = 'DEBUG';
-- 特定のUDF/プロシージャだけログレベルを変更
ALTER FUNCTION my_app_db.public.process_data(VARCHAR)
SET LOG_LEVEL = 'TRACE';
-- トレースレベルの設定
ALTER DATABASE my_app_db SET TRACE_LEVEL = 'ON_EVENT';| Level | Events Recorded | Use Case |
|---|---|---|
| OFF | None | Disable log collection entirely |
| FATAL | Fatal errors only | Detect critical failures |
| ERROR | FATAL + errors | Error monitoring |
| WARN | ERROR + warnings | Early problem detection |
| INFO | WARN + informational | Monitoring under normal operations (recommended default) |
| DEBUG | INFO + debug | Debugging in dev and test environments |
| TRACE | All events | Detailed tracing (note: expensive) |
LOG_LEVEL can be overridden in the order Account → Database → Schema → Object (function/procedure). If not set, the value is inherited from the next level up.
| TRACE_LEVEL | Behavior |
|---|---|
| OFF | Do not record trace events |
| ON_EVENT | Record only when SYSTEM$ADD_TRACE() is called |
| ALWAYS | Automatically record every function execution as a span |
-- Python UDFからログを出力
CREATE OR REPLACE FUNCTION process_order(order_json VARIANT)
RETURNS VARIANT
LANGUAGE PYTHON
RUNTIME_VERSION = '3.10'
HANDLER = 'run'
AS $
import logging
logger = logging.getLogger('order_processor')
def run(order_json):
logger.info(f"Processing order: {order_json['order_id']}")
try:
total = sum(item['price'] * item['qty'] for item in order_json['items'])
logger.info(f"Order total calculated: {total}")
return {"order_id": order_json['order_id'], "total": total, "status": "success"}
except Exception as e:
logger.error(f"Failed to process order: {str(e)}")
raise
$;
-- JavaScriptプロシージャからログを出力
CREATE OR REPLACE PROCEDURE sync_inventory()
RETURNS VARCHAR
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS $
snowflake.log("info", "Starting inventory sync");
var rs = snowflake.execute({sqlText: "SELECT COUNT(*) FROM inventory"});
rs.next();
var count = rs.getColumnValue(1);
snowflake.log("info", "Inventory records: " + count);
return "Synced " + count + " records";
$;
-- SQLスクリプトからログを出力
CALL SYSTEM$LOG('INFO', 'Data pipeline started');
-- トレースイベントの出力
CALL SYSTEM$ADD_TRACE('pipeline_run', '{"stage": "transform", "rows": 50000}');| Column | Type | Description |
|---|---|---|
| TIMESTAMP | TIMESTAMP_NTZ | When the event occurred |
| RESOURCE_ATTRIBUTES | VARIANT | Execution context (database name, schema name, function name, etc.) |
| RECORD_TYPE | VARCHAR | Event type (LOG / SPAN / SPAN_EVENT) |
| RECORD | VARIANT | Event details (log message, severity, etc.) |
| RECORD_ATTRIBUTES | VARIANT | Custom attributes (data attached via SYSTEM$ADD_TRACE) |
| SCOPE | VARIANT | Scope information (logger name, span name, etc.) |
-- 直近1時間のエラーログを取得
SELECT
timestamp,
resource_attributes['snow.database.name']::VARCHAR AS db_name,
resource_attributes['snow.schema.name']::VARCHAR AS schema_name,
resource_attributes['snow.executable.name']::VARCHAR AS function_name,
record['severity_text']::VARCHAR AS severity,
record['body']['text']::VARCHAR AS message
FROM observability_db.events.app_events
WHERE record_type = 'LOG'
AND record['severity_text']::VARCHAR IN ('ERROR', 'FATAL')
AND timestamp >= DATEADD(HOUR, -1, CURRENT_TIMESTAMP())
ORDER BY timestamp DESC;
-- 関数別の実行回数とエラー率を集計
SELECT
resource_attributes['snow.executable.name']::VARCHAR AS function_name,
COUNT(*) AS total_events,
COUNT_IF(record['severity_text']::VARCHAR = 'ERROR') AS error_count,
ROUND(error_count / total_events * 100, 2) AS error_rate_pct
FROM observability_db.events.app_events
WHERE record_type = 'LOG'
AND timestamp >= DATEADD(DAY, -7, CURRENT_TIMESTAMP())
GROUP BY function_name
ORDER BY error_rate_pct DESC;
-- トレーススパンの実行時間を分析
SELECT
scope['name']::VARCHAR AS span_name,
record_attributes,
DATEDIFF('millisecond',
record['start_time']::TIMESTAMP_NTZ,
timestamp
) AS duration_ms
FROM observability_db.events.app_events
WHERE record_type = 'SPAN'
ORDER BY duration_ms DESC
LIMIT 20;Observability
問題 1
You want logger.info() output from a Python UDF to be recorded in an Event Table for debugging. Which combination is the minimum required configuration?
正解: A
Recording logs in an Event Table requires three steps: (1) create the table with CREATE EVENT TABLE, (2) designate the account's Event Table with ALTER ACCOUNT SET EVENT_TABLE, and (3) configure LOG_LEVEL on the target database or object. Setting LOG_LEVEL alone is not enough if no Event Table is designated. TRACE_LEVEL is for trace spans; log messages are controlled by LOG_LEVEL.
Can I change the data retention period for Event Tables?
Yes. You can change the retention period with the ALTER DATABASE SET EVENT_RETENTION_TIME_IN_DAYS parameter. The default is 1 day. Increase this value when you need long-term log analysis, but storage costs grow with the retention period. For long-term storage, also consider periodically copying or inserting Event Table data into regular tables for persistence.
What kinds of events can be written to Event Tables?
Event Tables capture three main kinds of events: (1) LOG messages — custom logs emitted from UDFs/stored procedures via system.log() or SYSTEM$LOG(); (2) TRACE events — function execution traces and span information recorded via SYSTEM$ADD_TRACE(); and (3) METRIC data — measurements such as execution time and row counts. The LOG_LEVEL parameter (OFF/FATAL/ERROR/WARN/INFO/DEBUG/TRACE) controls which severity levels are recorded.
How many Event Tables can be enabled per account?
Only one Event Table can be active per account. The single Event Table specified with ALTER ACCOUNT SET EVENT_TABLE = db.schema.my_events becomes the destination for events from every database and schema. You can create multiple Event Tables, but only one can be enabled as the event collection target at a time.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Snowflake Certifications: All 11 Exams Explained (2026)
Every SnowPro certification — Associate, Core, Specialty, Ad...
Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)
All 11 SnowPro exams ranked by difficulty with study-time es...
Snowflake Study Guide: Fastest Pass Route by Exam (2026)
How to pass SnowPro certifications efficiently — official ma...
SnowPro Core (COF-C03): Complete Exam Guide (2026)
Pass the SnowPro Core exam — six domains, scope, sample ques...
SnowPro Associate Platform (SOL-C01): Complete Guide (2026)
The entry-level SnowPro Associate exam — scope, weighting, s...