# Logging query id for failures

**URL:** https://discourse.getdbt.com/t/logging-query-id-for-failures/8360
**Category:** Help
**Tags:** testing, snowflake, dbt-core
**Created:** [May 19, 2023, 5:13pm UTC](https://discourse.getdbt.com/t/logging-query-id-for-failures/8360 "2023-05-19T17:13:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![u.bhatt](https://avatars.discourse-cdn.com/v4/letter/u/ed8c4c/32.png) [@u.bhatt](https://discourse.getdbt.com/u/u.bhatt)
#### Post date: [May 19, 2023, 5:13pm UTC](https://discourse.getdbt.com/t/logging-query-id-for-failures/8360/1 "2023-05-19T17:13:09Z")

</div>

The results.json captures the query id for successful model runs for snowflake materializations. However we don’t get the query id for failures. Is it possible to get the query id for failures ; if so how can we proceed ?

---

<div class="post-metadata">

### Author: ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)
#### Post date: [May 20, 2023, 12:49pm UTC](https://discourse.getdbt.com/t/logging-query-id-for-failures/8360/2 "2023-05-20T12:49:06Z")

</div>

For failures u will not see query id in run results.json because dbt adds query id to the run\_results.json only for successfully executions.

dbt logs query id in dbt.log file for failed executions.

U have to check the dbt.log file for queryid

---

<div class="post-metadata">

### Author: ![u.bhatt](https://avatars.discourse-cdn.com/v4/letter/u/ed8c4c/32.png) [@u.bhatt](https://discourse.getdbt.com/u/u.bhatt)
#### Post date: [May 22, 2023, 1:45am UTC](https://discourse.getdbt.com/t/logging-query-id-for-failures/8360/3 "2023-05-22T01:45:54Z")

</div>

Could link to some reference/documentation for the same?

---

<div class="post-metadata">

### Author: ![Surya](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/surya/32/3763_2.png) [@Surya](https://discourse.getdbt.com/u/Surya)
#### Post date: [May 22, 2023, 4:29am UTC](https://discourse.getdbt.com/t/logging-query-id-for-failures/8360/4 "2023-05-22T04:29:10Z")

</div>

@u.bhatt  
here is the GitHub issues which talked abt it

> <https://github.com/dbt-labs/dbt-snowflake/issues/165#issuecomment-1143399471>
>
> \### Is this your first time opening an issue?
> 
> \- \[X\] I have read the \[expectatio…ns for open source contributors\](https://docs.getdbt.com/docs/contributing/oss-expectations)
> 
> \### Describe the Feature
> 
> I have been hunting down some performance issues recently and was having a hard time finding the query related to my model.
> It would be extremely useful to display the query\_id in the printed logs:
> !\[image\](https://user-images.githubusercontent.com/18498445/171298126-957fa20b-ac1e-46a8-a5b2-95ca598d0604.png)
> 
> 
> 
> \### Describe alternatives you've considered
> 
> I am using Snowflake and look for queries fired by DBT using the search history (or query history tables)
> 
> \### Who will this benefit?
> 
> Any dbt user who would like to get more insights into the query fired by dbt. 
> It depends on the database but will usually give useful information such as the explain plan. 
> This helps anyone who needs to investigate what's happening in the database.
> 
> \### Are you interested in contributing this feature?
> 
> I'd need help on where to start but happy to help!
> 
> \### Anything else?
> 
> https://getdbt.slack.com/archives/C2JRTGLLS/p1653515842370159
