Maximizing Application Observability with Snowflake Event Tables

Maximizing Application Observability with Snowflake Event Tables

Monitoring and observability are crucial aspects that customers prioritize when building and managing applications. However, until the introduction of Snowflake's logging and tracing via Event Tables, capturing application logs and traces was a challenging task with no centralized location for consumption.

Fortunately, this new feature empowers developers and data engineers to effortlessly instrument their code, capturing logs and traces across various components such as UDFs, UDTFs, and stored procedures. Moreover, it supports multiple programming languages, including Java, Scala, JavaScript, Python, and Snowflake Scripting. Let's delve deeper into this innovative capability.

Event Tables play a vital role in capturing and logging events, logs, and trace events from user-defined functions and stored procedures. This article explains the significance of Event Tables, how to set them up, and their usage in logging and tracing application events. With Snowflake, you can have multiple event tables, but only one can be active per account. By associating the table with the account, defining event levels, and setting logging preferences, you can effectively leverage the power of Event Tables.

To set up an active Event Table, the ACCOUNTADMIN role is required. Privileges and step-by-step commands for creating and configuring an Event Table are provided, ensuring a seamless setup process. Once the Event Table is established, events can be captured by calling functions or stored procedures using code snippets. The article showcases a JavaScript function example that demonstrates logging events at various levels and tracing with span attributes.

To view the logged events, a query can be executed on the active Event Table after a short delay due to asynchronous data transmission. However, it's important to note that logging and tracing from Python worksheets, anonymous procedures, and SQL blocks are not currently supported by Snowflake.

The article sheds light on the cost implications of logging and emphasizes the need to optimize usage to minimize expenses. Snowflake's serverless compute model facilitates event ingestion into the Event Table, and monitoring usage is made possible through the EVENT_USAGE_HISTORY view.

By combining Event Tables with other Snowflake features like Alerts and Email Notifications, users can be promptly notified of new events and errors within their applications, ensuring efficient management of their data ecosystem.

Steps :

use role accountadmin;

use database snowflake_db;

create event table event_tbl;

alter account set event_table = snowflake_db.snwoflake_sch.event_tbl;

alter session set log_level = INFO;

alter session set trace_level = ON_EVENT;

create or replace function logsAndTraceEmittingFunction()

returns string

language javascript

as

$$

snowflake.log(“info”, “TestingLog”);

snowflake.addEvent(“TestEvent”, {“key1”: 1});

snowflake.setSpanAttribute(“Attribute”, 62.46);

return “done”;

$$;


Select logsAndTraceEmittingFunction();

select * from snowflake_db.snwoflake_sch.event_tbl;

The article concludes by providing useful resources, such as tutorials, official quickstarts, documentation, code samples, and language support matrices, allowing readers to explore further and enhance their understanding of Snowflake's logging and tracing capabilities.

Getting started with Event Tables : https://docs.snowflake.com/en/developer-guide/logging-tracing/tutorials/logging-tracing-getting-started

Event Tables and Alerts: https://quickstarts.snowflake.com/guide/alert_on_events/index.html#0

Code samples: https://docs.snowflake.com/en/developer-guide/logging-tracing/logging-tracing-overview

To view or add a comment, sign in

More articles by Karthick Ramamoorthy

Others also viewed

Explore content categories