访问跟踪数据¶
跟踪数据存储在为支持跟踪而设置的事件表中。您可以通过对事件表执行 SELECT 命令,从而访问数据。
备注
在开始发出跟踪数据之前,您必须先设置事件表。有关更多信息,请参阅 设置事件表。
事件表具有一组预定义的列,用于获取有关已记录消息的信息,包括:
span 开始时的时间戳。
事件创建时的时间戳。
记录的数据类型,例如数据是针对 span 还是 span 事件。
span 或事件的名称。
与 span 或事件关联的属性(如果有)。
有关事件表列的参考信息,请参阅 事件表列。
跟踪数据查询示例¶
以下部分使用示例数据说明如何在事件表中查询跟踪数据。
收集的数据¶
以下示例中的输出显示以下内容:在为使用 Python 编写的三个单独的处理程序获取跟踪数据后,事件表中选定的列子集的内容。
有关用于收集跟踪数据的事件表列的参考信息,请参阅 跟踪事件的数据。
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| TIMESTAMP | START_TIMESTAMP | RESOURCE_ATTRIBUTES | RECORD_TYPE | RECORD | RECORD_ATTRIBUTES |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:45:49 | 2023-04-20 0:45:49 | **See excerpt below** | SPAN | { "kind": "SPAN_KIND_INTERNAL", "name": "snow.auto_instrumented", "status": { "code": "STATUS_CODE_UNSET" } } | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:45:49 | | | SPAN_EVENT | { "name": "test_udtf_init" } | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:45:49 | | | SPAN_EVENT | { "name": "test_udtf_process" } | { "input": "42" } |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:45:49 | | | SPAN_EVENT | { "name": "test_udtf_end_partition" } | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:46:00 | 2023-04-20 0:46:00 | | SPAN | { "kind": "SPAN_KIND_INTERNAL", "name": "snow.auto_instrumented", "status": { "code": "STATUS_CODE_UNSET" } } | { "example.func.times_two": "begin", "example.func.times_two.response": 8 } |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:46:00 | | | SPAN_EVENT | { "name": "event_without_attributes" } | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:46:00 | | | SPAN_EVENT | { "name": "event_with_attributes" } | { "example.key1": "value1", "example.key2": "value2" } |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:46:08 | 2023-04-20 0:46:08 | | SPAN | { "kind": "SPAN_KIND_INTERNAL", "name": "snow.auto_instrumented", "status": { "code": "STATUS_CODE_UNSET" } } | { "example.proc.do_tracing": "begin" } |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:46:08 | | | SPAN_EVENT | { "name": "event_with_attributes" } | { "example.key1": "value1", "example.key2": "value2" } |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
RESOURCE_ATTRIBUTES 摘录
以下 JSON 摘录包含三个处理程序中每个处理程序的 RESOURCE_ATTRIBUTES 列中包含的两个属性,这些处理程序的数据包含在前面的输出中。这些摘录后面的 SELECT 查询代码从这些属性中选择值。
RESOURCE_ATTRIBUTES 列包含有关事件来源的数据。有关参考信息,请参阅 RESOURCE_ATTRIBUTES 列。
{
...
"snow.executable.name": "DIGITS_OF_NUMBER(INPUT NUMBER):TABLE: (RESULT NUMBER)",
"snow.executable.type": "FUNCTION",
...
}
{
...
"snow.executable.name": "TIMES_TWO(X NUMBER):NUMBER(38,0)",
"snow.executable.type": "FUNCTION",
...
}
{
...
"snow.executable.name": "DO_TRACING():VARIANT",
"snow.executable.type": "PROCEDURE",
...
}
使用 SELECT 语句查询¶
在查询数据时,您可以使用 括号表示法 选择列中的属性值,如下表所示:
COLUMN_NAME['attribute_name']
下面示例中的代码查询上表,目的是隔离与 DIGITS_OF_NUMBER
函数相关的数据。
SET EVENT_TABLE_NAME='my_db.public.my_events';
SELECT
TIMESTAMP as time,
RESOURCE_ATTRIBUTES['snow.executable.name'] as handler_name,
RESOURCE_ATTRIBUTES['snow.executable.type'] as handler_type,
RECORD['name'] as event_name,
RECORD_ATTRIBUTES as attributes
FROM
IDENTIFIER($event_table_name)
WHERE
RECORD_TYPE = 'SPAN_EVENT'
AND HANDLER_NAME LIKE 'DIGITS_OF_NUMBER%';
查询结果¶
以下示例中的输出说明了查询的结果。
-------------------------------------------------------------------------------------------------------------------------------------------
| TIME | HANDLER_NAME | HANDLER_TYPE | EVENT_NAME | ATTRIBUTES |
-------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:45:49 | DIGITS_OF_NUMBER(INPUT NUMBER):TABLE: (RESULT NUMBER) | FUNCTION | test_udtf_init | |
-------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:45:49 | DIGITS_OF_NUMBER(INPUT NUMBER):TABLE: (RESULT NUMBER) | FUNCTION | test_udtf_process | { "input": "42" } |
-------------------------------------------------------------------------------------------------------------------------------------------
| 2023-04-20 0:45:49 | DIGITS_OF_NUMBER(INPUT NUMBER):TABLE: (RESULT NUMBER) | FUNCTION | test_udtf_end_partition | |
-------------------------------------------------------------------------------------------------------------------------------------------