Integrating BigQuery & dbt with Dagster+ Insights#
BigQuery costs can be integrated into the Dagster Insights UI. The dagster-cloud package contains utilities for capturing and submitting BigQuery cost metrics about data operations to Dagster+.
If you use dbt to materialize tables in BigQuery, use this guide to integrate BigQuery cost metrics into the Insights UI. For instructions on integrating direct BigQuery queries, see Integrating Direct BigQuery Usage with Dagster+ Insights.
BigQuery credentials which have access to the INFORMATION_SCHEMA.JOBS table (e.g. BigQuery Resource viewer role). These credentials should be provided used by your dbt profile. For more information on granting access to this table, see the BigQuery documentation.
@dbt_assets(...)defmy_asset(context: AssetExecutionContext, dbt: DbtCliResource):# Chain `with_insights` after any other metadata fetch, e.g. `fetch_row_count`yieldfrom dbt_resource.cli(["build"], context=context).stream().with_insights()
This passes through all underlying events and emits additional AssetObservations with BigQuery cost metrics. These metrics are obtained by querying the underlying INFORMATION_SCHEMA.JOBS table, using the BigQuery client from the dbt adapter.
First, append with_insights() to the dbt CLI call in your Dagster op function:
@op(out={})defmy_dbt_op(context: OpExecutionContext, dbt: DbtCliResource):# Chain `with_insights` after any other metadata fetch, e.g. `fetch_row_count`yieldfrom dbt.cli(["build"], context=context, manifest=dbt_manifest_path
).stream().with_insights()@jobdefmy_dbt_job():...
my_dbt_op()...
This passes through all underlying events and emits additional AssetObservations with BigQuery cost metrics. These metrics are obtained by querying the underlying INFORMATION_SCHEMA.JOBS table, using the BigQuery client from the dbt adapter.
This allows you to add a comment, containing the dbt invocation ID and unique ID, to every query recorded in BigQuery's INFORMATION_SCHEMA.JOBS table. Using this data, Insights will attribute cost metrics in BigQuery to the corresponding Dagster jobs and assets.