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

dbtプロジェクトのモニタリング機能を有効にする

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.

dbtプロジェクトオブジェクトのスケジュールされた実行を監視する

Snowsight のナビゲーションメニューで Transformation » dbt Projects を選択し、dbtプロジェクトオブジェクトの実行履歴、タスクグラフ、クエリ詳細を表示します。ワークスペースがタスクスケジュールに従って実行されるdbtプロジェクトオブジェクトに接続されると、ワークスペース内からタスク実行履歴とタスクグラフを開くことができます。

プログラムでdbtのアーティファクトとログにアクセスする

Use the DBT_PROJECT_EXECUTION_HISTORY table function and dbt system functions to access dbt artifacts and logs programmatically.

dbtプロジェクトのモニタリング機能を有効にする

dbtプロジェクトオブジェクトのモニタリング機能を有効にするには、以下の SQL 例で示すように、dbtプロジェクトオブジェクトが作成されたデータベースとスキーマ上で LOG_LEVEL、TRACE_LEVEL および METRIC_LEVEL を設定します。

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';
Copy

dbtプロジェクトオブジェクトのスケジュールされた実行を監視する

タスクを使用してスケジュール上でdbtプロジェクトを実行し、dbtプロジェクトオブジェクトにワークスペースが接続されている場合は、dbt Projects on Snowflake のワークスペースを使用して、タスク実行履歴およびタスクグラフのモニタリング情報にすばやくアクセスできます(該当する場合)。

注釈

この機能はdbtプロジェクトオブジェクトに接続されたワークスペースでのみ利用できます。

ワークスペースからdbtプロジェクトオブジェクトのスケジュールされた実行を監視するには

  1. ワークスペースエディターの右上にあるdbtプロジェクトメニューから、Scheduled runs の下にある View schedules を選択します。

  2. リストから検査するスケジュール(タスク)を選択し、View details を選択します。

    タスクの情報ペインが開き、Task details、タスク Graph (該当する場合)、およびこのタスクの Run history を表示できます。詳細については、 Snowsight でタスクとタスクグラフを表示する をご参照ください。

  3. Run history から、リスト内のスケジュールされたdbtプロジェクト実行の場合は、右端のクエリ履歴を開く ボタンを選択すると、クエリ詳細、クエリプロファイル、実行のクエリテレメトリが表示されます。詳細については、 特定のクエリの詳細とプロファイルを確認する をご参照ください。

Snowsight でdbtプロジェクトを監視する

Snowsight の Monitoring を使用して、dbtプロジェクトの実行(実行)に関する詳細なモニタリング情報を表示できます。dbtプロジェクトオブジェクトのモニタリング情報を表示するには、権限が必要です。

  1. ナビゲーションメニューで Transformation » dbt Projects を選択します。ヒストグラムには、dbtプロジェクトの実行頻度と、実行されたプロジェクトのリストが表示されます。

    dbtプロジェクトのリストには、次の情報を含む列が含まれています。日付範囲、コマンド、実行ステータスでリストのフィルタリングが可能です。

    • PROJECT - dbtプロジェクトオブジェクトの名前と、選択した期間における実行(実行)数。

    • LAST COMMAND - 最後の実行時に実行されたdbtコマンド。

    • LAST RUN STATUS - 実行の結果。SucceededExecuting または 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.

  2. 個々のプロジェクトの実行を検査するには、リストからdbtプロジェクトオブジェクトを選択します。

    そのdbtプロジェクトオブジェクトに対する、データベースオブジェクトエクスプローラーのdbtプロジェクト詳細ページが開きます。

    デフォルトでは Run history タブが選択され、選択された期間に実行された各ジョブについて、以下の情報が表示されます。

    • COMMAND - 最後の実行時に実行されたdbtコマンド。

    • STATUS - 実行の結果。SucceededExecuting または Failed

    • RUN TIME - 最後の実行からの経過時間。ソート順を逆にするには、列ヘッダーを選択します。デフォルトでは、最新の実行が最初に表示されます。

    • PARAMETERS The dbt command-line arguments (ARGS) specified in the EXECUTE DBT PROJECT command for the last dbt project run.

  3. 実行のジョブの詳細を見るには、リストから選択します。

    次のタブが含まれる、dbt実行詳細ペインが開きます。

    • デフォルトでは Job details タブが選択され、次の情報が表示されます。

      • Status - 実行の結果。SucceededExecuting または Failed

      • Start timeEnd time および Duration - 実行開始時間、終了時間、実行にかかった時間。

      • Warehouse size - 実行の実行に使用されたウェアハウスのサイズ。

      • Query ID - dbtプロジェクトコマンドを実行したクエリの一意の識別子。クエリ履歴でクエリの詳細を表示するには、クエリ ID を選択します。

      • SQL text - 実行した EXECUTE DBT PROJECT コマンド。

      • dbt <command> - 実行された dbt コマンドの場合(例: run または build)、dbt model、実行を実行するための time taken、およびそのモデル実行の status が表示されます。

    • Output タブには、実行中にdbtプロジェクトによって生成された標準出力が表示されます。

    • Trace タブには、実行中にdbtプロジェクトによって生成されたトレース情報が表示されます。トレースの詳細については、トレースデータの表示 をご参照ください。

  4. より詳細なクエリ情報を表示するには、Job details タブから Query ID を選択します。

    ジョブ実行クエリのクエリ履歴ページが開き、選択したdbt実行に対する Query DetailsQuery Profile、および 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

SYSTEM$GET_DBT_LOG

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.

SYSTEM$LOCATE_DBT_ARTIFACTS

Folder path (for example, snow://…/results/query_id_…/) containing artifact files such as manifest.json, compiled SQL, logs.

Browse or copy specific files with LIST, GET, or COPY FILES.

Just a locator (a URL); you still run GET/COPY FILES to fetch.

SYSTEM$LOCATE_DBT_ARCHIVE

Single ZIP file URL (for example, …/dbt_artifacts.zip).

Handy when you want to download one file (for example, with GET).

Use GET '<url>' file:///local/dir to download.

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);
Copy
============================== 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);
Copy
+-------------------------------------------------------------------------------------------------+
| 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/';
Copy

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);
Copy
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/';
Copy
results/dbt_artifacts.zip
results/logs/dbt.log
results/target/manifest.json
results/target/semantic_manifest.json