Logging and Tracing Overview

You can record the activity of your Snowflake function and procedure handler code (including code you write using Snowpark APIs) by capturing log messages and trace events from the code as it executes. Once you’ve collected the data, you can query it with SQL to analyze the results.

In particular, you can record and analyze the following:

  • Log messages that are independent, detailed messages with information about the state of a specific piece of your code.

  • Trace events with structured data you can use to get information spanning and grouping multiple parts of your code.

Get Started

Use the following high-level steps to begin capturing and using log and trace data.

  1. Create an event table.

    In Snowflake, you store your log and trace data in an event table, a special kind of table with a predefined set of columns.

  2. Begin emitting log or trace data from handler code.

    Once you’ve created an event table and associated it with your account, you use an API in the language of your handler to emit log messages from handler code. After you’ve captured log and trace data, you can query the data to analyze the results.

    For more information, refer to:

  3. Query the event table to analyze collected log and trace data.

    For more information, refer to the following:

Compare Log Messages and Trace Events

The following table compares the characteristics and benefits of log messages and trace events.

Characteristic

Log entries

Trace events

Intended use

Record detailed but unstructured information about the state of your code. Use this information to understand what happened during a particular invocation of your function or procedure.

Record a brief but structured summary of each invocation of your code. Aggregate this information to understand behavior of your code at a high level.

Structure as a payload

None. A log entry is just a string.

Structured with attributes you can attach to trace events. Attributes are key-value pairs that can be easily queried with a SQL query.

Supports grouping

No. Each log entry is an independent event.

Yes. Trace events are organized into spans. A span can have its own attributes.

Quantity limits

Unlimited. All log entries emitted by your code are ingested into the event table.

The number of trace events per span is capped at 128. There is also a limit on the number of span attributes.

Complexity of queries against recorded data

Relatively high. Your queries must parse each log entry to extract meaningful information from it.

Relatively low. Your queries can take advantage of the structured nature of trace events.