Billy McMonagle
07/21/2022, 6:15 PMBilly McMonagle
07/21/2022, 6:16 PM--log-format json
option, so that the json-formatted logs will be shipped to our logging service and be easier to read. Unfortunately, I'm not sure that this is possible due to this codeBilly McMonagle
07/21/2022, 6:17 PMAnna Geller
Billy McMonagle
07/21/2022, 6:44 PMAnna Geller
Billy McMonagle
07/21/2022, 6:46 PMBilly McMonagle
07/27/2022, 7:54 PMshell_task = DbtShellTask(
name="DBT",
profile_name=APP,
environment=DBT_ENVIRONMENT,
stream_output=True,
log_stderr=True,
)
# emit dbt json-formatted logs directly for friendly display in datadog.
formatter = logging.Formatter("%(message)s")
for handler in shell_task.logger.parent.handlers:
if not isinstance(handler, CloudHandler):
handler.setFormatter(formatter)
The task is then executed like this (showing only the most relevant code):
@task
def execute_dbt(
command,
schema=None,
select=None,
exclude=None,
full_refresh=False,
**kwargs,
):
dbt = init_dbt(schema)
if select:
command += f" --select {select}"
if exclude:
command += f" --exclude {exclude}"
if full_refresh:
command += " --full-refresh"
dbt.run(command=command, *kwargs)
dbt_build = execute_dbt(
task_args={"name": "dbt Build"},
command=f"dbt --log-format json build",
select=select,
exclude=exclude,
full_refresh=full_refresh,
upstream_tasks=[dbt_dependencies],
)
Anna Geller
Jacob Blanco
08/16/2022, 6:14 AMAnna Geller