Snowflake에서 dbt 프로젝트 모니터링¶
This topic explains the ways you can use monitoring features for dbt Projects on Snowflake to inspect dbt project executions—–manual or task-scheduled–—and how to view logs and artifacts.
Section |
Description |
|---|---|
Capture logging and tracing events for a dbt project object and for any scheduled task that runs it. To enable this feature, you must set logging, tracing, and metrics on the schema where the dbt project object and task are deployed. |
|
|sf-web-interface|의 탐색 메뉴에서 :ui:`Transformation` |raa| :ui:`dbt Projects`를 선택하여 dbt 프로젝트 오브젝트에 대한 실행 기록, 작업 그래프, 쿼리 세부 정보를 볼 수 있습니다. 작업 일정에 따라 실행되는 dbt 프로젝트 오브젝트에 작업 공간이 연결되면 작업 공간 내에서 작업 실행 기록 및 작업 그래프를 열 수 있습니다. |
|
Use the DBT_PROJECT_EXECUTION_HISTORY table function and dbt system functions to access dbt artifacts and logs programmatically. |
dbt 프로젝트에 대한 모니터링 기능 활성화¶
dbt 프로젝트 오브젝트에 대한 모니터링 기능을 활성화하려면, dbt 프로젝트 오브젝트가 생성되는 데이터베이스 및 스키마에 LOG_LEVEL, TRACE_LEVEL, METRIC_LEVEL을 설정하세요. 다음 SQL 예제와 같습니다.
ALTER SCHEMA my_db.my_dbt_project_schema SET LOG_LEVEL = 'INFO';
ALTER SCHEMA my_db.my_dbt_project_schema SET TRACE_LEVEL = 'ALWAYS';
ALTER SCHEMA my_db.my_dbt_project_schema SET METRIC_LEVEL = 'ALL';
dbt 프로젝트 오브젝트의 예약된 실행 모니터링¶
작업을 사용하여 일정에 따라 dbt 프로젝트를 실행하고 작업 공간을 dbt 프로젝트 오브젝트에 연결한 경우, |sf-dbt|용 작업 공간을 사용하여 작업 실행 기록 및 작업 그래프에 대한 모니터링 정보에 빠르게 액세스할 수 있습니다(해당되는 경우).
참고
이 기능은 dbt 프로젝트 오브젝트에 연결된 작업 공간에만 사용할 수 있습니다.
작업 공간에서 dbt 프로젝트 오브젝트의 예약된 실행을 모니터링하려면:
작업 공간 편집기의 오른쪽 상단에 있는 dbt 프로젝트 메뉴의 :ui:`Scheduled runs`에서 :ui:`View schedules`를 선택합니다.
목록에서 검사할 일정(작업)을 선택한 다음, :ui:`View details`를 선택합니다.
작업에 대한 정보 창이 열리고, 여기서 Task details, 작업 Graph`(해당되는 경우), 이 작업의 :ui:`Run history`를 볼 수 있습니다. 자세한 내용은 :doc:/user-guide/ui-snowsight-tasks` 섹션을 참조하십시오.
목록에서 예약된 dbt 프로젝트 실행에 대한 Run history`에서 맨 오른쪽에 있는 쿼리 기록 열기 버튼을 선택하여 쿼리 세부 정보, 쿼리 프로필, 실행에 대한 쿼리 원격 분석을 확인합니다. 자세한 내용은 :ref:`label-snowsight_specific_query_details 섹션을 참조하십시오.
|sf-web-interface|에서 dbt 프로젝트 모니터링¶
|sf-web-interface|의 :ui:`Monitoring`을 사용하여 dbt 프로젝트 실행에 대한 자세한 모니터링 정보를 볼 수 있습니다. dbt 프로젝트 오브젝트에 대한 모니터링 정보를 보려면 권한이 있어야 합니다.
탐색 메뉴에서 Transformation » :ui:`dbt Projects`를 선택합니다. 히스토그램은 dbt 프로젝트 실행 빈도와 실행된 프로젝트 목록을 보여줍니다.
dbt 프로젝트 목록에는 다음 정보가 있는 열이 포함됩니다. 날짜 범위, 명령, 실행 상태를 기준으로 목록을 필터링할 수 있습니다.
PROJECT - 선택한 기간 동안 dbt 프로젝트 오브젝트의 이름과 실행 횟수입니다.
LAST COMMAND - 마지막 실행 중에 실행된 dbt 명령입니다.
LAST RUN STATUS - 실행 결과: Succeeded, Executing 또는 :ui:`Failed`입니다.
LAST RUN - 마지막 실행 이후 경과된 시간입니다. 정렬 순서를 반대로 하려면 열 헤더를 선택하세요. 기본적으로 가장 최근 실행이 먼저 표시됩니다.
PREVIOUS RUNS - 선택한 기간의 상태별 실행 횟수입니다.
DATABASE 및 SCHEMA - dbt 프로젝트 오브젝트가 저장되는 데이터베이스 및 스키마입니다.
LAST RUN PARAMETERS - The dbt command-line arguments (ARGS) specified in the EXECUTE DBT PROJECT command for the last dbt project run.
개별 프로젝트 실행을 검사하려면 목록에서 dbt 프로젝트 오브젝트를 선택하세요.
데이터베이스 오브젝트 탐색기의 dbt 프로젝트 세부 정보 페이지가 해당 dbt 프로젝트 오브젝트에 대해 열립니다.
Run history 탭은 기본적으로 선택되며, 선택한 기간에 실행된 각 작업에 대해 다음 정보가 제공됩니다.
COMMAND - 마지막 실행 중에 실행된 dbt 명령입니다.
STATUS - 실행 결과: Succeeded, Executing 또는 :ui:`Failed`입니다.
RUN TIME - 마지막 실행 이후 경과된 시간입니다. 정렬 순서를 반대로 하려면 열 헤더를 선택하세요. 기본적으로 가장 최근 실행이 먼저 표시됩니다.
PARAMETERS The dbt command-line arguments (ARGS) specified in the EXECUTE DBT PROJECT command for the last dbt project run.
실행에 대한 작업 세부 정보를 보려면 목록에서 선택하세요.
다음 탭이 포함된 dbt 실행 세부 정보 창이 열립니다.
Job details 탭은 기본적으로 선택되며 다음 정보를 표시합니다.
Status - 실행 결과: Succeeded, Executing 또는 :ui:`Failed`입니다.
Start time, End time, Duration - 실행이 시작된 시간, 실행이 종료된 시간, 실행에 소요된 시간입니다.
Warehouse size - 실행하는 데 사용된 웨어하우스의 크기입니다.
Query ID - dbt 프로젝트 명령을 실행한 쿼리의 고유 식별자입니다. 쿼리 기록에서 쿼리 세부 정보를 보려면 쿼리 ID를 선택하세요.
SQL text - 실행된 EXECUTE DBT PROJECT 명령입니다.
dbt <command> - 실행된 dbt 명령의 경우(예:
run``또는 ``build), dbt model, 실행에 대한 time taken, 해당 모델 실행의 :ui:`status`를 보여줍니다.
Output 탭에는 실행 중에 dbt 프로젝트에서 생성된 표준 출력이 표시됩니다.
Trace 탭에는 실행 중에 dbt 프로젝트에서 생성된 추적 정보가 표시됩니다. 추적에 대한 자세한 내용은 추적 데이터 보기 섹션을 참조하세요.
더 자세한 쿼리 정보를 보려면 Job details 탭에서 :ui:`Query ID`를 선택하세요.
작업 실행 쿼리에 대한 쿼리 기록 페이지가 열리며, 선택한 dbt 실행에 대한 Query Details, Query Profile, :ui:`Query Telemetry`를 볼 수 있는 탭이 표시됩니다.
자세한 내용은 특정 쿼리의 세부 정보 및 프로필 검토하기 섹션을 참조하십시오.
프로그래밍 방식으로 dbt 아티팩트 및 로그에 액세스¶
Use the DBT_PROJECT_EXECUTION_HISTORY table function and the following system functions to access dbt artifacts and logs programmatically.
Function |
What it returns |
Typical use |
Notes |
|---|---|---|---|
Text log output (the run’s log tail) |
Quick debugging in SQL. For example, see errors and warnings without downloading files. |
Returns log content; nothing is created or moved. |
|
Folder path (for example, |
Browse or copy specific files with LIST, GET, or COPY FILES. |
Just a locator (a URL); you still run GET/COPY FILES to fetch. |
|
Single ZIP file URL (for example, |
Handy when you want to download one file (for example, with GET). |
Use |
Get logs and download a ZIP file of the latest dbt project query¶
The following example queries Snowflake’s dbt execution history to show the most recent query ID for the dbt Project. It pulls the log output for that execution and returns the location of the zipped dbt artifacts for that execution.
The Snowflake CLI example downloads the artifacts ZIP file or specific files (like manifest.json) to your local folder using GET.
To download the ZIP file from Snowsight, navigate to Monitoring » Query History. Select the query, navigate to Query Details, and select Download Build Artifacts under dbt Output.
You must use a role with the OWNERSHIP, USAGE, or MONITOR privilege on your dbt Projects.
--Look up the most recent dbt Project execution
SET latest_query_id = (SELECT query_id
FROM TABLE(INFORMATION_SCHEMA.DBT_PROJECT_EXECUTION_HISTORY())
WHERE OBJECT_NAME = 'MY_DBT_PROJECT'
ORDER BY query_end_time DESC LIMIT 1);
--Get the dbt run logs for the most recent dbt Project execution
SELECT SYSTEM$GET_DBT_LOG($latest_query_id);
============================== 15:14:53.100781 | 46d19186-61b8-4442-8339-53c771083f16 ==============================
[0m15:14:53.100781 [info ] [Dummy-1 ]: Running with dbt=1.9.4
...
[0m15:14:58.198545 [debug] [Dummy-1 ]: Command `cli run` succeeded at 15:14:58.198121 after 5.19 seconds
To view the stage path where Snowflake stored the dbt Project run’s artifacts (that is, the results folder for that execution), use the
SYSTEM$LOCATE_DBT_ARTIFACTS function. You can then use that path with GET or COPY FILES with the Snowflake CLI to download
things like manifest.json, compiled SQL, or logs.
--Get the location of the dbt Project archive ZIP file (see all files)
SELECT SYSTEM$LOCATE_DBT_ARTIFACTS($latest_query_id);
+-------------------------------------------------------------------------------------------------+
| SYSTEM$LOCATE_DBT_ARTIFACTS($LATEST_QUERY_ID) |
+-------------------------------------------------------------------------------------------------+
| snow://dbt/TESTDBT.PUBLIC.MY_DBT_PROJECT/results/query_id_01c01096-010c-0ccb-0000-a99506bd199e/ |
+-------------------------------------------------------------------------------------------------+
--List all the files of a dbt run
ls 'snow://dbt/TESTDBT.PUBLIC.MY_DBT_PROJECT/results/query_id_01bf3f5a-010b-4d87-0000-53493abb7cce/';
You can also create a fresh internal stage, locate the Snowflake-managed path for the specified dbt Project run’s artifacts, and copy those artifacts into your stage for retrieval, as shown in the following example:
CREATE OR REPLACE STAGE my_dbt_stage ENCRYPTION = (TYPE = 'SNOWFLAKE_SSE');
SELECT SYSTEM$LOCATE_DBT_ARTIFACTS($latest_query_id);
snow://dbt/TESTDBT.PUBLIC.MY_DBT_PROJECT/results/query_id_01bf51c1-010b-5676-0000-53493ae6db02/
COPY FILES INTO @my_dbt_stage/results/ FROM 'snow://dbt/TESTDBT.PUBLIC.MY_DBT_PROJECT/results/query_id_01bf51c1-010b-5676-0000-53493ae6db02/';
results/dbt_artifacts.zip
results/logs/dbt.log
results/target/manifest.json
results/target/semantic_manifest.json
snowsql -q "SELECT query_id
FROM TABLE(INFORMATION_SCHEMA.DBT_PROJECT_EXECUTION_HISTORY())
WHERE OBJECT_NAME = 'MY_DBT_PROJECT'
ORDER BY query_end_time DESC LIMIT 1;"
snowsql -q "SELECT SYSTEM\$GET_DBT_LOG('01bf3f89-0300-0001-0000-0000000c1229')"
| ============================== 11:17:39.152234 | 4df65841-7aa3-40e2-81cb-2007c09c2b81
| 11:17:39.152234 [info ] [Dummy-1 ]: Running with dbt=1.9.4
....
snowsql -q "SELECT SYSTEM\$LOCATE_DBT_ARCHIVE('01bf3f89-0300-0001-0000-0000000c1229')"
snow://dbt_project/TESTDBT.PUBLIC.MY_DBT_PROJECT/results/query_id_01bf3f89-0300-0001-0000-0000000c1229/dbt_artifacts.zip
snowsql -q "GET 'snow://dbt_project/TESTDBT.PUBLIC.MY_DBT_PROJECT/results/query_id_01bf3f89-0300-0001-0000-0000000c1229/dbt_artifacts.zip' file:///Users/user_name/Code/temp"
Type SQL statements or !help
+-----------------------------------------------------------------+--------+------------+-----
| file | size | status | ....
|-----------------------------------------------------------------+--------+------------+-----
| query_id_01bf3f89-0300-0001-0000-0000000c1229/dbt_artifacts.zip | 137351 | DOWNLOADED |...
+-----------------------------------------------------------------+--------+------------+-----