Skip to content

Commit

Permalink
[docs][insights] Add instructions for using insights w/ dbt jobs + ops
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed Nov 2, 2023
1 parent 51d50e2 commit 89ef18b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/content/api/modules.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/content/api/searchindex.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/content/api/sections.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,47 @@ To complete the steps in this guide, you'll need:

---

## Step 1: Instrument your dbt asset definition
## Step 1: Instrument your Dagster code

<TabGroup>
<TabItem name="Using assets">
First, instrument the Dagster <PyObject module="dagster_dbt" object="dbt_assets" decorator /> function with `dbt_with_snowflake_insights`:

```python
from dagster_cloud.dagster_insights import dbt_with_snowflake_insights


@dbt_assets(...)
def my_asset(context: AssetExecutionContext):
def my_asset(context: AssetExecutionContext, dbt: DbtCliResource):
# Typically you have a `yield from dbt_resource.cli(...)`.
# Wrap the original call with `dbt_with_snowflake_insights` as below.
dbt_cli_invocation = dbt_resource.cli(["build"], context=context)
yield from dbt_with_snowflake_insights(context, dbt_cli_invocation)
```

This passes through all underlying events and emits an `AssetObservation` for each asset materialization. The observation contains the dbt invocation ID and unique ID that are recorded in the Dagster event log.
This passes through all underlying events and emits an `AssetObservation` for each asset materialization. The observation contains the dbt invocation ID and unique ID that are recorded in the Dagster event log. </TabItem> <TabItem name="Using ops and jobs"> First, instrument the op function with `dbt_with_snowflake_insights`:

```python
from dagster_cloud.dagster_insights import dbt_with_snowflake_insights


@op(out={})
def my_dbt_op(context: OpExecutionContext, dbt: DbtCliResource):
# Typically you have a `yield from dbt_resource.cli(...)`.
# Wrap the original call with `dbt_with_snowflake_insights` as below.
dbt_cli_invocation = dbt.cli(
["build"], context=context, manifest=dbt_manifest_path
)
yield from dbt_with_snowflake_insights(context, dbt_cli_invocation)

@job
def my_dbt_job():
...
my_dbt_op()
...
```

This passes through all underlying events and emits an `AssetObservation` for each asset materialization. The observation contains the dbt invocation ID and unique ID that are recorded in the Dagster event log. </TabItem> </TabGroup>

---

Expand Down

0 comments on commit 89ef18b

Please sign in to comment.