How to extract runtime of a DBT task via Airflow to then trigger a Datadog notification?

Adding a question here on behalf of one of our Cloud customers -

Whilst we wait for Datadog support in Astronomer I am trying to extract the run time of a dbt task and report this in a datadog notification. I have tried several approaches without success. My current best guess is the following, but it results in an error with no explanation in Airflow UI. Can someone advise how to achieve the desired notification?

end_dd = DatadogNotification(
    msg_title=r'DBT hourly run for {{ execution_date.strftime("%d-%m-%Y %H:%M") }} has Completed Successfully',
    msg=f'Run time: { macros.datetime_diff_for_humans(dag_run.get_task_instance('run_dbt').start_date) } {EnvHandler["dbt_alert_channel"]}',
1 Like