-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle Sentry issue for CSV downloading errors #212
base: main
Are you sure you want to change the base?
Conversation
03efd31
to
bcd85d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we raise an error, we won't return the tmp_file
and maybe won't remove it in the finally
close?
udata_hydra/utils/file.py
Outdated
except aiohttp.ClientResponseError as e: | ||
raise IOError(f"Error downloading CSV: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this makes the error more explicit than previously?
I think the issue is more about marking these as "expected" in sentry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the error is more explicit that way, at least it does describe it in the title. For now in Sentry it's not easy to identify what is the issue is when listing the errors, and that way we can see immediately in list mode that it's an "expected" error.
We could also create a specific exception for this, which would include attributes to identify the ressource, as we did for the custom ParseException
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also create a specific exception for this, which would include attributes to identify the ressource, as we did for the custom ParseException. What do you think?
Update: it has been done in this PR, as a proposal. Please review again!
e55a3ab
to
32d7f95
Compare
Good point, thanks. Logic has been modified since then, try/catch block now has a finally block to close and return the temp file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should make it easier to grok through sentry errors, nice work!
🚢
@magopian Thanks! Should we do something similar for udata? What do you think? (I can do the PR if needed) |
I'm all up for it! |
A proposal: opendatateam/udata#3201 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this additional sentry logging!
|
||
|
||
async def handle_parse_exception(e: ParseException, table_name: str, check: Record | None) -> None: | ||
"""Specific ParseException handling. Store error if in a check context. Also cleanup :table_name: if needed.""" | ||
db = await context.pool("csv") | ||
await db.execute(f'DROP TABLE IF EXISTS "{table_name}"') | ||
if check: | ||
if config.SENTRY_DSN: | ||
if sentry_sdk.Hub.current.client: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change from config.SENTRY_DSN
to sentry_sdk.Hub.current.client
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be the recommend way to test if the Sentry client is properly started in several example like that one and it covers a larger number of cases of Sentry not being properly initialized compared to config.SENTRY_DSN
.
But I agree it weakens the readability. Should we revert that?
Attempt to handle numerous Sentry errors similar to #145755 in a more explicit and generic way:
IOException
using a new parent classExceptionWithSentryDetails
which sends details to Sentry as tags, also inherited by the recent customParseException
errors.py
file from/analysis
to/utils
, since it's more broadly used throughout the codesentry_sdk.Hub.current.client
instead ofconfig.SENTRY_DSN
to check if Sentry is correctly working, as it is the recommended way