Accessing trace data¶
Trace data is stored in an event table you set up to support tracing. You can access the data by executing the SELECT command on the event table.
Note
Before you can begin emitting trace data, you must set up an event table. For more information, refer to Event table overview.
An event table has a set of predefined columns that capture information about the logged messages, including:
The timestamp when a span began.
The timestamp when the event was created.
The type of data recorded, such as whether the data is for a span or span event.
The name of the span or event.
Attributes, if any, associated with the span or event.
For reference information about event table columns, refer to Event table columns.
Trace data query example¶
The following sections illustrate with example data how you can query the event table for trace data.
Collected data¶
Output in the following example shows content from a selected subset of columns from an event table after trace data has been captured for three separate handlers written in Python.
For reference information on event table columns that collect trace data, refer to Data for trace events.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 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 Excerpts
The following JSON excerpts contains two of the attributes included in the RESOURCE_ATTRIBUTES column for each of the three handlers whose data is included in the preceding output. The SELECT query code following these excerpts selects values from these attributes.
The RESOURCE_ATTRIBUTES column contains data about the event’s source. For reference information, refer to RESOURCE_ATTRIBUTES column.
{
...
"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",
...
}
Query with SELECT statement¶
When querying for data, you can select attribute values within a column by using bracket notation, as in the following form:
COLUMN_NAME['attribute_name']
Code in the example below queries the preceding table with the intention of isolating data related to the DIGITS_OF_NUMBER
function.
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%';
Query results¶
Output in the following example illustrates the query’s result.
-------------------------------------------------------------------------------------------------------------------------------------------
| 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 | |
-------------------------------------------------------------------------------------------------------------------------------------------