日志记录、跟踪和指标
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.
Logging, tracing, and metrics are among the observability features Snowflake provides to make it easier for you to debug and optimize applications. Snowflake captures observability data in a structure based on the OpenTelemetry (https://opentelemetry.io/) standard.
具体而言,您可以记录和分析以下内容:
- Log messages — Independent, detailed messages with information about the state of a specific piece of your code.
- Metrics data — CPU and memory metrics that Snowflake generates.
- Trace events — Structured data you can use to get information spanning and grouping multiple parts of your code.
开始使用
使用以下高级步骤开始捕获并使用日志和跟踪数据。
-
确保您有一个活动事件表。您可以执行下列操作之一:
- Use the default event table that is active by default.
- Create and set as active an event table.
Snowflake 会在事件表中使用代码收集遥测数据。
-
Set telemetry levels so that data is collected.
With levels, you can specify which data – and how much data – is collected. Make sure the levels are set correctly.
-
开始从处理程序代码发出日志或跟踪数据。
创建事件表并将其与账户关联后,可使用处理程序语言的 API,进而从处理程序代码发出日志消息。捕获日志和跟踪数据后,即可查询数据以分析结果。
有关对代码进行检测的更多信息,请参阅以下内容:
- 查询事件表,分析收集到的日志和跟踪数据。
有关更多信息,请参阅以下内容:
设置遥测级别
You can manage the level of telemetry data stored in the event table — such as log, trace, and metrics data — by setting the level for each type of data. Use level settings to ensure that you’re capturing the amount and kind of data you want.
For more information, see Setting levels for logging, metrics, and tracing.
比较日志消息和跟踪事件
下表比较了日志消息和跟踪事件的特征和优势。
| 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. |